... | ... |
@@ -20,82 +20,82 @@ |
20 | 20 |
#define LEMON_COUNTER_H |
21 | 21 |
|
22 | 22 |
#include <string> |
23 | 23 |
#include <iostream> |
24 | 24 |
|
25 | 25 |
///\ingroup timecount |
26 | 26 |
///\file |
27 | 27 |
///\brief Tools for counting steps and events |
28 | 28 |
|
29 | 29 |
namespace lemon |
30 | 30 |
{ |
31 | 31 |
|
32 |
template<class P> class |
|
32 |
template<class P> class _NoSubCounter; |
|
33 | 33 |
|
34 | 34 |
template<class P> |
35 | 35 |
class _SubCounter |
36 | 36 |
{ |
37 | 37 |
P &_parent; |
38 | 38 |
std::string _title; |
39 | 39 |
std::ostream &_os; |
40 | 40 |
int count; |
41 | 41 |
public: |
42 | 42 |
|
43 | 43 |
typedef _SubCounter<_SubCounter<P> > SubCounter; |
44 |
typedef |
|
44 |
typedef _NoSubCounter<_SubCounter<P> > NoSubCounter; |
|
45 | 45 |
|
46 | 46 |
_SubCounter(P &parent) |
47 | 47 |
: _parent(parent), _title(), _os(std::cerr), count(0) {} |
48 | 48 |
_SubCounter(P &parent,std::string title,std::ostream &os=std::cerr) |
49 | 49 |
: _parent(parent), _title(title), _os(os), count(0) {} |
50 | 50 |
_SubCounter(P &parent,const char *title,std::ostream &os=std::cerr) |
51 | 51 |
: _parent(parent), _title(title), _os(os), count(0) {} |
52 | 52 |
~_SubCounter() { |
53 | 53 |
_os << _title << count <<std::endl; |
54 | 54 |
_parent+=count; |
55 | 55 |
} |
56 | 56 |
_SubCounter &operator++() { count++; return *this;} |
57 | 57 |
int operator++(int) { return count++; } |
58 | 58 |
_SubCounter &operator--() { count--; return *this;} |
59 | 59 |
int operator--(int) { return count--; } |
60 | 60 |
_SubCounter &operator+=(int c) { count+=c; return *this;} |
61 | 61 |
_SubCounter &operator-=(int c) { count-=c; return *this;} |
62 | 62 |
void reset(int c=0) {count=c;} |
63 | 63 |
operator int() {return count;} |
64 | 64 |
}; |
65 | 65 |
|
66 | 66 |
template<class P> |
67 |
class |
|
67 |
class _NoSubCounter |
|
68 | 68 |
{ |
69 | 69 |
P &_parent; |
70 | 70 |
public: |
71 |
typedef _SubNoCounter<_SubNoCounter<P> > SubCounter; |
|
72 |
typedef _SubNoCounter<_SubNoCounter<P> > SubNoCounter; |
|
71 |
typedef _NoSubCounter<_NoSubCounter<P> > SubCounter; |
|
72 |
typedef _NoSubCounter<_NoSubCounter<P> > NoSubCounter; |
|
73 | 73 |
|
74 |
_SubNoCounter(P &parent) :_parent(parent) {} |
|
75 |
_SubNoCounter(P &parent,std::string,std::ostream &) |
|
74 |
_NoSubCounter(P &parent) :_parent(parent) {} |
|
75 |
_NoSubCounter(P &parent,std::string,std::ostream &) |
|
76 | 76 |
:_parent(parent) {} |
77 |
|
|
77 |
_NoSubCounter(P &parent,std::string) |
|
78 | 78 |
:_parent(parent) {} |
79 |
|
|
79 |
_NoSubCounter(P &parent,const char *,std::ostream &) |
|
80 | 80 |
:_parent(parent) {} |
81 |
|
|
81 |
_NoSubCounter(P &parent,const char *) |
|
82 | 82 |
:_parent(parent) {} |
83 |
~_SubNoCounter() {} |
|
84 |
_SubNoCounter &operator++() { ++_parent; return *this;} |
|
83 |
~_NoSubCounter() {} |
|
84 |
_NoSubCounter &operator++() { ++_parent; return *this;} |
|
85 | 85 |
int operator++(int) { _parent++; return 0;} |
86 |
|
|
86 |
_NoSubCounter &operator--() { --_parent; return *this;} |
|
87 | 87 |
int operator--(int) { _parent--; return 0;} |
88 |
_SubNoCounter &operator+=(int c) { _parent+=c; return *this;} |
|
89 |
_SubNoCounter &operator-=(int c) { _parent-=c; return *this;} |
|
88 |
_NoSubCounter &operator+=(int c) { _parent+=c; return *this;} |
|
89 |
_NoSubCounter &operator-=(int c) { _parent-=c; return *this;} |
|
90 | 90 |
void reset(int) {} |
91 | 91 |
void reset() {} |
92 | 92 |
operator int() {return 0;} |
93 | 93 |
}; |
94 | 94 |
|
95 | 95 |
|
96 | 96 |
/// \addtogroup timecount |
97 | 97 |
/// @{ |
98 | 98 |
|
99 | 99 |
///A counter class |
100 | 100 |
|
101 | 101 |
///This class makes it easier to count certain events. You can increment |
... | ... |
@@ -108,25 +108,25 @@ |
108 | 108 |
std::ostream &_os; |
109 | 109 |
int count; |
110 | 110 |
public: |
111 | 111 |
///\e |
112 | 112 |
|
113 | 113 |
///\todo document please. |
114 | 114 |
/// |
115 | 115 |
typedef _SubCounter<Counter> SubCounter; |
116 | 116 |
///\e |
117 | 117 |
|
118 | 118 |
///\todo document please. |
119 | 119 |
/// |
120 |
typedef |
|
120 |
typedef _NoSubCounter<Counter> NoSubCounter; |
|
121 | 121 |
|
122 | 122 |
///\e |
123 | 123 |
Counter() : _title(), _os(std::cerr), count(0) {} |
124 | 124 |
///\e |
125 | 125 |
Counter(std::string title,std::ostream &os=std::cerr) |
126 | 126 |
: _title(title), _os(os), count(0) {} |
127 | 127 |
///\e |
128 | 128 |
Counter(const char *title,std::ostream &os=std::cerr) |
129 | 129 |
: _title(title), _os(os), count(0) {} |
130 | 130 |
///Destructor. Prints the given title and the value of the counter. |
131 | 131 |
~Counter() { |
132 | 132 |
_os << _title << count <<std::endl; |
... | ... |
@@ -147,26 +147,26 @@ |
147 | 147 |
void reset(int c=0) {count=c;} |
148 | 148 |
///\e |
149 | 149 |
operator int() {return count;} |
150 | 150 |
}; |
151 | 151 |
|
152 | 152 |
///'Do nothing' version of \ref Counter |
153 | 153 |
|
154 | 154 |
///'Do nothing' version of \ref Counter. |
155 | 155 |
///\sa Counter |
156 | 156 |
class NoCounter |
157 | 157 |
{ |
158 | 158 |
public: |
159 |
typedef _SubNoCounter<NoCounter> SubCounter; |
|
160 |
typedef _SubNoCounter<NoCounter> SubNoCounter; |
|
159 |
typedef _NoSubCounter<NoCounter> SubCounter; |
|
160 |
typedef _NoSubCounter<NoCounter> NoSubCounter; |
|
161 | 161 |
|
162 | 162 |
NoCounter() {} |
163 | 163 |
NoCounter(std::string,std::ostream &) {} |
164 | 164 |
NoCounter(const char *,std::ostream &) {} |
165 | 165 |
NoCounter(std::string) {} |
166 | 166 |
NoCounter(const char *) {} |
167 | 167 |
NoCounter &operator++() { return *this; } |
168 | 168 |
int operator++(int) { return 0; } |
169 | 169 |
NoCounter &operator--() { return *this; } |
170 | 170 |
int operator--(int) { return 0; } |
171 | 171 |
NoCounter &operator+=(int) { return *this;} |
172 | 172 |
NoCounter &operator-=(int) { return *this;} |
0 comments (0 inline)