boost-propertytree

Boost 1.46.1, Property Tree: How to iterate through ptree receiving sub ptrees?

此生再无相见时 提交于 2019-11-28 22:15:41
问题 First of all I shall say that I think I got how it should be done but my code will not compile any way I try. I based my assumption on this official example of empty ptree trick. There you can find next line: const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); Which shows that it is (or should be) possible to get subptree out from ptree. So I assumed we could iterate thru ptree with something like BOOST_FOREACH in such manner: BOOST_FOREACH(const boost::property_tree:

How to iterate a boost property tree?

↘锁芯ラ 提交于 2019-11-28 20:24:43
问题 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.... 回答1: BOOST_FOREACH is just a convenient way for iterating that can be done by iterator,

Parsing XML Attributes with Boost

旧时模样 提交于 2019-11-28 06:55:06
I would like to share with you an issue I'm having while trying to process some attributes from XML elements in C++ with Boost libraries (version 1.52.0). Given the following code: #define ATTR_SET ".<xmlattr>" #define XML_PATH1 "./pets.xml" #include <iostream> #include <string> #include <boost/foreach.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> using namespace std; using namespace boost; using namespace boost::property_tree; const ptree& empty_ptree(){ static ptree t; return t; } int main() { ptree tree; read_xml(XML_PATH1, tree); const ptree &

Creating JSON arrays in Boost using Property Trees

大城市里の小女人 提交于 2019-11-28 03:05:38
I'm trying to create a JSON array using boost property trees. The documentation says: "JSON arrays are mapped to nodes. Each element is a child node with an empty name." So I'd like to create a property tree with empty names, then call write_json(...) to get the array out. However, the documentation doesn't tell me how to create unnamed child nodes. I tried ptree.add_child("", value) , but this yields: Assertion `!p.empty() && "Empty path not allowed for put_child."' failed The documentation doesn't seem to address this point, at least not in any way I can figure out. Can anyone help?

Add xml-stylesheet processing instructions to boost property_tree

人盡茶涼 提交于 2019-11-28 02:12:56
I am using boost/property_tree to create an XML file. Unfortunately I cannot figure out how to add xml-stylesheet processing instructions to the file. Desirable output: <?xml version="1.0" encoding="utf-8"?> <-- This is added automatically <?xml-stylesheet type="text/xsl" href="report.xsl"?> <-- How to add this line <report> ... </report> Is that possible with boost/property_tree/ptree? It appears that boost/property_tree xml writer doesn't have a support for xml stylesheets processing instructions. First line (xml version) is simply hardcoded in the write_xml_internal function. So I've just

Boost property_tree: multiple values per key

假如想象 提交于 2019-11-28 01:58:07
问题 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

boost::property_tree XML pretty printing

主宰稳场 提交于 2019-11-27 11:28:47
I'm using boost::property_tree to read and write XML configuration files in my application. But when I write the file the output looks kind of ugly with lots of empty lines in the file. The problem is that it's supposed to be edited by humans too so I'd like to get a better output. As an example I wrote a small test program : #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> int main( void ) { using boost::property_tree::ptree; ptree pt; // reading file.xml read_xml("file.xml", pt); // writing the unchanged ptree in file2.xml boost::property_tree::xml

Why does Boost property tree write_json save everything as string? Is it possible to change that?

久未见 提交于 2019-11-27 10:39:15
I'm trying to serialize using boost property tree write_json, it saves everything as strings, it's not that data are wrong, but I need to cast them explicitly every time and I want to use them somewhere else. (like in python or other C++ json (non boost) library) here is some sample code and what I get depending on locale: boost::property_tree::ptree root, arr, elem1, elem2; elem1.put<int>("key0", 0); elem1.put<bool>("key1", true); elem2.put<float>("key2", 2.2f); elem2.put<double>("key3", 3.3); arr.push_back( std::make_pair("", elem1) ); arr.push_back( std::make_pair("", elem2) ); root.put

Creating JSON arrays in Boost using Property Trees

流过昼夜 提交于 2019-11-27 05:03:17
问题 I'm trying to create a JSON array using boost property trees. The documentation says: "JSON arrays are mapped to nodes. Each element is a child node with an empty name." So I'd like to create a property tree with empty names, then call write_json(...) to get the array out. However, the documentation doesn't tell me how to create unnamed child nodes. I tried ptree.add_child("", value) , but this yields: Assertion `!p.empty() && "Empty path not allowed for put_child."' failed The documentation

Serializing and deserializing JSON with Boost

一世执手 提交于 2019-11-27 03:03:21
I'm newbie to C++. What's the easiest way to serialize and deserialize data of type std::Map using boost . I've found some examples with using PropertyTree but they are obscure for me. ArtemGr Note that property_tree interprets the keys as paths, e.g. putting the pair "a.b"="z" will create an {"a":{"b":"z"}} JSON, not an {"a.b":"z"}. Otherwise, using property_tree is trivial. Here is a little example. #include <sstream> #include <map> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree; using boost::property_tree::read_json;