Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsnFifo< Type > 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 <PsnFifo.h>

Inheritance diagram for PsnFifo< Type >:

Inheritance graph
[legend]
Collaboration diagram for PsnFifo< Type >:

Collaboration graph
[legend]
List of all members.

Public Methods

 PsnFifo (const int taille)
 constructor

virtual ~PsnFifo ()
 destructor

virtual const Type & getPreceedingValue (const unsigned int indice) const
 get a value before the current value

virtual const PsDategetPreceedingDate (const unsigned int indice) const
 get the date associated to a value before the current value

virtual void set (const Type &val, const PsDate &date)
 add a value to the fifo

virtual void setInPlace (const Type &val, const PsDate &date)
 make an allready copied value available for reading

virtual Type & 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

PsnAbstractArray< 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


Detailed Description

template<typename Type>
class PsnFifo< Type >

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 30 of file PsnFifo.h.


Constructor & Destructor Documentation

template<typename Type>
PsnFifo< Type >::PsnFifo const int    taille
 

constructor

Definition at line 105 of file PsnFifo.h.

References PsnFifo< Type >::_tab.

00105                                         : 
00106    PsnAbstractFifo <Type> (taille), 
00107    _numberOfValues ( 0 ),
00108    _mostRecentValueIndex (taille-1) 
00109 {
00110    _tab = new PsnArray < valeurDate >  (taille) ;
00111    //cerr<<"PsnFifo<Type>::PsnFifo created "<<endl;
00112 }

template<typename Type>
PsnFifo< Type >::~PsnFifo   [virtual]
 

destructor

Definition at line 117 of file PsnFifo.h.

References PsnFifo< Type >::_tab.

00117                              {
00118    if ( _tab != NULL ) delete _tab ;
00119 }


Member Function Documentation

template<typename Type>
void PsnFifo< Type >::clear   [virtual]
 

clear the file

Implements PsnAbstractFifo< Type >.

Definition at line 209 of file PsnFifo.h.

References PsnFifo< Type >::_numberOfValues.

00209                           {
00210    _numberOfValues = 0 ;
00211 }

template<typename Type>
Type & PsnFifo< Type >::getNextPlaceHolder   [virtual]
 

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

Implements PsnAbstractFifo< Type >.

Definition at line 184 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, and PsnFifo< Type >::_mostRecentValueIndex.

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

template<typename Type>
unsigned int PsnFifo< Type >::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 PsnAbstractFifo< Type >.

Definition at line 190 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, and PsnFifo< Type >::_numberOfValues.

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

template<typename Type>
const PsDate & PsnFifo< Type >::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 PsnAbstractFifo< Type >.

Definition at line 124 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, PsnFifo< Type >::_mostRecentValueIndex, and PsDate.

00125 {
00126    assert ( i < _fifoSize - 2 ) ;
00127    int indice = (_fifoSize + _mostRecentValueIndex - i ) % _fifoSize ;
00128    return (*_tab) [indice].dateValeur ;
00129 }

template<typename Type>
const Type & PsnFifo< Type >::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 PsnAbstractFifo< Type >.

Definition at line 132 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, and PsnFifo< Type >::_mostRecentValueIndex.

00132                                                                     {
00133    assert ( i < _fifoSize - 2 ) ;
00134    int indice = (_fifoSize + _mostRecentValueIndex - i ) % _fifoSize ;
00135    return (*_tab) [indice].valeur ;
00136 }

template<typename Type>
void PsnFifo< Type >::printDebuggingInformation void    const [virtual]
 

printDebuggingInformation print any usefull debugging information

Implements PsnAbstractFifo< Type >.

Definition at line 216 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, PsnFifo< Type >::_mostRecentValueIndex, PsnFifo< Type >::_numberOfValues, PsnFifo< Type >::_tab, PsnAbstractArray< valeurDate >::printDebuggingInformation(), and PsnAbstractFifo< Type >::printDebuggingInformation().

