From b7cdedc8e75b294cf662727d5a5998b7493cacff Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Thu, 8 Jul 2010 07:55:40 +0000
Subject: [PATCH] protect against invalid handles

Noticed by Flo

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2542 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/base/src/generic_property.hh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/modules/base/src/generic_property.hh b/modules/base/src/generic_property.hh
index 03ddafedf..12e53932e 100644
--- a/modules/base/src/generic_property.hh
+++ b/modules/base/src/generic_property.hh
@@ -34,6 +34,7 @@
 #include <boost/variant.hpp>
 
 #include <ost/module_config.hh>
+#include <ost/invalid_handle.hh>
 
 namespace ost {
 
@@ -169,6 +170,7 @@ protected:
 public:
   /// \brief checks existence of property
   bool HasProp(const String& key) const {
+    CheckHandleValidity(*static_cast<const H*>(this));
     return this->GetImpl()->HasProp(key);
   }
     
@@ -181,6 +183,7 @@ public:
   /// a representation suitable for output.
   String GetPropAsString(const String& key) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     if(!HasProp(key)) return "";
     std::ostringstream rep("");
     rep << this->GetImpl()->GenericProp(key);
@@ -189,6 +192,7 @@ public:
     /// \brief returns String property, raises an exception if it does not exist
     String GetStringProp(const String& key) const
     {
+      CheckHandleValidity(*static_cast<const H*>(this));      
       return this->gp_get<String>(key);
     }
 
@@ -196,6 +200,7 @@ public:
   ///     not exist
   Real GetFloatProp(const String& key) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     if(HasProp(key)) {
       GenericPropValue value=this->GetImpl()->GenericProp(key);
       if (value.which()==1) {
@@ -217,18 +222,21 @@ public:
   /// \brief returns integer property, raises an exception if it does not exist
   int GetIntProp(const String& key) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     return this->gp_get<int>(key);
   }
 
   /// \brief returns boolean property, raises an exception if it does not exist
   bool GetBoolProp(const String& key) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     return this->gp_get<bool>(key);
   }
 
   /// \brief returns String property, or the given default if it does not exist
   String GetStringProp(const String& key, const String& def) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     return this->gp_get<String>(key,def);
   }
 
@@ -236,6 +244,7 @@ public:
   ///     not exist
   Real GetFloatProp(const String& key, Real def) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     if(this->HasProp(key)) {
       GenericPropValue value=GetImpl()->GenericProp(key);
       if (value.which()==1) {
@@ -254,17 +263,20 @@ public:
   /// \brief returns integer property, or the given default if it does not exist
   int GetIntProp(const String& key, int def) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     return this->gp_get<int>(key, def);
   }
 
   /// \brief returns boolean property, or the given default if it does not exist
   bool GetBoolProp(const String& key, bool def) const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     return this->gp_get<bool>(key, def);
   }
 
   std::map<String,GenericPropValue> GetPropMap() const
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     return this->GetImpl()->GetPropMap();
   }  
 };
@@ -277,35 +289,41 @@ class  TEMPLATE_EXPORT GenericPropContainer :
 public:
   void ClearProps()
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     this->GetImpl()->ClearProps();
   }
   
   /// \brief sets String property
   void SetStringProp(const String& key, const String& value)
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     this->GetImpl()->GenericProp(key)=value;
   }
 
   /// \brief sets floating point property
   void SetFloatProp(const String& key, Real value)
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     this->GetImpl()->GenericProp(key)=value;
   }
 
   /// \brief sets integer property
   void SetIntProp(const String& key, int value)
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     this->GetImpl()->GenericProp(key)=value;
   }
 
   /// \ brief sets boolean property
   void SetBoolProp(const String& key, bool value)
   {
+    CheckHandleValidity(*static_cast<const H*>(this));    
     this->GetImpl()->GenericProp(key)=value;
   }
   
   void RemoveProp(const String& key)
   {
+    CheckHandleValidity(*static_cast<const H*>(this));
     this->GetImpl()->RemoveProp(key);
   }
 };
-- 
GitLab