Fix template version of Invalid.
3 * Part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
18 #ifndef LEMON_COUNTER_H
19 #define LEMON_COUNTER_H
26 ///\brief Tools for counting steps and events
31 template<class P> class _SubNoCounter;
42 typedef _SubCounter<_SubCounter<P> > SubCounter;
43 typedef _SubNoCounter<_SubCounter<P> > SubNoCounter;
45 _SubCounter(P &parent)
46 : _parent(parent), _title(), _os(std::cerr), count(0) {}
47 _SubCounter(P &parent,std::string title,std::ostream &os=std::cerr)
48 : _parent(parent), _title(title), _os(os), count(0) {}
49 _SubCounter(P &parent,const char *title,std::ostream &os=std::cerr)
50 : _parent(parent), _title(title), _os(os), count(0) {}
52 _os << _title << count <<std::endl;
55 _SubCounter &operator++() { count++; return *this;}
56 int operator++(int) { return count++; }
57 _SubCounter &operator--() { count--; return *this;}
58 int operator--(int) { return count--; }
59 _SubCounter &operator+=(int c) { count+=c; return *this;}
60 _SubCounter &operator-=(int c) { count-=c; return *this;}
61 void reset(int c=0) {count=c;}
62 operator int() {return count;}
70 typedef _SubNoCounter<_SubNoCounter<P> > SubCounter;
71 typedef _SubNoCounter<_SubNoCounter<P> > SubNoCounter;
73 _SubNoCounter(P &parent) :_parent(parent) {}
74 _SubNoCounter(P &parent,std::string title,std::ostream &os=std::cerr)
76 _SubNoCounter(P &parent,const char *title,std::ostream &os=std::cerr)
79 _SubNoCounter &operator++() { ++_parent; return *this;}
80 int operator++(int) { _parent++; return 0;}
81 _SubNoCounter &operator--() { --_parent; return *this;}
82 int operator--(int) { _parent--; return 0;}
83 _SubNoCounter &operator+=(int c) { _parent+=c; return *this;}
84 _SubNoCounter &operator-=(int c) { _parent-=c; return *this;}
85 void reset(int c=0) {}
86 operator int() {return 0;}
90 /// \addtogroup timecount
95 ///This class makes it easier to count certain events. You can increment
96 ///or decrement the counter using operator++ and operator--.
97 ///A report is automatically printed on destruction.
107 ///\todo document please.
109 typedef _SubCounter<Counter> SubCounter;
112 ///\todo document please.
114 typedef _SubNoCounter<Counter> SubNoCounter;
117 Counter() : _title(), _os(std::cerr), count(0) {}
119 Counter(std::string title,std::ostream &os=std::cerr)
120 : _title(title), _os(os), count(0) {}
122 Counter(const char *title,std::ostream &os=std::cerr)
123 : _title(title), _os(os), count(0) {}
124 ///Destructor. Prints the given title and the value of the counter.
126 _os << _title << count <<std::endl;
129 Counter &operator++() { count++; return *this;}
131 int operator++(int) { return count++;}
133 Counter &operator--() { count--; return *this;}
135 int operator--(int) { return count--;}
137 Counter &operator+=(int c) { count+=c; return *this;}
139 Counter &operator-=(int c) { count-=c; return *this;}
141 void reset(int c=0) {count=c;}
143 operator int() {return count;}
146 ///'Do nothing' version of \ref Counter
148 ///'Do nothing' version of \ref Counter.
153 typedef _SubNoCounter<NoCounter> SubCounter;
154 typedef _SubNoCounter<NoCounter> SubNoCounter;
157 NoCounter(std::string title,std::ostream &os=std::cerr) {}
158 NoCounter(const char *title,std::ostream &os=std::cerr) {}
159 NoCounter &operator++() { return *this; }
160 int operator++(int) { return 0; }
161 NoCounter &operator--() { return *this; }
162 int operator--(int) { return 0; }
163 NoCounter &operator+=(int c) { return *this;}
164 NoCounter &operator-=(int c) { return *this;}
165 void reset(int c=0) {}
166 operator int() {return 0;}