问题
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:
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:
- Can persist / restore STL containers
- Is windows developer friendly (e.g. if it needs built, does it have a VS200x solution file)
- 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?
回答1:
Boost Serialization is what you need:
- serializing containers
- it's cross-platform and windows-friendly despite the fact that it doesn't have VS2008 solution file
- serializing derived class
[EDIT] actually I was wrong, it includes VS7.1 solution file
回答2:
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
来源:https://stackoverflow.com/questions/4804653/c-object-persistence-library-similar-to-eternity