views:

110

answers:

4

Hello!

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

+4  A: 

Have you considered std::map<>?

jeffamaphone
Right now I am using a wrapper around `boost::unordered_map` which could be easily switched, to `std::map` (still I really enjoy hash-based structures :) But `boost` and other template libraries are actually known for their solutions to any problems, so, I thought that something more convenient may exist...
HardCoder1986
Considering he is going to use std::map, I wonder what could be the simplest way to serialize it?
Vargas
@Vargas **`boost::serialize`, I suspect.** In my case I had to write custom serialization routine for `boost::unordered_map` and, well, it's not that tough as it seems first :)
HardCoder1986
+8  A: 

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.

wilhelmtell
+2  A: 

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().

Jeremy Friesner
+1  A: 

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);
J. Calleja