19 #ifndef OST_GENETRIC_PROPERTY_HH
20 #define OST_GENETRIC_PROPERTY_HH
34 #include <boost/variant.hpp>
54 typedef std::map<String,GenericPropValue> PropertyMap;
65 map_(rhs.map_ ? new PropertyMap(*rhs.map_) : NULL)
90 bool HasProp(
const String& key)
const
92 return map_ && map_->find(key) != map_->end();
113 map_=
new PropertyMap(*impl.map_);
122 PropertyMap GetPropMap()
const
125 map_=
new PropertyMap;
130 std::vector<String> GetPropList()
const
132 std::vector<String> prop_list;
134 PropertyMap::const_iterator i;
135 for (i=map_->begin(); i!=map_->end(); ++i) {
136 prop_list.push_back(i->first);
143 mutable PropertyMap* map_;
146 template <
typename H>
153 return boost::get<T>(GetImpl()->GenericProp(key));
155 std::ostringstream m(
"");
156 m <<
"unknown property " << key;
164 return boost::get<T>(GetImpl()->GenericProp(key));
170 return static_cast<H*
>(
this)->GpImpl();
175 return static_cast<const H*
>(
this)->GpImpl();
182 return this->GetImpl()->HasProp(key);
195 if(!HasProp(key))
return "";
196 std::ostringstream rep(
"");
197 rep << this->GetImpl()->GenericProp(key);
205 return this->gp_get<String>(key);
215 switch (value.which()) {
217 return boost::get<Real>(value);
219 return static_cast<Real>(boost::get<int>(value));
221 return static_cast<Real>(boost::get<bool>(value));
223 std::ostringstream m(
"");
224 m <<
"property '" << key <<
"' is not numeric";
227 std::ostringstream m(
"");
228 m <<
"unknown property " << key;
237 switch (value.which()) {
239 return boost::get<int>(value);
241 return boost::get<bool>(value);
243 std::ostringstream m(
"");
244 m <<
"property '" << key <<
"' is not integral";
247 std::ostringstream m(
"");
248 m <<
"unknown property " << key;
253 bool GetBoolProp(
const String& key)
const
256 return this->gp_get<bool>(key);
263 return this->gp_get<String>(key,def);
271 if(this->HasProp(key)) {
273 switch (value.which()) {
275 return boost::get<Real>(value);
277 return static_cast<Real>(boost::get<int>(value));
279 return static_cast<Real>(boost::get<bool>(value));
281 std::ostringstream m(
"");
282 m <<
"property '" << key <<
"' is not numeric";
289 int GetIntProp(
const String& key,
int def)
const
292 if(this->HasProp(key)) {
294 switch (value.which()) {
296 return boost::get<int>(value);
298 return static_cast<int>(boost::get<bool>(value));
300 std::ostringstream m(
"");
301 m <<
"property '" << key <<
"' is not integral";
308 bool GetBoolProp(
const String& key,
bool def)
const
311 return this->gp_get<bool>(key, def);
314 std::map<String,GenericPropValue> GetPropMap()
const
317 return this->GetImpl()->GetPropMap();
320 std::vector<String> GetPropList()
const
323 return this->GetImpl()->GetPropList();
328 template <
typename H>
336 this->GetImpl()->ClearProps();
343 this->GetImpl()->GenericProp(key)=value;
350 this->GetImpl()->GenericProp(key)=value;
354 void SetIntProp(
const String& key,
int value)
357 this->GetImpl()->GenericProp(key)=value;
361 void SetBoolProp(
const String& key,
bool value)
364 this->GetImpl()->GenericProp(key)=value;
370 this->GetImpl()->RemoveProp(key);