Changeset 5887
- Timestamp:
- Oct 6, 2009, 4:51:08 AM (15 years ago)
- Location:
- code/branches/core5/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/BaseObject.cc
r5883 r5887 245 245 246 246 /** 247 @brief Adds an object which listens to the events of this object. 247 @brief Adds an object which listens to the events of this object. The events are sent to the other objects mainstate. 248 248 */ 249 249 void BaseObject::addEventListener(BaseObject* listener) … … 268 268 } 269 269 270 /** 271 @brief Adds a new event-state to the object. Event-states are states which can be changed by events. 272 @param name The name of the event 273 @param state The object containing information about the event-state 274 */ 270 275 void BaseObject::addEventState(const std::string& name, EventState* state) 271 276 { … … 280 285 } 281 286 287 /** 288 @brief Returns the event-state with the given name. 289 */ 282 290 EventState* BaseObject::getEventState(const std::string& name) const 283 291 { … … 406 414 } 407 415 } 416 417 /** 418 @brief Manually loads all event states, even if the class doesn't officially support them. This is needed by some classes like @ref EventDispatcher or @ref EventTarget. 419 */ 420 void BaseObject::loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier) 421 { 422 Element* events = xmlelement.FirstChildElement("events", false); 423 if (events) 424 { 425 // get the list of all states present 426 std::list<std::string> eventnames; 427 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 428 { 429 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 430 eventnames.push_back(child->Value()); 431 } 432 else if (mode == XMLPort::SaveObject) 433 { 434 } 435 436 // iterate through all states and get the event sources 437 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 438 { 439 std::string statename = (*it); 440 441 // if the event state is already known, continue with the next state 442 orxonox::EventState* eventstate = object->getEventState(statename); 443 if (eventstate) 444 continue; 445 446 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(identifier->getXMLPortObjectContainer(statename)); 447 if (!container) 448 { 449 ExecutorMember<BaseObject>* setfunctor = createExecutor(createFunctor(&BaseObject::addEventSource), std::string( "BaseObject" ) + "::" + "addEventSource" + "(" + statename + ")"); 450 ExecutorMember<BaseObject>* getfunctor = createExecutor(createFunctor(&BaseObject::getEventSource), std::string( "BaseObject" ) + "::" + "getEventSource" + "(" + statename + ")"); 451 setfunctor->setDefaultValue(1, statename); 452 getfunctor->setDefaultValue(1, statename); 453 454 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(statename, identifier, setfunctor, getfunctor, false, true); 455 identifier->addXMLPortObjectContainer(statename, container); 456 } 457 container->port(object, *events, mode); 458 } 459 } 460 } 408 461 } -
code/branches/core5/src/libraries/core/BaseObject.h
r5882 r5887 172 172 /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ 173 173 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } 174 175 static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier); 174 176 175 177 protected: 178 void addEventState(const std::string& name, EventState* container); 179 EventState* getEventState(const std::string& name) const; 180 181 std::string name_; //!< The name of the object 182 std::string oldName_; //!< The old name of the object 183 mbool bActive_; //!< True = the object is active 184 mbool bVisible_; //!< True = the object is visible 185 std::string mainStateName_; 186 Functor* mainStateFunctor_; 187 188 private: 176 189 /** @brief Adds an object which listens to the events of this object. */ 177 190 inline void registerEventListener(BaseObject* object) … … 181 194 { this->eventListeners_.erase(object); } 182 195 183 void addEventState(const std::string& name, EventState* container);184 EventState* getEventState(const std::string& name) const;185 186 std::string name_; //!< The name of the object187 std::string oldName_; //!< The old name of the object188 mbool bActive_; //!< True = the object is active189 mbool bVisible_; //!< True = the object is visible190 std::string mainStateName_;191 Functor* mainStateFunctor_;192 193 private:194 196 void setXMLName(const std::string& name); 195 197 Template* getTemplate(unsigned int index) const; -
code/branches/core5/src/modules/objects/eventsystem/EventDispatcher.cc
r5886 r5887 54 54 55 55 XMLPortObject(EventDispatcher, BaseObject, "targets", addTarget, getTarget, xmlelement, mode); 56 57 // since we need event sources mapped to any state, we have to parse XML by ourselves 58 this->loadAllEventStates(xmlelement, mode, this, Class(EventDispatcher)); 56 59 } 57 60 -
code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc
r5882 r5887 29 29 #include "EventTarget.h" 30 30 #include "core/CoreIncludes.h" 31 #include "core/XMLPort.h" 31 32 32 33 namespace orxonox … … 43 44 } 44 45 46 void EventTarget::XMLPort(Element& xmlelement, XMLPort::Mode mode) 47 { 48 SUPER(EventTarget, XMLPort, xmlelement, mode); 49 50 // since we need event sources mapped to any state, we have to parse XML by ourselves 51 this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget)); 52 } 53 45 54 void EventTarget::processEvent(Event& event) 46 55 { -
code/branches/core5/src/modules/objects/eventsystem/EventTarget.h
r5882 r5887 43 43 virtual ~EventTarget(); 44 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 45 47 virtual void processEvent(Event& event); 46 48
Note: See TracChangeset
for help on using the changeset viewer.