Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProgressSemaphorePool.cpp
1 #include "ProgressSemaphorePool.hh"
2 #include "ProgressSemaphore.hh"
3 
4 using namespace BIAS;
5 using namespace std;
6 
8 {
9 }
10 
12 {
13 }
14 
15 
17 Register(const std::string &name)
18 {
20  map<string, SharedPtr<ProgressSemaphore> >::iterator it;
21  it = Semaphores_.find(name);
22  if (it != Semaphores_.end())
23  sem = it->second;
24  else {
26  Semaphores_[name]=sem;
27  }
28  return sem;
29 }
30 
31 
32 
34 GetAllSemaphoreNames(std::vector<std::string> &names)
35 {
36  names.clear();
37  map<string, SharedPtr<ProgressSemaphore> >::iterator it;
38  it = Semaphores_.begin();
39  while (it!=Semaphores_.end()) {
40  names.push_back(it->first);
41  it++;
42  }
43 }
44 
45 
47 {
48  Semaphores_.clear();
49 }
50 
53 {
54  map<string, SharedPtr<ProgressSemaphore> >::iterator it;
55  it = Semaphores_.begin();
56  while (it!=Semaphores_.end()) {
57  it->second->SetTerminateFlag();
58  it++;
59  }
60 }
61 
64 {
65  unsigned int count=0;
66  float accu=0.0f;
67  map<string, SharedPtr<ProgressSemaphore> >::iterator it;
68  it = Semaphores_.begin();
69  while (it!=Semaphores_.end()) {
70  float prog = it->second->GetProgress();
71  BIASASSERT(prog>=0. && prog<=1.);
72  accu += prog;
73  count ++;
74  it++;
75  }
76  float result = accu/float(count);
77 #ifdef BIAS_DEBUG
78  BIASASSERT(result>=0. && result <=1.);
79 #endif
80  return result;
81 }
82 
83 
85 Exists(const string &name)
86 {
87  map<string, SharedPtr<ProgressSemaphore> >::iterator it;
88  it = Semaphores_.find(name);
89  return it != Semaphores_.end();
90 
91 }
std::map< std::string, SharedPtr< ProgressSemaphore > > Semaphores_
pointer with reference count and automatic deletion
Definition: SharedPtr.hh:50
this class represents a progress counter which multiple processes can use.
void GetAllSemaphoreNames(std::vector< std::string > &names)
bool Exists(const std::string &name)
SharedPtr< ProgressSemaphore > Register(const std::string &name)