19 #ifndef OST_GENETRIC_PROPERTY_HH
20 #define OST_GENETRIC_PROPERTY_HH
34 #include <boost/variant.hpp>
55 typedef std::map<String,GenericPropValue>
PropertyMap;
66 map_(rhs.map_ ? new PropertyMap(*rhs.map_) : NULL)
93 return map_ && map_->find(key) != map_->end();
133 std::vector<String> prop_list;
135 PropertyMap::const_iterator i;
136 for (i=map_->begin(); i!=map_->end(); ++i) {
137 prop_list.push_back(i->first);
147 template <
typename H>
154 return boost::get<T>(GetImpl()->GenericProp(key));
156 std::ostringstream m(
"");
157 m <<
"unknown property " << key;
165 return boost::get<T>(GetImpl()->GenericProp(key));
171 return static_cast<H*
>(
this)->GpImpl();
176 return static_cast<const H*
>(
this)->GpImpl();
183 return this->GetImpl()->HasProp(key);
196 if(!HasProp(key))
return "";
197 std::ostringstream rep(
"");
198 rep << this->GetImpl()->GenericProp(key);
206 return this->gp_get<String>(key);
216 switch (value.which()) {
218 return boost::get<Real>(value);
220 return static_cast<Real>(boost::get<int>(value));
222 return static_cast<Real>(boost::get<bool>(value));
224 std::ostringstream m(
"");
225 m <<
"property '" << key <<
"' is not numeric";
228 std::ostringstream m(
"");
229 m <<
"unknown property " << key;
238 switch (value.which()) {
240 return boost::get<int>(value);
242 return boost::get<bool>(value);
244 std::ostringstream m(
"");
245 m <<
"property '" << key <<
"' is not integral";
248 std::ostringstream m(
"");
249 m <<
"unknown property " << key;
257 return this->gp_get<bool>(key);
264 return this->gp_get<geom::Vec3>(key);
271 return this->gp_get<String>(key,def);
279 if(this->HasProp(key)) {
281 switch (value.which()) {
283 return boost::get<Real>(value);
285 return static_cast<Real>(boost::get<int>(value));
287 return static_cast<Real>(boost::get<bool>(value));
289 std::ostringstream m(
"");
290 m <<
"property '" << key <<
"' is not numeric";
300 if(this->HasProp(key)) {
302 switch (value.which()) {
304 return boost::get<int>(value);
306 return static_cast<int>(boost::get<bool>(value));
308 std::ostringstream m(
"");
309 m <<
"property '" << key <<
"' is not integral";
319 return this->gp_get<bool>(key, def);
325 return this->GetImpl()->GetPropMap();
331 return this->GetImpl()->GetPropList();
336 template <
typename H>
344 this->GetImpl()->ClearProps();
351 this->GetImpl()->GenericProp(key)=value;
358 this->GetImpl()->GenericProp(key)=value;
365 this->GetImpl()->GenericProp(key)=value;
372 this->GetImpl()->GenericProp(key)=value;
379 this->GetImpl()->GenericProp(key)=value;
385 this->GetImpl()->RemoveProp(key);
int GetIntProp(const String &key) const
returns integer property, raises an exception if it does not exist
const GenericPropContainerImpl * GetImpl() const
void RemoveProp(const String &key)
void CheckHandleValidity(const H &handle)
void SetBoolProp(const String &key, bool value)
\ brief sets boolean property
int GetIntProp(const String &key, int def) const
returns integer property, or the given default if it does not exist
GenericPropContainerImpl(const GenericPropContainerImpl &rhs)
bool HasProp(const String &key) const
checks existence of property
void Assign(const GenericPropContainerImpl &impl)
void SetVec3Prop(const String &key, geom::Vec3 value)
\ brief sets Vec3 property
void RemoveProp(const String &key)
void SetIntProp(const String &key, int value)
sets integer property
T gp_get(const String &key) const
void SetFloatProp(const String &key, Real value)
sets floating point property
bool GetBoolProp(const String &key) const
returns boolean property, raises an exception if it does not exist
~GenericPropContainerImpl()
String GetStringProp(const String &key) const
returns String property, raises an exception if it does not exist
std::vector< String > GetPropList() const
void SetStringProp(const String &key, const String &value)
sets String property
std::vector< String > GetPropList() const
GenericPropContainerImpl()
Real GetFloatProp(const String &key, Real def) const
returns floating point property, or the given default if it does not exist
GenericPropError(const String &m)
Three dimensional vector class, using Real precision.
GenericPropValue & GenericProp(const String &key)
PropertyMap GetPropMap() const
String GetStringProp(const String &key, const String &def) const
returns String property, or the given default if it does not exist
bool HasProp(const String &key) const
const GenericPropValue & GenericProp(const String &key) const
std::map< String, String > PropertyMap
Real GetFloatProp(const String &key) const
returns floating point property, raises an exception if it does not exist
geom::Vec3 GetVec3Prop(const String &key) const
returns Vec3 property, raises an exception if it does not exist
T gp_get(const String &key, const T &def) const
base class for the implementation
GenericPropContainerImpl & operator=(const GenericPropContainerImpl &r)
base class for the handler classes
std::map< String, GenericPropValue > GetPropMap() const
GenericPropContainerImpl * GetImpl()
String GetPropAsString(const String &key) const
returns a String representation of stored value
bool GetBoolProp(const String &key, bool def) const
returns boolean property, or the given default if it does not exist
boost::variant< String, Real, int, bool, geom::Vec3 > GenericPropValue