C++ object persistence library similar to eternity

4.2k views Asked by At

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?

2

There are 2 answers

3
Andriy Tylychko On BEST ANSWER

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

2
Andriy Tylychko On

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