OMK::Fifo< T > Class Template Reference

a Fifo to store attribute history thread safety : provided no reader tries to acces values with an offset greater than the numbre of values returned by getNumberOfPresentValues, multiple reads can take place concurrently with one write. More...

#include <OMKFifo.h>

Inheritance diagram for OMK::Fifo< T >:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Fifo (const int taille)
 constructor
virtual ~Fifo ()
 destructor
virtual const T & getPreceedingValue (const unsigned int indice) const
 get a value before the current value
virtual const DategetPreceedingDate (const unsigned int indice) const
 get the date associated to a value before the current value
virtual void set (const T &val, const Date &date)
 add a value to the fifo
virtual void setInPlace (const T &val, const Date &date)
 make an allready copied value available for reading
virtual T & getNextPlaceHolder ()
 get a reference to the next place that will be used to store a value
virtual void clear ()
 clear the file
virtual unsigned int getNumberOfPresentValues (int maxCherche=-1) const
 get the number of values in the fifo
virtual void printDebuggingInformation (void) const
 printDebuggingInformation print any usefull debugging information

Protected Attributes

std::vector< ValeurDate_tab
 the array in wich the values are kept
unsigned int _numberOfValues
 the number of valid values in _tab
unsigned int _mostRecentValueIndex
 the place the most recent value was stored

Classes

class  ValeurDate
 internal class More...

Detailed Description

template<typename T>
class OMK::Fifo< T >

a Fifo to store attribute history thread safety : provided no reader tries to acces values with an offset greater than the numbre of values returned by getNumberOfPresentValues, multiple reads can take place concurrently with one write.

Definition at line 34 of file OMKFifo.h.


Constructor & Destructor Documentation

template<typename T>
OMK::Fifo< T >::Fifo ( const int  taille  ) 

constructor

Definition at line 109 of file OMKFifo.h.

00110 : AbstractFifo< T >( size ),
00111 _tab( size ),
00112 _numberOfValues( 0 ),
00113 _mostRecentValueIndex( size - 1 )
00114 {
00115 }

template<typename T>
OMK::Fifo< T >::~Fifo (  )  [virtual]

destructor

Definition at line 120 of file OMKFifo.h.

00121 {
00122 }


Member Function Documentation

template<typename T>
const T & OMK::Fifo< T >::getPreceedingValue ( const unsigned int  indice  )  const [virtual]

get a value before the current value

Parameters:
index if 0, get the most recent value, if 1, get the preceeding value...

Implements OMK::AbstractFifo< T >.

Definition at line 135 of file OMKFifo.h.

References OMK::AbstractFifo< T >::_fifoSize, OMK::Fifo< T >::_mostRecentValueIndex, OMK::Fifo< T >::_tab, and OMASSERTM.

00135                                                           {
00136    OMASSERTM( i < _fifoSize - 2, "" ) ;
00137    int indice = (_fifoSize + _mostRecentValueIndex - i ) % _fifoSize ;
00138    return _tab[indice].valeur ;
00139 }

template<typename T>
const Date & OMK::Fifo< T >::getPreceedingDate ( const unsigned int  indice  )  const [virtual]

get the date associated to a value before the current value

Parameters:
index if 0, get the date of the most recent value, if 1, get the date associated to the preceeding value...

Implements OMK::AbstractFifo< T >.

Definition at line 127 of file OMKFifo.h.

References OMK::AbstractFifo< T >::_fifoSize, OMK::Fifo< T >::_mostRecentValueIndex, OMK::Fifo< T >::_tab, and OMASSERTM.

00128 {
00129    OMASSERTM ( i < _fifoSize - 2, "" ) ;
00130    int indice = (_fifoSize + _mostRecentValueIndex - i ) % _fifoSize ;
00131    return _tab[indice].dateValeur ;
00132 }

template<typename T>
void OMK::Fifo< T >::set ( const T &  val,
const Date date 
) [virtual]

add a value to the fifo

Implements OMK::AbstractFifo< T >.

Definition at line 144 of file OMKFifo.h.

References OMK::AbstractFifo< T >::_fifoSize, OMK::Fifo< T >::_mostRecentValueIndex, OMK::Fifo< T >::_numberOfValues, and OMK::Fifo< T >::_tab.

00145 {
00146    unsigned int newMostRecentValueIndex = ( _mostRecentValueIndex + 1 ) % _fifoSize ;
00147 
00148    Date & dateOfMostRecentValue( _tab[_mostRecentValueIndex].dateValeur ) ;
00149    
00150    if (dateOfMostRecentValue < dateOfNewValue ) {
00151       _tab[newMostRecentValueIndex].dateValeur = dateOfNewValue ;
00152       if ( _numberOfValues != _fifoSize ) {
00153          _numberOfValues ++ ;
00154       }
00155     }
00156 
00157    _tab[newMostRecentValueIndex].valeur = newValue ;
00158 
00159    _mostRecentValueIndex = newMostRecentValueIndex ;
00160 }

template<typename T>
void OMK::Fifo< T >::setInPlace ( const T &  val,
const Date date 
) [virtual]

make an allready copied value available for reading

Implements OMK::AbstractFifo< T >.

Definition at line 163 of file OMKFifo.h.

