Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++: program settings - boost.PropertyTree or boost.program_options?

I was looking for a solution to store program settings or options or configuration in C++. These could be settings that are exposed in a GUI and need to be saved between runs of my code.

In my search I came across boost.PropertyTree which seemed to be a good choice. I know boost is well respected code so I'm comfortable using it and so I started developing using this. Then I come across boost.program_options which seems to allow you to do the same thing but also looks more specialized for the specific use-case of program settings.

Now I'm wondering which is the most appropriate for the job? (or is there a 3rd option that is better than both)

EDIT: fyi this is for a plugin so it will not use command line options (as in, it's not even possible).

UPDATE

I ended up sticking with boost.PropertyTree. I needed to be able to save changed options back to the INI, and I didn't see a way of doing that with boost.program_options.

like image 468
User Avatar asked May 09 '11 23:05

User


2 Answers

Use boost::program_options. It's exactly what it's for. In one library you get command line options, environment variables options and an INI-like configuration file parser. And they're all integrated together in the Right way, so when then the user specifies the same option in more than one of these sources the library knows the Right priority order to consider.

boost::property_tree on the other hand is a more generalized library. The library parses the text stream into a uniform data model. But You need to do the real parsing -- that of making sense of the blob of data for your needs. The library doesn't know when to expect a parameter when it sees a particular option string, or to disallow specific values or types of values for a particular option.

like image 75
wilhelmtell Avatar answered Oct 24 '22 01:10

wilhelmtell


After some digging around I think boost.PropertyTree is still the best solution because it gives me the capability to save the options after changing them from within the program which is a requirement.

like image 31
User Avatar answered Oct 23 '22 23:10

User