“最佳”输入C ++的文件格式? [英] "Best" Input File Formats for C++?

查看:113
本文介绍了“最佳”输入C ++的文件格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用一个新的软件,最终需要一些强大的可扩展文件IO。有很多格式。 XML,JSON,INI等。但是,总是有瑕疵和迷你,所以我想我会要求一些社区的投入。

I am starting work on a new piece of software that will end up needing some robust and expandable file IO. There are a lot of formats out there. XML, JSON, INI, etc. However, there are always plusses and minuses so I thought I would ask for some community input.

以下是一些粗略的要求:

Here are some rough requirements:


  1. ...我不想重塑轮子,如果我不必。它不必是一个正式的IEEE标准,但你可以Google和获得一些信息作为一个新用户,可能有一些支持工具(编辑)超出vi。 (虽然软件用户通常都是计算机熟练且乐于使用vi。)

  2. 轻松与C ++集成。

  3. 支持表格输入(2d,n-dimensional)
  4. $不支持。 b $ b
  5. 支持POD类型

  6. 可以扩展为需要更多输入,与变量绑定等。

  7. 解析速度不非常重要

  8. 理想情况下可以轻松写入(反映)阅读

  9. 在Windows和Linux上运行良好

  10. 支持合成(一个文件引用要读取的其他文件等)。

  11. 人类可读。

  1. The format is a "standard"...I don't want to reinvent the wheel if I don't have to. It doesn't have to be a formal IEEE standard, but something you could Google and get some information on as a new user, may have some support tools (editors) beyond vi. (Though the software users will generally be computer savvy and happy to use vi.)
  2. Easily integrates with C++. I don't want to have to pull along a 100mb library and three different compilers to get it up and running.
  3. Supports tabular input (2d, n-dimensional)
  4. Supports POD types
  5. Can expand as more inputs are required, binds well to variables, etc.
  6. Parsing speed is not terribly important
  7. Ideally, as easy to write (reflect) as it is to read
  8. Works well on Windows and Linux
  9. Supports compositing (one file referencing another file to read, and so on.)
  10. Human Readable

在一个完美的世界里,我将使用一个只有头文件的库或一些干净的STL实现,但是如果它工作良好,我可以利用Boost或一些小的外部库。

In a perfect world, I would use a header-only library or some clean STL implementation, but I'm fine with leveraging Boost or some small external library if it works well.

那么,你对各种格式的想法是什么?缺点?优点?

So, what are your thoughts on various formats? Drawbacks? Advantages?

编辑

要考虑的选项?还有什么要添加的吗?

Options to consider? Anything else to add?


  • XML

  • YAML

  • SQLite

  • Google协议缓冲

  • Boost序列化

  • INI

  • JSON

  • XML
  • YAML
  • SQLite
  • Google Protocol Buffers
  • Boost Serialization
  • INI
  • JSON

推荐答案

为了我的目的, XML 。

For my purposes, I think the way to go is XML.


  1. 格式是一种标准格式,但允许修改和灵活性,以便随着计划需求的变化而更改模式。

  2. 有多个库选项。有些是较大的(Xerces-C),有些是较小的(ezxml),但有很多选项,所以我们不会锁定在一个提供者或非常具体的解决方案。

  3. 可以支持表格输入(2d,n维)。这需要在我们端进行更多的解析工作,而且可能是XML的最薄弱点。

  4. 支持POD类型:绝对。

  5. 因为需要更多的输入,通过模式修改和解析器修改很好地绑定到变量等。

  6. 解析速度并不是非常重要,因此处理文本文件不是问题。

  7. XML可以以编程方式写入,就像读取一样简单。

  8. 在Windows和Linux或任何其他支持C和文本文件的操作系统上运行良好。

  9. 支持合成(一个文件引用另一个文件,

  10. 人类可读的许多文本编辑器(Sublime,vi等)支持语法突出显示的开箱即用。许多网络浏览器显示的数据很好。

  1. The format is a standard, but allows for modification and flexibility for the schema to change as the program requirements evolve.
  2. There are several library options. Some are larger (Xerces-C) some are smaller (ezxml), but there are many options, so we won't be locked in to a single provider or very specific solution.
  3. It can supports tabular input (2d, n-dimensional). This requires more parsing work on "our" end, and is likely the weakest point for XML.
  4. Supports POD types: Absolutely.
  5. Can expand as more inputs are required, binds well to variables, etc. through schema modifications and parser modifications.
  6. Parsing speed is not terribly important, so processing a text file or files is not an issue.
  7. XML can be programmatically written just as easily as read.
  8. Works well on Windows and Linux or any other OS that supports C and text files.
  9. Supports compositing (one file referencing another file to read, and so on.)
  10. Human Readable with many text editors (Sublime, vi, etc.) supporting syntax highlighting out of the box. Many web browsers display the data well.

感谢所有伟大的反馈!我想如果我们想要一个纯二进制解决方案,Protocol Buffers或boost :: serialization可能是我们去的方式。

Thanks for all the great feedback! I think if we wanted a purely binary solution, Protocol Buffers or boost::serialization is likely the way that we would go.

这篇关于“最佳”输入C ++的文件格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