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

PsMap.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 PsMapHEADER
00019 #define PsMapHEADER
00020 
00021 #include <Psn.h>
00022 #include <PsName.h>
00023 
00024 #include <iterator>
00025 //#include <algo.h>
00026 #include <map>
00027 
00028 #include "PsPolator.h"
00029 
00032 #ifdef _OLDALLOCATORS
00033 template <typename index , typename objectType>
00034 class PsMap: public map <index, objectType, less<index>, STL_ALLOC>, public PsType
00035 #else
00036 template <typename index , typename objectType>
00037 class PsMap: public map <index, objectType, less<index>, STL_ALLOC<pair <const index, objectType> > >, public PsType
00038 #endif
00039 {
00040 public:
00041 
00043   PsMap () {}
00044 
00046   virtual ~PsMap () {}
00047 
00049   void addObjectWithIndex (const index & nomObj, objectType refObj)
00050    { 
00051       insert (pair<const index, objectType>(nomObj,refObj)) ;
00052    }
00053 
00055   objectType getObjectOfIndex (const index & nomObj) const
00056     {
00057 #ifdef _TYPENAMENOTIMPLICIT
00058        typename PsMap<index, objectType>::const_iterator i;
00059 #else
00060        const_iterator i;
00061 #endif
00062        i=find(nomObj);
00063        if (i==end()) 
00064           {
00065              return NULL;
00066           }
00067        else 
00068           {
00069              return (*i).second;
00070           }
00071     }
00072    
00074    virtual void insertInStream (ostream & = cout) const ;
00075    
00077    virtual void extract (istream & = cin) ;
00078 
00080    virtual void pack (PsOutgoingSynchronisationMessage & out ) const ;
00081 
00083    virtual void unpack (PsIncomingSynchronisationMessage & in ) ;
00084  
00086    virtual PsPolatorNT * createPolator(void) 
00087    {
00088       return new PsPolator< PsMap<index,objectType> >() ;
00089    } ;
00090 };
00091 
00092 
00093 
00094 template <typename index, typename objectType >
00095 inline void PsMap <index, objectType>::insertInStream (ostream & out) const {
00096    out << size () << " " ;
00097 #ifdef _TYPENAMENOTIMPLICIT
00098        typename PsMap<index, objectType>::const_iterator i = begin () ;
00099 #else
00100    const_iterator i = begin () ;
00101 #endif
00102    while (i != end ()) 
00103       {
00104          out << (*i).first <<" "<< (*i).second <<" ";
00105          ++ i  ;
00106       }
00107 }
00108 
00109 
00110 template <typename index, typename objectType >
00111 inline void PsMap <index, objectType>::extract (istream & in) 
00112 {
00113    int nbElements ;
00114    index ind ;
00115    objectType elem ;
00116    clear () ;
00117    in >> nbElements ;
00118    for (int j = 0 ; j < nbElements ; j ++) {
00119       in >> ind >> elem ;
00120       insert (pair<const index, objectType>(ind,elem)) ;
00121 
00122    }
00123 }
00124 
00125 template <typename index, typename objectType >
00126 void PsMap <index, objectType>::pack (PsOutgoingSynchronisationMessage & out ) const 
00127 {
00128    out << size ()  ;
00129 #ifdef _TYPENAMENOTIMPLICIT
00130        typename PsMap<index, objectType>::
00131 #endif
00132    const_iterator i = begin () ;
00133    while (i != end ()) {
00134       out << (*i).first << (*i).second ;
00135       ++ i  ;
00136    }
00137 }
00138 
00139 template <typename index, typename objectType >
00140 void PsMap <index, objectType>::unpack (PsIncomingSynchronisationMessage & in ) 
00141 {
00142    size_t numberOfElements ;
00143    in>>numberOfElements ;
00144    index ind ;
00145    objectType obj ;
00146    for (int i= 0 ; i < numberOfElements ; ++i)
00147       {
00148          in>>ind>>obj;
00149          insert( PsMap::value_type(ind,obj) ) ;
00150       }
00151 }
00152 
00153 #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