19 #ifndef OST_GENETRIC_PROPERTY_HH
20 #define OST_GENETRIC_PROPERTY_HH
35 #include <boost/variant.hpp>
48 virtual const char*
what()
const throw() {
59 typedef std::map<String,GenericPropValue> PropertyMap;
70 map_(rhs.map_ ? new PropertyMap(*rhs.map_) : NULL)
95 bool HasProp(
const String& key)
const
97 return map_ && map_->find(key) != map_->end();
118 map_=
new PropertyMap(*impl.map_);
127 PropertyMap GetPropMap()
const
130 map_=
new PropertyMap;
135 std::vector<String> GetPropList()
const
137 std::vector<String> prop_list;
139 PropertyMap::const_iterator i;
140 for (i=map_->begin(); i!=map_->end(); ++i) {
141 prop_list.push_back(i->first);
148 mutable PropertyMap* map_;
151 template <
typename H>
158 return boost::get<T>(GetImpl()->GenericProp(key));
160 std::ostringstream m(
"");
161 m <<
"unknown property " << key;
169 return boost::get<T>(GetImpl()->GenericProp(key));
175 return static_cast<H*
>(
this)->GpImpl();
180 return static_cast<const H*
>(
this)->GpImpl();
187 return this->GetImpl()->HasProp(key);
200 if(!HasProp(key))
return "";
201 std::ostringstream rep(
"");
202 rep << this->GetImpl()->GenericProp(key);
210 return this->gp_get<String>(key);
220 if (value.which()==1) {
221 return boost::get<Real>(this->GetImpl()->GenericProp(key));
222 }
else if (value.which()==2) {
223 return boost::get<int>(this->GetImpl()->GenericProp(key));
225 std::ostringstream m(
"");
226 m <<
"property '" << key <<
"' is not numeric";
229 std::ostringstream m(
"");
230 m <<
"unknown property " << key;
240 return this->gp_get<int>(key);
244 bool GetBoolProp(
const String& key)
const
247 return this->gp_get<bool>(key);
254 return this->gp_get<String>(key,def);
262 if(this->HasProp(key)) {
264 if (value.which()==1) {
265 return boost::get<Real>(GetImpl()->GenericProp(key));
266 }
else if (value.which()==2) {
267 return boost::get<int>(GetImpl()->GenericProp(key));
269 std::ostringstream m(
"");
270 m <<
"property '" << key <<
"' is not numeric";
278 int GetIntProp(
const String& key,
int def)
const
281 return this->gp_get<int>(key, def);
285 bool GetBoolProp(
const String& key,
bool def)
const
288 return this->gp_get<bool>(key, def);
291 std::map<String,GenericPropValue> GetPropMap()
const
294 return this->GetImpl()->GetPropMap();
297 std::vector<String> GetPropList()
const
300 return this->GetImpl()->GetPropList();
305 template <
typename H>
313 this->GetImpl()->ClearProps();
320 this->GetImpl()->GenericProp(key)=value;
327 this->GetImpl()->GenericProp(key)=value;
331 void SetIntProp(
const String& key,
int value)
334 this->GetImpl()->GenericProp(key)=value;
338 void SetBoolProp(
const String& key,
bool value)
341 this->GetImpl()->GenericProp(key)=value;
347 this->GetImpl()->RemoveProp(key);