3 ms·
I've used Boost Fusion associative maps, in conjunction with a bit of glue code and an appropriate JSON or XML library, to provide pretty seemless serialisation
by nly 12y ago
I've used Boost Fusion associative maps, in conjunction with a bit of glue code and an appropriate JSON or XML library, to provide pretty seemless serialisation and de-serialisation for both XML and JSON for a while. For XML it's a little tricky because you have to have a means of mapping the simple flat relationship between a struct and its fields, to the various relationships between XML elements, subelements, attributes, and CDATA etc. Here's an example of what my declarations for XML look like in some code I wrote last year.
BOOST_FUSION_ADAPT_ADT (
xml_encoded<Description>,
XML_ATTR (string, "summary")
XML_TEXT (string)
)
BOOST_FUSION_ADAPT_ADT (
xml_encoded<Event>,
XML_ATTR (string, "name")
XML_SUBTREE (shared_ptr<Description const>, "description")
XML_ATTR (optional<unsigned>, "since")
)
The #defines for each macro are short, and beyond Fusion there's only a small support header
Here's a talk from CppConn describing a similar use case, but for binary data formats https://www.youtube.com/watch?v=wbZdZKpUVeg https://www.youtube.com/watch?v=wbZdZKpUVeg