19 #include <co/object.h>
20 #include <co/objectVersion.h>
21 #include <servus/serializable.h>
33 LBASSERTINFO( nElems <= maxElems,
34 nElems <<
" > " << maxElems );
37 else if( nElems <= maxElems )
59 void DataIStream::_readSerializable( T&
object,
const boost::true_type& )
61 const size_t size = read< size_t >();
67 void DataIStream::_readArray( Array< T > array,
const boost::true_type& )
69 _read( array.data, array.getNumBytes( ));
75 void DataIStream::_readArray( Array< T > array,
const boost::false_type& )
77 for(
size_t i = 0; i < array.num; ++i )
78 *
this >> array.data[ i ];
82 void DataIStream::_readArray( Array< void > array,
const boost::false_type& )
84 _read( array.data, array.getNumBytes( ));
87 template<
class T >
inline DataIStream&
96 template<
class T >
inline DataIStream&
101 LBASSERTINFO( nElems < LB_BIT48,
102 "Out-of-sync co::DataIStream: " << nElems <<
" elements?" );
103 buffer.resize( nElems );
104 return *
this >> Array< T >( buffer.getData(), nElems );
108 template<
class T >
inline DataIStream&
113 value.resize( nElems );
114 for( uint64_t i = 0; i < nElems; ++i )
119 template<
class K,
class V >
inline DataIStream&
125 for( uint64_t i = 0; i < nElems; ++i )
127 typename std::map< K, V >::key_type key;
128 typename std::map< K, V >::mapped_type value;
129 *
this >> key >> value;
130 map.insert( std::make_pair( key, value ));
135 template<
class T >
inline DataIStream&
141 for( uint64_t i = 0; i < nElems; ++i )
145 value.insert( item );
150 template<
class K,
class V >
inline DataIStream&
156 for( uint64_t i = 0; i < nElems; ++i )
158 typename stde::hash_map< K, V >::key_type key;
159 typename stde::hash_map< K, V >::mapped_type value;
160 *
this >> key >> value;
161 map.insert( std::make_pair( key, value ));
166 template<
class T >
inline DataIStream&
172 for( uint64_t i = 0; i < nElems; ++i )
176 value.insert( item );
186 explicit ObjectFinder(
const uint128_t&
id ) : _id( id ) {}
188 {
return candidate->
getID() == _id; }
195 template<
typename O,
typename C >
inline void
196 DataIStream::deserializeChildren( O*
object,
const std::vector< C* >& old_,
197 std::vector< C* >& result )
199 ObjectVersions versions;
201 std::vector< C* > old = old_;
205 for( ObjectVersions::const_iterator i = versions.begin();
206 i != versions.end(); ++i )
208 const ObjectVersion& version = *i;
210 if( version.identifier == uint128_t( ))
212 result.push_back( 0 );
216 typename std::vector< C* >::iterator j =
217 lunchbox::find_if( old, ObjectFinder( version.identifier ));
222 object->create( &child );
225 LBASSERT( !object->isMaster( ));
227 LBCHECK( localNode->mapObject( child, version ));
228 result.push_back( child );
234 if( object->isMaster( ))
235 child->sync( VERSION_HEAD );
237 child->sync( version.version );
239 result.push_back( child );
243 while( !old.empty( ))
245 C* child = old.back();
250 if( child->isAttached() && !child->isMaster( ))
253 localNode->unmapObject( child );
255 object->release( child );
261 template<>
inline DataIStream&
263 {
return _readFlatVector( value );}
268 {
return _readFlatVector( value ); }
273 {
return _readFlatVector( value ); }
278 {
return _readFlatVector( value ); }
283 {
return _readFlatVector( value ); }
288 {
return _readFlatVector( value ); }
293 {
return _readFlatVector( value ); }
298 {
return _readFlatVector( value ); }
303 {
return _readFlatVector( value ); }
308 {
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
Object-oriented network library.
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.