C++ object persistence library similar to eternity
Asked Answered
S

2

2

I'm looking for a C++ object persistence library to replace the Eternity library that I've been prototyping with for about a day. The Eternity library came up short.

I've created an object hierarchy similar to this:

object heirarchy

I have an std::list of ArchiveJob*'s that I'd like to persist and restore in XML format. Each ArchiveJob has various child objects, some allocated on the stack, some on the heap.

Eternity did a good job of persisting these objects correctly, but it failed when restoring them.

(for those familiar with Eternity, the following "restore" operation failed to read any data from the XML file)

xml_read( sequence<pointers>(), *pList, pList->begin(), xml, "ScheduleList" );

This call allocated memory for the ArchiveJob object, but all its children were uninitialized.

Can someone recommend an object hierarchy persistence solution that:

  1. Can persist / restore STL containers
  2. Is windows developer friendly (e.g. if it needs built, does it have a VS200x solution file)
  3. Can handle complex object hierarchies

Should I spend time learning XML serialization with boost? How does it handle complex object hierarchies stored in a master object in an STL container?

Spyglass answered 26/1, 2011 at 12:39 Comment(0)
L
4

Boost Serialization is what you need:

  1. serializing containers
  2. it's cross-platform and windows-friendly despite the fact that it doesn't have VS2008 solution file
  3. serializing derived class

[EDIT] actually I was wrong, it includes VS7.1 solution file

Lizettelizotte answered 26/1, 2011 at 13:19 Comment(3)
have you had any experience of using boost serialization to serialize object heirarchies like this - did you run into any roadblocks, or did you find it easy to use?Spyglass
yeah, i used it for MMORPG, with custom binary archiver (more portable than one from the library examples). my hierarchy was simple enough, no roadblocks. documentation structure could be a bit better, but it's not a big dealLizettelizotte
Update: I've implemented the solution using boost::serialization. It's brilliant - I'm converted - I'll be using boost::serialization for all my projects that require it !!!Spyglass
L
0

another alternative is Google Protocol Buffers. It's not XML based if you're bound strictly to XML. It's also a bit more complicated since you need to use special syntax in external files. About hierarchy you can read this discussion

Lizettelizotte answered 26/1, 2011 at 14:52 Comment(2)
I'd had a look at Google Protocol Buffers in the past, and I didn't consider them suitable for my purposes. I've just written a prototype for and am extremely pleased with Boost Serialization. It's a bit of a pain having to build the damn thing though - especially when you've got more than one version of VC installed!Spyglass
I'd just recently found boostpro.com. Boost libraries built and distributed with a nice setup file. Great stuff! They should put a link to the boostpro website on boost dot org ;)Spyglass

© 2022 - 2024 — McMap. All rights reserved.