C ++ - parameter issue

I am looking for a simple and efficient container of parameters that will act as a representation of an in-memory-xml file (or ini-file, as another example).

I mean, basically, it can store sections and parameter sets for each section, have simple accessors like GetValue("ParameterName") and a simple return value.

It would be great if it were serializable.

I wrote something similar yesterday and, well, it fits my needs, but maybe there is something more convenient and flexible available?

Maybe some kind of parameter map in boost ?

thanks

+4
source share
4 answers

Take a look at boost :: program_options . It does what you want and much more: parsing INI files, parsing environment variables, parsing options, and expanding the command line.

+8
source

Did you consider std :: map <> ?

+4
source

It is wrong if it is full or not, but the Message Class in MUSCLE does all of the above. You can use it to serialize any data (structured or not) or use it as a container in memory for parsed .ini style configuration files through ParseFile () / UnparseFile () .

+2
source

You can use Boost.PropertyTree .

It reads and writes xml and ini files.

Saves 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); 
+1
source

Source: https://habr.com/ru/post/1316725/


All Articles