Changeset 197 for code/branches
- Timestamp:
- Nov 13, 2007, 3:22:29 AM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 13 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/BaseObject.h
r176 r197 2 2 #define _BaseObject_H__ 3 3 4 #include "ClassHierarchy.h" 5 #include "OrxonoxClass.h" 4 #include "IdentifierIncludes.h" 6 5 7 6 namespace orxonox … … 26 25 { this->getIdentifier()->isDirectParentOf(identifier); } 27 26 28 // Identifier* identifier_; 27 inline bool isA(BaseIdentifier<class B>* identifier) 28 { this->getIdentifier()->isA(identifier->getIdentifier()); } 29 inline bool isDirectlyA(BaseIdentifier<class B>* identifier) 30 { this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); } 31 inline bool isChildOf(BaseIdentifier<class B>* identifier) 32 { this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 33 inline bool isDirectChildOf(BaseIdentifier<class B>* identifier) 34 { this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 35 inline bool isParentOf(BaseIdentifier<class B>* identifier) 36 { this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 37 inline bool isDirectParentOf(BaseIdentifier<class B>* identifier) 38 { this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 29 39 30 // protected: 31 // IdentifierList* parents_; // INTERN! Don't touch this! 40 inline bool isA(BaseIdentifier<class B> identifier) 41 { this->getIdentifier()->isA(identifier.getIdentifier()); } 42 inline bool isDirectlyA(BaseIdentifier<class B> identifier) 43 { this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); } 44 inline bool isChildOf(BaseIdentifier<class B> identifier) 45 { this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 46 inline bool isDirectChildOf(BaseIdentifier<class B> identifier) 47 { this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 48 inline bool isParentOf(BaseIdentifier<class B> identifier) 49 { this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 50 inline bool isDirectParentOf(BaseIdentifier<class B> identifier) 51 { this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 52 /* 53 inline bool isA(OrxonoxClass* object) 54 { this->getIdentifier()->isA(object->getIdentifier()); } 55 inline bool isDirectlyA(OrxonoxClass* object) 56 { this->getIdentifier()->isDirectlyA(object->getIdentifier); } 57 inline bool isChildOf(OrxonoxClass* object) 58 { this->getIdentifier()->isChildOf(object->getIdentifier); } 59 inline bool isDirectChildOf(OrxonoxClass* object) 60 { this->getIdentifier()->isDirectChildOf(object->getIdentifier); } 61 inline bool isParentOf(OrxonoxClass* object) 62 { this->getIdentifier()->isParentOf(object->getIdentifier); } 63 inline bool isDirectParentOf(OrxonoxClass* object) 64 { this->getIdentifier()->isDirectParentOf(object->getIdentifier); } 65 */ 32 66 33 67 }; -
code/branches/objecthierarchie/src/CMakeLists.txt
r162 r197 2 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES orxonox.cc ClassHierarchy.cc OrxonoxClass.cc BaseObject.cc)5 SET(INC_FILES ClassHierarchy.h OrxonoxClass.h BaseObject.h Test.h)4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.cc Identifier.cc ClassHierarchy.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc) 5 SET(INC_FILES ClassHierarchy.h Identifier.h IdentifierList.h ObjectList.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h) 6 6 7 7 #Creates an executable -
code/branches/objecthierarchie/src/ClassHierarchy.cc
r172 r197 4 4 namespace orxonox 5 5 { 6 // ###############################7 // ### Identifier ###8 // ###############################9 // Identifier* Identifier::pointer_ = NULL;10 /*11 Identifier* Identifier::registerClass(IdentifierList* parents)12 {13 if (!pointer_)14 {15 pointer_ = new Identifier();16 pointer_->initialize(parents);17 }18 19 return pointer_;20 }21 */22 Identifier::Identifier()23 {24 this->bCreatedOneObject_ = false;25 this->directParents_ = new IdentifierList();26 this->allParents_ = new IdentifierList();27 this->directChildren_ = new IdentifierList();28 this->allChildren_ = new IdentifierList();29 this->objects_ = new ObjectList();30 }31 32 Identifier::~Identifier()33 {34 delete this->directParents_;35 delete this->allParents_;36 delete this->directChildren_;37 delete this->allChildren_;38 delete this->objects_;39 delete &this->name_;40 }41 42 void Identifier::initialize(IdentifierList* parents)43 {44 std::cout << "*** Initialize " << this->name_ << "-Singleton.\n";45 if (parents)46 {47 this->bCreatedOneObject_ = true;48 49 IdentifierListElement* temp1;50 IdentifierListElement* temp2;51 IdentifierListElement* temp3;52 53 temp1 = parents->first_;54 while (temp1)55 {56 temp2 = temp1->identifier_->directParents_->first_;57 while (temp2)58 {59 temp3 = parents->first_;60 while(temp3)61 {62 if (temp3->identifier_ == temp2->identifier_)63 temp3->bDirect_ = false;64 65 temp3 = temp3->next_;66 }67 68 temp2 = temp2->next_;69 }70 temp1 = temp1->next_;71 }72 73 temp1 = parents->first_;74 while (temp1)75 {76 if (temp1->bDirect_)77 {78 this->directParents_->add(temp1->identifier_);79 temp1->identifier_->directChildren_->add(this);80 }81 82 this->allParents_->add(temp1->identifier_);83 temp1->identifier_->allChildren_->add(this);84 85 temp1 = temp1->next_;86 }87 }88 }89 90 void Identifier::addObject(OrxonoxClass* object)91 {92 std::cout << "*** Added " << this->name_ << " to list.\n";93 this->objects_->add(object);94 }95 96 void Identifier::removeObject(OrxonoxClass* object)97 {98 std::cout << "*** Removed " << this->name_ << " from list.\n";99 this->objects_->remove(object);100 }101 102 bool Identifier::isA(Identifier* identifier)103 {104 return (identifier == this || this->allParents_->isInList(identifier));105 }106 107 bool Identifier::isDirectlyA(Identifier* identifier)108 {109 return (identifier == this);110 }111 112 bool Identifier::isChildOf(Identifier* identifier)113 {114 return this->allParents_->isInList(identifier);115 }116 117 bool Identifier::isDirectChildOf(Identifier* identifier)118 {119 return this->directParents_->isInList(identifier);120 }121 122 bool Identifier::isParentOf(Identifier* identifier)123 {124 return this->allChildren_->isInList(identifier);125 }126 127 bool Identifier::isDirectParentOf(Identifier* identifier)128 {129 return this->directChildren_->isInList(identifier);130 }131 132 133 // ###############################134 // ### IdentifierList ###135 // ###############################136 IdentifierList::IdentifierList()137 {138 this->first_ = NULL;139 }140 141 IdentifierList::~IdentifierList()142 {143 IdentifierListElement* temp;144 while (this->first_)145 {146 temp = this->first_->next_;147 delete this->first_;148 this->first_ = temp;149 }150 }151 152 void IdentifierList::add(Identifier* identifier)153 {154 IdentifierListElement* temp = this->first_;155 this->first_ = new IdentifierListElement(identifier);156 this->first_->next_ = temp;157 }158 159 void IdentifierList::remove(Identifier* identifier)160 {161 if (!identifier)162 return;163 164 if (this->first_->identifier_ == identifier)165 {166 IdentifierListElement* temp = this->first_->next_;167 delete this->first_;168 this->first_ = temp;169 170 return;171 }172 173 IdentifierListElement* temp = this->first_;174 while (temp->next_)175 {176 if (temp->next_->identifier_ == identifier)177 {178 IdentifierListElement* temp2 = temp->next_->next_;179 delete temp->next_;180 temp->next_ = temp2;181 182 return;183 }184 185 temp = temp->next_;186 }187 }188 189 bool IdentifierList::isInList(Identifier* identifier)190 {191 IdentifierListElement* temp = this->first_;192 while (temp)193 {194 if (temp->identifier_ == identifier)195 return true;196 197 temp = temp->next_;198 }199 200 return false;201 }202 203 std::string IdentifierList::toString()204 {205 IdentifierListElement* temp = this->first_;206 std::string output = "";207 208 while (temp)209 {210 output += temp->identifier_->getName();211 output += " ";212 213 temp = temp->next_;214 }215 216 return output;217 }218 219 220 // ###############################221 // ### IdentifierListElement ###222 // ###############################223 IdentifierListElement::IdentifierListElement(Identifier* identifier)224 {225 this->identifier_ = identifier;226 this->next_ = NULL;227 this->bDirect_ = true;228 }229 230 IdentifierListElement::~IdentifierListElement()231 {232 }233 234 235 // ###############################236 // ### ObjectList ###237 // ###############################238 ObjectList::ObjectList()239 {240 this->first_ = NULL;241 }242 243 ObjectList::~ObjectList()244 {245 ObjectListElement* temp;246 while (this->first_)247 {248 temp = this->first_->next_;249 delete this->first_;250 this->first_ = temp;251 }252 }253 254 void ObjectList::add(OrxonoxClass* object)255 {256 ObjectListElement* temp = this->first_;257 this->first_ = new ObjectListElement(object);258 this->first_->next_ = temp;259 }260 261 void ObjectList::remove(OrxonoxClass* object)262 {263 if (!object)264 return;265 266 if (this->first_->object_ == object)267 {268 ObjectListElement* temp = this->first_->next_;269 delete this->first_;270 this->first_ = temp;271 272 return;273 }274 275 ObjectListElement* temp = this->first_;276 while (temp->next_)277 {278 if (temp->next_->object_ == object)279 {280 ObjectListElement* temp2 = temp->next_->next_;281 delete temp->next_;282 temp->next_ = temp2;283 284 return;285 }286 287 temp = temp->next_;288 }289 }290 291 292 // ###############################293 // ### ObjectListElement ###294 // ###############################295 ObjectListElement::ObjectListElement(OrxonoxClass* object)296 {297 this->object_ = object;298 this->next_ = NULL;299 }300 301 ObjectListElement::~ObjectListElement()302 {303 }304 305 306 6 // ############################### 307 7 // ### ClassHierarchy ### -
code/branches/objecthierarchie/src/ClassHierarchy.h
r176 r197 10 10 // - insert into class-lists 11 11 // - ClassIdentifier 12 // - BaseIdentifier 12 13 13 14 // IN WORK: 14 // - BaseIdentifier15 15 // - Factory 16 16 … … 45 45 }; 46 46 47 // ##### Identifier #####48 class IdentifierList;49 class ObjectList;50 class OrxonoxClass;51 52 class Identifier53 {54 template <class T>55 friend class ClassIdentifier;56 57 template <class T>58 friend class BaseIdentifier;59 60 public:61 void addObject(OrxonoxClass* object);62 void removeObject(OrxonoxClass* object);63 64 bool isA(Identifier* identifier);65 bool isDirectlyA(Identifier* identifier);66 bool isChildOf(Identifier* identifier);67 bool isDirectChildOf(Identifier* identifier);68 bool isParentOf(Identifier* identifier);69 bool isDirectParentOf(Identifier* identifier);70 71 std::string getName() { return this->name_; }72 IdentifierList* getDirectParents() { return this->directParents_; }73 IdentifierList* getAllParents() { return this->allParents_; }74 IdentifierList* getDirectChildren() { return this->directChildren_; }75 IdentifierList* getAllChildren() { return this->allChildren_; }76 77 private:78 Identifier();79 Identifier(const Identifier& identifier) {}80 virtual ~Identifier();81 void initialize(IdentifierList* parents);82 83 IdentifierList* directParents_;84 IdentifierList* allParents_;85 IdentifierList* directChildren_;86 IdentifierList* allChildren_;87 88 ObjectList* objects_;89 std::string name_;90 91 bool bCreatedOneObject_;92 };93 94 95 // ##### ClassIdentifier #####96 template <class T>97 class ClassIdentifier : public Identifier98 {99 public:100 static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass);101 static ClassIdentifier<T>* getIdentifier();102 static T* create();103 104 private:105 ClassIdentifier();106 ClassIdentifier(const ClassIdentifier<T>& identifier) {}107 ~ClassIdentifier();108 109 static ClassIdentifier<T>* pointer_;110 111 };112 113 template <class T>114 ClassIdentifier<T>* ClassIdentifier<T>::pointer_ = NULL;115 116 template <class T>117 ClassIdentifier<T>::ClassIdentifier()118 {119 }120 121 template <class T>122 ClassIdentifier<T>::~ClassIdentifier()123 {124 this->pointer_ = NULL;125 }126 127 template <class T>128 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(IdentifierList* parents, std::string name, bool bRootClass)129 {130 std::cout << "*** Register Class in " << name << "-Singleton.\n";131 if (!pointer_)132 {133 std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n";134 if (parents || bRootClass)135 {136 pointer_ = new ClassIdentifier();137 pointer_->name_ = name;138 pointer_->initialize(parents);139 }140 else141 {142 pointer_ = getIdentifier();143 }144 }145 146 return pointer_;147 }148 149 template <class T>150 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()151 {152 // std::cout << "*** Get Identifier.\n";153 if (!pointer_)154 {155 std::cout << "*** Get Identifier -> Create Class\n";156 ClassHierarchy::getSingleton()->startCreatingHierarchy();157 T* temp = new T();158 ClassHierarchy::getSingleton()->stopCreatingHierarchy();159 delete temp;160 }161 162 return pointer_;163 }164 165 template <class T>166 T* ClassIdentifier<T>::create()167 {168 return new T();169 }170 171 172 // ##### BaseIdentifier #####173 template <class B>174 class BaseIdentifier// : public Identifier175 {176 public:177 BaseIdentifier();178 179 template <class T>180 BaseIdentifier<B>& operator= (ClassIdentifier<T>* identifier)181 {182 std::cout << "####### Class(" << identifier->getName() << ")->isA( Class(" << ClassIdentifier<B>::getIdentifier()->getName() << ") ) = " << identifier->isA( ClassIdentifier<B>::getIdentifier() ) << "\n";183 if (!identifier->isA(ClassIdentifier<B>::getIdentifier()))184 {185 std::cout << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<B>::getIdentifier()->getName() << "!\n";186 std::cout << "Error: BaseIdentifier<" << ClassIdentifier<B>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";187 std::cout << "Aborting...\n";188 abort();189 }190 this->identifier_ = identifier;191 return *this;192 }193 194 operator Identifier()195 {196 return this->identifier_;197 }198 199 private:200 Identifier* identifier_;201 };202 203 template <class B>204 BaseIdentifier<B>::BaseIdentifier()205 {206 this->identifier_ = ClassIdentifier<B>::getIdentifier();207 }208 209 210 // ##### Identifier List #####211 class IdentifierListElement;212 213 class IdentifierList214 {215 public:216 IdentifierList();217 ~IdentifierList();218 void add(Identifier* identifier);219 void remove(Identifier* identifier);220 bool isInList(Identifier* identifier);221 std::string toString();222 223 IdentifierListElement* first_;224 };225 226 class IdentifierListElement227 {228 public:229 IdentifierListElement(Identifier* identifier);230 ~IdentifierListElement();231 232 Identifier* identifier_;233 IdentifierListElement* next_;234 bool bDirect_;235 };236 237 238 // ##### Object List #####239 class ObjectListElement;240 241 class ObjectList242 {243 public:244 ObjectList();245 ~ObjectList();246 void add(OrxonoxClass* object);247 void remove(OrxonoxClass* object);248 249 ObjectListElement* first_;250 };251 252 class ObjectListElement253 {254 public:255 ObjectListElement(OrxonoxClass* object);256 ~ObjectListElement();257 258 OrxonoxClass* object_;259 ObjectListElement* next_;260 };261 47 262 48 // ##### Macros ##### … … 267 53 if (this->getIdentifier()) \ 268 54 this->getIdentifier()->removeObject(this); \ 269 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true)); \ 55 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true, false)); \ 56 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \ 57 this->getParents()->add(this->getIdentifier()); \ 58 this->getIdentifier()->addObject(this) 59 60 #define registerAbstractRootObject(ClassName) \ 61 std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \ 62 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && !this->getParents()) \ 63 this->setParents(new IdentifierList()); \ 64 if (this->getIdentifier()) \ 65 this->getIdentifier()->removeObject(this); \ 66 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true, true)); \ 270 67 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \ 271 68 this->getParents()->add(this->getIdentifier()); \ … … 275 72 std::cout << "*** Register Object: " << #ClassName << "\n"; \ 276 73 this->getIdentifier()->removeObject(this); \ 277 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false)); \ 74 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false, false)); \ 75 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \ 76 this->getParents()->add(this->getIdentifier()); \ 77 this->getIdentifier()->addObject(this) 78 79 #define registerAbstractObject(ClassName) \ 80 std::cout << "*** Register Object: " << #ClassName << "\n"; \ 81 this->getIdentifier()->removeObject(this); \ 82 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false, true)); \ 278 83 if (ClassHierarchy::getSingleton()->isCreatingHierarchy() && this->getParents()) \ 279 84 this->getParents()->add(this->getIdentifier()); \ -
code/branches/objecthierarchie/src/OrxonoxClass.cc
r162 r197 1 #include "ClassHierarchy.h" 1 2 #include "OrxonoxClass.h" 2 #include "ClassHierarchy.h"3 3 4 4 namespace orxonox -
code/branches/objecthierarchie/src/OrxonoxClass.h
r162 r197 2 2 #define _OrxonoxClass_H__ 3 3 4 #include "IdentifierList.h" 5 #include "Identifier.h" 6 4 7 namespace orxonox 5 8 { 6 class Identifier;7 class IdentifierList;8 9 9 class OrxonoxClass 10 10 { -
code/branches/objecthierarchie/src/Test.h
r162 r197 2 2 #define _Test_H__ 3 3 4 5 #include "BaseObject.h" 6 #include "ClassHierarchy.h" 7 #include "OrxonoxClass.h" 4 #include "IdentifierIncludes.h" 8 5 9 6 namespace orxonox -
code/branches/objecthierarchie/src/orxonox.cc
r176 r197 33 33 #include "BaseObject.h" 34 34 #include "Test.h" 35 #include "test1.h" 36 #include "test2.h" 37 #include "test3.h" 35 38 36 39 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE … … 123 126 test4 = new A3(); 124 127 */ 125 128 /* 126 129 std::cout << "Test 5\n"; 127 130 A1* test5_01 = new A1(); … … 143 146 A3B2C1* test5_17 = new A3B2C1(); 144 147 A3B2C2* test5_18 = new A3B2C2(); 145 148 */ 146 149 /* 147 150 OrxonoxClass* test5; … … 175 178 } 176 179 */ 177 /* 180 178 181 #define testandcout(code) \ 179 182 std::cout << #code << " " << code << "\n" 180 183 181 184 /* 182 185 std::cout << "\n"; 183 186 std::cout << "isA(XYZ)-Test:\n"; … … 434 437 std::cout << "A2 parent of A2B1C1: " << Class(A2)->isParentOf(Class(A2B1C1)) << "\n"; 435 438 */ 436 439 /* 437 440 std::cout << "Test 7\n"; 438 441 std::cout << "1\n"; … … 443 446 test7_02 = Class(A1B1); 444 447 445 // std::cout << Identifier(test7_02).getName() << "\n"; 446 447 /* 448 std::cout << test7_01.getIdentifier()->getName() << "\n"; 449 std::cout << test7_02.getIdentifier()->getName() << "\n"; 450 */ 451 /* 452 std::cout << "2\n"; 453 448 454 BaseIdentifier<A1B1> test7_03; 449 455 test7_03 = Class(A1); … … 455 461 test7_05 = Class(A2); 456 462 */ 463 464 std::cout << "Test 8\n"; 465 466 std::cout << "1\n"; 467 Test1* test8_01 = new Test1; 468 Test3* test8_03 = new Test3; 469 test8_03->usefullClassesIsATest(test8_01); 470 457 471 std::cout << "2\n"; 472 Test2* test8_02 = new Test2; 473 test8_03->usefullClassesIsATest(test8_02); 474 475 std::cout << "3\n"; 476 test8_01->setUsefullClass1(Class(Test1)); 477 test8_01->setUsefullClass1(test8_02->getIdentifier()); 478 test8_01->setUsefullClass2(Class(Test2)); 479 test8_01->setUsefullClassOfTypeTest3(Class(Test3)); 480 test8_01->setUsefullClassOfTypeTest3(test8_03->getIdentifier()); 481 482 483 testandcout(test8_01->isA(Class(Test1))); 484 testandcout(test8_01->isA(Class(Test2))); 485 testandcout(test8_01->isA(Class(Test3))); 486 487 Test2* test8_04 = new Test2; 488 testandcout(test8_02->isA(Class(Test1))); 489 testandcout(test8_02->isA(Class(Test2))); 490 testandcout(test8_02->isA(Class(Test3))); 491 492 Test3* test8_05 = new Test3; 493 testandcout(test8_03->isA(Class(Test1))); 494 testandcout(test8_03->isA(Class(Test2))); 495 testandcout(test8_03->isA(Class(Test3))); 496 497 delete test8_01; 498 delete test8_02; 499 delete test8_03; 458 500 459 501
Note: See TracChangeset
for help on using the changeset viewer.