Boost serialization end of file -
Boost serialization end of file -
i serialize multiple objects binary archive boost. when reading objects binary_iarchive
, there way know how many objects in archive or way observe end of archive ?
the way found utilize try-catch observe stream exception. in advance.
i can think of number of approaches:
serialize stl containers to/from archive (see documentation). archive automatically maintain track of how many objects there in containers.
serialize count variable before serializing objects. when reading objects, you'll know beforehand how many objects expect read back.
i find approach kinda gross, i'm listing anyway sake of completeness. :-p have lastly object deed kind of sentinel indicates end of list of objects. perhaps add together islast
fellow member variable object.
this not pretty, have separate "index file" alongside archive stores number of objects in archive.
use tellp
position of underlying stream object observe if you're @ end of file:
example:
std::streampos streamend = stream.seekp(0, std::ios_base::end).tellp(); stream.seekp(0, std::ios_base::beg); while (stream.tellp() < streamend) { // deserialize objects }
this might not work xml archives.
boost boost-serialization eof
Comments
Post a Comment