[132] | 1 | #ifndef _ClassHierarchy_H__ |
---|
| 2 | #define _ClassHierarchy_H__ |
---|
| 3 | |
---|
| 4 | #include <string> |
---|
| 5 | |
---|
| 6 | // DONE: |
---|
| 7 | // - klassenhierarchie aufbauen |
---|
| 8 | // - klassen-identifier |
---|
| 9 | |
---|
| 10 | // TODO: |
---|
| 11 | // - durch listen iterieren |
---|
| 12 | // - isA usw vergleiche |
---|
| 13 | // - new überladen + objekt in liste eintragen |
---|
| 14 | // - searchtree für classname-strings |
---|
| 15 | |
---|
| 16 | //namespace orxonox |
---|
| 17 | //{ |
---|
| 18 | class ClassName; |
---|
| 19 | class ClassList; |
---|
| 20 | class ObjectList; |
---|
| 21 | class BaseObject; |
---|
| 22 | |
---|
| 23 | template <class T> |
---|
| 24 | class ClassNameSingleton |
---|
| 25 | { |
---|
| 26 | public: |
---|
| 27 | static ClassName* getClassName(BaseObject* object, bool bIsRootClass); |
---|
| 28 | static ClassName* getNewClassName(); |
---|
| 29 | BaseObject* create(); |
---|
| 30 | |
---|
| 31 | private: |
---|
| 32 | ClassNameSingleton(); |
---|
| 33 | ~ClassNameSingleton(); |
---|
| 34 | static ClassNameSingleton *pointer; |
---|
| 35 | static ClassName *className; |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | class ClassName |
---|
| 39 | { |
---|
| 40 | public: |
---|
| 41 | ClassName(const std::string& name, ClassNameSingleton<class T>* factory); |
---|
| 42 | ~ClassName(); |
---|
| 43 | |
---|
| 44 | std::string name; |
---|
| 45 | ClassName *parentClass; |
---|
| 46 | ClassList *childClasses; |
---|
| 47 | ObjectList *objects; |
---|
| 48 | ClassNameSingleton<class T> *factory; |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | class ClassListItem |
---|
| 52 | { |
---|
| 53 | public: |
---|
| 54 | ClassListItem(ClassName* className); |
---|
| 55 | ~ClassListItem(); |
---|
| 56 | |
---|
| 57 | ClassListItem *next; |
---|
| 58 | ClassName *className; |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | class ClassList |
---|
| 62 | { |
---|
| 63 | public: |
---|
| 64 | ClassList(); |
---|
| 65 | ~ClassList(); |
---|
| 66 | void add(ClassName* className); |
---|
| 67 | |
---|
| 68 | ClassListItem *first; |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | class ObjectListItem |
---|
| 72 | { |
---|
| 73 | public: |
---|
| 74 | ObjectListItem(BaseObject* object); |
---|
| 75 | ~ObjectListItem(); |
---|
| 76 | |
---|
| 77 | ObjectListItem *next; |
---|
| 78 | BaseObject *object; |
---|
| 79 | }; |
---|
| 80 | |
---|
| 81 | class ObjectList |
---|
| 82 | { |
---|
| 83 | public: |
---|
| 84 | ObjectList(); |
---|
| 85 | ~ObjectList(); |
---|
| 86 | void add(BaseObject* object); |
---|
| 87 | void remove(BaseObject* object); |
---|
| 88 | |
---|
| 89 | ObjectListItem *first; |
---|
| 90 | }; |
---|
| 91 | |
---|
| 92 | class ClassNameTree |
---|
| 93 | { |
---|
| 94 | public: |
---|
| 95 | static ClassNameTree* getSingleton(); |
---|
| 96 | BaseObject* create(ClassName* className); |
---|
| 97 | BaseObject* create(std::string& name); |
---|
| 98 | ClassName* getClassName(std::string& name); |
---|
| 99 | ClassName* getClassName(std::string& name, ClassName* root); |
---|
| 100 | ClassName* getRootClass() { return this->rootClass; } |
---|
| 101 | void setRootClass(ClassName* className) { this->rootClass = className; } |
---|
| 102 | |
---|
| 103 | private: |
---|
| 104 | ClassNameTree(); |
---|
| 105 | ~ClassNameTree(); |
---|
| 106 | static ClassNameTree *pointer; |
---|
| 107 | ClassName* rootClass; |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | #define className(ClassName) \ |
---|
| 112 | ClassNameSingleton<ClassName>::getNewClassName() |
---|
| 113 | |
---|
| 114 | #define registerObject(ClassName, bIsRootClass) \ |
---|
| 115 | this->className = ClassNameSingleton<ClassName>::getClassName(this, bIsRootClass) |
---|
| 116 | |
---|
| 117 | #define unregisterObject() \ |
---|
| 118 | this->className->objects->remove(this) |
---|
| 119 | |
---|
| 120 | #define factory(ClassName) \ |
---|
| 121 | ClassNameTree::getSingleton()->create(ClassName) |
---|
| 122 | //} |
---|
| 123 | |
---|
| 124 | #endif |
---|