00216                                                          {
00217    cerr<< "PsnFifo<"<<typeid(Type).name()<<">::"<<this<<"::printDebuggingInformation()"<<endl ;
00218    PsnAbstractFifo<Type>::printDebuggingInformation() ;
00219    cerr << "number of valid values : " << _numberOfValues << endl
00220         << "last written value at : " << _mostRecentValueIndex << endl
00221         << "values stored in array : "<< endl;
00222    _tab->printDebuggingInformation( _fifoSize ) ;
00223 }

template<typename Type>
void PsnFifo< Type >::set const Type &    val,
const PsDate   date
[virtual]
 

add a value to the fifo

Implements PsnAbstractFifo< Type >.

Definition at line 141 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, PsnFifo< Type >::_mostRecentValueIndex, PsnFifo< Type >::_numberOfValues, PsnFifo< Type >::_tab, and PsDate.

00141                                                                              {
00142    //cerr<<"PsnFifo<"<<typeid(Type).name()<<">::"<<this<<"::set("<<newValue<<", "<<dateOfNewValue<<")"<<endl;
00143    unsigned int newMostRecentValueIndex = ( _mostRecentValueIndex + 1 ) % _fifoSize ;
00144 
00145    PsDate & dateOfMostRecentValue((*_tab)[_mostRecentValueIndex].dateValeur) ;
00146    
00147    if (dateOfMostRecentValue < dateOfNewValue ) {
00148       (*_tab)[newMostRecentValueIndex].dateValeur = dateOfNewValue ;
00149       if ( _numberOfValues != _fifoSize ) {
00150          _numberOfValues ++ ;
00151       }
00152     }
00153 
00154    //cerr<<"newValue "<<newValue <<", old Value"<<(*_tab)[newMostRecentValueIndex].valeur<<endl;
00155    (*_tab)[newMostRecentValueIndex].valeur = newValue ;
00156    //cerr<<"newValue "<<(*_tab)[newMostRecentValueIndex].valeur <<endl;
00157 
00158    _mostRecentValueIndex = newMostRecentValueIndex ;
00159 }

template<typename Type>
void PsnFifo< Type >::setInPlace const Type &    val,
const PsDate   date
[virtual]
 

make an allready copied value available for reading

Implements PsnAbstractFifo< Type >.

Definition at line 162 of file PsnFifo.h.

References PsnAbstractFifo< Type >::_fifoSize, PsnFifo< Type >::_mostRecentValueIndex, PsnFifo< Type >::_numberOfValues, PsnFifo< Type >::_tab, and PsDate.

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


Member Data Documentation

template<typename Type>
unsigned int PsnFifo< Type >::_mostRecentValueIndex [protected]
 

the place the most recent value was stored

Definition at line 95 of file PsnFifo.h.

Referenced by PsnFifo< Type >::getNextPlaceHolder(), PsnFifo< Type >::getPreceedingDate(), PsnFifo< Type >::getPreceedingValue(), PsnFifo< Type >::printDebuggingInformation(), PsnFifo< Type >::set(), and PsnFifo< Type >::setInPlace().

template<typename Type>
unsigned int PsnFifo< Type >::_numberOfValues [protected]
 

the number of valid values in _tab

Definition at line 92 of file PsnFifo.h.

Referenced by PsnFifo< Type >::clear(), PsnFifo< Type >::getNumberOfPresentValues(), PsnFifo< Type >::printDebuggingInformation(), PsnFifo< Type >::set(), and PsnFifo< Type >::setInPlace().

template<typename Type>
PsnAbstractArray<valeurDate>* PsnFifo< Type >::_tab [protected]
 

the array in wich the values are kept

Definition at line 89 of file PsnFifo.h.

Referenced by PsnFifo< Type >::printDebuggingInformation(), PsnFifo< Type >::PsnFifo(), PsnFifo< Type >::set(), PsnFifo< Type >::setInPlace(), and PsnFifo< Type >::~PsnFifo().


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

Documentation generated on Mon Nov 25 15:26:00 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001