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 if (value.which()==1) {
216 return boost::get<Real>(this->GetImpl()->GenericProp(key));
217 }
else if (value.which()==2) {
218 return boost::get<int>(this->GetImpl()->GenericProp(key));
220 std::ostringstream m(
"");
221 m <<
"property '" << key <<
"' is not numeric";
224 std::ostringstream m(
"");
225 m <<
"unknown property " << key;
235 return this->gp_get<int>(key);
239 bool GetBoolProp(
const String& key)
const
242 return this->gp_get<bool>(key);
249 return this->gp_get<String>(key,def);
257 if(this->HasProp(key)) {
259 if (value.which()==1) {
260 return boost::get<Real>(GetImpl()->GenericProp(key));
261 }
else if (value.which()==2) {
262 return boost::get<int>(GetImpl()->GenericProp(key));
264 std::ostringstream m(
"");
265 m <<
"property '" << key <<
"' is not numeric";
273 int GetIntProp(
const String& key,
int def)
const
276 return this->gp_get<int>(key, def);
280 bool GetBoolProp(
const String& key,
bool def)
const
283 return this->gp_get<bool>(key, def);
286 std::map<String,GenericPropValue> GetPropMap()
const
289 return this->GetImpl()->GetPropMap();
292 std::vector<String> GetPropList()
const
295 return this->GetImpl()->GetPropList();
300 template <
typename H>
308 this->GetImpl()->ClearProps();
315 this->GetImpl()->GenericProp(key)=value;
322 this->GetImpl()->GenericProp(key)=value;
326 void SetIntProp(
const String& key,
int value)
329 this->GetImpl()->GenericProp(key)=value;
333 void SetBoolProp(
const String& key,
bool value)
336 this->GetImpl()->GenericProp(key)=value;
342 this->GetImpl()->RemoveProp(key);