Changeset 805 for code/branches/core/src/orxonox/core/Identifier.h
- Timestamp:
- Feb 12, 2008, 4:24:14 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/src/orxonox/core/Identifier.h
r790 r805 89 89 { 90 90 template <class T> 91 friend class ClassIdentifier; // Forward declaration91 friend class ClassIdentifier; 92 92 93 93 template <class T> 94 friend class SubclassIdentifier; // Forward declaration95 96 friend class Factory; // Forward declaration94 friend class SubclassIdentifier; 95 96 friend class Factory; 97 97 98 98 public: … … 106 106 bool isParentOf(const Identifier* identifier) const; 107 107 108 static std::map<std::string, Identifier*>& getIdentifierMap();108 // static std::map<std::string, Identifier*>& getIdentifierMap(); 109 109 110 110 /** @brief Removes all objects of the corresponding class. */ … … 186 186 class ClassIdentifier : public Identifier 187 187 { 188 template <class TT> 189 friend class ClassManager; 190 188 191 public: 189 staticClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass);190 staticvoid addObject(T* object);191 static ClassIdentifier<T>* getIdentifier();192 ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass); 193 void addObject(T* object); 194 // static ClassIdentifier<T>* getIdentifier(); 192 195 void removeObjects() const; 193 196 void setName(const std::string& name); … … 225 228 226 229 // Check if at least one object of the given type was created 227 if (! getIdentifier()->bCreatedOneObject_)230 if (!this->bCreatedOneObject_) 228 231 { 229 232 // If no: We have to store the informations and initialize the Identifier 230 getIdentifier()->setName(name);233 this->setName(name); 231 234 232 235 COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl; 233 236 if (bRootClass) 234 getIdentifier()->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.237 this->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case. 235 238 else 236 getIdentifier()->initialize(parents);239 this->initialize(parents); 237 240 } 238 241 239 return getIdentifier();242 return this; 240 243 } 241 244 … … 243 246 @brief Creates the only instance of this class for the template class T. 244 247 @return The Identifier itself 245 */ 248 *//* 246 249 template <class T> 247 250 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() … … 258 261 return &theOneAndOnlyInstance; 259 262 } 260 263 */ 261 264 /** 262 265 @brief Sets the name of the class. … … 266 269 void ClassIdentifier<T>::setName(const std::string& name) 267 270 { 268 // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map271 // // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map 269 272 if (!this->bSetName_) 270 273 { 271 274 this->name_ = name; 272 this->getIdentifierMap().insert(std::pair<std::string, Identifier*>(name, this));275 // this->getIdentifierMap().insert(std::pair<std::string, Identifier*>(name, this)); 273 276 this->bSetName_ = true; 274 277 } … … 282 285 void ClassIdentifier<T>::addObject(T* object) 283 286 { 284 COUT(4) << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;285 object->getMetaList().add( ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));287 COUT(4) << "*** Added object to " << this->getName() << "-list." << std::endl; 288 object->getMetaList().add(this->objects_, this->objects_->add(object)); 286 289 } 287 290 … … 314 317 SubclassIdentifier() 315 318 { 316 this->identifier_ = ClassIdentifier<T>::getIdentifier(); 319 T* temp = new T; 320 this->subclassIdentifier_ = temp->getIdentifier(); 321 delete temp; 322 323 this->identifier_ = this->subclassIdentifier_; 317 324 } 318 325 … … 324 331 SubclassIdentifier<T>& operator=(Identifier* identifier) 325 332 { 326 if (!identifier->isA( ClassIdentifier<T>::getIdentifier()))333 if (!identifier->isA(this->subclassIdentifier_)) 327 334 { 328 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;329 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;335 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << this->subclassIdentifier_->getName() << "!" << std::endl; 336 COUT(1) << "Error: SubclassIdentifier<" << this->subclassIdentifier_->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl; 330 337 COUT(1) << "Aborting..." << std::endl; 331 338 abort(); … … 372 379 if (this->identifier_) 373 380 { 374 COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;381 COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << this->subclassIdentifier_->getName() << "!" << std::endl; 375 382 COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl; 376 383 COUT(1) << "Aborting..." << std::endl; … … 407 414 408 415 private: 409 Identifier* identifier_; //!< The assigned identifier 416 Identifier* identifier_; //!< The assigned identifier 417 Identifier* subclassIdentifier_; //!< The identifier of the subclass 410 418 }; 411 419 }
Note: See TracChangeset
for help on using the changeset viewer.