Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 31, 2008, 3:31:21 AM (16 years ago)
Author:
landauf
Message:
  • added EventListener: this class fires an event if another class with a specified name fires
  • added EventDispatcher: this class dispatches events to several other classes (EventTarget) if it gets an event itself
  • added EventTarget: used in EventDispatcher to access all classes with a specified name
  • added XMLNameListener: this listener gets called every time a new class was loaded through XML with a name != "". used to find classes with a given name even if they're not existing at the moment.
File:
1 edited

Legend:

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

    r2069 r2074  
    3838#include "XMLPort.h"
    3939#include "XMLFile.h"
     40#include "XMLNameListener.h"
    4041#include "Template.h"
    4142#include "util/String.h"
     
    8182    {
    8283        for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
    83             (*it)->eventListeners_.erase(this);
     84            (*it)->unregisterEventListener(this);
     85
     86        for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     87            it->first->removeEvent(this);
    8488    }
    8589
     
    9296    void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    9397    {
    94         XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode);
     98        XMLPortParam(BaseObject, "name", setXMLName, getName, xmlelement, mode);
    9599        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
    96100        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
     
    135139
    136140    /**
     141        @brief Loads the name of the object through XML and calls all XMLNameListener.
     142        @param name The name of the object
     143    */
     144    void BaseObject::setXMLName(const std::string& name)
     145    {
     146        this->setName(name);
     147
     148        for (ObjectList<XMLNameListener>::iterator it = ObjectList<XMLNameListener>::begin(); it != ObjectList<XMLNameListener>::end(); ++it)
     149            it->loadedNewXMLName(this);
     150    }
     151
     152    /**
    137153        @brief Returns the levelfile that loaded this object.
    138154        @return The levelfile
     
    187203    void BaseObject::addEvent(BaseObject* event, const std::string& sectionname)
    188204    {
    189         event->eventListeners_[this] = sectionname;
     205        event->registerEventListener(this, sectionname);
    190206        this->events_.push_back(event);
     207    }
     208
     209    void BaseObject::removeEvent(BaseObject* event)
     210    {
     211        this->events_.remove(event);
    191212    }
    192213
     
    232253    void BaseObject::fireEvent(bool activate)
    233254    {
    234         Event event(activate, this);
     255        this->fireEvent(activate, this);
     256    }
     257
     258    void BaseObject::fireEvent(bool activate, BaseObject* originator)
     259    {
     260        Event event(activate, originator);
    235261
    236262        for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     
    241267    }
    242268
     269    void BaseObject::fireEvent(Event& event)
     270    {
     271        for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     272            it->first->processEvent(event);
     273    }
     274
    243275    void BaseObject::processEvent(Event& event)
    244276    {
Note: See TracChangeset for help on using the changeset viewer.