include/shark/Core/Counter.h
Go to the documentation of this file.
00001 //===========================================================================
00036 //===========================================================================
00037 #ifndef SHARK_CORE_COUNTER_H
00038 #define SHARK_CORE_COUNTER_H
00039 
00040 namespace shark {
00041 
00045     class Counter {
00046     public:
00047 
00051         Counter() : m_counter(0) {  }
00052 
00056         Counter( const Counter & rhs ) : m_counter(rhs.m_counter) {}
00057 
00058 
00064         Counter & operator=( const Counter & rhs ) {
00065             m_counter = rhs.m_counter;
00066             return( *this );
00067         }
00068 
00074         template<typename Scalar>
00075         bool operator==( const Scalar & rhs ) const {
00076             return( m_counter == static_cast<unsigned int>( rhs ) );
00077         }
00078 
00084         template<typename Scalar>
00085         bool operator<( const Scalar & rhs ) const {
00086             return( m_counter < rhs );
00087         }
00088 
00093         const Counter & operator++() const {
00094             m_counter++;
00095             return( *this );
00096         }
00097 
00102         Counter operator++(int) const {
00103             Counter c( *this );
00104             m_counter++;
00105             return( c );
00106         }
00107 
00108         void operator--() const {
00109             m_counter--;
00110         }
00111 
00116         Counter & operator++() {
00117             m_counter++;
00118             return( *this );
00119         }
00120 
00125         Counter operator++(int) {
00126             Counter c( *this );
00127             m_counter++;
00128             return( c );
00129         }
00130 
00131         void operator--() {
00132             m_counter--;
00133         }
00134 
00138         void reset() const {
00139             m_counter = 0;
00140         }
00141 
00145         operator unsigned int() const {
00146             return( m_counter );
00147         }
00148 
00149     protected:
00150         mutable unsigned int m_counter; 
00151 
00152 
00153     };
00154 
00161     //template<typename Stream>
00162     //Stream & operator<<( Stream & s, const Counter & c ) {
00163     //  s << static_cast<unsigned int>( c );
00164     //  return( s );
00165     //}
00166 
00167 }
00168 
00169 #endif // SHARK_CORE_COUNTER_H