Changeset 2084 for code/branches/objecthierarchy/src/core
- Timestamp:
- Nov 1, 2008, 2:51:02 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/CoreIncludes.h
r2034 r2084 46 46 #include "Factory.h" 47 47 #include "ClassFactory.h" 48 #include "Functor.h" 48 49 #include "util/Debug.h" 49 50 … … 128 129 orxonox::Factory::getIdentifier(networkID) 129 130 131 /** 132 @brief Registers a member function as callback when an object of 'type' is created. 133 @param 134 */ 135 #define RegisterConstructionCallback(ThisClassName, TargetClassName, FunctionName) \ 136 orxonox::ClassIdentifier<TargetClassName>::getIdentifier()->addConstructionCallback( \ 137 createFunctor(&ThisClassName::FunctionName)->setObject(this)) 138 130 139 #endif /* _CoreIncludes_H__ */ -
code/branches/objecthierarchy/src/core/Functor.h
r2019 r2084 167 167 } 168 168 169 voidsetObject(T* object)169 FunctorMember* setObject(T* object) 170 170 { 171 171 this->bConstObject_ = false; 172 172 this->object_ = object; 173 return this; 173 174 } 174 175 175 voidsetObject(const T* object)176 FunctorMember* setObject(const T* object) 176 177 { 177 178 this->bConstObject_ = true; 178 179 this->constObject_ = object; 180 return this; 179 181 } 180 182 -
code/branches/objecthierarchy/src/core/Identifier.cc
r2063 r2084 63 63 this->bHasConfigValues_ = false; 64 64 this->bHasConsoleCommands_ = false; 65 this->bHasConstructionCallback_ = false; 65 66 66 67 this->children_ = new std::set<const Identifier*>(); … … 508 509 509 510 /** 511 @brief Adds a construction callback functor that gets called every time an object is created. 512 @param functor Functor pointer to any function with no argument. 513 */ 514 void Identifier::addConstructionCallback(Functor* functor) 515 { 516 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 517 { 518 if (this->constructionCallbacks_[i] == functor) 519 return; 520 } 521 this->constructionCallbacks_.push_back(functor); 522 this->bHasConstructionCallback_ = true; 523 } 524 525 /** 526 @brief Removes a construction callback functor that gets called every time an object is created. 527 @param functor Functor pointer to any function with no argument. 528 */ 529 void Identifier::removeConstructionCallback(Functor* functor) 530 { 531 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 532 { 533 if (this->constructionCallbacks_[i] == functor) 534 { 535 this->constructionCallbacks_.erase(this->constructionCallbacks_.begin() + i); 536 } 537 } 538 if (constructionCallbacks_.empty()) 539 this->bHasConstructionCallback_ = false; 540 } 541 542 /** 510 543 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 511 544 @param out The outstream -
code/branches/objecthierarchy/src/core/Identifier.h
r2063 r2084 57 57 #include <set> 58 58 #include <map> 59 #include <vector> 59 60 #include <string> 60 61 #include <utility> … … 221 222 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */ 222 223 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; } 224 /** @brief Returns true if this class has at least one construction callback Functor registered. */ 225 inline bool hasConstructionCallback() const { return this->bHasConstructionCallback_; } 223 226 224 227 /** @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 */ … … 247 250 ConsoleCommand* getConsoleCommand(const std::string& name) const; 248 251 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 252 253 void addConstructionCallback(Functor* functor); 254 void removeConstructionCallback(Functor* functor); 249 255 250 256 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); … … 267 273 /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */ 268 274 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 275 276 bool bHasConstructionCallback_; //!< True if at least one Functor is registered to get informed when an object of type T is created. 277 std::vector<Functor*> constructionCallbacks_; //!< All construction callback Functors of this class. 269 278 270 279 ObjectListBase* objects_; //!< The list of all objects of this class … … 441 450 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl; 442 451 object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object))); 452 if (this->bHasConstructionCallback_) 453 { 454 // Call all registered callbacks that a new object of type T has been created. 455 // Do NOT deliver a T* pointer here because it's way too risky (object not yet fully created). 456 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 457 (*constructionCallbacks_[i])(); 458 } 443 459 } 444 460
Note: See TracChangeset
for help on using the changeset viewer.