Changeset 218 for code/branches/objecthierarchie/src/Identifier.h
- Timestamp:
- Nov 19, 2007, 5:57:02 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchie/src/Identifier.h
r197 r218 6 6 #include "ObjectList.h" 7 7 #include "OrxonoxClass.h" 8 #include "Factory.h" 8 9 9 10 namespace orxonox … … 21 22 void addObject(OrxonoxClass* object); 22 23 void removeObject(OrxonoxClass* object); 24 25 virtual OrxonoxClass* fabricate() {}; 23 26 24 27 bool isA(Identifier* identifier); … … 61 64 static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass, bool bIsAbstractClass); 62 65 static ClassIdentifier<T>* getIdentifier(); 66 OrxonoxClass* fabricate(); 67 T* fabricateClass(); 63 68 64 69 private: … … 83 88 { 84 89 this->pointer_ = NULL; 90 } 91 92 template <class T> 93 OrxonoxClass* ClassIdentifier<T>::fabricate() 94 { 95 return this->fabricateClass(); 96 } 97 98 template <class T> 99 T* ClassIdentifier<T>::fabricateClass() 100 { 101 return new T; 85 102 } 86 103 … … 97 114 pointer_->name_ = name; 98 115 pointer_->bIsAbstractClass_ = bIsAbstractClass; 116 117 ClassFactory::add(name, pointer_); 118 99 119 pointer_->initialize(parents); 100 120 } … … 124 144 } 125 145 126 127 146 // ##### BaseIdentifier ##### 128 147 template <class B> 129 class BaseIdentifier // : public Identifier148 class BaseIdentifier 130 149 { 131 150 public: 132 151 BaseIdentifier(); 133 152 134 //template <class T> 135 BaseIdentifier<B>& operator= (/*Class*/Identifier/*<T>*/* identifier) 153 BaseIdentifier<B>& operator= (Identifier* identifier) 136 154 { 137 155 if (!identifier->isA(ClassIdentifier<B>::getIdentifier())) … … 145 163 return *this; 146 164 } 165 166 Identifier* operator* () 167 { 168 return this->identifier_; 169 } 170 171 Identifier* operator-> () const 172 { 173 return this->identifier_; 174 } 175 176 B* fabricate() 177 { 178 OrxonoxClass* newObject = this->identifier_->fabricate(); 179 if (newObject) 180 { 181 return dynamic_cast<B*>(newObject); 182 } 183 else 184 { 185 if (this->identifier_) 186 { 187 std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<B>::getIdentifier()->getName() << "!\n"; 188 std::cout << "Error: Couldn't fabricate a new Object.\n"; 189 std::cout << "Aborting...\n"; 190 } 191 else 192 { 193 std::cout << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n"; 194 std::cout << "Aborting...\n"; 195 } 196 197 abort(); 198 } 199 } 200 147 201 inline Identifier* getIdentifier() 148 202 { return this->identifier_; }
Note: See TracChangeset
for help on using the changeset viewer.