Changeset 1583
- Timestamp:
- Jun 10, 2008, 3:01:24 AM (16 years ago)
- Location:
- code/branches/core3/src/core
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/src/core/ClassFactory.h
r1543 r1583 74 74 { 75 75 COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl; 76 ClassIdentifier<T>::getIdentifier( )->addFactory(new ClassFactory<T>);76 ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>); 77 77 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 78 78 -
code/branches/core3/src/core/ConsoleCommand.h
r1549 r1583 42 42 43 43 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \ 44 orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier( )->addConsoleCommand(command, bCreateShortcut)44 orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut) 45 45 46 46 -
code/branches/core3/src/core/CoreIncludes.h
r1543 r1583 55 55 */ 56 56 #define InternRegisterObject(ClassName, bRootClass) \ 57 this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier()->registerClass(this->getParents(), #ClassName, bRootClass)); \ 58 if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \ 59 this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \ 60 orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this); \ 57 this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)); \ 61 58 if (orxonox::Identifier::isCreatingHierarchy()) \ 62 return 59 { \ 60 if (this->getParents()) \ 61 { \ 62 orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeClassHierarchy(this->getParents(), bRootClass); \ 63 this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \ 64 } \ 65 this->setConfigValues(); \ 66 return; \ 67 } \ 68 orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this) 63 69 64 70 /** -
code/branches/core3/src/core/IRC.cc
r1505 r1583 42 42 SetConsoleCommand(IRC, msg, false).setAccessLevel(AccessLevel::User); 43 43 SetConsoleCommand(IRC, nick, false).setAccessLevel(AccessLevel::User); 44 45 IRC* instance_irc = &IRC::getInstance();46 44 47 45 IRC::IRC() -
code/branches/core3/src/core/Identifier.cc
r1574 r1583 58 58 59 59 this->bCreatedOneObject_ = false; 60 this->bSetName_ = false; 60 61 this->factory_ = 0; 61 62 … … 86 87 @return The identifier (unique instance) 87 88 */ 88 Identifier *Identifier::getIdentifier(std::string &name, Identifier *proposal)89 Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal) 89 90 { 90 91 static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers. 91 92 std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name); 92 if (it == identifiers.end()) 93 { 94 // there isn't an entry yet, put the proposal in it 93 94 if (it != identifiers.end()) 95 { 96 // There is already an entry: return it and delete the proposal 97 delete proposal; 98 return (*it).second; 99 } 100 else 101 { 102 // There is no entry: put the proposal into the map and return it 95 103 identifiers[name] = proposal; 96 } 97 else 98 { 99 // this happens when a template exists twice --> delete the proposal 100 delete proposal; 101 } 102 return identifiers[name]; 104 return proposal; 105 } 103 106 } 104 107 … … 149 152 150 153 /** 154 @brief Sets the name of the class. 155 @param name The name 156 */ 157 void Identifier::setName(const std::string& name) 158 { 159 if (!this->bSetName_) 160 { 161 this->name_ = name; 162 this->bSetName_ = true; 163 Identifier::getIdentifierMapIntern()[name] = this; 164 Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this; 165 } 166 } 167 168 /** 151 169 @brief Creates an object of the type the Identifier belongs to. 152 170 @return The new object -
code/branches/core3/src/core/Identifier.h
r1574 r1583 87 87 { 88 88 template <class T> 89 friend class ClassIdentifier;90 91 template <class T>92 89 friend class SubclassIdentifier; 93 90 … … 114 111 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 115 112 inline const std::string& getName() const { return this->name_; } 113 void setName(const std::string& name); 116 114 117 115 virtual void updateConfigValues() const = 0; … … 220 218 221 219 protected: 220 Identifier(); 221 Identifier(const Identifier& identifier); // don't copy 222 virtual ~Identifier(); 223 224 void initialize(std::set<const Identifier*>* parents); 225 static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); 226 222 227 /** @brief Returns the map that stores all Identifiers. @return The map */ 223 228 static std::map<std::string, Identifier*>& getIdentifierMapIntern(); … … 225 230 static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern(); 226 231 232 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 233 227 234 private: 228 Identifier();229 Identifier(const Identifier& identifier); // don't copy230 virtual ~Identifier();231 void initialize(std::set<const Identifier*>* parents);232 233 235 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 234 236 inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); } … … 254 256 } 255 257 256 static Identifier* getIdentifier(std::string &name, Identifier *proposal);257 258 258 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 259 259 std::set<const Identifier*>* children_; //!< The children of the class the Identifier belongs to … … 262 262 std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 263 263 264 bool bSetName_; //!< True if the name is set 264 265 std::string name_; //!< The name of the class the Identifier belongs to 265 266 266 ObjectListBase* objects_; //!< The list of all objects of this class 267 267 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 268 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents)269 268 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 270 269 unsigned int classID_; //!< The network ID to identify a class through the network … … 298 297 { 299 298 public: 300 ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass); 301 void setName(const std::string& name); 299 static ClassIdentifier<T> *getIdentifier(); 300 static ClassIdentifier<T> *getIdentifier(const std::string& name); 301 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 302 static bool isFirstCall(); 302 303 303 304 void updateConfigValues() const; … … 309 310 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 310 311 311 static ClassIdentifier<T> *getIdentifier();312 313 312 private: 314 ClassIdentifier() ;313 ClassIdentifier() {} 315 314 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 316 315 ~ClassIdentifier() {} // don't delete 317 316 318 bool bSetName_; //!< True if the name is set319 317 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; //!< All loadable parameters 320 318 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; //!< All attachable objects … … 327 325 328 326 /** 329 @brief Constructor: Creates the ObjectList.330 */331 template <class T>332 ClassIdentifier<T>::ClassIdentifier()333 {334 this->bSetName_ = false;335 }336 337 /**338 327 @brief Registers a class, which means that the name and the parents get stored. 339 328 @param parents A list, containing the Identifiers of all parents of the class 340 @param name A string, containing exactly the name of the class341 329 @param bRootClass True if the class is either an Interface or the BaseObject itself 342 @return The ClassIdentifier itself 343 */ 344 template <class T> 345 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass) 346 { 347 this->setName(name); 348 330 */ 331 template <class T> 332 void ClassIdentifier<T>::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass) 333 { 349 334 // Check if at least one object of the given type was created 350 335 if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy()) 351 336 { 352 337 // If no: We have to store the informations and initialize the Identifier 353 COUT(4) << "*** ClassIdentifier: Register Class in " << name<< "-Singleton -> Initialize Singleton." << std::endl;338 COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl; 354 339 if (bRootClass) 355 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.340 this->initialize(0); // 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. 356 341 else 357 342 this->initialize(parents); 358 343 } 359 360 return this; 361 } 362 363 /** 364 @brief Creates the only instance of this class for the template class T and retrieves a unique Identifier for the given name. 344 } 345 346 /** 347 @brief Returns true if the function gets called the first time, false otherwise. 348 @return True if this function got called the first time. 349 */ 350 template <class T> 351 bool ClassIdentifier<T>::isFirstCall() 352 { 353 static bool bFirstCall = true; 354 355 if (bFirstCall) 356 { 357 bFirstCall = false; 358 return true; 359 } 360 else 361 { 362 return false; 363 } 364 } 365 366 /** 367 @brief Returns the only instance of this class. 365 368 @return The unique Identifier 366 369 */ … … 369 372 { 370 373 // check if the static field has already been filled 371 if (ClassIdentifier<T>:: classIdentifier_s == 0)374 if (ClassIdentifier<T>::isFirstCall()) 372 375 { 373 376 // Get the name of the class … … 375 378 376 379 // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used. 377 ClassIdentifier<T> *proposal = new ClassIdentifier<T>();380 ClassIdentifier<T>* proposal = new ClassIdentifier<T>(); 378 381 379 382 // Get the entry from the map 380 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifier(name, proposal); 383 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal); 384 385 if (ClassIdentifier<T>::classIdentifier_s == proposal) 386 { 387 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl; 388 } 389 else 390 { 391 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl; 392 } 381 393 } 382 394 … … 386 398 387 399 /** 388 @brief Sets the name of the class. 389 @param name The name 390 */ 391 template <class T> 392 void ClassIdentifier<T>::setName(const std::string& name) 393 { 394 if (!this->bSetName_) 395 { 396 this->name_ = name; 397 this->bSetName_ = true; 398 Identifier::getIdentifierMapIntern()[name] = this; 399 Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this; 400 } 400 @brief Does the same as getIdentifier() but sets the name if this wasn't done yet. 401 @param name The name of this Identifier 402 @return The Identifier 403 */ 404 template <class T> 405 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name) 406 { 407 ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); 408 identifier->setName(name); 409 return identifier; 401 410 } 402 411 … … 407 416 void ClassIdentifier<T>::updateConfigValues() const 408 417 { 409 for (Iterator<T> it = this-> objects_->begin(); it; ++it)418 for (Iterator<T> it = this->getObjects()->begin(); it; ++it) 410 419 (*it)->setConfigValues(); 411 420 } -
code/branches/core3/src/core/TclThreadManager.cc
r1505 r1583 58 58 SetConsoleCommand(TclThreadManager, flush, false).setArgumentCompleter(0, autocompletion::tclthreads()); 59 59 60 TclThreadManager* instance_tclthreadmanager = &TclThreadManager::getInstance();61 62 60 TclThreadManager::TclThreadManager() 63 61 {
Note: See TracChangeset
for help on using the changeset viewer.