Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7868 in orxonox.OLD for trunk/src/lib/event


Ignore:
Timestamp:
May 26, 2006, 1:21:32 PM (19 years ago)
Author:
bensch
Message:

trunk: merge Check in the Event-changes:
r7867 | bensch | 2006-05-26 13:19:46 +0200 (Fri, 26 May 2006) | 1 line

Events better subscribed


r7866 | bensch | 2006-05-26 13:11:10 +0200 (Fri, 26 May 2006) | 1 line

Events are subscribed at the EventListener, and not the EventHandler

Location:
trunk/src/lib/event
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/event_def.h

    r5553 r7868  
    1212#include "SDL/SDL_keysym.h"
    1313#endif
    14 #include "stdincl.h"
    1514
    1615
  • trunk/src/lib/event/event_handler.cc

    r7756 r7868  
    171171   unsubscribe(EventListener* el, elState state) function
    172172*/
    173 void EventHandler::unsubscribe(elState state, int eventType)
     173void EventHandler::unsubscribe(EventListener* el, elState state, int eventType)
    174174{
    175175  PRINTF(4)("Unsubscribing event type nr: %i\n", eventType);
    176176  if (state == ES_ALL)
    177177    for (unsigned int i = 0; i < ES_NUMBER; i++)
    178       this->listeners[i][eventType].clear();
    179   else
    180     this->listeners[state][eventType].clear();
    181 }
    182 
    183 
    184 /**
    185  * unsubscribe all events from a specific listener
     178    {
     179      std::vector<EventListener*>::iterator listener =
     180         std::find(this->listeners[i][eventType].begin(),
     181                   this->listeners[i][eventType].end(),
     182                   el);
     183      if (listener != this->listeners[i][eventType].end())
     184        this->listeners[i][eventType].erase(listener);
     185    }
     186  else
     187  {
     188    std::vector<EventListener*>::iterator listener =
     189        std::find(this->listeners[state][eventType].begin(),
     190                  this->listeners[state][eventType].end(),
     191                  el);
     192    if (listener != this->listeners[state][eventType].end())
     193      this->listeners[state][eventType].erase(listener);
     194  }
     195}
     196
     197
     198/**
     199 * @brief unsubscribe all events from a specific listener
    186200 * @param el: the listener that wants to unsubscribe itself
    187201 * @param state: the state in which the events shall be unsubscribed
    188 
    189 */
     202 */
    190203void EventHandler::unsubscribe(EventListener* el, elState state)
    191204{
  • trunk/src/lib/event/event_handler.h

    r7756 r7868  
    3535
    3636  void subscribe(EventListener* el, elState state, int eventType);
    37   void unsubscribe(elState state, int eventType);
     37  void unsubscribe(EventListener* el, elState state, int eventType);
    3838  void unsubscribe(EventListener* el, elState state = ES_ALL);
    3939  void flush(elState state);
  • trunk/src/lib/event/event_listener.cc

    r4866 r7868  
    1919#include "event_handler.h"
    2020
    21 using namespace std;
    22 
    23 
    2421/**
    25  * standard constructor
    26 */
     22 * @brief standard constructor
     23 */
    2724EventListener::EventListener ()
    2825{
     
    3229
    3330/**
    34  *  standard deconstructor
    35 */
     31 * @brief standard deconstructor
     32 *
     33 * Unsubscribes all Subscribed Events, of this EventListener.
     34 */
    3635EventListener::~EventListener ()
    3736{
     
    3938  EventHandler::getInstance()->unsubscribe(this, ES_ALL);
    4039}
     40
     41bool EventListener::isEventSubscribed(elState state, int eventType) const
     42{
     43  return EventHandler::getInstance()->isSubscribed(state, eventType);
     44}
     45
     46
     47/**
     48 * @brief Subscribes an Events to this EventListener.
     49 * @param state the state to subscribe to.
     50 * @param eventType the Type of Event to subscribe.
     51 */
     52void EventListener::subscribeEvent(elState state, int eventType)
     53{
     54  EventHandler::getInstance()->subscribe(this, state, eventType);
     55}
     56
     57
     58/**
     59 * @brief Unubscribes an Event from this EventListener.
     60 * @param state the state to unsubscribe from.
     61 * @param eventType the Type of Event to unsubscribe.
     62 */
     63void EventListener::unsubscribeEvent(elState state, int eventType)
     64{
     65  EventHandler::getInstance()->unsubscribe(this, state, eventType);
     66}
     67
     68void EventListener::unsubscribeEvents(elState state)
     69{
     70  EventHandler::getInstance()->unsubscribe(this, state);
     71}
     72
  • trunk/src/lib/event/event_listener.h

    r5291 r7868  
    99#include "base_object.h"
    1010#include "event.h"
     11#include "event_def.h"
    1112
    1213//! A class for event listener
     
    1718  virtual ~EventListener();
    1819
     20  bool isEventSubscribed(elState state, int eventType) const;
     21
     22  void subscribeEvent(elState state, int eventType);
     23  void unsubscribeEvent(elState state, int eventType);
     24  void unsubscribeEvents(elState state = ES_ALL);
     25
    1926  /**
    20    * abstract function that processes events from the handler
     27   * @brief abstract function that processes events from the handler
    2128   * @param event: the event
    2229   */
    2330  virtual void process(const Event &event) = 0;
     31
    2432};
    2533
Note: See TracChangeset for help on using the changeset viewer.