References OMK::AbstractFifo< T >::_fifoSize, OMK::Fifo< T >::_mostRecentValueIndex, OMK::Fifo< T >::_numberOfValues, OMK::Fifo< T >::_tab, and OMASSERTM.

00164 {
00165    unsigned int newMostRecentValueIndex = ( _mostRecentValueIndex + 1 ) % _fifoSize ;
00166 
00167    Date & dateOfMostRecentValue(_tab[_mostRecentValueIndex].dateValeur) ;
00168    
00169    if (dateOfMostRecentValue < dateOfNewValue ) {
00170       _tab[newMostRecentValueIndex].dateValeur = dateOfNewValue ;
00171       if ( _numberOfValues != _fifoSize ) {
00172          _numberOfValues ++ ;
00173       }
00174     }
00175 
00176    //this assertion will fail if setInplace is used a a different simulation step than getNextPlaceHolder
00177    // or if newValue isn't a reference to a value of the container
00178    OMASSERTM(&(_tab[newMostRecentValueIndex].valeur) == &newValue, "" ) ;
00179 
00180    _mostRecentValueIndex = newMostRecentValueIndex ;
00181 }

template<typename T>
T & OMK::Fifo< T >::getNextPlaceHolder (  )  [virtual]

get a reference to the next place that will be used to store a value

Implements OMK::AbstractFifo< T >.

Definition at line 185 of file OMKFifo.h.

References OMK::AbstractFifo< T >::_fifoSize, OMK::Fifo< T >::_mostRecentValueIndex, and OMK::Fifo< T >::_tab.

00186 {
00187    return _tab[( _mostRecentValueIndex + 1 ) % _fifoSize].valeur ;
00188 }

template<typename T>
void OMK::Fifo< T >::clear (  )  [virtual]

clear the file

Implements OMK::AbstractFifo< T >.

Definition at line 210 of file OMKFifo.h.

References OMK::Fifo< T >::_numberOfValues.

00210                     {
00211    _numberOfValues = 0 ;
00212 }

template<typename T>
unsigned int OMK::Fifo< T >::getNumberOfPresentValues ( int  maxCherche = -1  )  const [virtual]

get the number of values in the fifo

Parameters:
lookingFor the number of values the caller is looking for. If == -1, get all values, otherwise, once lookingFor values are found, that number is returned

Implements OMK::AbstractFifo< T >.

Definition at line 191 of file OMKFifo.h.

References OMK::AbstractFifo< T >::_fifoSize, OMK::Fifo< T >::_numberOfValues, and OMASSERTM.

00191                                                                      {
00192    unsigned int res ;
00193    if ( (maxCherche == -1) || (_numberOfValues < (unsigned int) maxCherche) ) {
00194       res = _numberOfValues ;
00195    }
00196    else {
00197       res = maxCherche ; 
00198    }
00199    //for multithreading reasons, limit the results to _fifoSize - 2 
00200    OMASSERTM( _fifoSize >=  2, "" ) ;
00201    if (res >= _fifoSize - 1) {
00202       res = _fifoSize - 2 ;
00203    }
00204    return res ;
00205 }

template<typename T>
void OMK::Fifo< T >::printDebuggingInformation ( void   )  const [virtual]

printDebuggingInformation print any usefull debugging information

Reimplemented from OMK::AbstractFifo< T >.

Definition at line 217 of file OMKFifo.h.

References OMK::Fifo< T >::_mostRecentValueIndex, and OMK::Fifo< T >::_numberOfValues.

00218 {
00219    std::cerr<< "Fifo<"<<typeid(T).name()<<">::"<<this<<"::printDebuggingInformation()"<<std::endl ;
00220    AbstractFifo<T>::printDebuggingInformation() ;
00221    std::cerr << "number of valid values : " << _numberOfValues << std::endl
00222         << "last written value at : " << _mostRecentValueIndex << std::endl ;
00223 }


Member Data Documentation

template<typename T>
std::vector<ValeurDate> OMK::Fifo< T >::_tab [protected]

the array in wich the values are kept

Definition at line 93 of file OMKFifo.h.

Referenced by OMK::Fifo< T >::getNextPlaceHolder(), OMK::Fifo< T >::getPreceedingDate(), OMK::Fifo< T >::getPreceedingValue(), OMK::Fifo< T >::set(), and OMK::Fifo< T >::setInPlace().

template<typename T>
unsigned int OMK::Fifo< T >::_numberOfValues [protected]

the number of valid values in _tab

Definition at line 96 of file OMKFifo.h.

Referenced by OMK::Fifo< T >::clear(), OMK::Fifo< T >::getNumberOfPresentValues(), OMK::Fifo< T >::printDebuggingInformation(), OMK::Fifo< T >::set(), and OMK::Fifo< T >::setInPlace().

template<typename T>
unsigned int OMK::Fifo< T >::_mostRecentValueIndex [protected]

the place the most recent value was stored

Definition at line 99 of file OMKFifo.h.

Referenced by OMK::Fifo< T >::getNextPlaceHolder(), OMK::Fifo< T >::getPreceedingDate(), OMK::Fifo< T >::getPreceedingValue(), OMK::Fifo< T >::printDebuggingInformation(), OMK::Fifo< T >::set(), and OMK::Fifo< T >::setInPlace().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:02 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007