Equalizer  1.4.1
dataOStream.ipp
00001 
00002 /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include <co/object.h>
00019 #include <co/objectVersion.h>
00020 
00021 namespace co
00022 {
00026     template<>
00027     inline DataOStream& DataOStream::operator << ( const std::string& str )
00028     {
00029         const uint64_t nElems = str.length();
00030         _write( &nElems, sizeof( nElems ));
00031         if ( nElems > 0 )
00032             _write( str.c_str(), nElems );
00033 
00034         return *this;
00035     }
00036 
00038     template<> inline DataOStream&
00039     DataOStream::operator << ( const Object* const& object )
00040     {
00041         LBASSERT( !object || object->isAttached( ));
00042         (*this) << ObjectVersion( object );
00043         return *this;
00044     }
00045 
00047     template< class T > inline DataOStream&
00048     DataOStream::operator << ( const lunchbox::Buffer< T >& buffer )
00049     {
00050         return (*this) << buffer.getSize()
00051                        << Array< const T >( buffer.getData(), buffer.getSize());
00052     }
00053 
00054     template< class T > inline DataOStream&
00055     DataOStream::operator << ( const std::vector< T >& value )
00056     {
00057         const uint64_t nElems = value.size();
00058         *this << nElems;
00059         for( uint64_t i = 0; i < nElems; ++i )
00060             *this << value[i];
00061         return *this;
00062     }
00063 
00064     template< class K, class V > inline DataOStream&
00065     DataOStream::operator << ( const std::map< K, V >& value )
00066     {
00067         const uint64_t nElems = value.size();
00068         *this << nElems;
00069         for( typename std::map< K, V >::const_iterator it = value.begin();
00070              it != value.end(); ++it )
00071         {
00072             *this << it->first << it->second;
00073         }
00074         return *this;
00075     }
00076 
00077     template< class T > inline DataOStream&
00078     DataOStream::operator << ( const std::set< T >& value )
00079     {
00080         const uint64_t nElems = value.size();
00081         *this << nElems;
00082         for( typename std::set< T >::const_iterator it = value.begin();
00083              it != value.end(); ++it )
00084         {
00085             *this << *it;
00086         }
00087         return *this;
00088     }
00089 
00090     template< class K, class V > inline DataOStream&
00091     DataOStream::operator << ( const stde::hash_map< K, V >& value )
00092     {
00093         const uint64_t nElems = value.size();
00094         *this << nElems;
00095         for( typename stde::hash_map< K, V >::const_iterator it = value.begin();
00096              it != value.end(); ++it )
00097         {
00098             *this << it->first << it->second;
00099         }
00100         return *this;
00101     }
00102 
00103     template< class T > inline DataOStream&
00104     DataOStream::operator << ( const stde::hash_set< T >& value )
00105     {
00106         const uint64_t nElems = value.size();
00107         *this << nElems;
00108         for( typename stde::hash_set< T >::const_iterator it = value.begin();
00109              it != value.end(); ++it )
00110         {
00111             *this << *it;
00112         }
00113         return *this;
00114     }
00115 
00116     template< typename C > inline void
00117     DataOStream::serializeChildren( const std::vector<C*>& children )
00118     {
00119         const uint64_t nElems = children.size();
00120         (*this) << nElems;
00121 
00122         for( typename std::vector< C* >::const_iterator i = children.begin();
00123              i != children.end(); ++i )
00124         {
00125             C* child = *i;
00126             (*this) << ObjectVersion( child );
00127             LBASSERTINFO( !child || child->isAttached(),
00128                           "Found unmapped object during serialization" );
00129         }
00130     }
00134     template<> inline DataOStream&
00135     DataOStream::operator << ( const std::vector< uint8_t >& value )
00136     { return _writeFlatVector( value ); }
00137 
00139     template<> inline DataOStream&
00140     DataOStream::operator << ( const std::vector< uint16_t >& value )
00141     { return _writeFlatVector( value ); }
00142 
00144     template<> inline DataOStream&
00145     DataOStream::operator << ( const std::vector< int16_t >& value )
00146     { return _writeFlatVector( value ); }
00147 
00149     template<> inline DataOStream&
00150     DataOStream::operator << ( const std::vector< uint32_t >& value )
00151     { return _writeFlatVector( value ); }
00152 
00154     template<> inline DataOStream&
00155     DataOStream::operator << ( const std::vector< int32_t >& value )
00156     { return _writeFlatVector( value ); }
00157 
00159     template<> inline DataOStream&
00160     DataOStream::operator << ( const std::vector< uint64_t >& value )
00161     { return _writeFlatVector( value ); }
00162 
00164     template<> inline DataOStream&
00165     DataOStream::operator << ( const std::vector< int64_t >& value )
00166     { return _writeFlatVector( value ); }
00167 
00169     template<> inline DataOStream&
00170     DataOStream::operator << ( const std::vector< float >& value )
00171     { return _writeFlatVector( value ); }
00172 
00174     template<> inline DataOStream&
00175     DataOStream::operator << ( const std::vector< double >& value )
00176     { return _writeFlatVector( value ); }
00177 
00179     template<> inline DataOStream&
00180     DataOStream::operator << ( const std::vector< ObjectVersion >& value )
00181     { return _writeFlatVector( value ); }
00183 }
Generated on Mon Nov 26 2012 14:41:48 for Equalizer 1.4.1 by  doxygen 1.7.6.1