19 #include <co/object.h>
20 #include <co/objectVersion.h>
32 LBASSERTINFO( nElems <= maxElems,
33 nElems <<
" > " << maxElems );
36 else if( nElems <= maxElems )
59 void DataIStream::_readArray( Array< T > array,
const boost::true_type& )
61 _read( array.data, array.getNumBytes( ));
67 void DataIStream::_readArray( Array< T > array,
const boost::false_type& )
69 for(
size_t i = 0; i < array.num; ++i )
70 *
this >> array.data[ i ];
73 template<
class T >
inline DataIStream&
82 template<
class T >
inline DataIStream&
87 LBASSERTINFO( nElems < LB_BIT48,
88 "Out-of-sync co::DataIStream: " << nElems <<
" elements?" );
89 buffer.resize( nElems );
90 return *
this >> Array< T >( buffer.getData(), nElems );
94 template<
class T >
inline DataIStream&
99 value.resize( nElems );
100 for( uint64_t i = 0; i < nElems; ++i )
105 template<
class K,
class V >
inline DataIStream&
111 for( uint64_t i = 0; i < nElems; ++i )
113 typename std::map< K, V >::key_type key;
114 typename std::map< K, V >::mapped_type value;
115 *
this >> key >> value;
116 map.insert( std::make_pair( key, value ));
121 template<
class T >
inline DataIStream&
127 for( uint64_t i = 0; i < nElems; ++i )
131 value.insert( item );
136 template<
class K,
class V >
inline DataIStream&
142 for( uint64_t i = 0; i < nElems; ++i )
144 typename stde::hash_map< K, V >::key_type key;
145 typename stde::hash_map< K, V >::mapped_type value;
146 *
this >> key >> value;
147 map.insert( std::make_pair( key, value ));
152 template<
class T >
inline DataIStream&
158 for( uint64_t i = 0; i < nElems; ++i )
162 value.insert( item );
172 explicit ObjectFinder(
const uint128_t&
id ) : _id( id ) {}
174 {
return candidate->
getID() == _id; }
181 template<>
inline void DataIStream::_swap( Array< void > )
const { }
183 template<
typename O,
typename C >
inline void
184 DataIStream::deserializeChildren( O*
object,
const std::vector< C* >& old_,
185 std::vector< C* >& result )
187 ObjectVersions versions;
189 std::vector< C* > old = old_;
193 for( ObjectVersions::const_iterator i = versions.begin();
194 i != versions.end(); ++i )
196 const ObjectVersion& version = *i;
198 if( version.identifier == uint128_t( ))
200 result.push_back( 0 );
204 typename std::vector< C* >::iterator j =
205 lunchbox::find_if( old, ObjectFinder( version.identifier ));
210 object->create( &child );
213 LBASSERT( !object->isMaster( ));
215 LBCHECK( localNode->mapObject( child, version ));
216 result.push_back( child );
222 if( object->isMaster( ))
223 child->sync( VERSION_HEAD );
225 child->sync( version.version );
227 result.push_back( child );
231 while( !old.empty( ))
233 C* child = old.back();
238 if( child->isAttached() && !child->isMaster( ))
241 localNode->unmapObject( child );
243 object->release( child );
249 template<>
inline DataIStream&
251 {
return _readFlatVector( value );}
256 {
return _readFlatVector( value ); }
261 {
return _readFlatVector( value ); }
266 {
return _readFlatVector( value ); }
271 {
return _readFlatVector( value ); }
276 {
return _readFlatVector( value ); }
281 {
return _readFlatVector( value ); }
286 {
return _readFlatVector( value ); }
291 {
return _readFlatVector( value ); }
296 {
return _readFlatVector( value ); }
CO_API const uint128_t & getID() const
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
A helper struct bundling an object identifier and version.
uint128_t identifier
the object identifier
CO_API const void * getRemainingBuffer(const uint64_t size)
DataIStream & operator>>(T &value)
Read a plain data item.
uint128_t version
the object version
CO_API uint64_t getRemainingBufferSize()
A std::istream-like input data stream for binary data.