19 #include <co/object.h> 20 #include <co/objectVersion.h> 21 #include <lunchbox/algorithm.h> 22 #include <servus/serializable.h> 35 LBASSERTINFO(nElems <= maxElems, nElems <<
" > " << maxElems);
38 else if (nElems <= maxElems)
60 void DataIStream::_readSerializable(T&
object,
const boost::true_type&)
62 const size_t size = read<size_t>();
68 void DataIStream::_readArray(Array<T> array,
const boost::true_type&)
70 _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 inline void DataIStream::_readArray(Array<void> array,
const boost::false_type&)
84 _read(array.data, array.getNumBytes());
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);
112 value.resize(nElems);
113 for (uint64_t i = 0; i < nElems; ++i)
118 template <
class K,
class V>
124 for (uint64_t i = 0; i < nElems; ++i)
126 typename std::map<K, V>::key_type key;
127 typename std::map<K, V>::mapped_type value;
128 *
this >> key >> value;
129 map.insert(std::make_pair(key, value));
140 for (uint64_t i = 0; i < nElems; ++i)
149 template <
class K,
class V>
155 for (uint64_t i = 0; i < nElems; ++i)
156 map.insert({read<K>(), read<V>()});
166 for (uint64_t i = 0; i < nElems; ++i)
167 value.insert(read<T>());
176 explicit ObjectFinder(
const uint128_t&
id)
180 bool operator()(
co::Object* candidate) {
return candidate->
getID() == _id; }
186 template <
typename O,
typename C>
187 inline void DataIStream::deserializeChildren(O*
object,
188 const std::vector<C*>& old_,
189 std::vector<C*>& result)
191 ObjectVersions versions;
193 std::vector<C*> old = old_;
197 for (ObjectVersions::const_iterator i = versions.begin();
198 i != versions.end(); ++i)
208 typename std::vector<C*>::iterator j =
209 lunchbox::find_if(old, ObjectFinder(version.
identifier));
214 object->create(&child);
217 LBASSERT(!object->isMaster());
219 LBCHECK(localNode->mapObject(child, version));
220 result.push_back(child);
226 if (object->isMaster())
227 child->sync(VERSION_HEAD);
231 result.push_back(child);
237 C* child = old.back();
242 if (child->isAttached() && !child->isMaster())
245 localNode->unmapObject(child);
247 object->release(child);
256 return _readFlatVector(value);
263 return _readFlatVector(value);
270 return _readFlatVector(value);
277 return _readFlatVector(value);
284 return _readFlatVector(value);
291 return _readFlatVector(value);
298 return _readFlatVector(value);
305 return _readFlatVector(value);
312 return _readFlatVector(value);
319 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.