Changeset 1747 for code/trunk/src/core/Identifier.h
- Timestamp:
- Sep 9, 2008, 4:25:52 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core3 (added) merged: 1573-1574,1583-1586,1591-1594,1596-1597,1603,1606-1607,1610-1611,1655,1658,1676-1679,1681-1685,1687,1716-1723,1725-1729,1736
- Property svn:mergeinfo changed
-
code/trunk/src/core/Identifier.h
r1639 r1747 62 62 #include <stdlib.h> 63 63 64 #include "ObjectList.h" 65 #include "Debug.h" 64 #include "MetaObjectList.h" 66 65 #include "Iterator.h" 67 #include "MetaObjectList.h" 66 #include "Super.h" 67 #include "util/Debug.h" 68 68 #include "util/String.h" 69 69 … … 91 91 { 92 92 template <class T> 93 friend class ClassIdentifier;94 95 template <class T>96 93 friend class SubclassIdentifier; 97 94 … … 110 107 bool isDirectParentOf(const Identifier* identifier) const; 111 108 112 virtual const ObjectList<BaseObject>* getObjectList() const = 0;113 114 virtual void updateConfigValues() const = 0;109 /** @brief Returns the list of all existing objects of this class. @return The list */ 110 inline ObjectListBase* getObjects() const 111 { return this->objects_; } 115 112 116 113 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 117 114 inline const std::string& getName() const { return this->name_; } 118 115 void setName(const std::string& name); 116 117 virtual void updateConfigValues(bool updateChildren = true) const = 0; 119 118 120 119 /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */ … … 210 209 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname); 211 210 212 v irtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;213 virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0;214 215 v irtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;216 virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;211 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); 212 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); 213 214 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 215 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 217 216 218 217 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); … … 221 220 222 221 protected: 222 Identifier(); 223 Identifier(const Identifier& identifier); // don't copy 224 virtual ~Identifier(); 225 226 void initialize(std::set<const Identifier*>* parents); 227 static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); 228 229 virtual void createSuperFunctionCaller() const = 0; 230 223 231 /** @brief Returns the map that stores all Identifiers. @return The map */ 224 232 static std::map<std::string, Identifier*>& getIdentifierMapIntern(); … … 226 234 static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern(); 227 235 228 private:229 Identifier();230 Identifier(const Identifier& identifier); // don't copy231 virtual ~Identifier();232 void initialize(std::set<const Identifier*>* parents);233 234 236 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 235 237 inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); } … … 237 239 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 238 240 241 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 242 ObjectListBase* objects_; //!< The list of all objects of this class 243 244 private: 239 245 /** 240 246 @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. … … 255 261 } 256 262 257 static Identifier* getIdentifier(std::string &name, Identifier *proposal);263 static void destroyAllIdentifiers(); 258 264 259 265 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to … … 263 269 std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 264 270 271 bool bSetName_; //!< True if the name is set 265 272 std::string name_; //!< The name of the class the Identifier belongs to 266 267 273 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 274 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 275 unsigned int classID_; //!< The network ID to identify a class through the network … … 277 282 std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class 278 283 std::map<std::string, ConsoleCommand*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase 284 285 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 286 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 279 287 }; 280 288 … … 297 305 class ClassIdentifier : public Identifier 298 306 { 307 #define SUPER_INTRUSIVE_DECLARATION_INCLUDE 308 #include "Super.h" 309 299 310 public: 300 ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass); 311 static ClassIdentifier<T> *getIdentifier(); 312 static ClassIdentifier<T> *getIdentifier(const std::string& name); 313 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 314 static bool isFirstCall(); 301 315 void addObject(T* object); 302 void setName(const std::string& name); 303 /** @brief Returns the list of all existing objects of this class. @return The list */ 304 inline ObjectList<T>* getObjects() const { return this->objects_; } 305 /** @brief Returns a list of all existing objects of this class. @return The list */ 306 inline ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; } 307 308 void updateConfigValues() const; 309 310 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); 311 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); 312 313 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 314 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 315 316 static ClassIdentifier<T> *getIdentifier(); 316 317 void updateConfigValues(bool updateChildren = true) const; 317 318 318 319 private: 319 ClassIdentifier();320 320 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 321 ~ClassIdentifier() {} // don't delete 322 323 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 324 bool bSetName_; //!< True if the name is set 325 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; //!< All loadable parameters 326 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; //!< All attachable objects 321 ClassIdentifier() 322 { 323 SuperFunctionInitialization<0, T>::initialize(this); 324 } 325 ~ClassIdentifier() 326 { 327 SuperFunctionDestruction<0, T>::destroy(this); 328 } 327 329 328 330 static ClassIdentifier<T> *classIdentifier_s; … … 333 335 334 336 /** 335 @brief Constructor: Creates the ObjectList.336 */337 template <class T>338 ClassIdentifier<T>::ClassIdentifier()339 {340 // this->objects_ = ObjectList<T>::getList();341 this->objects_ = new ObjectList<T>();342 this->bSetName_ = false;343 }344 345 /**346 337 @brief Registers a class, which means that the name and the parents get stored. 347 338 @param parents A list, containing the Identifiers of all parents of the class 348 @param name A string, containing exactly the name of the class349 339 @param bRootClass True if the class is either an Interface or the BaseObject itself 350 @return The ClassIdentifier itself 351 */ 352 template <class T> 353 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass) 354 { 355 this->setName(name); 356 340 */ 341 template <class T> 342 void ClassIdentifier<T>::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass) 343 { 357 344 // Check if at least one object of the given type was created 358 345 if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy()) 359 346 { 360 347 // If no: We have to store the informations and initialize the Identifier 361 COUT(4) << "*** ClassIdentifier: Register Class in " << name<< "-Singleton -> Initialize Singleton." << std::endl;348 COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl; 362 349 if (bRootClass) 363 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.350 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. 364 351 else 365 352 this->initialize(parents); 366 353 } 367 368 return this;369 354 } 370 355 371 356 /** 372 @brief Creates the only instance of this class for the template class T and retrieves a unique Identifier for the given name. 357 @brief Returns true if the function gets called the first time, false otherwise. 358 @return True if this function got called the first time. 359 */ 360 template <class T> 361 bool ClassIdentifier<T>::isFirstCall() 362 { 363 static bool bFirstCall = true; 364 365 if (bFirstCall) 366 { 367 bFirstCall = false; 368 return true; 369 } 370 else 371 { 372 return false; 373 } 374 } 375 376 /** 377 @brief Returns the only instance of this class. 373 378 @return The unique Identifier 374 379 */ … … 377 382 { 378 383 // check if the static field has already been filled 379 if (ClassIdentifier<T>:: classIdentifier_s == 0)384 if (ClassIdentifier<T>::isFirstCall()) 380 385 { 381 386 // Get the name of the class … … 383 388 384 389 // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used. 385 ClassIdentifier<T> *proposal = new ClassIdentifier<T>();390 ClassIdentifier<T>* proposal = new ClassIdentifier<T>(); 386 391 387 392 // Get the entry from the map 388 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifier(name, proposal); 393 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal); 394 395 if (ClassIdentifier<T>::classIdentifier_s == proposal) 396 { 397 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl; 398 } 399 else 400 { 401 COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl; 402 } 389 403 } 390 404 … … 394 408 395 409 /** 396 @brief Sets the name of the class. 397 @param name The name 398 */ 399 template <class T> 400 void ClassIdentifier<T>::setName(const std::string& name) 401 { 402 if (!this->bSetName_) 403 { 404 this->name_ = name; 405 this->bSetName_ = true; 406 Identifier::getIdentifierMapIntern()[name] = this; 407 Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this; 408 } 410 @brief Does the same as getIdentifier() but sets the name if this wasn't done yet. 411 @param name The name of this Identifier 412 @return The Identifier 413 */ 414 template <class T> 415 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name) 416 { 417 ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier(); 418 identifier->setName(name); 419 return identifier; 409 420 } 410 421 … … 417 428 { 418 429 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl; 419 object->getMetaList().add(this->objects_, this->objects_->add( object));430 object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object))); 420 431 } 421 432 … … 424 435 */ 425 436 template <class T> 426 void ClassIdentifier<T>::updateConfigValues() const 427 { 428 for (Iterator<T> it = this->objects_->start(); it; ++it) 429 ((T*)*it)->setConfigValues(); 430 } 431 432 /** 433 @brief Returns a XMLPortParamContainer that loads a parameter of this class. 434 @param paramname The name of the parameter 435 @return The container 436 */ 437 template <class T> 438 XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname) 439 { 440 typename std::map<std::string, XMLPortClassParamContainer<T>*>::const_iterator it = xmlportParamContainers_.find(paramname); 441 if (it != xmlportParamContainers_.end()) 442 return (XMLPortParamContainer*)((*it).second); 443 else 444 return 0; 445 } 446 447 /** 448 @brief Adds a new XMLPortParamContainer that loads a parameter of this class. 449 @param paramname The name of the parameter 450 @param container The container 451 */ 452 template <class T> 453 void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) 454 { 455 this->xmlportParamContainers_[paramname] = (XMLPortClassParamContainer<T>*)container; 456 } 457 458 /** 459 @brief Returns a XMLPortObjectContainer that attaches an object to this class. 460 @param sectionname The name of the section that contains the attachable objects 461 @return The container 462 */ 463 template <class T> 464 XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname) 465 { 466 typename std::map<std::string, XMLPortClassObjectContainer<T, class O>*>::const_iterator it = xmlportObjectContainers_.find(sectionname); 467 if (it != xmlportObjectContainers_.end()) 468 return (XMLPortObjectContainer*)((*it).second); 469 else 470 return 0; 471 } 472 473 /** 474 @brief Adds a new XMLPortObjectContainer that attaches an object to this class. 475 @param sectionname The name of the section that contains the attachable objects 476 @param container The container 477 */ 478 template <class T> 479 void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) 480 { 481 this->xmlportObjectContainers_[sectionname] = (XMLPortClassObjectContainer<T, class O>*)container; 437 void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const 438 { 439 if (!this->hasConfigValues()) 440 return; 441 442 for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it) 443 it->setConfigValues(); 444 445 if (updateChildren) 446 for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it) 447 (*it)->updateConfigValues(false); 482 448 } 483 449
Note: See TracChangeset
for help on using the changeset viewer.