6 #ifndef TURI_INI_BOOST_PROPERTY_TREE_UTILS_HPP 7 #define TURI_INI_BOOST_PROPERTY_TREE_UTILS_HPP 9 #define BOOST_SPIRIT_THREADSAFE 14 #include <boost/property_tree/ptree.hpp> 15 #include <boost/lexical_cast.hpp> 50 size_t expected_elements) {
52 if (expected_elements == 0)
return ret;
53 const boost::property_tree::ptree& section = data.get_child(key);
54 ret.resize(expected_elements);
58 for(
const auto& val: section) {
59 const auto& key = val.first;
62 ret[sid] = boost::lexical_cast<T>(val.second.get_value<std::string>());
67 if (sid >= ret.size()) {
68 log_and_throw(std::string(
"Invalid ID in ") + key +
" section." 69 "Segment IDs are expected to be sequential.");
71 ret[sid] = boost::lexical_cast<T>(val.second.get_value<std::string>());
101 std::map<std::string, T> ret;
103 if (data.count(key) == 0) {
106 const boost::property_tree::ptree& section = data.get_child(key);
109 for(
const auto& val: section) {
110 ret.insert(std::make_pair(val.first,
111 val.second.get_value<T>()));
132 template <
typename T>
134 const std::string& key,
135 const std::vector<T>&
values) {
136 for (
size_t i = 0; i < values.size(); ++i) {
138 std::stringstream strm;
139 strm.fill(
'0'); strm.width(4); strm << i;
140 data.put(key +
"." + strm.str(), values[i]);
160 template <
typename T>
162 const std::string& key,
163 const std::map<std::string, T>&
values) {
165 std::string m_heading = key +
".";
166 for(
const auto& map_entry : values) {
167 std::string mkey(m_heading);
168 mkey += map_entry.first;
169 data.put(mkey, map_entry.second);
std::map< std::string, T > read_dictionary_section(const boost::property_tree::ptree &data, std::string key)
std::set< T > values(const std::map< Key, T > &map)
std::vector< T > read_sequence_section(const boost::property_tree::ptree &data, std::string key, size_t expected_elements)
void write_dictionary_section(boost::property_tree::ptree &data, const std::string &key, const std::map< std::string, T > &values)
void write_sequence_section(boost::property_tree::ptree &data, const std::string &key, const std::vector< T > &values)