Changeset 219 for code/branches
- Timestamp:
- Nov 19, 2007, 10:10:11 PM (17 years ago)
- Location:
- code/branches/objecthierarchie/src
- Files:
-
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/BaseObject.h
r197 r219 64 64 { this->getIdentifier()->isDirectParentOf(object->getIdentifier); } 65 65 */ 66 67 66 }; 68 67 } -
code/branches/objecthierarchie/src/CMakeLists.txt
r218 r219 2 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.cc Identifier.cc Factory.cc ClassHierarchy.ccOrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc)5 SET(INC_FILES IdentifierIncludes.h ClassHierarchy.hIdentifier.h Factory.h IdentifierList.h ObjectList.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h)4 SET(SRC_FILES orxonox.cc IdentifierList.cc ObjectList.cc Identifier.cc Factory.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc) 5 SET(INC_FILES IdentifierIncludes.h Identifier.h Factory.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/Factory.cc
r218 r219 1 1 #include "Factory.h" 2 2 #include "Identifier.h" 3 #include "BaseObject.h" 3 4 4 5 namespace orxonox 5 6 { 6 ClassFactory* ClassFactory::pointer_ = NULL;7 ClassFactory* ClassFactory::pointer_s = NULL; 7 8 8 OrxonoxClass* ClassFactory::fabricate(const std::string& name)9 BaseObject* ClassFactory::fabricate(const std::string& name) 9 10 { 10 if (!pointer_ )11 pointer_ = new ClassFactory;11 if (!pointer_s) 12 pointer_s = new ClassFactory; 12 13 13 return pointer_ ->identifierMap_[name]->fabricate();14 return pointer_s->identifierMap_[name]->fabricate(); 14 15 } 15 16 16 17 void ClassFactory::add(const std::string& name, Identifier* identifier) 17 18 { 18 if (!pointer_ )19 pointer_ = new ClassFactory;19 if (!pointer_s) 20 pointer_s = new ClassFactory; 20 21 21 pointer_ ->identifierMap_[name] = identifier;22 pointer_s->identifierMap_[name] = identifier; 22 23 } 23 24 } -
code/branches/objecthierarchie/src/Factory.h
r218 r219 8 8 { 9 9 class Identifier; 10 class OrxonoxClass;10 class BaseObject; 11 11 12 12 class ClassFactory 13 13 { 14 14 public: 15 static OrxonoxClass* fabricate(const std::string& name);15 static BaseObject* fabricate(const std::string& name); 16 16 static void add(const std::string& name, Identifier* identifier); 17 17 … … 21 21 ~ClassFactory() {} 22 22 23 static ClassFactory* pointer_ ;23 static ClassFactory* pointer_s; 24 24 std::map<std::string, Identifier*> identifierMap_; 25 25 }; -
code/branches/objecthierarchie/src/Identifier.cc
r197 r219 6 6 // ### Identifier ### 7 7 // ############################### 8 int Identifier::hierarchyCreatingCounter_s = 0; 9 8 10 Identifier::Identifier() 9 11 { 10 12 this->bCreatedOneObject_ = false; 11 this->directParents_ = new IdentifierList();12 this->allParents_ = new IdentifierList();13 this->directChildren_ = new IdentifierList();14 this->allChildren_ = new IdentifierList();15 this->objects_ = new ObjectList();13 // this->directParents_ = new IdentifierList(); 14 // this->allParents_ = new IdentifierList(); 15 // this->directChildren_ = new IdentifierList(); 16 // this->allChildren_ = new IdentifierList(); 17 // this->objects_ = new ObjectList(); 16 18 } 17 19 18 20 Identifier::~Identifier() 19 21 { 20 delete this->directParents_;21 delete this->allParents_;22 delete this->directChildren_;23 delete this->allChildren_;24 delete this->objects_;22 // delete this->directParents_; 23 // delete this->allParents_; 24 // delete this->directChildren_; 25 // delete this->allChildren_; 26 // delete this->objects_; 25 27 delete &this->name_; 26 28 } … … 40 42 while (temp1) 41 43 { 42 temp2 = temp1->identifier_->directParents_ ->first_;44 temp2 = temp1->identifier_->directParents_.first_; 43 45 while (temp2) 44 46 { … … 62 64 if (temp1->bDirect_) 63 65 { 64 this->directParents_ ->add(temp1->identifier_);65 temp1->identifier_->directChildren_ ->add(this);66 this->directParents_.add(temp1->identifier_); 67 temp1->identifier_->directChildren_.add(this); 66 68 } 67 69 68 this->allParents_ ->add(temp1->identifier_);69 temp1->identifier_->allChildren_ ->add(this);70 this->allParents_.add(temp1->identifier_); 71 temp1->identifier_->allChildren_.add(this); 70 72 71 73 temp1 = temp1->next_; … … 77 79 { 78 80 std::cout << "*** Added " << this->name_ << " to list.\n"; 79 this->objects_ ->add(object);81 this->objects_.add(object); 80 82 } 81 83 … … 83 85 { 84 86 std::cout << "*** Removed " << this->name_ << " from list.\n"; 85 this->objects_ ->remove(object);87 this->objects_.remove(object); 86 88 } 87 89 88 90 bool Identifier::isA(Identifier* identifier) 89 91 { 90 return (identifier == this || this->allParents_ ->isInList(identifier));92 return (identifier == this || this->allParents_.isInList(identifier)); 91 93 } 92 94 … … 98 100 bool Identifier::isChildOf(Identifier* identifier) 99 101 { 100 return this->allParents_ ->isInList(identifier);102 return this->allParents_.isInList(identifier); 101 103 } 102 104 103 105 bool Identifier::isDirectChildOf(Identifier* identifier) 104 106 { 105 return this->directParents_ ->isInList(identifier);107 return this->directParents_.isInList(identifier); 106 108 } 107 109 108 110 bool Identifier::isParentOf(Identifier* identifier) 109 111 { 110 return this->allChildren_ ->isInList(identifier);112 return this->allChildren_.isInList(identifier); 111 113 } 112 114 113 115 bool Identifier::isDirectParentOf(Identifier* identifier) 114 116 { 115 return this->directChildren_ ->isInList(identifier);117 return this->directChildren_.isInList(identifier); 116 118 } 117 119 } -
code/branches/objecthierarchie/src/Identifier.h
r218 r219 2 2 #define _Identifier_H__ 3 3 4 #include "ClassHierarchy.h" 4 #include <iostream> 5 5 6 #include "IdentifierList.h" 6 7 #include "ObjectList.h" 7 #include "OrxonoxClass.h"8 //#include "OrxonoxClass.h" 8 9 #include "Factory.h" 10 11 // DONE AND TESTED: 12 // - build class hierarchy 13 // - isA, isChildOf, ... 14 // - insert into class-lists 15 // - ClassIdentifier 16 // - BaseIdentifier 17 // - Factory 18 19 // IN WORK: 20 21 // TO DO: 22 // - iterate through lists 9 23 10 24 namespace orxonox 11 25 { 26 class BaseObject; 27 12 28 // ##### Identifier ##### 13 29 class Identifier … … 23 39 void removeObject(OrxonoxClass* object); 24 40 25 virtual OrxonoxClass* fabricate() {};41 virtual BaseObject* fabricate() {}; 26 42 27 43 bool isA(Identifier* identifier); … … 33 49 34 50 std::string getName() { return this->name_; } 35 IdentifierList* getDirectParents() { return this->directParents_; } 36 IdentifierList* getAllParents() { return this->allParents_; } 37 IdentifierList* getDirectChildren() { return this->directChildren_; } 38 IdentifierList* getAllChildren() { return this->allChildren_; } 51 IdentifierList* getDirectParents() { return &(this->directParents_); } 52 IdentifierList* getAllParents() { return &(this->allParents_); } 53 IdentifierList* getDirectChildren() { return &(this->directChildren_); } 54 IdentifierList* getAllChildren() { return &(this->allChildren_); } 55 56 static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 39 57 40 58 private: … … 44 62 void initialize(IdentifierList* parents); 45 63 46 IdentifierList* directParents_; 47 IdentifierList* allParents_; 48 IdentifierList* directChildren_; 49 IdentifierList* allChildren_; 50 51 ObjectList* objects_; 64 static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; std::cout << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n"; } 65 static void stopCreatingHierarchy() { hierarchyCreatingCounter_s--; std::cout << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n"; } 66 67 IdentifierList directParents_; 68 IdentifierList allParents_; 69 IdentifierList directChildren_; 70 IdentifierList allChildren_; 71 72 ObjectList objects_; 52 73 std::string name_; 53 74 54 75 bool bIsAbstractClass_; 55 76 bool bCreatedOneObject_; 77 78 static int hierarchyCreatingCounter_s; 56 79 }; 57 80 … … 64 87 static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass, bool bIsAbstractClass); 65 88 static ClassIdentifier<T>* getIdentifier(); 66 OrxonoxClass* fabricate();89 BaseObject* fabricate(); 67 90 T* fabricateClass(); 68 91 … … 72 95 ~ClassIdentifier(); 73 96 74 static ClassIdentifier<T>* pointer_ ;97 static ClassIdentifier<T>* pointer_s; 75 98 76 99 }; 77 100 78 101 template <class T> 79 ClassIdentifier<T>* ClassIdentifier<T>::pointer_ = NULL;102 ClassIdentifier<T>* ClassIdentifier<T>::pointer_s = NULL; 80 103 81 104 template <class T> … … 87 110 ClassIdentifier<T>::~ClassIdentifier() 88 111 { 89 this->pointer_ = NULL;90 } 91 92 template <class T> 93 OrxonoxClass* ClassIdentifier<T>::fabricate()94 { 95 return this->fabricateClass();112 this->pointer_s = NULL; 113 } 114 115 template <class T> 116 BaseObject* ClassIdentifier<T>::fabricate() 117 { 118 return dynamic_cast<BaseObject*>(this->fabricateClass()); 96 119 } 97 120 … … 99 122 T* ClassIdentifier<T>::fabricateClass() 100 123 { 101 return new T; 124 if (!this->bIsAbstractClass_) 125 { 126 return new T; 127 } 128 else 129 { 130 std::cout << "Error: Couldn't create a new Object - Class " << this->name_ << " is abstract!\n"; 131 std::cout << "Aborting...\n"; 132 abort(); 133 } 102 134 } 103 135 … … 106 138 { 107 139 std::cout << "*** Register Class in " << name << "-Singleton.\n"; 108 if (!pointer_ )140 if (!pointer_s) 109 141 { 110 142 std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n"; 111 143 if (parents || bRootClass) 112 144 { 113 pointer_ = new ClassIdentifier();114 pointer_ ->name_ = name;115 pointer_ ->bIsAbstractClass_ = bIsAbstractClass;116 117 ClassFactory::add(name, pointer_ );118 119 pointer_ ->initialize(parents);145 pointer_s = new ClassIdentifier(); 146 pointer_s->name_ = name; 147 pointer_s->bIsAbstractClass_ = bIsAbstractClass; 148 149 ClassFactory::add(name, pointer_s); 150 151 pointer_s->initialize(parents); 120 152 } 121 153 else 122 154 { 123 pointer_ = getIdentifier();124 } 125 } 126 127 return pointer_ ;155 pointer_s = getIdentifier(); 156 } 157 } 158 159 return pointer_s; 128 160 } 129 161 … … 132 164 { 133 165 // std::cout << "*** Get Identifier.\n"; 134 if (!pointer_ )166 if (!pointer_s) 135 167 { 136 168 std::cout << "*** Get Identifier -> Create Class\n"; 137 ClassHierarchy::getSingleton()->startCreatingHierarchy();169 Identifier::startCreatingHierarchy(); 138 170 T* temp = new T(); 139 ClassHierarchy::getSingleton()->stopCreatingHierarchy();171 Identifier::stopCreatingHierarchy(); 140 172 delete temp; 141 173 } 142 174 143 return pointer_ ;175 return pointer_s; 144 176 } 145 177 … … 176 208 B* fabricate() 177 209 { 178 OrxonoxClass* newObject = this->identifier_->fabricate();210 BaseObject* newObject = this->identifier_->fabricate(); 179 211 if (newObject) 180 212 { -
code/branches/objecthierarchie/src/IdentifierIncludes.h
r218 r219 1 #include "ClassHierarchy.h"2 1 #include "Identifier.h" 3 2 #include "Factory.h" … … 5 4 #include "ObjectList.h" 6 5 #include "OrxonoxClass.h" 6 7 8 #define registerRootObject(ClassName) \ 9 std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \ 10 if (Identifier::isCreatingHierarchy() && !this->getParents()) \ 11 this->setParents(new IdentifierList()); \ 12 if (this->getIdentifier()) \ 13 this->getIdentifier()->removeObject(this); \ 14 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true, false)); \ 15 if (Identifier::isCreatingHierarchy() && this->getParents()) \ 16 this->getParents()->add(this->getIdentifier()); \ 17 this->getIdentifier()->addObject(this) 18 19 #define registerAbstractRootObject(ClassName) \ 20 std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \ 21 if (Identifier::isCreatingHierarchy() && !this->getParents()) \ 22 this->setParents(new IdentifierList()); \ 23 if (this->getIdentifier()) \ 24 this->getIdentifier()->removeObject(this); \ 25 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, true, true)); \ 26 if (Identifier::isCreatingHierarchy() && this->getParents()) \ 27 this->getParents()->add(this->getIdentifier()); \ 28 this->getIdentifier()->addObject(this) 29 30 #define registerObject(ClassName) \ 31 std::cout << "*** Register Object: " << #ClassName << "\n"; \ 32 this->getIdentifier()->removeObject(this); \ 33 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false, false)); \ 34 if (Identifier::isCreatingHierarchy() && this->getParents()) \ 35 this->getParents()->add(this->getIdentifier()); \ 36 this->getIdentifier()->addObject(this) 37 38 #define registerAbstractObject(ClassName) \ 39 std::cout << "*** Register Object: " << #ClassName << "\n"; \ 40 this->getIdentifier()->removeObject(this); \ 41 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, false, true)); \ 42 if (Identifier::isCreatingHierarchy() && this->getParents()) \ 43 this->getParents()->add(this->getIdentifier()); \ 44 this->getIdentifier()->addObject(this) 45 46 #define unregisterObject() \ 47 this->getIdentifier()->removeObject(this) 48 49 #define Class(ClassName) \ 50 ClassIdentifier<ClassName>::getIdentifier() 51 52 #define CreateFactory(ClassName) \ 53 Identifier* global_##ClassName##_Identifier = ClassIdentifier<ClassName>::getIdentifier() 54 55 #define Factory(Name) \ 56 ClassFactory::fabricate(Name) -
code/branches/objecthierarchie/src/OrxonoxClass.cc
r197 r219 1 #include "ClassHierarchy.h"2 1 #include "OrxonoxClass.h" 3 2 -
code/branches/objecthierarchie/src/OrxonoxClass.h
r218 r219 2 2 #define _OrxonoxClass_H__ 3 3 4 #include "Identifier.h" 4 5 #include "IdentifierList.h" 5 #include "Identifier.h"6 6 7 7 namespace orxonox -
code/branches/objecthierarchie/src/Test.h
r218 r219 10 10 { 11 11 public: 12 Interface1() { register RootObject(Interface1); }12 Interface1() { registerAbstractRootObject(Interface1); } 13 13 }; 14 14 … … 16 16 { 17 17 public: 18 Interface2() { register RootObject(Interface2); }18 Interface2() { registerAbstractRootObject(Interface2); } 19 19 }; 20 20 -
code/branches/objecthierarchie/src/orxonox.cc
r218 r219 504 504 std::cout << "1\n"; 505 505 Identifier* test9_01 = Class(A3); 506 OrxonoxClass* test9_02 = test9_01->fabricate();506 BaseObject* test9_02 = test9_01->fabricate(); 507 507 std::cout << test9_02->getIdentifier()->getName() << "\n"; 508 508 509 509 std::cout << "\n2\n"; 510 OrxonoxClass* test9_03 = Class(A1B2)->fabricate();510 BaseObject* test9_03 = Class(A1B2)->fabricate(); 511 511 std::cout << test9_03->getIdentifier()->getName() << "\n"; 512 512 … … 518 518 519 519 std::cout << "\n4\n"; 520 OrxonoxClass* test9_06 = Factory("A2B2");520 BaseObject* test9_06 = Factory("A2B2"); 521 521 std::cout << test9_06->getIdentifier()->getName() << "\n"; 522 522
Note: See TracChangeset
for help on using the changeset viewer.