Guest User

GQE - TPROPERTY- HEADER

a guest
Jan 24th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #ifndef TPROPERTY_HPP_INCLUDED
  2. #define TPROPERTY_HPP_INCLUDED
  3.  
  4. #include <typeinfo>
  5. #include "IProperty.hpp"
  6.  
  7. namespace GQE
  8. {
  9.   /// The Template version of the IProperty class for custom property values
  10.   template<class TYPE=unsigned int>
  11.     class TProperty : public IProperty
  12.   {
  13.     public:
  14.       /**
  15.        * TProperty default constructor
  16.        * @param[in] thePropertyID to use for this property
  17.        */
  18.       TProperty(const std::string thePropertyID) :
  19.         IProperty(typeid(TYPE).name(), thePropertyID)
  20.     {
  21.     }
  22.  
  23.       /**
  24.        * GetValue will return the property value
  25.        * @return the property value
  26.        */
  27.       TYPE GetValue()
  28.       {
  29.         return mValue;
  30.       }
  31.  
  32.       /**
  33.        * SetValue will set the property value to the value
  34.        * provided.
  35.        */
  36.       void SetValue(TYPE theValue)
  37.       {
  38.         mValue=theValue;
  39.       }
  40.  
  41.       /**
  42.        * Update will be called giving each property a chance to change itself
  43.        * during the Update phase of the GameLoop (see IEntity::UpdateFixed)
  44.        */
  45.       void Update()
  46.       {
  47.       }
  48.  
  49.       /**
  50.        * MakeClone is responsible for creating a clone of this IProperty
  51.        * derived class and returning it as part of the Prototype and Instance
  52.        * system. The value of the Property will also be copied into the clone.
  53.        * @return pointer to the IProperty derived class clone that was created
  54.        */
  55.       IProperty* MakeClone()
  56.       {
  57.         TProperty<TYPE>* anProperty = new(std::nothrow) TProperty<TYPE>(GetID());
  58.  
  59.         // Make sure new didn't fail before setting the value for this property
  60.         if(NULL != anProperty)
  61.         {
  62.           anProperty->SetValue(mValue);
  63.         }
  64.  
  65.         // Return cloned anProperty or NULL if none was created
  66.         return anProperty;
  67.       }
  68.     private:
  69.       TYPE mValue;
  70.   };
  71. } // namespace GQE
  72. #endif // TPROPERTY_HPP_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment