Skip to content
Snippets Groups Projects
Commit b7cdedc8 authored by marco's avatar marco
Browse files

protect against invalid handles

Noticed by Flo

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2542 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 09e0140e
Branches
Tags
No related merge requests found
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <ost/module_config.hh> #include <ost/module_config.hh>
#include <ost/invalid_handle.hh>
namespace ost { namespace ost {
...@@ -169,6 +170,7 @@ protected: ...@@ -169,6 +170,7 @@ protected:
public: public:
/// \brief checks existence of property /// \brief checks existence of property
bool HasProp(const String& key) const { bool HasProp(const String& key) const {
CheckHandleValidity(*static_cast<const H*>(this));
return this->GetImpl()->HasProp(key); return this->GetImpl()->HasProp(key);
} }
...@@ -181,6 +183,7 @@ public: ...@@ -181,6 +183,7 @@ public:
/// a representation suitable for output. /// a representation suitable for output.
String GetPropAsString(const String& key) const String GetPropAsString(const String& key) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
if(!HasProp(key)) return ""; if(!HasProp(key)) return "";
std::ostringstream rep(""); std::ostringstream rep("");
rep << this->GetImpl()->GenericProp(key); rep << this->GetImpl()->GenericProp(key);
...@@ -189,6 +192,7 @@ public: ...@@ -189,6 +192,7 @@ public:
/// \brief returns String property, raises an exception if it does not exist /// \brief returns String property, raises an exception if it does not exist
String GetStringProp(const String& key) const String GetStringProp(const String& key) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->gp_get<String>(key); return this->gp_get<String>(key);
} }
...@@ -196,6 +200,7 @@ public: ...@@ -196,6 +200,7 @@ public:
/// not exist /// not exist
Real GetFloatProp(const String& key) const Real GetFloatProp(const String& key) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
if(HasProp(key)) { if(HasProp(key)) {
GenericPropValue value=this->GetImpl()->GenericProp(key); GenericPropValue value=this->GetImpl()->GenericProp(key);
if (value.which()==1) { if (value.which()==1) {
...@@ -217,18 +222,21 @@ public: ...@@ -217,18 +222,21 @@ public:
/// \brief returns integer property, raises an exception if it does not exist /// \brief returns integer property, raises an exception if it does not exist
int GetIntProp(const String& key) const int GetIntProp(const String& key) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->gp_get<int>(key); return this->gp_get<int>(key);
} }
/// \brief returns boolean property, raises an exception if it does not exist /// \brief returns boolean property, raises an exception if it does not exist
bool GetBoolProp(const String& key) const bool GetBoolProp(const String& key) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->gp_get<bool>(key); return this->gp_get<bool>(key);
} }
/// \brief returns String property, or the given default if it does not exist /// \brief returns String property, or the given default if it does not exist
String GetStringProp(const String& key, const String& def) const String GetStringProp(const String& key, const String& def) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->gp_get<String>(key,def); return this->gp_get<String>(key,def);
} }
...@@ -236,6 +244,7 @@ public: ...@@ -236,6 +244,7 @@ public:
/// not exist /// not exist
Real GetFloatProp(const String& key, Real def) const Real GetFloatProp(const String& key, Real def) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
if(this->HasProp(key)) { if(this->HasProp(key)) {
GenericPropValue value=GetImpl()->GenericProp(key); GenericPropValue value=GetImpl()->GenericProp(key);
if (value.which()==1) { if (value.which()==1) {
...@@ -254,17 +263,20 @@ public: ...@@ -254,17 +263,20 @@ public:
/// \brief returns integer property, or the given default if it does not exist /// \brief returns integer property, or the given default if it does not exist
int GetIntProp(const String& key, int def) const int GetIntProp(const String& key, int def) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->gp_get<int>(key, def); return this->gp_get<int>(key, def);
} }
/// \brief returns boolean property, or the given default if it does not exist /// \brief returns boolean property, or the given default if it does not exist
bool GetBoolProp(const String& key, bool def) const bool GetBoolProp(const String& key, bool def) const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->gp_get<bool>(key, def); return this->gp_get<bool>(key, def);
} }
std::map<String,GenericPropValue> GetPropMap() const std::map<String,GenericPropValue> GetPropMap() const
{ {
CheckHandleValidity(*static_cast<const H*>(this));
return this->GetImpl()->GetPropMap(); return this->GetImpl()->GetPropMap();
} }
}; };
...@@ -277,35 +289,41 @@ class TEMPLATE_EXPORT GenericPropContainer : ...@@ -277,35 +289,41 @@ class TEMPLATE_EXPORT GenericPropContainer :
public: public:
void ClearProps() void ClearProps()
{ {
CheckHandleValidity(*static_cast<const H*>(this));
this->GetImpl()->ClearProps(); this->GetImpl()->ClearProps();
} }
/// \brief sets String property /// \brief sets String property
void SetStringProp(const String& key, const String& value) void SetStringProp(const String& key, const String& value)
{ {
CheckHandleValidity(*static_cast<const H*>(this));
this->GetImpl()->GenericProp(key)=value; this->GetImpl()->GenericProp(key)=value;
} }
/// \brief sets floating point property /// \brief sets floating point property
void SetFloatProp(const String& key, Real value) void SetFloatProp(const String& key, Real value)
{ {
CheckHandleValidity(*static_cast<const H*>(this));
this->GetImpl()->GenericProp(key)=value; this->GetImpl()->GenericProp(key)=value;
} }
/// \brief sets integer property /// \brief sets integer property
void SetIntProp(const String& key, int value) void SetIntProp(const String& key, int value)
{ {
CheckHandleValidity(*static_cast<const H*>(this));
this->GetImpl()->GenericProp(key)=value; this->GetImpl()->GenericProp(key)=value;
} }
/// \ brief sets boolean property /// \ brief sets boolean property
void SetBoolProp(const String& key, bool value) void SetBoolProp(const String& key, bool value)
{ {
CheckHandleValidity(*static_cast<const H*>(this));
this->GetImpl()->GenericProp(key)=value; this->GetImpl()->GenericProp(key)=value;
} }
void RemoveProp(const String& key) void RemoveProp(const String& key)
{ {
CheckHandleValidity(*static_cast<const H*>(this));
this->GetImpl()->RemoveProp(key); this->GetImpl()->RemoveProp(key);
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment