Im trying to learn how to use serialization/deserialization at the moment, using cereal. To test things out, I serialized the objects of a 3D scene into a .xml file (it's easier to understand when you can actually read the output, after all). The serialization works without problems, and the deserialization also seems to do so. When I now want to recreate the objects, I have no problem accessing the first one...but how do I get the rest ?
Serialization in the .cpp (abbreviated):
std::ofstream os("testdata.xml");
for (int i=0; i<alloftheobjects; i++)
{
3DObject *Object = new 3DObject;
Object->ID = ID;
Object->vertices = vectorOfPoints;
Object->triangles = vectorOfTriangles;
cereal::XMLOutputArchive archive(os);
archive(cereal::make_nvp("ID", Object->ID),
cereal::make_nvp("Points", Object->vertices),
cereal::make_nvp("Triangles", Object->triangles));
delete Object;
}
It works, and creates testdata.xml, looking something like this:
<?xml version="1.0" encoding="utf-8"?>
<cereal>
<ID>0111</ID>
<Points size="dynamic">
<value0 size="dynamic">
<value0>-5</value0>
<value1>-5</value1>
<value2>1</value2>
</value0>
....rest of the points
</Points >
<Triangles size="dynamic">
...triangle data
</Triangles>
</cereal>
<?xml version="1.0" encoding="utf-8"?>
<cereal>
<ID>0112</ID>
<Points size="dynamic">
...pointdata
</Points >
<Triangles size="dynamic">
...triangle data
</Triangles>
</cereal>
...
etc.
When I now use
std::ifstream is("testsdata.xml");
cereal::XMLInputArchive archive(is);
int ID;
std::vector<std::vector<double>> vertices;
std::vector<std::vector<int>> triangles;
archive(ID, vertices, triangles);
to deserialize, it compiles, runs and I can access the first set of data (ID, vertices, triangles, up to the first </cereal>
. But I have no bloody clue how I can access the rest of it.
It is quite possible that Im missing something blatantly obvious and Im overlooking something while staring right at it. But Im also not sure if serializing the data this way is even a sound approach.