属性文件库C(或C ++) [英] Properties file library for C (or C++)

查看:153
本文介绍了属性文件库C(或C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题是pretty不言自明的:没有人知道的(好)属性文件阅读器库C或,如果没有,C ++

The title is pretty self-explanatory: does anyone know of a (good) properties file reader library for C or, if not, C++?

推荐答案

STLSoft 的的1.10阿尔法包含 platformstl :: properties_file 类。它可以被用来从文件读取

STLSoft's 1.10 alpha contains a platformstl::properties_file class. It can be used to read from a file:

using platformstl::properties_file;

properties_file  properties("stuff.properties");

properties_file::value_type  value = properties["name"];

或从存储器:

properties_file  properties(
    "name0=value1\n name1 value1 \n name\\ 2 : value\\ 2  ",
    properties_file::contents);

properties_file::value_type  value0 = properties["name0"];

properties_file::value_type  value1 = properties["name1"];

properties_file::value_type  value2 = properties["name 2"];

看起来像最新版本1.10有一堆的COM prehensive单元测试,而且他们已经升级类来处理在<给定的所有规则和示例href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load%28java.io.InputStream%29\">Java文档。

唯一明显擦的是, VALUE_TYPE 是<一个实例href=\"http://www.stlsoft.org/doc-1.9/classstlsoft%5F1%5F1basic%5F%5Fstring%5F%5Fview.html\"><$c$c>stlsoft::basic_string_view ,这有点类似于的std ::字符串这个博士道博的文章中描述) code>,但实际上不拥有它的存储器。他们这样做presumably,以避免不必要的拨款,presumably性能方面的原因,这是后话了STLSoft设计所珍视。但它意味着你不能只写

The only apparent rub is that the value_type is an instance of stlsoft::basic_string_view (described in this Dr Dobb's article), which is somewhat similar to std::string, but doesn't actually own its memory. Presumably they do this to avoid unneccessary allocations, presumably for performance reasons, which is something the STLSoft design holds dear. But it means that you can't just write

std::string  value0 = properties["name0"];

您可以,但是,这样做:

You can, however, do this:

std::string  value0 = properties["name0"].c_str();

和这样的:

std::cout << properties["name0"];

我不知道我同意这种设计的决定,因为它是如何可能的读取性能 - 从文件或从存储器 - 将需要绝对的最后一个周期。我觉得他们应该改变它在默认情况下使用的std ::字符串,然后使用字符串查看如果明确要求。

I'm not sure I agree with this design decision, since how likely is it that reading properties - from file or from memory - is going to need the absolute last cycle. I think they should change it to use std::string by default, and then use the "string view" if explicitly required.

除此之外,在 properties_file 类看起来像它的伎俩。

Other than that, the properties_file class looks like it does the trick.

这篇关于属性文件库C(或C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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