ACT-CV - Machine Vision for Cognitive Modeling
ResultHolder.h
Go to the documentation of this file.
1 // -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4; coding: iso-8859-1; -*-
2 
3 /*
4 ACT-CV - Machine Vision for Cognitive Modeling
5 Copyright (c) 2008 Marc Halbruegge
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
26 #ifndef RESULTHOLDER_H_
27 #define RESULTHOLDER_H_
28 
29 #include <vector>
30 #include <map>
31 #include <garbagecoll.h>
32 
34 template<typename _t>
35 class ResultSource {
36 public:
37  virtual void EnterCriticalSection()=0;
38  virtual std::vector<_t>& GetData() = 0;
39  virtual void LeaveCriticalSection()=0;
40 };
41 
42 
47 template<typename _t>
48 class ResultData : public ReferenceCount {
49 public:
50  typename std::vector<_t> data;
51  typename std::vector<_t>::const_iterator iter;
52 
53  ResultData() {};
54  ResultData(const std::vector<_t> &d)
55  : data(d) {
56  iter = data.begin();
57  }
58 };
59 
60 // small helper, to be deleted
61 static std::ostream& operator << (std::ostream& o, const Line& l) {
62  o << l.end1x << " "
63  << l.end1y << " "
64  << l.end2x << " "
65  << l.end2y;
66  return o;
67 }
68 
69 // small helper, to be deleted
70 static std::ostream& operator << (std::ostream& o, const ObjectPosition& pos) {
71  o << pos.x << " "
72  << pos.y << " "
73  << pos.width << " "
74  << pos.height << " "
75  << pos.name;
76  return o;
77 }
78 
80 template<typename _t>
81 class ResultHolder : public ReferenceCount {
82 protected:
84  std::map<int, GCPointer<ResultData<_t> > > results;
85 public:
87 
88  int FindFirst() {
89  int newHandle = static_cast<int>(results.size()+1);
90 
91  source->EnterCriticalSection();
92  results[newHandle]
93  = new ResultData<_t>(source->GetData());
94  source->LeaveCriticalSection();
95  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
96  return newHandle;
97  }
98 
99  bool FindNext(int handle, _t *result) {
100  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
101  if (results[handle]->iter == results[handle]->data.end()) {
102  return false;
103  } else {
104  *result = *(results[handle]->iter);
105  //std::cout << *result << std::endl;
106  results[handle]->iter++;
107  return true;
108  }
109  }
110 
111  void FindFinish(int handle) {
112  results.erase(handle);
113  MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
114  }
115 
116 };
117 
118 #endif /*RESULTHOLDER_H_*/


ACT-CV - Machine Vision for Cognitive Modeling
© 2015 Marc Halbruegge (actcvlibrary@googlemail.com)