Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/counter.h
- Timestamp:
- 07/13/08 20:51:02 (17 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/counter.h
r168 r209 1 /* -*- C++-*-2 * 3 * This file is a part of LEMON, a generic C++ optimization library 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 27 27 ///\brief Tools for counting steps and events 28 28 29 namespace lemon 29 namespace lemon 30 30 { 31 31 … … 33 33 34 34 template<class P> 35 class _SubCounter 35 class _SubCounter 36 36 { 37 37 P &_parent; … … 50 50 _SubCounter(P &parent,const char *title,std::ostream &os=std::cerr) 51 51 : _parent(parent), _title(title), _os(os), count(0) {} 52 ~_SubCounter() { 52 ~_SubCounter() { 53 53 _os << _title << count <<std::endl; 54 54 _parent+=count; … … 64 64 65 65 template<class P> 66 class _NoSubCounter 66 class _NoSubCounter 67 67 { 68 68 P &_parent; … … 70 70 typedef _NoSubCounter<_NoSubCounter<P> > SubCounter; 71 71 typedef _NoSubCounter<_NoSubCounter<P> > NoSubCounter; 72 72 73 73 _NoSubCounter(P &parent) :_parent(parent) {} 74 _NoSubCounter(P &parent,std::string,std::ostream &) 75 :_parent(parent) {} 76 _NoSubCounter(P &parent,std::string) 74 _NoSubCounter(P &parent,std::string,std::ostream &) 75 :_parent(parent) {} 76 _NoSubCounter(P &parent,std::string) 77 77 :_parent(parent) {} 78 78 _NoSubCounter(P &parent,const char *,std::ostream &) … … 103 103 /// for different types of operations. 104 104 /// A report containing the given title and the value of the counter 105 /// is automatically printed on destruction. 105 /// is automatically printed on destruction. 106 106 /// 107 107 /// The following example shows the usage of counters and subcounters. … … 134 134 /// 135 135 /// \sa NoCounter 136 class Counter 136 class Counter 137 137 { 138 138 std::string _title; … … 142 142 143 143 /// SubCounter class 144 144 145 145 /// This class can be used to setup subcounters for a \ref Counter 146 146 /// to have finer reports. A subcounter provides exactly the same … … 148 148 /// decrements the value of its parent. 149 149 /// Subcounters can also have subcounters. 150 /// 150 /// 151 151 /// The parent counter must be given as the first parameter of the 152 152 /// constructor. Apart from that a title and an \c ostream object … … 157 157 /// would like to turn off this report, use \ref NoSubCounter 158 158 /// instead. 159 /// 159 /// 160 160 /// \sa NoSubCounter 161 161 typedef _SubCounter<Counter> SubCounter; 162 162 163 /// SubCounter class without printing report on destruction 164 163 /// SubCounter class without printing report on destruction 164 165 165 /// This class can be used to setup subcounters for a \ref Counter. 166 166 /// It is the same as \ref SubCounter but it does not print report … … 169 169 /// 170 170 /// Replacing \ref SubCounter "SubCounter"s with \ref NoSubCounter 171 /// "NoSubCounter"s makes it possible to turn off reporting 171 /// "NoSubCounter"s makes it possible to turn off reporting 172 172 /// subcounter values without actually removing the definitions 173 173 /// and the increment or decrement operators. … … 179 179 Counter() : _title(), _os(std::cerr), count(0) {} 180 180 /// Constructor. 181 Counter(std::string title,std::ostream &os=std::cerr) 181 Counter(std::string title,std::ostream &os=std::cerr) 182 182 : _title(title), _os(os), count(0) {} 183 183 /// Constructor. … … 205 205 /// \note This function does not reset the values of 206 206 /// \ref SubCounter "SubCounter"s but it resets \ref NoSubCounter 207 /// "NoSubCounter"s along with the main counter. 207 /// "NoSubCounter"s along with the main counter. 208 208 void reset(int c=0) {count=c;} 209 209 /// Returns the value of the counter.
Note: See TracChangeset
for help on using the changeset viewer.