Guest User

GQE - Object Properties - HEADER

a guest
Jan 24th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #ifndef PROPERTY_MANAGER_HPP_INCLUDED
  2. #define PROPERTY_MANAGER_HPP_INCLUDED
  3.  
  4. #include <map>
  5. #include <typeinfo>
  6. #include "IProperty.hpp"
  7. #include "TProperty.hpp"
  8.  
  9. namespace GQE
  10. {
  11.   class PropertyManager
  12.   {
  13.     public:
  14.       PropertyManager();
  15.       virtual ~PropertyManager();
  16.  
  17.       bool HasID(const std::string thePropertyID);
  18.  
  19.       template<class TYPE>
  20.       TYPE Get(const std::string thePropertyID)
  21.       {
  22.         if(mList.find(thePropertyID) != mList.end())
  23.         {
  24.           if(mList.at(thePropertyID)->GetType()->Name() == typeid(TYPE).name())
  25.             return static_cast<TProperty<TYPE>*>(mList[thePropertyID])->GetValue();
  26.         }
  27.         else
  28.         {
  29.           WLOG() << "PropertyManager:Get() returning blank property("
  30.             << thePropertyID << ") type" << std::endl;
  31.         }
  32.         TYPE anReturn=TYPE();
  33.         return anReturn;
  34.       }
  35.  
  36.       template<class TYPE>
  37.       void Set(const std::string thePropertyID, TYPE theValue)
  38.       {
  39.         if(mList.find(thePropertyID) != mList.end())
  40.         {
  41.           if(mList.at(thePropertyID)->GetType()->Name() == typeid(TYPE).name())
  42.           {
  43.             static_cast<TProperty<TYPE>*>(mList[thePropertyID])->SetValue(theValue);
  44.           }
  45.         }
  46.         else
  47.         {
  48.           ELOG() << "PropertyManager:Set() unable to find property("
  49.             << thePropertyID << ")" << std::endl;
  50.         }
  51.       }
  52.  
  53.       template<class TYPE>
  54.       void Add(const std::string thePropertyID, TYPE theValue)
  55.       {
  56.         // Only add the property if it doesn't already exist
  57.         if(mList.find(thePropertyID) == mList.end())
  58.         {
  59.           TProperty<TYPE>* anProperty=new(std::nothrow) TProperty<TYPE>(thePropertyID);
  60.           anProperty->SetValue(theValue);
  61.           mList[anProperty->GetID()]=anProperty;
  62.         }
  63.       }
  64.  
  65.       void Add(IProperty* theProperty);
  66.  
  67.       void Clone(const PropertyManager& thePropertyManager);
  68.  
  69.     protected:
  70.  
  71.     private:
  72.       std::map<const std::string, IProperty*> mList;
  73.   };
  74. }
  75. #endif
Advertisement
Add Comment
Please, Sign In to add comment