开发者

C++ - parameter question

I am looking for some simple开发者_运维知识库 and efficient parameter container that would act like a in-memory-xml file representation (or ini-file, as another sample).

I mean, basically it could store sections and sets of parameters for each section, have easy accessors like GetValue("ParameterName") and simple return value casting.

It would be great if it is serializable.

I wrote something like that yesterday and, well, it suits my needs, but probably there is something more convenient and flexible available?

Maybe some kind of parameter map in boost?

Thank you


Take a look at boost::program_options. It does what you want and more: INI file parsing, environment variables parsing, commandline options parsing and extensibility.


Have you considered std::map<>?


Dunno if it's overkill or not, but the Message class in MUSCLE does all of the things you listed above. You can use it to serialize any kind of data (structured or not), or use it as an in-memory container for parsed .ini style config files via ParseFile()/UnparseFile().


You can use Boost.PropertyTree.

It reads and writes xml and ini files.

It stores the parameters as a tree and you can use dot notation to access the values:

std::string value = pt.get<std::string>("debug.filename");

You can also insert new values using:

pt.put("debug.filename", fileName);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