00001 /************************************************************************/ 00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00003 /* 1993-2002, thereinafter the Software */ 00004 /* */ 00005 /* The Software has been developped within the Siames Project. */ 00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00007 /* property rights */ 00008 /* */ 00009 /* The Software has been registered with the Agence pour la Protection */ 00010 /* des Programmes (APP) under registration number */ 00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00012 /* */ 00013 /* This file may be distributed under the terms of the Q Public License */ 00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00015 /* the file LICENSE.QPL included in the packaging of this file. */ 00016 /* */ 00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00018 /* Universite Rennes 1 for the software may use this file in */ 00019 /* acordance with that specific license */ 00020 /************************************************************************/ 00021 00022 #if !defined _SIMPLETYPET_INL_ 00023 #define _SIMPLETYPET_INL_ 00024 00025 #include "OMKSimpleTypeT.h" 00026 #include <list> 00027 #include <map> 00028 #include <vector> 00029 #include "OMKOutgoingSynchronisationMessage.h" 00030 #include "OMKIncomingSynchronisationMessage.h" 00031 #include "OMKPolator.h" 00032 00033 //============================================================================= 00034 // stream operators for string 00035 //----------------------------------------------------------------------------- 00036 inline OMK::OutgoingSynchronisationMessage& 00037 operator << ( OMK::OutgoingSynchronisationMessage& out, const std::string& value ) 00038 { 00039 out.pack( value ) ; 00040 return out ; 00041 } 00042 //----------------------------------------------------------------------------- 00043 inline OMK::IncomingSynchronisationMessage& 00044 operator >> ( OMK::IncomingSynchronisationMessage& in, std::string& value ) 00045 { 00046 in.get( value ) ; 00047 return in ; 00048 } 00049 //============================================================================= 00050 00051 //============================================================================= 00052 // stream operators for pair 00053 //----------------------------------------------------------------------------- 00054 template< typename T1, typename T2 > 00055 std::ostream& operator << ( std::ostream& out, const std::pair< T1, T2 >& value ) 00056 { 00057 out << value.first << " " << value.second << " " ; 00058 return out ; 00059 } 00060 //----------------------------------------------------------------------------- 00061 template< typename T1, typename T2 > 00062 std::istream& operator >> ( std::istream& in, std::pair< T1, T2 >& value ) 00063 { 00064 in >> value.first >> value.second ; 00065 return in ; 00066 } 00067 //----------------------------------------------------------------------------- 00068 template< typename T1, typename T2 > 00069 OMK::OutgoingSynchronisationMessage& 00070 operator << ( OMK::OutgoingSynchronisationMessage& out, const std::pair< T1, T2 >& value ) 00071 { 00072 out << value.first << value.second ; 00073 return out ; 00074 } 00075 //----------------------------------------------------------------------------- 00076 template< typename T1, typename T2 > 00077 OMK::IncomingSynchronisationMessage& 00078 operator >> ( OMK::IncomingSynchronisationMessage& in, std::pair< T1, T2 >& value ) 00079 { 00080 in >> value.first >> value.second ; 00081 return in ; 00082 } 00083 //============================================================================= 00084 00085 //============================================================================= 00086 // stream operators for list 00087 //----------------------------------------------------------------------------- 00088 template< typename T > 00089 std::ostream& operator << ( std::ostream& out, const std::list< T >& values ) 00090 { 00091 out << values.size() << " " ; 00092 for( typename std::list< T >::const_iterator i( values.begin() ) ; 00093 i != values.end() ; 00094 ++i ) 00095 { 00096 out << (*i) << " " ; 00097 } 00098 return out ; 00099 } 00100 //----------------------------------------------------------------------------- 00101 template< typename T > 00102 std::istream& operator >> ( std::istream& in, std::list< T >& values ) 00103 { 00104 // we do not want any element in the proposed list to avoid accumulation 00105 values.clear() ; 00106 unsigned int size( 0 ) ; 00107 in >> size ; 00108 for( unsigned int i( 0 ) ; i < size ; ++i ) 00109 { 00110 T value ; 00111 in >> value ; 00112 values.push_back( value ) ; 00113 } 00114 return in ; 00115 } 00116 //----------------------------------------------------------------------------- 00117 template< typename T > 00118 OMK::OutgoingSynchronisationMessage& 00119 operator << ( OMK::OutgoingSynchronisationMessage& out, const std::list< T >& values ) 00120 { 00121 out << values.size() ; 00122 for( typename std::list< T >::const_iterator i( values.begin() ) ; 00123 i != values.end() ; 00124 ++i ) 00125 { 00126 out << (*i) ; 00127 } 00128 return out ; 00129 } 00130 //----------------------------------------------------------------------------- 00131 template< typename T > 00132 OMK::IncomingSynchronisationMessage& 00133 operator >> ( OMK::IncomingSynchronisationMessage& in, std::list< T >& values ) 00134 { 00135 // we do not want any element in the proposed list to avoid accumulation 00136 values.clear() ; 00137 unsigned int size( 0 ) ; 00138 in >> size ; 00139 for( unsigned int i( 0 ) ; i < size ; ++i ) 00140 { 00141 T value ; 00142 in >> value ; 00143 values.push_back( value ) ; 00144 } 00145 return in ; 00146 } 00147 //============================================================================= 00148 00149 //============================================================================= 00150 // stream operators for vector 00151 //----------------------------------------------------------------------------- 00152 template< typename T > 00153 std::ostream& operator << ( std::ostream& out, const std::vector< T >& values ) 00154 { 00155 out << values.size() ; 00156 for( unsigned int i( 0 ) ; i < values.size() ; ++i ) 00157 { 00158 out << values[ i ] << " " ; 00159 } 00160 return out ; 00161 } 00162 //----------------------------------------------------------------------------- 00163 template< typename T > 00164 std::istream& operator >> ( std::istream& in, std::vector< T >& values ) 00165 { 00166 // we do not want any element in the proposed vector to avoid accumulation 00167 values.clear() ; 00168 unsigned int size( 0 ) ; 00169 in >> size ; 00170 values.reserve( size ) ; 00171 for( unsigned int i( 0 ) ; i < size ; ++i ) 00172 { 00173 T value ; 00174 in >> value ; 00175 values.push_back( value ) ; 00176 } 00177 return in ; 00178 } 00179 //----------------------------------------------------------------------------- 00180 template< typename T > 00181 OMK::OutgoingSynchronisationMessage& 00182 operator << ( OMK::OutgoingSynchronisationMessage& out, const std::vector< T >& values ) 00183 { 00184 out << values.size() ; 00185 for( unsigned int i( 0 ) ; i < values.size() ; ++i ) 00186 { 00187 out << values[ i ] ; 00188 } 00189 return out ; 00190 } 00191 //----------------------------------------------------------------------------- 00192 template< typename T > 00193 OMK::IncomingSynchronisationMessage& 00194 operator >> ( OMK::IncomingSynchronisationMessage& in, std::vector< T >& values ) 00195 { 00196 // we do not want any element in the proposed vector to avoid accumulation 00197 values.clear() ; 00198 unsigned int size( 0 ) ; 00199 in >> size ; 00200 values.reserve( size ) ; 00201 for( unsigned int i( 0 ) ; i < size ; ++i ) 00202 { 00203 T value ; 00204 in >> value ; 00205 values.push_back( value ) ; 00206 } 00207 return in ; 00208 } 00209 //============================================================================= 00210 00211 //============================================================================= 00212 // stream operators for map 00213 //----------------------------------------------------------------------------- 00214 template< typename T1, typename T2 > 00215 std::ostream& operator << ( std::ostream& out, const std::map< T1, T2 >& values ) 00216 { 00217 out << values.size() << " " ; 00218 for( typename std::map< T1, T2 >::const_iterator i( values.begin() ) ; 00219 i != values.end() ; 00220 ++i ) 00221 { 00222 out << i->first << " " 00223 << i->second << " " ; 00224 } 00225 return out ; 00226 } 00227 //----------------------------------------------------------------------------- 00228 template< typename T1, typename T2 > 00229 std::istream& operator >> ( std::istream& in, std::map< T1, T2 >& values ) 00230 { 00231 // we do not want any element in the proposed map to avoid accumulation 00232 values.clear() ; 00233 unsigned int size( 0 ) ; 00234 in >> size ; 00235 for( unsigned int i( 0 ) ; i < size ; ++i ) 00236 { 00237 T1 key ; 00238 T2 value ; 00239 in >> key >> value ; 00240 values[ key ] = value ; 00241 } 00242 return in ; 00243 } 00244 //----------------------------------------------------------------------------- 00245 template< typename T1, typename T2 > 00246 OMK::OutgoingSynchronisationMessage& 00247 operator << ( OMK::OutgoingSynchronisationMessage& out, const std::map< T1, T2 >& values ) 00248 { 00249 out << values.size() << " " ; 00250 for( typename std::map< T1, T2 >::const_iterator i( values.begin() ) ; 00251 i != values.end() ; 00252 ++i ) 00253 { 00254 out << i->first << " " 00255 << i->second << " " ; 00256 } 00257 return out ; 00258 } 00259 //----------------------------------------------------------------------------- 00260 template< typename T1, typename T2 > 00261 OMK::IncomingSynchronisationMessage& 00262 operator >> ( OMK::IncomingSynchronisationMessage& in, std::map< T1, T2 >& values ) 00263 { 00264 // we do not want any element in the proposed map to avoid accumulation 00265 values.clear() ; 00266 unsigned int size( 0 ) ; 00267 in >> size ; 00268 for( unsigned int i( 0 ) ; i < size ; ++i ) 00269 { 00270 T1 key ; 00271 T2 value ; 00272 in >> key >> value ; 00273 values[ key ] = value ; 00274 } 00275 return in ; 00276 } 00277 //============================================================================= 00278 00279 00280 //============================================================================= 00281 // stream pack/unpack for SimpleTypeT 00282 template< typename T > 00283 void OMK::Type::SimpleTypeT< T >::insertInStream( std::ostream& out ) const 00284 { 00285 out << _value << " " << " " ; 00286 } 00287 //----------------------------------------------------------------------------- 00288 template< typename T > 00289 void OMK::Type::SimpleTypeT< T >::extract( std::istream& in ) 00290 { 00291 in >> _value ; 00292 } 00293 //----------------------------------------------------------------------------- 00294 template< typename T > 00295 void OMK::Type::SimpleTypeT< T >::pack( OMK::OutgoingSynchronisationMessage& out ) const 00296 { 00297 out << _value ; 00298 } 00299 //----------------------------------------------------------------------------- 00300 template< typename T > 00301 void OMK::Type::SimpleTypeT< T >::unpack( OMK::IncomingSynchronisationMessage& in ) 00302 { 00303 in >> _value ; 00304 } 00305 //----------------------------------------------------------------------------- 00306 // Polator for SimpleTypeT 00307 template< typename T > 00308 OMK::Type::PolatorNT* OMK::Type::SimpleTypeT< T >::createPolator() 00309 { 00310 return new OMK::Type::Polator< OMK::Type::SimpleTypeT< T > >() ; 00311 } 00312 00313 #endif // defined _SIMPLETYPET_INL_
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |