runnydead
runnydead

Reputation: 628

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
    }
}

Upvotes: 16

Views: 25427

Answers (2)

Daniele Santi
Daniele Santi

Reputation: 771

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.

Upvotes: 5

Karl von Moor
Karl von Moor

Reputation: 8614

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.

Upvotes: 15

Related Questions