|
mkRPG
|
00001 #ifndef TYPEDOBJECT_HXX 00002 #define TYPEDOBJECT_HXX 00003 00004 #include "gameobject.h" 00005 00027 template<class T> 00028 class Type : public GameObjectType 00029 { 00030 public: 00031 Type(DefaultTypes &parent) : 00032 GameObjectType(parent), aTypedAncestor(nullptr) 00033 {} 00034 Type(T &ancestor) : 00035 GameObjectType(ancestor), aTypedAncestor(&ancestor) 00036 { 00037 ancestor.typedDescendants.append(static_cast<T*>(this)); 00038 } 00039 00040 const QList<T*> &descendants() const{ 00041 return typedDescendants; 00042 } 00043 00044 protected: 00045 T *aTypedAncestor; 00046 00047 private: 00048 QList<T*> typedDescendants; 00049 }; 00050 00066 template<class T> 00067 class TypedObject : public InheritableObject 00068 { 00069 public: 00070 TypedObject(T &type, GameObject &parent) : 00071 InheritableObject(parent, &type), aObjectType(&type) 00072 {} 00073 00074 00075 T& objectType(){ 00076 return *aObjectType; 00077 } 00078 void setObjectType(T &type){ 00079 aObjectType = &type; 00080 aAncestor = &type; 00081 } 00082 00083 protected: 00084 T *aObjectType; 00085 00086 }; 00087 00088 #endif // TYPEDOBJECT_HXX
1.7.6.1