00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #ifndef PsnFifoHEADER 00019 #define PsnFifoHEADER 00020 00021 #include <PsnAbstractFifo.h> 00022 #include <typeinfo> 00023 #include <PsnArray.h> 00024 00029 template < typename Type > 00030 class PsnFifo : public PsnAbstractFifo <Type> 00031 { 00032 00033 public : 00035 PsnFifo (const int taille) ; 00036 00037 00039 virtual ~PsnFifo () ; 00040 00044 virtual const Type & getPreceedingValue (const unsigned int indice) const ; 00045 00046 00050 virtual const PsDate & getPreceedingDate(const unsigned int indice) const ; 00051 00052 00054 virtual void set (const Type & val, const PsDate & date) ; 00055 00056 00058 virtual void setInPlace ( const Type & val, const PsDate & date) ; 00059 00060 00062 virtual Type & getNextPlaceHolder() ; 00063 00064 00066 virtual void clear () ; 00067 00068 00071 virtual unsigned int getNumberOfPresentValues( int maxCherche = -1 ) const ; 00072 00073 00075 virtual void printDebuggingInformation(void) const ; 00076 00077 protected : 00079 class valeurDate 00080 { 00081 public: 00082 valeurDate() : dateValeur(-2) { 00083 } 00084 PsDate dateValeur; 00085 Type valeur ; 00086 }; 00087 00089 PsnAbstractArray <valeurDate> * _tab ; 00090 00092 unsigned int _numberOfValues ; 00093 00095 unsigned int _mostRecentValueIndex ; 00096 } ; // PsnFifo 00097 00098 00099 00100 00101 00102 //------------------------------------------------------------------------ 00103 00104 template <typename Type> 00105 PsnFifo<Type>::PsnFifo (const int taille) : 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 } 00113 00114 00115 00116 template <typename Type> 00117 PsnFifo<Type>::~PsnFifo (void) { 00118 if ( _tab != NULL ) delete _tab ; 00119 } 00120 00121 //------------------------------------------------------------------------ 00122 00123 template <typename Type> 00124 const PsDate & PsnFifo<Type>::getPreceedingDate (unsigned int i) const 00125 { 00126 assert ( i < _fifoSize - 2 ) ; 00127 int indice = (_fifoSize + _mostRecentValueIndex - i ) % _fifoSize ; 00128 return (*_tab) [indice].dateValeur ; 00129 } 00130 00131 template <typename Type> 00132 const Type & PsnFifo<Type>::getPreceedingValue (unsigned int i) const { 00133 assert ( i < _fifoSize - 2 ) ; 00134 int indice = (_fifoSize + _mostRecentValueIndex - i ) % _fifoSize ; 00135 return (*_tab) [indice].valeur ; 00136 } 00137 00138 //------------------------------------------------------------------------ 00139 00140 template <typename Type> 00141 void PsnFifo<Type>::set (const Type & newValue, const PsDate & dateOfNewValue) { 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 } 00160 00161 template <typename Type> 00162 void PsnFifo<Type>::setInPlace ( const Type & newValue, const PsDate & dateOfNewValue ) 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 } 00181 00182 00183 template <typename Type> 00184 Type & PsnFifo<Type>::getNextPlaceHolder() 00185 { 00186 return (*_tab)[( _mostRecentValueIndex + 1 ) % _fifoSize].valeur ; 00187 } 00188 00189 template <typename Type> 00190 unsigned int PsnFifo<Type>::getNumberOfPresentValues( int maxCherche ) const { 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 } 00205 00206 //------------------------------------------------------------------------ 00207 00208 template <typename Type> 00209 void PsnFifo<Type>::clear() { 00210 _numberOfValues = 0 ; 00211 } 00212 00213 //------------------------------------------------------------------------ 00214 00215 template <typename Type> 00216 void PsnFifo<Type>::printDebuggingInformation (void) const { 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 } 00224 00225 #endif
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |