12 inline void stringify_from_x(std::string & repr,
const double & val)
18 sprintf(buf,
"%.*f", min, val);
19 if (val == strtod(buf,0))
21 repr = std::string(buf);
25 sprintf(buf,
"%.*f", 1, val);
26 int max =
sizeof(buf)-strlen(buf);
27 sprintf(buf,
"%.*f", max, val);
28 if (val != strtod(buf,0))
30 printf(
"stringify_from_x invariant failed!\n");
39 int test = min + diff/2;
40 sprintf(buf,
"%.*f", test, val);
41 if (val == strtod(buf,0))
46 sprintf(buf,
"%.*f", max, val);
47 repr = std::string(buf);
50 inline void stringify_to_x(
const std::string & repr,
double & val)
52 val = atof(repr.c_str());
56 inline void stringify_from_x(std::string & repr,
const int & val)
59 sprintf(buf,
"%d", val);
60 repr = std::string(buf);
62 inline void stringify_to_x(
const std::string & repr,
int & val)
64 val = atoi(repr.c_str());
68 inline void stringify_from_x(std::string & repr,
const long unsigned int & val)
71 sprintf(buf,
"%lu", val);
72 repr = std::string(buf);
74 inline void stringify_to_x(
const std::string & repr,
long unsigned int & val)
76 val = atoi(repr.c_str());
80 inline void stringify_from_x(std::string & repr,
const bool & val)
87 inline void stringify_to_x(
const std::string & repr,
bool & val)
91 else if (repr ==
"true")
94 throw std::runtime_error(
"parse error!");
107 template <
class PropMap>
111 typedef typename boost::property_traits<PropMap>::category category;
112 typedef typename boost::property_traits<PropMap>::key_type key_type;
113 typedef std::string value_type;
114 typedef std::string reference;
116 string_map(PropMap prop_map) : prop_map(prop_map) {}
119 template <
class PropMap>
125 template <
class PropMap>
127 get(
const string_map<PropMap> & map,
const typename string_map<PropMap>::key_type & k)
130 stringify_from_x(repr,
get(map.prop_map,k));
134 template <
class PropMap>
136 put(
const string_map<PropMap> & map,
const typename string_map<PropMap>::key_type & k,
const std::string repr)
138 typename boost::property_traits<PropMap>::value_type val;
139 stringify_to_x(repr, val);
140 put(map.prop_map, k, val);
Wraps a property as a string map.
Definition: string_map.h:108