23 #include <boost/archive/text_iarchive.hpp>
24 #include <boost/property_tree/ptree_serialization.hpp>
25 #include <boost/property_tree/xml_parser.hpp>
26 #include <boost/serialization/string.hpp>
27 #include <boost/version.hpp>
29 using boost::property_tree::xml_parser::read_xml;
30 using boost::property_tree::xml_parser::write_xml;
31 using boost::property_tree::xml_writer_settings;
32 using boost::property_tree::ptree_error;
33 using boost::property_tree::xml_parser::no_concat_text;
34 using boost::property_tree::xml_parser::no_comments;
35 using boost::property_tree::xml_parser::trim_whitespace;
36 using boost::property_tree::ptree;
38 boost::property_tree::ptree
41 boost::property_tree::ptree cfg;
42 std::string filename(path);
43 std::ifstream cfg_stream(filename);
45 if (!cfg_stream.good())
49 read_xml(cfg_stream, cfg, trim_whitespace | no_comments);
52 catch (ptree_error &e)
59 const std::string &path)
61 std::string filename(path);
62 std::ofstream cfg_stream(filename);
72 #if ((BOOST_VERSION / 100000) == 1 && (BOOST_VERSION / 100 % 1000) >= 58) || \
73 (BOOST_VERSION / 100000) > 1
76 boost::property_tree::xml_writer_make_settings<std::string>(
'\t', 1));
79 boost::property_tree::xml_writer_make_settings<char>(
'\t', 1));
82 catch (ptree_error &e)
84 std::throw_with_nested(std::runtime_error(
"Failed to serialize ptree"));
90 const std::string &data, boost::property_tree::ptree &tree) noexcept
92 boost::property_tree::ptree cfg;
93 std::istringstream iss(data);
97 boost::archive::text_iarchive archive(iss);
98 boost::property_tree::load(archive, cfg, 1);
102 catch (std::exception &e)
105 "Exception while extracting boost archive (as string) to property tree: "