CircularCounter< T > Class Template Reference

#include <TAPsCircularCounter.hpp>

Inheritance diagram for CircularCounter< T >:

Inheritance graph
[legend]
Collaboration diagram for CircularCounter< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 CircularCounter (T v1, T v2, T v3)
 CircularCounter ()
 Default Ctor.
void CountDown (T v)
void CountDown ()
CountDownAndReturnTheCountValue (T v)
CountDownAndReturnTheCountValue ()
void CountUp (T v)
void CountUp ()
CountUpAndReturnTheCountValue (T v)
CountUpAndReturnTheCountValue ()
GetValueCurrent () const
GetValueHighest () const
GetValueLowest () const
void SetValueCurrent (T v)
void SetValueHighest (T v)
void SetValueLowest (T v)
virtual ~CircularCounter ()
 Destructor.

Protected Member Functions

void CheckCountDown ()
void CheckCountUp ()

Protected Attributes

m_tCurrent
m_tHighest
m_tLowest

Friends

std::ostream & operator<< (std::ostream &output, CircularCounter< T > const &ctr)


Detailed Description

template<typename T>
class CircularCounter< T >

An interger circular counter with setable low and high limit value. The counter can be count up or count down with loop when it is over (below) the high (low) limit value.

Definition at line 25 of file TAPsCircularCounter.hpp.


Constructor & Destructor Documentation

template<typename T>
CircularCounter< T >::CircularCounter (  )  [inline]

Default Ctor.

Definition at line 45 of file TAPsCircularCounter.hpp.

00045                        : m_tCurrent(0)
00046     {
00047         if ( typeid(T) == typeid(unsigned char) ) {
00048             m_tLowest   = 0;
00049             m_tHighest  = static_cast<unsigned char>( UCHAR_MAX );
00050         }
00051         else if ( typeid(T) == typeid(char) ) {
00052             m_tLowest   = static_cast<char>( CHAR_MIN );
00053             m_tHighest  = static_cast<char>( CHAR_MAX );
00054         }
00055         else if ( typeid(T) == typeid(unsigned short) ) {
00056             m_tLowest   = 0;
00057             m_tHighest  = static_cast<unsigned short>( USHRT_MAX );
00058         }
00059         else if ( typeid(T) == typeid(short) ) {
00060             m_tLowest   = static_cast<short>( SHRT_MIN );
00061             m_tHighest  = static_cast<short>( SHRT_MAX );
00062         }
00063         else if ( typeid(T) == typeid(unsigned int) ) {
00064             m_tLowest   = 0;
00065             m_tHighest  = static_cast<unsigned int>( UINT_MAX );
00066         }
00067         else if ( typeid(T) == typeid(int) ) {
00068             m_tLowest   = static_cast<int>( INT_MIN );
00069             m_tHighest  = static_cast<int>( INT_MAX );
00070         }
00071         else if ( typeid(T) == typeid(unsigned long) ) {
00072             m_tLowest   = 0;
00073             m_tHighest  = static_cast<unsigned long>( ULONG_MAX );
00074         }
00075         else if ( typeid(T) == typeid(long) ) {
00076             m_tLowest   = static_cast<long>( LONG_MIN );
00077             m_tHighest  = static_cast<long>( LONG_MAX );
00078         }
00079     }

template<typename T>
CircularCounter< T >::CircularCounter ( v1,
v2,
v3 
) [inline]

The highest, current, and lowest value can be passed in any order.

Definition at line 84 of file TAPsCircularCounter.hpp.

00085     {
00086         if ( v1 >= v2 ) {
00087             if ( v1 >= v3 ) {
00088                 m_tHighest = v1;
00089                 if ( v2 >= v3 ) {
00090                     m_tCurrent = v2;
00091                     m_tLowest  = v3;
00092                 }
00093                 else {
00094                     m_tCurrent = v3;
00095                     m_tLowest  = v2;
00096                 }
00097             }
00098             else {
00099                 m_tHighest = v3;
00100                 m_tCurrent = v1;
00101                 m_tLowest  = v2;
00102             }
00103         }
00104         else {
00105             if ( v2 >= v3 ) {
00106                 m_tHighest = v2;
00107                 if ( v1 >= v3 ) {
00108                     m_tCurrent = v1;
00109                     m_tLowest  = v3;
00110                 }
00111                 else {
00112                     m_tCurrent = v3;
00113                     m_tLowe st = v1;
00114                 }
00115             }
00116             else {
00117                 m_tHighest = v3;
00118                 m_tCurrent = v2;
00119                 m_tLowe st = v1;
00120             }
00121         }
00122     }

template<typename T>
virtual CircularCounter< T >::~CircularCounter (  )  [inline, virtual]

Destructor.

Definition at line 125 of file TAPsCircularCounter.hpp.

00125 {};


Member Function Documentation

template<typename T>
void CircularCounter< T >::CheckCountDown (  )  [inline, protected]

Definition at line 203 of file TAPsCircularCounter.hpp.

00204     { if ( m_tCurrent < m_tLowest )     m_tCurrent = m_tHighest; }

