fra*_*ans 19 c++ boost-propertytree
我正在寻找一个行为类似于boost::property_tree但(可选)将每个值项的get/set实现留给开发人员的数据结构.
你应该可以做这样的事情:
std::function<int(void)> f_foo = ...;
my_property_tree tree;
tree.register<int>("some.path.to.key", f_foo);
auto v1 = tree.get<int>("some.path.to.key"); // <-- calls f_foo
auto v2 = tree.get<int>("some.other.path"); // <-- some fallback or throws exception
Run Code Online (Sandbox Code Playgroud)
我想你可能会滥用property_tree这个但是我还没有考虑过实现,除非我知道这是一个预期的用例,否则我会对此感到不好.
编写一个处理请求的类,例如val = tree.get("some.path.to.key")通过调用提供的函数,首先看起来并不太难,但我可以想象很多特殊情况会使这个庞大的库变得庞大.
一些额外的功能可能是:
子树处理:不仅处理终端密钥,而且将某些子树转发给单独的实现.例如
tree.register("some.path.config", some_handler);
// calls some_handler.get<int>("network.hostname")
v = tree.get<int>("some.path.config.network.hostname");
Run Code Online (Sandbox Code Playgroud)在值/键之间搜索
boost::property_tree)是否有一个接近我正在寻找的图书馆?有没有人boost::property_tree为此目的使用经验?(通过继承或将特殊对象到树像例如描述这里)
| 归档时间: |
|
| 查看次数: |
859 次 |
| 最近记录: |