Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 5, 2009, 9:57:05 PM (15 years ago)
Author:
landauf
Message:

Again some changes in the event-system:

  • Added "mainstate" event-state to BaseObject. It leads to the state which was defined with the mainstate attribute in XML.
  • Support event-forwarding to the mainstate of event-listeners.
  • The "targets" subsection of the EventDispatcher now supports all kinds of objects (not just EventTargets).
  • EventTarget now works in all places of the XML-file, not just in the "targets" section of EventDispatcher.

Added a sample XML-file which explains several aspects of the event-system.

Location:
code/branches/core5/src/libraries/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/BaseObject.cc

    r5879 r5882  
    118118
    119119        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     120        XMLPortObject(BaseObject, BaseObject, "eventlisteners", addEventListener, getEventListener, xmlelement, mode);
    120121       
    121122        Element* events = 0;
     
    123124            events = xmlelement.FirstChildElement("events", false);
    124125        else if (mode == XMLPort::SaveObject)
    125             ;
     126            {}
    126127        if (events)
    127128            this->XMLEventPort(*events, mode);
     
    137138        XMLPortEventState(BaseObject, BaseObject, "activity", setActive, xmlelement, mode);
    138139        XMLPortEventState(BaseObject, BaseObject, "visibility", setVisible, xmlelement, mode);
     140        XMLPortEventState(BaseObject, BaseObject, "mainstate", setMainState, xmlelement, mode);
    139141       
    140142        this->bRegisteredEventStates_ = true;
     
    242244    }
    243245
     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
    244270    void BaseObject::addEventState(const std::string& name, EventState* state)
    245271    {
  • code/branches/core5/src/libraries/core/BaseObject.h

    r5879 r5882  
    157157            void removeEventSource(BaseObject* source);
    158158            BaseObject* getEventSource(unsigned int index, const std::string& state) const;
     159           
     160            void addEventListener(BaseObject* listener);
     161            BaseObject* getEventListener(unsigned int index) const;
    159162
    160163            void fireEvent();
     
    208211            std::map<BaseObject*, std::string>  eventSources_;           //!< List of objects which send events to this object, mapped to the state which they affect
    209212            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
    210214            std::map<std::string, EventState*>  eventStates_;            //!< Maps the name of the event states to their helper objects
    211215            bool                                bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort)
Note: See TracChangeset for help on using the changeset viewer.