The standard_tree property processes only one string value for each key, because it is defined as:
typedef basic_ptree<std::string, std::string> ptree;
So, the only option is to use the strings and parse them. I believe that the best method is to define a new class that stores low and high values, and then create a translator class for the get and set methods. For instance:
struct low_high_value { low_high_value() : m_low(0), m_high(0) { } low_high_value(double low, double high) : m_low(low), m_high(high) { } double m_low; double m_high; };
The translator will:
struct low_high_value_translator { typedef std::string internal_type; typedef low_high_value external_type;
The previous get_value method is very simple. It should be improved if the file can be written by the user.
This class must be registered using:
namespace boost { namespace property_tree { template<typename Ch, typename Traits, typename Alloc> struct translator_between<std::basic_string< Ch, Traits, Alloc >, low_high_value> { typedef low_high_value_translator type; }; } }
After including the previous code, you can use property_tree as:
pt.get<low_high_value>("box.x") pt.put("box.u", low_high_value(-110, 200));
source share