Changeset 162 for code/branches/objecthierarchie/src
- Timestamp:
- Nov 5, 2007, 12:52:26 AM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/BaseObject.h
r150 r162 3 3 4 4 #include "ClassHierarchy.h" 5 #include "OrxonoxClass.h" 5 6 6 7 namespace orxonox 7 8 { 8 class BaseObject 9 class BaseObject : virtual public OrxonoxClass 9 10 { 10 11 public: … … 13 14 14 15 inline bool isA(Identifier* identifier) 15 { this-> identifier_->isA(identifier); }16 { this->getIdentifier()->isA(identifier); } 16 17 inline bool isDirectA(Identifier* identifier) 17 { this-> identifier_->isDirectA(identifier); }18 { this->getIdentifier()->isDirectA(identifier); } 18 19 inline bool isChildOf(Identifier* identifier) 19 { this-> identifier_->isChildOf(identifier); }20 { this->getIdentifier()->isChildOf(identifier); } 20 21 inline bool isDirectChildOf(Identifier* identifier) 21 { this-> identifier_->isDirectChildOf(identifier); }22 { this->getIdentifier()->isDirectChildOf(identifier); } 22 23 inline bool isParentOf(Identifier* identifier) 23 { this-> identifier_->isParentOf(identifier); }24 { this->getIdentifier()->isParentOf(identifier); } 24 25 inline bool isDirectParentOf(Identifier* identifier) 25 { this-> identifier_->isDirectParentOf(identifier); }26 { this->getIdentifier()->isDirectParentOf(identifier); } 26 27 27 ClassIdentifier<class BaseObject>* identifier_;28 // Identifier* identifier_; 28 29 29 protected: 30 IdentifierList* parents_; // INTERN! Don't touch this! 31 32 private: 30 // protected: 31 // IdentifierList* parents_; // INTERN! Don't touch this! 33 32 34 33 }; -
code/branches/objecthierarchie/src/CMakeLists.txt
r131 r162 2 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES orxonox.cc BaseObject.cc ClassHierarchy.cc)5 SET(INC_FILES BaseObject.h ClassHierarchy.h)4 SET(SRC_FILES orxonox.cc ClassHierarchy.cc OrxonoxClass.cc BaseObject.cc) 5 SET(INC_FILES ClassHierarchy.h OrxonoxClass.h BaseObject.h Test.h) 6 6 7 7 #Creates an executable -
code/branches/objecthierarchie/src/ClassHierarchy.cc
r150 r162 31 31 void Identifier::initialize(IdentifierList* parents) 32 32 { 33 std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; 33 34 if (parents) 34 35 { … … 76 77 } 77 78 78 void Identifier::addObject(BaseObject* object) 79 { 79 void Identifier::addObject(OrxonoxClass* object) 80 { 81 std::cout << "*** Added " << this->name_ << " to list.\n"; 80 82 this->objects_->add(object); 81 83 } 82 84 83 void Identifier::removeObject(BaseObject* object) 84 { 85 void Identifier::removeObject(OrxonoxClass* object) 86 { 87 std::cout << "*** Removed " << this->name_ << " from list.\n"; 85 88 this->objects_->remove(object); 86 89 } … … 218 221 } 219 222 220 void ObjectList::add( BaseObject* object)223 void ObjectList::add(OrxonoxClass* object) 221 224 { 222 225 ObjectListElement* temp = this->first_; … … 225 228 } 226 229 227 void ObjectList::remove( BaseObject* object)230 void ObjectList::remove(OrxonoxClass* object) 228 231 { 229 232 if (!object) … … 259 262 // ### ObjectListElement ### 260 263 // ############################### 261 ObjectListElement::ObjectListElement( BaseObject* object)264 ObjectListElement::ObjectListElement(OrxonoxClass* object) 262 265 { 263 266 this->object_ = object; 264 267 this->next_ = NULL; 265 268 } 269 270 271 // ############################### 272 // ### ClassHierarchy ### 273 // ############################### 274 ClassHierarchy* ClassHierarchy::pointer_ = NULL; 275 276 ClassHierarchy* ClassHierarchy::getSingleton() 277 { 278 if (!pointer_) 279 pointer_ = new ClassHierarchy(); 280 281 return pointer_; 282 } 283 284 ClassHierarchy::ClassHierarchy() 285 { 286 this->bCreatingHierarchy_ = false; 287 } 266 288 } -
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) \ -
code/branches/objecthierarchie/src/orxonox.cc
r116 r162 31 31 #include <OgreCEGUIRenderer.h> 32 32 33 #include "BaseObject.h" 34 #include "Test.h" 35 33 36 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE 34 37 #include <CoreFoundation/CoreFoundation.h> … … 83 86 void go() 84 87 { 85 createRoot();88 /* createRoot(); 86 89 defineResources(); 87 90 setupRenderSystem(); … … 93 96 createFrameListener(); 94 97 startRenderLoop(); 98 */ 99 std::cout << "Test 1\n"; 100 orxonox::BaseObject* test1; 101 test1 = new orxonox::BaseObject(); 102 test1 = new orxonox::BaseObject(); 103 test1 = new orxonox::BaseObject(); 104 105 std::cout << "Test 2\n"; 106 orxonox::A1* test2; 107 test2 = new orxonox::A1(); 108 test2 = new orxonox::A1(); 109 test2 = new orxonox::A1(); 110 111 std::cout << "Test 3\n"; 112 orxonox::BaseObject* test3; 113 test3 = new orxonox::BaseObject(); 114 test3 = new orxonox::BaseObject(); 115 test3 = new orxonox::BaseObject(); 116 117 std::cout << "Test 4\n"; 118 orxonox::A3* test4; 119 test4 = new orxonox::A3(); 120 test4 = new orxonox::A3(); 121 test4 = new orxonox::A3(); 122 95 123 } 96 124
Note: See TracChangeset
for help on using the changeset viewer.