C++类似于eternity的对象持久化库
我正在寻找一个 C++ 对象持久性库来替换我已经使用的 Eternity 库进行了大约一天的原型制作。永恒图书馆的能力不足。
我创建了一个与此类似的对象层次结构:
我有一个 std::list
我想以 XML 格式保存和恢复的 ArchiveJob*
。每个ArchiveJob 都有各种子对象,有些分配在堆栈上,有些分配在堆上。
Eternity 在正确持久化这些对象方面做得很好,但在恢复它们时却失败了。
(对于熟悉 Eternity 的人来说,以下“恢复”操作无法从 XML 文件中读取任何数据)
xml_read( sequence<pointers>(), *pList, pList->begin(), xml, "ScheduleList" );
此调用为 ArchiveJob
对象分配了内存,但其所有子级都未初始化。
有人可以推荐一个对象层次结构持久性解决方案吗?它:
- 可以持久/恢复 STL 容器
- Windows 开发人员友好(例如,如果需要构建,它是否有 VS200x 解决方案文件)
- 可以处理复杂的对象层次结构
我应该花时间学习 使用 boost 进行 XML 序列化?它如何处理存储在 STL 容器的主对象中的复杂对象层次结构?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Boost Serialization 是您所需要的:
[编辑]实际上我错了,它包括 VS7.1解决方案文件
Boost Serialization is what you need:
[EDIT] actually I was wrong, it includes VS7.1 solution file
另一种选择是 Google Protocol Buffers。如果您严格遵守 XML,它不是基于 XML 的。它也有点复杂,因为您需要在外部文件中使用特殊语法。关于层次结构,您可以阅读此讨论
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