Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ lightweight configuration library

I'm looking for a cross-platform C++ lighweight configuration library with non restrictive licence. I need something more complex than standard properties file with sections, but I don't want to use XML (too much writing :-)).

I would like to write configuration this way:

render = 
{
    window = 
    {
        width = 800,
        height = 600
    }
}
like image 586
runnydead Avatar asked Feb 12 '12 10:02

runnydead


2 Answers

There's boost's property_tree. The license allows commercial use.

Your example:

ptree pt;
pt.put("render.window.width", 800);
pt.put("render.window.height", 600);

This can e.g. be exported to JSON

write_json("my_config.json", pt);

which will then look like

{
  "render":
  {
    "window":
    {
      "width": 800;
      "height": 600;
    }
  }
}

The same way you can export to XML, INI and INFO.

like image 112
Karl von Moor Avatar answered Nov 20 '22 01:11

Karl von Moor


You can also try JsonCpp and write your configuration files in Json, which has a very similar syntax to the one you like:

// Configuration options
{
    // Default encoding for text
    "encoding" : "UTF-8",

    // Plug-ins loaded at start-up
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],

    // Tab indent size
    "indent" : { "length" : 3, "use_space": true }
}

Is under the MIT License so it's very permissive.

like image 23
Daniele Santi Avatar answered Nov 20 '22 01:11

Daniele Santi