|
Boost : |
From: Marcin Kalicinski (kalita_at_[hidden])
Date: 2006-04-21 18:26:39
> However, after thinking of how ptree compares to boost::serialization,
> I can't take away from my mind the idea that someone should
> assess the possibility to create a boost::serialization archive
> that reads/writes objects to/from an in-memory ptree.
> It seems feasible since boost::serialization can i/o to XML.
>
> Similarly, we should then be able to use boost::serialization
> to i/o ptree to an xml file - preferably resulting in the
> exact same data as if objects had been serialized directly
> to XML.
I'm really pleased to say I have already done that. It is indeed simple,
about 100 lines of code for input and output archives. The implementation of
ptree_archive class is not first class at the moment (it's rather a quick
hack), so I refrain from posting it at the moment.
But please have a look at this sample of how serialization data looks in
JSON format. To create that I just used write_json() after writing some
simple C++ data structures to ptree by means of ptree_archive:
{
"d":
{
"class_id_type": "1",
"class_name_type": "class Derived",
"tracking_type": "0",
"version_type": "0",
"Base":
{
"class_id_optional_type": "0",
"tracking_type": "0",
"version_type": "0",
"b": "78"
},
"d": "111"
},
"d2":
{
"class_id_type": "1",
"Base":
{
"b": "11"
},
"d": "146"
},
"b":
{
"class_id_type": "0",
"b": "52"
},
"i": "3",
"v":
{
"class_id_optional_type": "2",
"tracking_type": "0",
"version_type": "0",
"count": "5",
"item":
{
"count": "3",
"item": "1",
"item": "2",
"item": "3"
},
"item":
{
"count": "0"
},
"item":
{
"count": "0"
},
"item":
{
"count": "0"
},
"item":
{
"count": "0"
}
}
}
Note how all the housekeeping stuff (class_ids, tracking_ids etc.) makes is
unsuitable for hand-editing.
Best regards,
Marcin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk