18 #include <co/object.h>
19 #include <co/objectVersion.h>
29 const uint64_t nElems = str.length();
30 _write( &nElems,
sizeof( nElems ));
32 _write( str.c_str(), nElems );
48 DataOStream::operator << ( const lunchbox::Buffer< T >& buffer )
50 return (*
this) << buffer.getSize()
54 template<
class T >
inline DataOStream&
55 DataOStream::operator << ( const std::vector< T >& value )
57 const uint64_t nElems = value.size();
59 for( uint64_t i = 0; i < nElems; ++i )
64 template<
class K,
class V >
inline DataOStream&
65 DataOStream::operator << ( const std::map< K, V >& value )
67 const uint64_t nElems = value.size();
69 for(
typename std::map< K, V >::const_iterator it = value.begin();
70 it != value.end(); ++it )
72 *
this << it->first << it->second;
77 template<
class T >
inline DataOStream&
78 DataOStream::operator << ( const std::set< T >& value )
80 const uint64_t nElems = value.size();
82 for(
typename std::set< T >::const_iterator it = value.begin();
83 it != value.end(); ++it )
90 template<
class K,
class V >
inline DataOStream&
91 DataOStream::operator << ( const stde::hash_map< K, V >& value )
93 const uint64_t nElems = value.size();
95 for(
typename stde::hash_map< K, V >::const_iterator it = value.begin();
96 it != value.end(); ++it )
98 *
this << it->first << it->second;
103 template<
class T >
inline DataOStream&
104 DataOStream::operator << ( const stde::hash_set< T >& value )
106 const uint64_t nElems = value.size();
108 for(
typename stde::hash_set< T >::const_iterator it = value.begin();
109 it != value.end(); ++it )
116 template<
typename C >
inline void
117 DataOStream::serializeChildren(
const std::vector<C*>& children )
119 const uint64_t nElems = children.size();
122 for(
typename std::vector< C* >::const_iterator i = children.begin();
123 i != children.end(); ++i )
126 (*this) << ObjectVersion( child );
127 LBASSERTINFO( !child || child->isAttached(),
128 "Found unmapped object during serialization" );
134 template<>
inline DataOStream&
135 DataOStream::operator << ( const std::vector< uint8_t >& value )
136 {
return _writeFlatVector( value ); }
140 DataOStream::operator << ( const std::vector< uint16_t >& value )
141 {
return _writeFlatVector( value ); }
145 DataOStream::operator << ( const std::vector< int16_t >& value )
146 {
return _writeFlatVector( value ); }
150 DataOStream::operator << ( const std::vector< uint32_t >& value )
151 {
return _writeFlatVector( value ); }
155 DataOStream::operator << ( const std::vector< int32_t >& value )
156 {
return _writeFlatVector( value ); }
160 DataOStream::operator << ( const std::vector< uint64_t >& value )
161 {
return _writeFlatVector( value ); }
165 DataOStream::operator << ( const std::vector< int64_t >& value )
166 {
return _writeFlatVector( value ); }
170 DataOStream::operator << ( const std::vector< float >& value )
171 {
return _writeFlatVector( value ); }
175 DataOStream::operator << ( const std::vector< double >& value )
176 {
return _writeFlatVector( value ); }
180 DataOStream::operator << ( const std::vector< ObjectVersion >& value )
181 {
return _writeFlatVector( value ); }
A wrapper to (de)serialize arrays.
CO_API bool isAttached() const
A helper struct bundling an object identifier and version.
A std::ostream-like interface for object serialization.
DataOStream & operator<<(const T &value)
Write a plain data item by copying it to the stream.