19 #include <co/object.h>
20 #include <co/objectVersion.h>
61 template<
class T >
inline DataIStream&
66 LBASSERTINFO( nElems < LB_BIT48,
67 "Out-of-sync co::DataIStream: " << nElems <<
" elements?" );
68 buffer.resize( nElems );
69 return *
this >> Array< T >( buffer.getData(), nElems );
73 template<
class T >
inline DataIStream&
78 value.resize( nElems );
79 for( uint64_t i = 0; i < nElems; ++i )
84 template<
class K,
class V >
inline DataIStream&
90 for( uint64_t i = 0; i < nElems; ++i )
92 typename std::map< K, V >::key_type key;
93 typename std::map< K, V >::mapped_type value;
94 *
this >> key >> value;
95 map.insert( std::make_pair( key, value ));
100 template<
class T >
inline DataIStream&
106 for( uint64_t i = 0; i < nElems; ++i )
110 value.insert( item );
115 template<
class K,
class V >
inline DataIStream&
121 for( uint64_t i = 0; i < nElems; ++i )
123 typename stde::hash_map< K, V >::key_type key;
124 typename stde::hash_map< K, V >::mapped_type value;
125 *
this >> key >> value;
126 map.insert( std::make_pair( key, value ));
131 template<
class T >
inline DataIStream&
137 for( uint64_t i = 0; i < nElems; ++i )
141 value.insert( item );
151 ObjectFinder(
const UUID&
id ) : _id( id ) {}
153 {
return candidate->
getID() == _id; }
160 template<>
inline void DataIStream::_swap( Array< void > )
const { }
162 template<
typename O,
typename C >
inline void
163 DataIStream::deserializeChildren( O*
object,
const std::vector< C* >& old_,
164 std::vector< C* >& result )
166 ObjectVersions versions;
168 std::vector< C* > old = old_;
172 for( ObjectVersions::const_iterator i = versions.begin();
173 i != versions.end(); ++i )
175 const ObjectVersion& version = *i;
177 if( version.identifier == UUID( ))
179 result.push_back( 0 );
183 typename std::vector< C* >::iterator j =
184 lunchbox::find_if( old, ObjectFinder( version.identifier ));
189 object->create( &child );
192 LBASSERT( !object->isMaster( ));
194 LBCHECK( localNode->mapObject( child, version ));
195 result.push_back( child );
201 if( object->isMaster( ))
202 child->sync( VERSION_HEAD );
204 child->sync( version.version );
206 result.push_back( child );
210 while( !old.empty( ))
212 C* child = old.back();
217 if( child->isAttached() && !child->isMaster( ))
220 localNode->unmapObject( child );
222 object->release( child );
228 template<>
inline DataIStream&
230 {
return _readFlatVector( value );}
235 {
return _readFlatVector( value ); }
240 {
return _readFlatVector( value ); }
245 {
return _readFlatVector( value ); }
250 {
return _readFlatVector( value ); }
255 {
return _readFlatVector( value ); }
260 {
return _readFlatVector( value ); }
265 {
return _readFlatVector( value ); }
270 {
return _readFlatVector( value ); }
275 {
return _readFlatVector( value ); }
A wrapper to (de)serialize arrays.
CO_API const void * getRemainingBuffer(const uint64_t size)
uint128_t version
the object version
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
A helper struct bundling an object identifier and version.
size_t getNumBytes() const
uint128_t identifier
the object identifier
A std::istream-like input data stream for binary data.
CO_API uint64_t getRemainingBufferSize()
DataIStream & operator>>(T &value)
Read a plain data item.
CO_API const UUID & getID() const