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

PsList.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 PsListHEADER
00019 #define PsListHEADER
00020 
00021 #include <Psn.h>
00022 #include <PsType.h>
00023 
00024 #include <list>
00025 #include <PsPolator.h>
00026 
00027 //-----------------------------------------------------------------
00028 
00037 #ifdef _OLDALLOCATORS
00038 template <typename Type, typename allocator=STL_ALLOC > class PsList : public list <Type, STL_ALLOC>, public PsType
00039 #else
00040 template <typename Type, typename allocator=STL_ALLOC<Type> > class PsList : public list <Type, allocator >, public PsType
00041 #endif
00042 {
00043 public:
00044 
00046   PsList  () 
00047    {
00048    }
00049 
00051 #ifdef _OLDALLOCATORS
00052    PsList (const int n, const Type & initialValue): list<Type, STL_ALLOC>(n,initialValue) 
00053 #else
00054    PsList (const int n, const Type & initialValue): list<Type, allocator >(n,initialValue) 
00055 #endif
00056    {
00057    };
00058 
00060 #ifdef _OLDALLOCATORS
00061    PsList (const list<Type, STL_ALLOC> &l): list<Type, STL_ALLOC>(l) {};
00062 #else
00063    PsList (const list<Type, allocator > &l): list<Type, allocator >(l) {};
00064 #endif
00065 
00067 #ifdef _OLDALLOCATORS
00068   PsList (const PsList<Type> &l): list<Type, STL_ALLOC>(l) {};
00069 #else
00070   PsList (const PsList<Type> &l): list<Type, allocator >(l) {};
00071 #endif
00072 
00074    virtual ~PsList() {}
00075    
00077    virtual PsPolatorNT * createPolator(void) 
00078    {
00079       return (PsPolatorNT *) new PsPolator< PsList<Type> >() ;
00080    } ;
00081    
00082    
00084    virtual void pack (PsOutgoingSynchronisationMessage & out ) const ;
00085 
00087    virtual void unpack (PsIncomingSynchronisationMessage & in ) ;
00088 
00090    virtual void insertInStream (ostream & = cout) const ;
00091    
00092    
00094    virtual void extract (istream & = cin) ;
00095    
00096    
00098    virtual PsList <Type,allocator> & operator = (const PsList <Type,allocator> &) ;
00099    
00100 };
00101 
00102 
00103 template <typename Type, typename allocator >
00104 inline void PsList <Type,allocator>::insertInStream (ostream & out) const {
00105    out << size () << " " ;
00106 #ifdef _TYPENAMENOTIMPLICIT
00107    typename  PsList <Type,allocator>::
00108 #endif
00109       const_iterator i = begin () ;
00110    while (i != end ()) {
00111       out << *i << " " ;
00112       i ++ ;
00113    }
00114 }
00115 
00116 template <typename Type, typename allocator >
00117 inline void PsList <Type,allocator>::extract (istream & in) {
00118    int nbElements ;
00119    Type elem ;
00120    clear () ;
00121    in >> nbElements ;
00122    for (int j = 0 ; j < nbElements ; j ++) {
00123       in >> elem ;
00124       push_back (elem) ;
00125    }
00126 }
00127 
00128 template <typename Type, typename allocator >
00129 void PsList <Type,allocator>::pack (PsOutgoingSynchronisationMessage & out ) const 
00130 {
00131    out << size () ;
00132 #ifdef _TYPENAMENOTIMPLICIT
00133    typename  PsList <Type,allocator>::const_iterator i = begin () ;
00134 #else
00135    const_iterator i = begin () ;
00136 #endif
00137    while (i != end ()) 
00138       {
00139          out << *i ;
00140          i ++ ;
00141       }
00142    
00143 }
00144 
00145 template <typename Type, typename allocator >
00146 void PsList <Type,allocator>::unpack (PsIncomingSynchronisationMessage & in ) 
00147 {
00148    size_t numberOfElements ;
00149    in >> numberOfElements ;
00150    resize (numberOfElements) ;
00151    for (typename PsList <Type,allocator>::iterator i = begin() ; i != end() ; ++i)
00152       {
00153          (*i).unpack ( in ) ; 
00154       }
00155 }
00156 
00157 //-----------------------------------------------------------------------
00158 
00159 // TDTD 1997/9/4 inherit frome PsType : redefine mandatory methods
00160 
00161 template <typename Type, typename allocator >
00162 inline PsList <Type,allocator> & PsList <Type,allocator>::operator = (const PsList <Type,allocator> & p)
00163 {
00164 #ifdef _OLDALLOCATORS
00165   list <Type, STL_ALLOC>::operator = (p) ; // TDTD DANGER resolved on 1999/9/8
00166 #else
00167   list <Type, allocator >::operator = (p) ; // TDTD DANGER resolved on 1999/9/8
00168 #endif
00169   return *this ;
00170 }
00171 
00172 
00173 //  //TD added during update 1999/5/5 : otherwise, lists with pointer are seen as list of bool by implicit conversion
00174 //  inline istream & operator >> (istream & in, void *) {
00175 //     cerr << "WARNING : on ne doit pas passer ici, il ne s'y passe rien" << endl ;
00176 //     return in ;
00177 //  }
00178 
00179 
00180 #endif

logo OpenMask

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

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