Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PROPERTY_MANAGER_HPP_INCLUDED
- #define PROPERTY_MANAGER_HPP_INCLUDED
- #include <map>
- #include <typeinfo>
- #include "IProperty.hpp"
- #include "TProperty.hpp"
- namespace GQE
- {
- class PropertyManager
- {
- public:
- PropertyManager();
- virtual ~PropertyManager();
- bool HasID(const std::string thePropertyID);
- template<class TYPE>
- TYPE Get(const std::string thePropertyID)
- {
- if(mList.find(thePropertyID) != mList.end())
- {
- if(mList.at(thePropertyID)->GetType()->Name() == typeid(TYPE).name())
- return static_cast<TProperty<TYPE>*>(mList[thePropertyID])->GetValue();
- }
- else
- {
- WLOG() << "PropertyManager:Get() returning blank property("
- << thePropertyID << ") type" << std::endl;
- }
- TYPE anReturn=TYPE();
- return anReturn;
- }
- template<class TYPE>
- void Set(const std::string thePropertyID, TYPE theValue)
- {
- if(mList.find(thePropertyID) != mList.end())
- {
- if(mList.at(thePropertyID)->GetType()->Name() == typeid(TYPE).name())
- {
- static_cast<TProperty<TYPE>*>(mList[thePropertyID])->SetValue(theValue);
- }
- }
- else
- {
- ELOG() << "PropertyManager:Set() unable to find property("
- << thePropertyID << ")" << std::endl;
- }
- }
- template<class TYPE>
- void Add(const std::string thePropertyID, TYPE theValue)
- {
- // Only add the property if it doesn't already exist
- if(mList.find(thePropertyID) == mList.end())
- {
- TProperty<TYPE>* anProperty=new(std::nothrow) TProperty<TYPE>(thePropertyID);
- anProperty->SetValue(theValue);
- mList[anProperty->GetID()]=anProperty;
- }
- }
- void Add(IProperty* theProperty);
- void Clone(const PropertyManager& thePropertyManager);
- protected:
- private:
- std::map<const std::string, IProperty*> mList;
- };
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment