Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7911 in orxonox.OLD


Ignore:
Timestamp:
May 27, 2006, 5:56:15 PM (18 years ago)
Author:
bensch
Message:

gui: Only one copy of one eventListener can be assigned to one Event in each state. Everything else will be refused

Location:
branches/gui/src/lib/event
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/event/event_handler.cc

    r7910 r7911  
    183183  {
    184184    for(unsigned int i = 0; i < ES_NUMBER; i++)
    185       this->listeners[i][eventType].push_back(el);
    186   }
    187   else
    188     this->listeners[state][eventType].push_back(el);
     185      if (!this->findListener( NULL, (elState)i, eventType, el))
     186        this->listeners[i][eventType].push_back(el);
     187      else
     188      {
     189        PRINTF(2)("%s::%s was already subscribed to state %d event %d\n", el->getClassName(), el->getName(), i, eventType);
     190      }
     191  }
     192  else
     193  {
     194    if (!this->findListener( NULL, state, eventType, el))
     195      this->listeners[state][eventType].push_back(el);
     196    else
     197    {
     198      PRINTF(2)("%s::%s was already subscribed to state %d event %d\n", el->getClassName(), el->getName(), state, eventType);
     199    }
     200  }
    189201}
    190202
     
    204216    for (unsigned int i = 0; i < ES_NUMBER; i++)
    205217    {
    206       std::vector<EventListener*>::iterator listener =
    207         std::find(this->listeners[i][eventType].begin(),
    208                   this->listeners[i][eventType].end(),
    209                   el);
    210       if (listener != this->listeners[i][eventType].end())
     218      std::vector<EventListener*>::iterator listener;
     219      if (this->findListener(&listener, (elState)i, eventType, el))
    211220        this->listeners[i][eventType].erase(listener);
    212221    }
    213222  else
    214223  {
    215     std::vector<EventListener*>::iterator listener =
    216       std::find(this->listeners[state][eventType].begin(),
    217                 this->listeners[state][eventType].end(),
    218                 el);
    219     if (listener != this->listeners[state][eventType].end())
     224    std::vector<EventListener*>::iterator listener;
     225    if (this->findListener(&listener, state, eventType, el))
    220226      this->listeners[state][eventType].erase(listener);
    221227  }
     
    293299
    294300
     301bool EventHandler::findListener(std::vector<EventListener*>::iterator* it, elState state, int eventType, EventListener* listener)
     302{
     303  std::vector<EventListener*>::iterator findIterator =
     304    std::find(this->listeners[state][eventType].begin(), this->listeners[state][eventType].end(), listener);
     305  if (it != NULL)
     306    *it = findIterator;
     307  return ( findIterator != this->listeners[state][eventType].end());
     308
     309}
     310
     311
     312
    295313/**
    296314 * @brief if the unicode characters should be recorded.
     
    323341  }
    324342}
     343
    325344
    326345
     
    418437
    419438  /// setting a temporary state in case of an EventListener's process changes the state.
    420   printf("%d\n", this->listeners[state][event.type].size());
     439  printf("%d event: %d state: %d\n", this->listeners[state][event.type].size(), event.type, state);
    421440  for (unsigned int i = 0; i < this->listeners[state][event.type].size(); i++)
    422441  {
  • branches/gui/src/lib/event/event_handler.h

    r7903 r7911  
    5555  EventHandler();
    5656
     57  bool findListener(std::vector<EventListener*>::iterator* it, elState state, int eventType, EventListener* listener);
     58
    5759 private:
    5860  static EventHandler*         singletonRef;                    //!< the singleton reference
Note: See TracChangeset for help on using the changeset viewer.