Changeset 5882 for code/branches/core5/src
- Timestamp:
- Oct 5, 2009, 9:57:05 PM (15 years ago)
- Location:
- code/branches/core5/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/BaseObject.cc
r5879 r5882 118 118 119 119 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 120 XMLPortObject(BaseObject, BaseObject, "eventlisteners", addEventListener, getEventListener, xmlelement, mode); 120 121 121 122 Element* events = 0; … … 123 124 events = xmlelement.FirstChildElement("events", false); 124 125 else if (mode == XMLPort::SaveObject) 125 ;126 {} 126 127 if (events) 127 128 this->XMLEventPort(*events, mode); … … 137 138 XMLPortEventState(BaseObject, BaseObject, "activity", setActive, xmlelement, mode); 138 139 XMLPortEventState(BaseObject, BaseObject, "visibility", setVisible, xmlelement, mode); 140 XMLPortEventState(BaseObject, BaseObject, "mainstate", setMainState, xmlelement, mode); 139 141 140 142 this->bRegisteredEventStates_ = true; … … 242 244 } 243 245 246 /** 247 @brief Adds an object which listens to the events of this object. 248 */ 249 void BaseObject::addEventListener(BaseObject* listener) 250 { 251 this->eventListenersXML_.insert(listener); 252 listener->addEventSource(this, "mainstate"); 253 } 254 255 /** 256 @brief Returns an event listener with a given index. 257 */ 258 BaseObject* BaseObject::getEventListener(unsigned int index) const 259 { 260 unsigned int i = 0; 261 for (std::set<BaseObject*>::const_iterator it = this->eventListenersXML_.begin(); it != this->eventListenersXML_.end(); ++it) 262 { 263 if (i == index) 264 return *it; 265 ++i; 266 } 267 return 0; 268 } 269 244 270 void BaseObject::addEventState(const std::string& name, EventState* state) 245 271 { -
code/branches/core5/src/libraries/core/BaseObject.h
r5879 r5882 157 157 void removeEventSource(BaseObject* source); 158 158 BaseObject* getEventSource(unsigned int index, const std::string& state) const; 159 160 void addEventListener(BaseObject* listener); 161 BaseObject* getEventListener(unsigned int index) const; 159 162 160 163 void fireEvent(); … … 208 211 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect 209 212 std::set<BaseObject*> eventListeners_; //!< List of objects which listen to the events of this object 213 std::set<BaseObject*> eventListenersXML_; //!< List of objects which listen to the events of this object through the "eventlisteners" subsection in XML 210 214 std::map<std::string, EventState*> eventStates_; //!< Maps the name of the event states to their helper objects 211 215 bool bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort) -
code/branches/core5/src/modules/objects/eventsystem/EventDispatcher.cc
r5800 r5882 54 54 SUPER(EventDispatcher, XMLPort, xmlelement, mode); 55 55 56 XMLPortObject(EventDispatcher, EventTarget, "targets", addTarget, getTarget, xmlelement, mode);56 XMLPortObject(EventDispatcher, BaseObject, "targets", addTarget, getTarget, xmlelement, mode); 57 57 } 58 58 … … 60 60 { 61 61 for (std::list<EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 62 (*it)-> fireEvent(event);62 (*it)->processEvent(event); 63 63 } 64 64 -
code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc
r5866 r5882 42 42 { 43 43 } 44 45 void EventTarget::processEvent(Event& event) 46 { 47 this->fireEvent(event); 48 } 44 49 45 50 void EventTarget::changedName() -
code/branches/core5/src/modules/objects/eventsystem/EventTarget.h
r5866 r5882 42 42 EventTarget(BaseObject* creator); 43 43 virtual ~EventTarget(); 44 45 virtual void processEvent(Event& event); 44 46 45 47 virtual void changedName();
Note: See TracChangeset
for help on using the changeset viewer.