C++轻量级配置库

C++ lightweight configuration library

本文关键字:配置 轻量级 C++      更新时间:2023-10-16

我正在寻找具有非限制性许可证的跨平台C++轻量级配置库。我需要比带有部分的标准属性文件更复杂的东西,但我不想使用 XML(写得太多:-((。

我想这样写配置:

render = 
{
    window = 
    {
        width = 800,
        height = 600
    }
}

有 boost 的property_tree。该许可证允许商业用途。

您的示例:

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

例如,这可以导出为 JSON

write_json("my_config.json", pt);

然后看起来像

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

导出到 XML、INI 和 INFO 的方式相同。

您也可以尝试 JsonCpp 并用 Json 编写配置文件,它的语法与您喜欢的语法非常相似:

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

MIT License下,所以非常宽容。