boost-propertytree

Boost property_tree: multiple values per key, on a template class

爷,独闯天下 提交于 2019-12-11 03:25:16
问题 On this topic, Boost property_tree: multiple values per key, a method is proposed to read multiples keys of a boost tree. I will paste a modified version below template<int dim> struct my_vector { std::vector<double> a_vector; }; The translator would be: template<int dim> struct my_vector_translator { typedef std::string internal_type; typedef my_vector external_type; // Get a my_vector from a string boost::optional<external_type> get_value(const internal_type& str) { if (!str.empty()) { std:

boost::property_tree::read_xml segfaults in an asio handler spawned using boost::asio::spawn

三世轮回 提交于 2019-12-11 01:59:37
问题 The following code crashes with a seg fault at boost::property_tree::read_xml() call. This happens only if it's called inside of an io_service handler spawned using boost::asio::spawn(). If the handler is just posted, it works ok. Is there a fix or workaround for this? (boost 1.61) #include <boost/asio/spawn.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <iostream> #include <sstream> #include <thread> void process() { std::cerr << "start"<

adding namespaces to XML with boost

☆樱花仙子☆ 提交于 2019-12-10 17:34:29
问题 I'm trying to generate an xml using boost. Going fine so far, but the xml that gets generated needs to have a namespace. so instead of <name>"Harry"</name> it would say <ns1:name>"Harry"</ns1:name> Is there any way to add a namespace to the XML with boost without manually adding the "ns1" to every line? 回答1: Is there any way to add a namespace to the XML with boost without manually adding the "ns1" to every line? Assuming you use rapidxml, no you cannot. You could however extend rapidxml to

Parsing JSON with boost property tree

余生长醉 提交于 2019-12-10 02:21:15
问题 I'm building an application that gets movie information from themoviedb.com. The information is provided in a JSON file. I'm trying to store the information using boost property tree. But There is a little problem. I illustrate the problem by the following code: #include <vector> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <boost/foreach.hpp> using namespace std; using boost::property_tree::ptree; class single_t{ int sID; string sName;

boost::property_tree : Parsing of Complex xml strucure

柔情痞子 提交于 2019-12-10 00:08:22
问题 I am want to parse below xml structure using boost property_tree. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Txn ver="1.0"> <TOpts tCount="1" tformat="0" ttimeout="10" /> <TData> <Tvalue date="YYMMDD" time="HHMM" Ref="100"/> </TData> <TCustOpts> <Param name="SALE" value="xyz" /> </TCustOpts> </Txn> I am able to parse, first Topts field of above xml, But for TData & TCustOpts field, I am not getting right iteration and approach to parse the xml and facing exception. Can someone

Parsing XML File with Boost C++

你离开我真会死。 提交于 2019-12-08 17:29:46
I have to parse one xml file using boost c++, I have written one test code which is working for this xml. a.xml <a> <modules> <module>abc</module> <module>def</module> <module>ghi</module> </modules> </a> Output is coming abc def ghi but for this a.xml file, my test code is not showing any output, 3 blank lines are coming as output. <a> <modules> <module value = "abc"/> <module value = "def"/> <module value = "abc"/> </modules> </a> here is the test code: #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/foreach.hpp> #include <iostream> int

boost : Just iterate over elements of a ptree

ⅰ亾dé卋堺 提交于 2019-12-08 16:10:04
问题 This should be simple (I'm just learning boost so I'm missing something) I have read in some simple JSON using json_read and now have a ptree. All the examples on the web show using ptree.get("entry_name") to obtain an entry. All I want to do is something like: ptree pt; read_json(ss,pt); BOOST_FOREACH(ptree::value_type &v, pt) { std::cout << v.{entry_name} << v.{value} } i.e. loop through the ptree and write out each name (i.e. what you put into pt.get()) and it's corresponding value. Sorry

c++: program settings - boost.PropertyTree or boost.program_options?

偶尔善良 提交于 2019-12-08 15:11:47
问题 I was looking for a solution to store program settings or options or configuration in C++. These could be settings that are exposed in a GUI and need to be saved between runs of my code. In my search I came across boost.PropertyTree which seemed to be a good choice. I know boost is well respected code so I'm comfortable using it and so I started developing using this. Then I come across boost.program_options which seems to allow you to do the same thing but also looks more specialized for the

Does Boost Property Tree have methods for defining rules for the data to be parsed?

有些话、适合烂在心里 提交于 2019-12-08 10:54:28
I have a project that will be using a single JSON file in order to describe the inner contents of the directory it is contained within. The Boost Property Tree library appears to be the best choice for a JSON parsing library. However, this JSON file (like many others) is expected to have a very particular layout, and so far I haven't found a good manner of expressing the rules in code. Does the Boost Property Tree library have any methods allowing the user to do any of the following? Disallowing unrecognized keys. Specifying keys as required or optional. Specifying the expected value type of

XML version and encoding from boost ptree

白昼怎懂夜的黑 提交于 2019-12-08 08:56:11
问题 I am using boost ptree to parse xml read_xml(stream, pt, trim_whitespace | no_comments); <?xml version="1.0" encoding="windows-1252"?> <rss> <channel>.....</channel> </rss> How to read the version and encoding of the xml : I tried the following std::string encoding = pt.get<std::string>("<xmlattr>.encoding", ""); which gives empty string. How to get the version and encoding of xml? 回答1: The processing instruction is not an XML element (in fact, it's... a processing instruction). Processing