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

PsnMomeReaderFifo.h

Go to the documentation of this file.
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 PsnMomeReaderFifoHEADER
00019 #define PsnMomeReaderFifoHEADER
00020 
00023 template <typename Type>
00024 class PsnMomeReaderFifo : public PsnMomeFifo<Type>
00025 {
00026 public:
00027    PsnMomeReaderFifo(const int size, PsnRelaxedMemoryManager * myMemory);
00028    PsnMomeReaderFifo(void * fifoAddress , const unsigned int size);
00029    virtual ~PsnMomeReaderFifo() ;
00030 
00032    virtual void set (const Type & val, const PsDate & date) ;
00033 
00035    virtual void setInPlace ( const Type & newValue, const PsDate & date) ;
00036 
00038    virtual Type & getNextPlaceHolder() ;
00039 
00040     unsigned int getNumberOfPresentValues( int maxCherche = -1 ) const ;
00041    virtual void clear() ;
00042    virtual void printDebuggingInformation() const ;
00043 protected:
00044     unsigned int findFirstValid() const ;
00045    mutable PsDate _dateOfLastValidIndex ;
00046 };
00047 
00048 
00049 template <typename Type> 
00050 PsnMomeReaderFifo<Type>::PsnMomeReaderFifo(const int size, PsnRelaxedMemoryManager * myMemory) : 
00051    PsnMomeFifo<Type> (size,myMemory),
00052    _dateOfLastValidIndex ( PsDate ( -3 ) ) {
00053 
00054 }
00055 
00056 
00057 
00058 template <typename Type> 
00059 PsnMomeReaderFifo<Type>::PsnMomeReaderFifo(void * fifoAddress, const unsigned int size) : 
00060    PsnMomeFifo<Type> (fifoAddress,size),
00061    _dateOfLastValidIndex ( PsDate ( -3 ) ) {
00062 
00063 }
00064 
00065 
00066 
00067 template <typename Type> 
00068 PsnMomeReaderFifo<Type>::~PsnMomeReaderFifo() {
00069 
00070 }
00071 
00072 
00073 
00074 template <typename Type> 
00075 unsigned int PsnMomeReaderFifo<Type>::findFirstValid() const {
00076 #ifdef _DEBUGATTRIBUTSMOME
00077    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::findFirstValid ()"<<endl;
00078 #endif
00079    //findFirstValid only works if _dateOfLastValidIndex and _lastValidIndex have been correctly initialised with a correct pair of values and therefore (*tab)[_lastValidIndex] contains a valid value. This is always true, because nbValues() should be called before this member function is called. if it hasn't been called with a return result greater than 0, then _dateOfLastValidIndex keeps its initial value, explaining the following assertion.
00080    assert ( _dateOfLastValidIndex != -3 ) ;
00081 
00082    unsigned int lookAt = PsnRelaxedMemoryManager::getReadableQueueIndex() ;
00083 
00084    while ( ((*_tab)[lookAt].dateValeur < _dateOfLastValidIndex) && 
00085            ( lookAt != _lastValidIndex ) ) {
00086       lookAt = (lookAt - 1 + _fifoSize) % _fifoSize ;
00087 
00088    }
00089 
00090 //     if (lookAt != _lastValidIndex) {
00091 //        _lastValidIndex = lookAt ;
00092 //        _dateOfLastValidIndex = (*_tab)[lookAt].dateValeur ;
00093 //        _dateOfOldestValidValue = (*_tab)[lookAt].datePlusVieilleValeurValide ;
00094 //     }
00095 #ifdef _DEBUGATTRIBUTSMOME
00096    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::findFirstValid () = "<<lookAt<<" : "<<(*_tab)[lookAt].valeur<<endl;
00097 #endif
00098    return lookAt ;
00099 
00100 }
00101 
00102 
00103 
00104 template <typename Type> 
00105 unsigned int PsnMomeReaderFifo<Type>::getNumberOfPresentValues (int maxCherche) const {
00106 #if defined (_DEBUGRELAXEDCOHERANCE) || defined (_DEBUGATTRIBUTSMOME)
00107    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::getNumberOfPresentValues("<<maxCherche<<") "<<endl;
00108    printDebuggingInformation() ;
00109 #endif 
00110 
00111    bool onLoop = true ;
00112    unsigned int nbATrouver ;
00113    if (maxCherche == -1) {
00114       nbATrouver = _fifoSize ;
00115    }
00116    else {
00117       nbATrouver = maxCherche ; 
00118    }
00119    int lookAt ;
00120    if (_dateOfLastValidIndex != -3 ) {
00121       lookAt = findFirstValid () ;
00122    }
00123    else {
00124       lookAt = PsnRelaxedMemoryManager::getReadableQueueIndex() ;
00125    }
00126    unsigned int nbValidFound = 0 ;
00127 
00128 #if defined (_DEBUGRELAXEDCOHERANCE) || defined (_DEBUGATTRIBUTSMOME)
00129    cerr<<"  lookingAt "<<lookAt<<endl;
00130    cerr<<"   "<<lookAt<<" : "<<(*_tab)[lookAt].dateValeur<<" "<<(*_tab)[lookAt].datePlusVieilleValeurValide<<" "<<_dateOfOldestValidValue<<" "<<nbValidFound<<endl;
00131 #endif
00132 
00133    if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) {
00134       //if (lookAt != _lastValidIndex) {
00135          _lastValidIndex = lookAt ;
00136          _dateOfLastValidIndex = (*_tab)[lookAt].dateValeur ;
00137          _dateOfOldestValidValue = (*_tab)[lookAt].datePlusVieilleValeurValide ;
00138          //}
00139       long preceedingDate = _dateOfLastValidIndex ;
00140       nbValidFound++ ;
00141       //cerr<<(*_tab)[lookAt].valeur<<" "<<(*_tab)[lookAt].dateValeur<<endl;
00142       if (lookAt != 0 ) {
00143          lookAt--;
00144       }
00145       else {
00146          lookAt = _fifoSize -1 ;
00147       }
00148       while ( ( nbValidFound < nbATrouver) &&
00149               (lookAt != PsnRelaxedMemoryManager::getReadableQueueIndex() ) &&
00150               onLoop
00151               ) {
00152          if ( (*_tab)[lookAt].dateValeur >= _dateOfOldestValidValue ) {
00153             if ( (*_tab)[lookAt].dateValeur < preceedingDate ) {
00154                nbValidFound++ ;
00155                preceedingDate = (*_tab)[lookAt].dateValeur ;
00156             }
00157             else {
00158                onLoop = false ;
00159             }
00160          }
00161          if (lookAt != 0 ) {
00162             lookAt--;
00163          }
00164          else {
00165             lookAt = _fifoSize -1 ;
00166          }
00167       }
00168    }
00169    else {//the FIFO is still being initialised or is corrupt. try to find a valid value in it.
00170       unsigned int nbLookedAt = 1 ;
00171       while (nbLookedAt < _fifoSize) {
00172          if (lookAt != 0 ) {
00173             lookAt--;
00174          }
00175          else {
00176             lookAt = _fifoSize -1 ;
00177          }
00178          if ( (*_tab)[lookAt].dateValeur >=  _dateOfOldestValidValue ) {
00179             nbValidFound++ ;
00180             nbLookedAt = _fifoSize ;
00181 #ifdef _DEBUGATTRIBUTSMOME
00182             cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::getNumberOfPresentValues : "
00183                 <<"initialising the FIFO's data"<<endl;
00184             printDebuggingInformation();
00185 #endif
00186             //initialise the FIFO's data
00187             _lastValidIndex = lookAt ;
00188             _dateOfLastValidIndex = (*_tab)[lookAt].dateValeur ;
00189             _dateOfOldestValidValue = (*_tab)[lookAt].datePlusVieilleValeurValide ;
00190          }
00191          else {
00192             nbLookedAt++ ;
00193          }
00194       }
00195    }
00196 #if defined (_DEBUGRELAXEDCOHERANCE) || defined (_DEBUGATTRIBUTSMOME)
00197      cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::getNumberOfPresentValues = "<<nbValidFound<<endl;
00198 #endif
00199    return nbValidFound ;
00200 }
00201 
00202 
00203 
00204 
00205 template <typename Type> 
00206 void PsnMomeReaderFifo<Type>::set (const Type & val, const PsDate & date) {
00207    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::set ("<<val<<", "<<date<<") : double écrivain ! "<<endl;
00208    assert (false) ;
00209 }
00210 
00211 
00212 template <typename Type> 
00213 void PsnMomeReaderFifo<Type>::setInPlace(const Type & newValue, const PsDate & date) 
00214 {
00215    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::setInPlace ("<<newValue<<", "<<date<<") : double écrivain ! "<<endl;
00216    assert (false) ;
00217 
00218 }
00219 
00220 
00221 template <typename Type>
00222 Type & PsnMomeReaderFifo<Type>::getNextPlaceHolder() 
00223 {
00224    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::getNextPlaceHolder () : double écrivain ! "<<endl;
00225    assert (false) ;
00226 }
00227 
00228 
00229 template <typename Type> 
00230 void PsnMomeReaderFifo<Type>::clear () {
00231    cerr<<"PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::clear() : double écrivain ! "<<endl;
00232    assert (false) ;
00233 }
00234 
00235 
00236 
00237 template <typename Type> 
00238 void PsnMomeReaderFifo<Type>::printDebuggingInformation () const {
00239    cerr<<" PsnMomeReaderFifo<"<<typeid(Type).name()<<">::"<<this<<"::printDebuggingInformation () "<<endl;
00240    PsnMomeFifo<Type>::printDebuggingInformation() ;
00241    cerr<<"_dateOfLastValidIndex : "<<_dateOfLastValidIndex<<endl;
00242    cerr<<"readableIndex : "<<PsnRelaxedMemoryManager::getReadableQueueIndex()<<endl; 
00243    cerr<<"Réaffichage après une vrai synchronisation"<<endl;
00244    resyncFifo( ( PsnRelaxedMemoryManager *)PsnMemoryManager::whichMemoryManager(_tab) ) ;
00245    PsnMomeFifo<Type>::printDebuggingInformation() ;   
00246 }
00247 
00248 #endif
00249 
00250 

logo OpenMask

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

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