Changeset 2087 for code/trunk/src/core/Identifier.h
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/core/Identifier.h
r1856 r2087 57 57 #include <set> 58 58 #include <map> 59 #include <vector> 59 60 #include <string> 60 61 #include <utility> 61 62 #include <typeinfo> 62 63 #include <stdlib.h> 64 #include <cassert> 63 65 64 66 #include "MetaObjectList.h" 65 67 #include "Iterator.h" 66 68 #include "Super.h" 69 #include "Functor.h" 67 70 #include "util/Debug.h" 68 71 #include "util/String.h" … … 99 102 inline void addFactory(BaseFactory* factory) { this->factory_ = factory; } 100 103 101 BaseObject* fabricate( );104 BaseObject* fabricate(BaseObject* creator); 102 105 bool isA(const Identifier* identifier) const; 103 106 bool isExactlyA(const Identifier* identifier) const; … … 107 110 bool isDirectParentOf(const Identifier* identifier) const; 108 111 112 /** @brief Returns true if the class can be loaded through XML. */ 113 inline bool isLoadable() const { return this->bLoadable_; } 114 /** @brief Set the class to be loadable through XML or not. */ 115 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 116 109 117 /** @brief Returns the list of all existing objects of this class. @return The list */ 110 118 inline ObjectListBase* getObjects() const … … 204 212 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 205 213 214 /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */ 215 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; } 216 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */ 217 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); } 218 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */ 219 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); } 220 206 221 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 207 222 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 208 223 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */ 209 224 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; } 225 /** @brief Returns true if this class has at least one construction callback Functor registered. */ 226 inline bool hasConstructionCallback() const { return this->bHasConstructionCallback_; } 210 227 211 228 /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */ … … 228 245 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 229 246 247 void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container); 248 XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname); 249 230 250 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); 231 251 ConsoleCommand* getConsoleCommand(const std::string& name) const; 232 252 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 253 254 void addConstructionCallback(Functor* functor); 255 void removeConstructionCallback(Functor* functor); 233 256 234 257 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); … … 252 275 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 253 276 277 bool bHasConstructionCallback_; //!< True if at least one Functor is registered to get informed when an object of type T is created. 278 std::vector<Functor*> constructionCallbacks_; //!< All construction callback Functors of this class. 279 254 280 ObjectListBase* objects_; //!< The list of all objects of this class 255 281 … … 285 311 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 286 312 bool bSetName_; //!< True if the name is set 313 bool bLoadable_; //!< False = it's not permitted to load the object through XML 287 314 std::string name_; //!< The name of the class the Identifier belongs to 288 315 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) … … 300 327 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 301 328 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 329 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events 302 330 }; 303 331 … … 423 451 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl; 424 452 object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object))); 453 if (this->bHasConstructionCallback_) 454 { 455 // Call all registered callbacks that a new object of type T has been created. 456 // Do NOT deliver a T* pointer here because it's way too risky (object not yet fully created). 457 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 458 (*constructionCallbacks_[i])(); 459 } 425 460 } 426 461 … … 480 515 SubclassIdentifier<T>& operator=(Identifier* identifier) 481 516 { 482 if (!identifier ->isA(ClassIdentifier<T>::getIdentifier()))517 if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier())) 483 518 { 484 519 COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl; 485 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl; 486 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl; 487 COUT(1) << "Aborting..." << std::endl; 488 abort(); 520 if (identifier) 521 { 522 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl; 523 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl; 524 } 525 else 526 { 527 COUT(1) << "Error: Can't assign NULL identifier" << std::endl; 528 } 489 529 } 490 this->identifier_ = identifier; 530 else 531 { 532 this->identifier_ = identifier; 533 } 491 534 return *this; 492 535 } … … 495 538 @brief Overloading of the * operator: returns the assigned identifier. 496 539 */ 497 inline Identifier* operator*() 540 inline Identifier* operator*() const 498 541 { 499 542 return this->identifier_; … … 520 563 @return The new object 521 564 */ 522 T* fabricate( )523 { 524 BaseObject* newObject = this->identifier_->fabricate( );565 T* fabricate(BaseObject* creator) const 566 { 567 BaseObject* newObject = this->identifier_->fabricate(creator); 525 568 526 569 // Check if the creation was successful … … 546 589 } 547 590 548 abort(); 591 assert(false); 592 return 0; 549 593 } 550 594 }
Note: See TracChangeset
for help on using the changeset viewer.