Changeset 2065 for code/branches/objecthierarchy/src/core
- Timestamp:
- Oct 30, 2008, 2:44:48 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/BaseObject.cc
r2063 r2065 35 35 #include "tinyxml/tinyxml.h" 36 36 #include "CoreIncludes.h" 37 #include "EventIncludes.h" 37 38 #include "XMLPort.h" 38 39 #include "XMLFile.h" … … 79 80 BaseObject::~BaseObject() 80 81 { 82 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 83 (*it)->eventListeners_.erase(this); 81 84 } 82 85 … … 184 187 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 185 188 { 186 this->eventListeners_.insert(std::pair<std::string, BaseObject*>(sectionname, event)); 189 event->eventListeners_[this] = sectionname; 190 this->events_.push_back(event); 187 191 } 188 192 … … 190 194 { 191 195 unsigned int i = 0; 192 for (std:: set<std::pair<std::string, BaseObject*> >::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)196 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 193 197 { 194 198 if (i == index) 195 return (*it) .second;199 return (*it); 196 200 ++i; 197 201 } … … 230 234 Event event(activate, this); 231 235 232 for (std:: set<std::pair<std::string, BaseObject*>>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)233 { 234 event.sectionname_ = (*it).first;235 (*it).second->processEvent(event);236 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 237 { 238 event.sectionname_ = it->second; 239 it->first->processEvent(event); 236 240 } 237 241 } -
code/branches/objecthierarchy/src/core/BaseObject.h
r2063 r2065 36 36 #ifndef _BaseObject_H__ 37 37 #define _BaseObject_H__ 38 39 #include <map> 38 40 39 41 #include "CorePrereqs.h" … … 145 147 Gametype* oldGametype_; 146 148 std::set<Template*> templates_; 147 std::set<std::pair<std::string, BaseObject*> > eventListeners_; 149 std::map<BaseObject*, std::string> eventListeners_; 150 std::list<BaseObject*> events_; 148 151 std::map<std::string, EventContainer*> eventContainers_; 149 152 }; -
code/branches/objecthierarchy/src/core/Event.cc
r2063 r2065 29 29 #include "Event.h" 30 30 #include "BaseObject.h" 31 #include "Executor.h" 31 32 32 33 namespace orxonox 33 34 { 35 EventContainer::~EventContainer() 36 { 37 delete this->eventfunction_; 38 } 39 34 40 void EventContainer::process(BaseObject* object, const Event& event) 35 41 { -
code/branches/objecthierarchy/src/core/Event.h
r2063 r2065 31 31 32 32 #include "CorePrereqs.h" 33 #include "Executor.h"34 35 #define SetEvent(classname, eventname, functionname, event) \36 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, BaseObject)37 38 #define SetEventTemplate(classname, eventname, functionname, event, ...) \39 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, BaseObject)40 41 #define SetSubclassEvent(classname, eventname, functionname, event, subclassname) \42 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, subclassname)43 44 #define SetSubclassEventTemplate(classname, eventname, functionname, event, subclassname, ...) \45 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, subclassname)46 47 #define SetEventGeneric(containername, classname, eventname, executor, event, subclassname) \48 orxonox::EventContainer* containername = this->getEventContainer(eventname); \49 if (!containername) \50 { \51 containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \52 this->addEventContainer(eventname, containername); \53 } \54 event.castedOriginator_ = dynamic_cast<subclassname*>(event.originator_); \55 containername->process(this, event)56 57 33 58 34 namespace orxonox … … 72 48 public: 73 49 EventContainer(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {} 74 ~EventContainer() 75 { delete this->eventfunction_; } 50 ~EventContainer(); 76 51 77 52 void process(BaseObject* object, const Event& event); -
code/branches/objecthierarchy/src/core/XMLPort.h
r2019 r2065 480 480 481 481 BaseObject* newObject = identifier->fabricate((BaseObject*)object); 482 assert(newObject); 482 483 newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + " "); 483 // newObject->setFile(((BaseObject*)object)->getFile()); 484 // newObject->setNamespace(((BaseObject*)object)->getNamespace()); 484 485 O* castedObject = dynamic_cast<O*>(newObject); 486 assert(castedObject); 485 487 486 488 if (this->bLoadBefore_) … … 495 497 496 498 COUT(5) << ((BaseObject*)object)->getLoaderIndentation(); 497 (*this->loadexecutor_)(object, newObject);499 (*this->loadexecutor_)(object, castedObject); 498 500 499 501 if (!this->bLoadBefore_)
Note: See TracChangeset
for help on using the changeset viewer.