boost-propertytree

Is there a convenient way to erase a node from a property tree, preserving its child nodes?

妖精的绣舞 提交于 2019-12-01 00:49:30
I want to delete a node from a boost property tree, but I want to preserve its children and connect them to the parent of the deleted node (i.e. to their grandparent node). Is there an elegant way to achieve this? This might be the most efficient way to move the grandchildren: std::move(middle.begin(), middle.end(), back_inserter(parent)); Full sample Live On Coliru #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json; int main() { std:

Is there a convenient way to erase a node from a property tree, preserving its child nodes?

南楼画角 提交于 2019-11-30 18:27:57
问题 I want to delete a node from a boost property tree, but I want to preserve its children and connect them to the parent of the deleted node (i.e. to their grandparent node). Is there an elegant way to achieve this? 回答1: This might be the most efficient way to move the grandchildren: std::move(middle.begin(), middle.end(), back_inserter(parent)); Full sample Live On Coliru #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree;

C++: boost ptree relative key

巧了我就是萌 提交于 2019-11-30 09:41:40
问题 In C++ using ptree from boost , I need to find the relative key to access a.b.c2.e1 from a.b . This key is c2.e1 . How can I write a function which finds this relative key? #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using namespace boost::property_tree; std::string relative_key(const ptree &p1,const ptree &p2) { ?????????????? // return "b.c2.e1"; } int main() { ptree pt0; pt0.put("a.b.c1",4); pt0.put("a.b.c2.e1",4); pt0.put("a

C++: How to create an array using boost::property_tree?

老子叫甜甜 提交于 2019-11-30 06:44:33
I don't see a way to create an array using boost::property tree. The following code ... #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <iostream> int main() { try { boost::property_tree::ptree props; props.push_back(std::make_pair("foo", "bar")); props.push_back(std::make_pair("foo", "baz")); boost::property_tree::write_json("prob.json", props); } catch (const std::exception & ex) { std::cout << ex.what() << std::endl; } } ... just gives me ... { "foo": "bar", "foo": "baz" } The docs on boost::property_tree are sparse. How do I create an JSON

Change how boost::property_tree reads translates strings to bool

∥☆過路亽.° 提交于 2019-11-30 04:58:51
I've gotten lost in the header files for the boost property_tree and given the lack of documentation around the lower layers, I've decided to ask what the easy way is to over-ride the stream translator to change how Boolean values are parsed. The problem is that on the input side of a property tree, there are users, and they can modify the configuration files. A Boolean value might be specified in a number of ways, like: dosomething.enabled=true dosomething.enabled=trUE dosomething.enabled=yes dosomething.enabled=ON dosomething.enabled=1 The default behaviour is to check for 0 or 1 and then

Using boost property tree to read int array

北城余情 提交于 2019-11-30 04:31:40
I have some JSON with a handful of integer array variables, like so: {"a": [8, 6, 2], "b": [2, 2, 1]} I would like to use boost property_tree, for instance: std::stringstream ss; boost::property_tree::ptree pt; ss << "{\"a\": [8, 6, 2], \"b\": [2, 2, 1]}"; boost::property_tree::read_json(ss, pt); std::vector<int> a = pt.get<std::vector<int> >("a"); This doesn't work, nor does any variation on an int pointer that I've tried. How may I read an array from a property tree? JSON support, is spotty with boost property tree. The property tree dataset is not typed, and does not support arrays as such.

How to iterate a boost property tree?

浪子不回头ぞ 提交于 2019-11-30 01:49:54
I am know approaching to boost property tree and saw that it is a good feature of boost libs for c++ programming. Well, I have one doubt? how to iterate a property tree using iterators or similar? In reference there is just an example of browsing the tree through: BOOST_FOREACH But is there nothing more? Something like an stl-like container? It would be a better solution, speaking about code quality.... BOOST_FOREACH is just a convenient way for iterating that can be done by iterator, begin() and end() Your_tree_type::const_iterator end = tree.end(); for (your_tree_type::const_iterator it =

How to feed Boost.PropertyTree with a string, not a file?

你。 提交于 2019-11-29 17:21:00
问题 Boost has a tutorial on how to load XML from a file. How do I feed it with a string that I either create in code or receive from a user (e.g. with cin )? 回答1: Wrap the string in an istringstream. 回答2: Heres some code that works for me... // Create an empty property tree object ptree xmlTree; // Read the XML config string into the property tree. Catch any exception try { stringstream ss; ss << xmlConfigString; read_xml(ss, xmlTree); } catch (xml_parser_error &e) { LOGERROR ("Failed to read

Boost property_tree: multiple values per key

て烟熏妆下的殇ゞ 提交于 2019-11-29 08:12:27
Boost property tree seems like an excellent library to use for parsing config files. However, I can't figure out how to handle situations where there are multiple values per key. For example, let's say I was specifying a box like this: box { x -1 1 y -1 1 z -1 1 } where x , y , and z are the bounds of the box on the x , y , and z axes respectively, specified using property_tree's INFO format. I see mention in the manual of using quotes for values that use spaces, but then I don't see that I could import those values as numbers. I'd have to parse the string into numbers, which seems to defeat

Change how boost::property_tree reads translates strings to bool

混江龙づ霸主 提交于 2019-11-29 02:35:42
问题 I've gotten lost in the header files for the boost property_tree and given the lack of documentation around the lower layers, I've decided to ask what the easy way is to over-ride the stream translator to change how Boolean values are parsed. The problem is that on the input side of a property tree, there are users, and they can modify the configuration files. A Boolean value might be specified in a number of ways, like: dosomething.enabled=true dosomething.enabled=trUE dosomething.enabled