Changeset 219 for code/branches/objecthierarchie/src/Identifier.h
- Timestamp:
- Nov 19, 2007, 10:10:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 {
Note: See TracChangeset
for help on using the changeset viewer.