Changeset 162 for code/branches/objecthierarchie/src/ClassHierarchy.h
- Timestamp:
- Nov 5, 2007, 12:52:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/ClassHierarchy.h
r150 r162 3 3 4 4 #include <string> 5 #include <iostream> 5 6 6 7 // DONE: … … 18 19 namespace orxonox 19 20 { 21 // ##### ClassHierarchy ##### 22 class ClassHierarchy 23 { 24 public: 25 static ClassHierarchy* getSingleton(); 26 bool isCreatingHierarchy() { return this->bCreatingHierarchy_; } 27 void createHierarchy(bool bCreatingHierarchy) { this->bCreatingHierarchy_ = bCreatingHierarchy; std::cout << "*** Switched Hierarchy-Creating-Mode to" << bCreatingHierarchy << "\n"; } 28 29 private: 30 ClassHierarchy(); 31 32 static ClassHierarchy* pointer_; 33 bool bCreatingHierarchy_; 34 }; 35 20 36 // ##### Identifier ##### 21 37 class IdentifierList; 22 38 class ObjectList; 23 class BaseObject;39 class OrxonoxClass; 24 40 template <class T> 25 41 class ClassIdentifier; … … 31 47 32 48 public: 33 void addObject( BaseObject* object);34 void removeObject( BaseObject* object);49 void addObject(OrxonoxClass* object); 50 void removeObject(OrxonoxClass* object); 35 51 36 52 bool isA(Identifier* identifier); … … 60 76 { 61 77 public: 62 static ClassIdentifier<T>* registerClass(IdentifierList* parents );78 static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass); 63 79 static ClassIdentifier<T>* getIdentifier(); 64 80 static T* create(); … … 71 87 }; 72 88 73 #define getStringFromClassName(ClassName) \74 #ClassName75 76 89 template <class T> 77 90 ClassIdentifier<T>* ClassIdentifier<T>::pointer_ = NULL; … … 83 96 84 97 template <class T> 85 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(IdentifierList* parents) 86 { 98 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(IdentifierList* parents, std::string name, bool bRootClass) 99 { 100 std::cout << "*** Register Class in " << name << "-Singleton.\n"; 87 101 if (!pointer_) 88 102 { 89 pointer_ = new ClassIdentifier(); 90 pointer_->name_ = getStringFromClassName(T); 91 pointer_->initialize(parents); 103 std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n"; 104 if (parents || bRootClass) 105 { 106 pointer_ = new ClassIdentifier(); 107 pointer_->name_ = name; 108 pointer_->initialize(parents); 109 } 110 else 111 { 112 pointer_ = getIdentifier(); 113 } 92 114 } 93 115 … … 98 120 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 99 121 { 122 std::cout << "*** Get Identifier.\n"; 100 123 if (!pointer_) 101 124 { 125 std::cout << "*** Get Identifier -> Create Class\n"; 126 ClassHierarchy::getSingleton()->createHierarchy(true); 102 127 T* temp = new T(); 128 ClassHierarchy::getSingleton()->createHierarchy(false); 103 129 delete temp; 104 130 } … … 147 173 ObjectList(); 148 174 ~ObjectList(); 149 void add( BaseObject* object);150 void remove( BaseObject* object);175 void add(OrxonoxClass* object); 176 void remove(OrxonoxClass* object); 151 177 152 178 ObjectListElement* first_; … … 156 182 { 157 183 public: 158 ObjectListElement( BaseObject* object);159 160 BaseObject* object_;184 ObjectListElement(OrxonoxClass* object); 185 186 OrxonoxClass* object_; 161 187 ObjectListElement* next_; 162 188 }; 163 164 189 165 190 // ##### Macros ##### 166 191 #define registerRootObject(ClassName) \ 167 this->parents_ = new IdentifierList(); \ 168 this->identifier_ = ClassIdentifier<ClassName>::registerClass(this->parents_); \ 169 this->parents_->add(this->identifier_); \ 170 this->identifier_->addObject(this) 192 std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \ 193 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && !this->getParents()) \ 194 this->setParents(new IdentifierList()); \ 195 if (this->getIdentifier()) \ 196 this->getIdentifier()->removeObject(this); \ 197 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true)); \ 198 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \ 199 this->getParents()->add(this->getIdentifier()); \ 200 this->getIdentifier()->addObject(this) 171 201 172 202 #define registerObject(ClassName) \ 173 this->identifier_->removeObject(this); \ 174 this->identifier_ = ClassIdentifier<ClassName>::registerClass(this->parents_); \ 175 this->parents_->add(this->identifier_); \ 176 this->identifier_->addObject(this) 203 std::cout << "*** Register Object: " << #ClassName << "\n"; \ 204 this->getIdentifier()->removeObject(this); \ 205 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false)); \ 206 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \ 207 this->getParents()->add(this->getIdentifier()); \ 208 this->getIdentifier()->addObject(this) 177 209 178 210 #define unregisterObject() \ 179 delete this->parents_; \ 180 this->identifier_->removeObject(this) 211 this->getIdentifier()->removeObject(this) 181 212 182 213 #define Class(ClassName) \
Note: See TracChangeset
for help on using the changeset viewer.