template<typename T>
void CircularCounter< T >::CheckCountUp (  )  [inline, protected]

Definition at line 201 of file TAPsCircularCounter.hpp.

00202     { if ( m_tCurrent > m_tHighest )    m_tCurrent = m_tLowest; }

template<typename T>
void CircularCounter< T >::CountDown ( v  )  [inline]

Definition at line 167 of file TAPsCircularCounter.hpp.

00168     {
00169         m_tCurrent -= v;
00170         CheckCountDown();
00171     }

template<typename T>
void CircularCounter< T >::CountDown (  )  [inline]

Definition at line 162 of file TAPsCircularCounter.hpp.

00163     {
00164         --m_tCurrent;
00165         CheckCountDown();
00166     }

template<typename T>
T CircularCounter< T >::CountDownAndReturnTheCountValue ( v  )  [inline]

Definition at line 191 of file TAPsCircularCounter.hpp.

00192     {
00193         m_tCurrent -= v;
00194         CheckCountDown();
00195         return m_tCurrent;
00196     }

template<typename T>
T CircularCounter< T >::CountDownAndReturnTheCountValue (  )  [inline]

Definition at line 185 of file TAPsCircularCounter.hpp.

00186     {
00187         --m_tCurrent;
00188         CheckCountDown();
00189         return m_tCurrent;
00190     }

template<typename T>
void CircularCounter< T >::CountUp ( v  )  [inline]

Definition at line 157 of file TAPsCircularCounter.hpp.

00158     {
00159         m_tCurrent += v;
00160         CheckCountUp();
00161     }

template<typename T>
void CircularCounter< T >::CountUp (  )  [inline]

Definition at line 152 of file TAPsCircularCounter.hpp.

00153     {
00154         ++m_tCurrent;
00155         CheckCountUp();
00156     }

template<typename T>
T CircularCounter< T >::CountUpAndReturnTheCountValue ( v  )  [inline]

Definition at line 179 of file TAPsCircularCounter.hpp.

00180     {
00181         m_tCurrent += v;
00182         CheckCountUp();
00183         return m_tCurrent;
00184     }

template<typename T>
T CircularCounter< T >::CountUpAndReturnTheCountValue (  )  [inline]

Definition at line 173 of file TAPsCircularCounter.hpp.

00174     {
00175         ++m_tCurrent;
00176         CheckCountUp();
00177         return m_tCurrent;
00178     }

template<typename T>
T CircularCounter< T >::GetValueCurrent (  )  const [inline]

Definition at line 130 of file TAPsCircularCounter.hpp.

00130 { return m_tCurrent; }

template<typename T>
T CircularCounter< T >::GetValueHighest (  )  const [inline]

Definition at line 131 of file TAPsCircularCounter.hpp.

00131 { return m_tHighest; }

template<typename T>
T CircularCounter< T >::GetValueLowest (  )  const [inline]

Definition at line 129 of file TAPsCircularCounter.hpp.

00129 { return m_tLowest; }

template<typename T>
void CircularCounter< T >::SetValueCurrent ( v  )  [inline]

Definition at line 137 of file TAPsCircularCounter.hpp.

00138     {
00139         if      ( v > m_tHighest )  m_tCurrent = m_tHighest;
00140         else if ( v < m_tLowest )   m_tCurrent = m_tLowest;
00141         else                        m_tCurrent = v;
00142     }

template<typename T>
void CircularCounter< T >::SetValueHighest ( v  )  [inline]

Definition at line 143 of file TAPsCircularCounter.hpp.

00144     {
00145         if ( m_tHighest > m_tLowest )   m_tHighest = v;
00146         if ( m_tHighest < m_tCurrent )  m_tCurrent = v;
00147     }

template<typename T>
void CircularCounter< T >::SetValueLowest ( v  )  [inline]

Definition at line 132 of file TAPsCircularCounter.hpp.

00133     {
00134         if ( m_tLowest < m_tHighest )   m_tLowest  = v;
00135         if ( m_tLowest > m_tCurrent )   m_tCurrent = v;
00136     }


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  output,
CircularCounter< T > const &  ctr 
) [friend]

Definition at line 31 of file TAPsCircularCounter.hpp.

00032     {
00033         output  << "CircularCounter<" << typeid(T).name() << ">"
00034                 <<  " Highest Value (" << ctr.m_tHighest
00035                 << ") Current Value (" << ctr.m_tCurrent
00036                 << ") Lowest Value ("  << ctr.m_tLowest;
00037                 << ")\n";
00038         return output;
00039     }


Member Data Documentation

template<typename T>
T CircularCounter< T >::m_tCurrent [protected]

Definition at line 208 of file TAPsCircularCounter.hpp.

template<typename T>
T CircularCounter< T >::m_tHighest [protected]

Definition at line 209 of file TAPsCircularCounter.hpp.

template<typename T>
T CircularCounter< T >::m_tLowest [protected]

Definition at line 207 of file TAPsCircularCounter.hpp.


The documentation for this class was generated from the following file:

Generated on Mon Oct 13 11:44:30 2008 for TAPs by  doxygen 1.5.6