iCub-main
EventDispatcher.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2010 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef LM_EVENTDISPATCHER__
20 #define LM_EVENTDISPATCHER__
21 
22 #include <list>
23 
25 
26 namespace iCub {
27 namespace learningmachine {
28 
29 
45 private:
49  std::list<IEventListener*> listeners;
50 
54  EventDispatcher() { }
55 
59  EventDispatcher(const EventDispatcher& other);
60 
64  virtual ~EventDispatcher();
65 
69  EventDispatcher& operator=(const EventDispatcher& other);
70 
71 public:
85  return instance;
86  }
87 
93  virtual void addListener(IEventListener* listener) {
94  this->listeners.push_back(listener);
95  }
96 
101  virtual void removeListener(int idx);
102 
109  virtual void removeListener(IEventListener* listener);
110 
116  virtual IEventListener& getAt(int idx);
117 
123  virtual IEventListener& getAt(int idx) const;
124 
128  virtual void clear();
129 
137  virtual void raise(IEvent& event);
138 
144  virtual int countListeners() const {
145  return this->listeners.size();
146  }
147 
153  virtual bool hasListeners() {
154  return (!this->listeners.empty());
155  }
156 
157 };
158 
159 } // learningmachine
160 } // iCub
161 
162 #endif
The EventDispatcher manages the relation between the various instances of IEventListeners and IEvents...
virtual bool hasListeners()
Tells whether there are listeners for events.
virtual void clear()
Clears all the IEventListeners from the EventDispatcher.
virtual IEventListener & getAt(int idx)
Returns the IEventListener at a specified index.
static EventDispatcher & instance()
An instance retrieval method that follows the Singleton pattern.
virtual void addListener(IEventListener *listener)
Adds an IEventListener to the list.
virtual int countListeners() const
Counts the number of registered listeners.
virtual void removeListener(int idx)
Removes an IEventListener from the list.
static uint32_t idx[BOARD_NUM]
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.