19 #include <co/object.h>
20 #include <co/objectVersion.h>
30 const uint64_t nElems = str.length();
31 _write( &nElems,
sizeof( nElems ));
33 _write( str.c_str(), nElems );
48 template<
class T >
inline
49 DataOStream& DataOStream::operator << ( const lunchbox::RefPtr< T >& ptr )
51 return *
this << ptr.get();
54 template<
class T >
inline
55 DataOStream& DataOStream::operator << ( const lunchbox::Buffer< T >& buffer )
57 return (*
this) << buffer.getSize()
58 << Array< const T >( buffer.getData(), buffer.getSize());
61 template<
class T >
inline
62 DataOStream& DataOStream::operator << ( const std::vector< T >& value )
64 const uint64_t nElems = value.size();
66 for( uint64_t i = 0; i < nElems; ++i )
71 template<
class K,
class V >
inline
72 DataOStream& DataOStream::operator << ( const std::map< K, V >& value )
74 const uint64_t nElems = value.size();
76 for(
typename std::map< K, V >::const_iterator it = value.begin();
77 it != value.end(); ++it )
79 *
this << it->first << it->second;
84 template<
class T >
inline
85 DataOStream& DataOStream::operator << ( const std::set< T >& value )
87 const uint64_t nElems = value.size();
89 for(
typename std::set< T >::const_iterator it = value.begin();
90 it != value.end(); ++it )
97 template<
class K,
class V >
inline
98 DataOStream& DataOStream::operator << ( const stde::hash_map< K, V >& value )
100 const uint64_t nElems = value.size();
102 for(
typename stde::hash_map< K, V >::const_iterator it = value.begin();
103 it != value.end(); ++it )
105 *
this << it->first << it->second;
110 template<
class T >
inline
111 DataOStream& DataOStream::operator << ( const stde::hash_set< T >& value )
113 const uint64_t nElems = value.size();
115 for(
typename stde::hash_set< T >::const_iterator it = value.begin();
116 it != value.end(); ++it )
123 template<
typename C >
inline
124 void DataOStream::serializeChildren(
const std::vector<C*>& children )
126 const uint64_t nElems = children.size();
129 for(
typename std::vector< C* >::const_iterator i = children.begin();
130 i != children.end(); ++i )
133 (*this) << ObjectVersion( child );
134 LBASSERTINFO( !child || child->isAttached(),
135 "Found unmapped object during serialization" );
142 DataOStream& DataOStream::operator << ( const std::vector< uint8_t >& value )
143 {
return _writeFlatVector( value ); }
147 DataOStream& DataOStream::operator << ( const std::vector< uint16_t >& value )
148 {
return _writeFlatVector( value ); }
152 DataOStream& DataOStream::operator << ( const std::vector< int16_t >& value )
153 {
return _writeFlatVector( value ); }
157 DataOStream& DataOStream::operator << ( const std::vector< uint32_t >& value )
158 {
return _writeFlatVector( value ); }
162 DataOStream& DataOStream::operator << ( const std::vector< int32_t >& value )
163 {
return _writeFlatVector( value ); }
167 DataOStream& DataOStream::operator << ( const std::vector< uint64_t >& value )
168 {
return _writeFlatVector( value ); }
172 DataOStream& DataOStream::operator << ( const std::vector< int64_t >& value )
173 {
return _writeFlatVector( value ); }
177 DataOStream& DataOStream::operator << ( const std::vector< float >& value )
178 {
return _writeFlatVector( value ); }
182 DataOStream& DataOStream::operator << ( const std::vector< double >& value )
183 {
return _writeFlatVector( value ); }
187 DataOStream::operator << ( const std::vector< ObjectVersion >& value )
188 {
return _writeFlatVector( value ); }
DataOStream & operator<<(const T &value)
Write a plain data item by copying it to the stream.
A helper struct bundling an object identifier and version.
CO_API bool isAttached() const
A std::ostream-like interface for object serialization.