ComponentObservable.hpp
1 /*
2  * Copyright © 2013 mathdu07
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef COMPONENTOBSERVABLE_H_
19 #define COMPONENTOBSERVABLE_H_
20 
21 #include <set>
22 #include <SFML/UI/ComponentObserver.hpp>
23 
24 
25 namespace sf
26 {
27 namespace ui
28 {
29 class ComponentEvent;
30 
32 {
33 //CONSTRUCTORS - DESTRUCTOR -----------------------------------------------------------
34 public:
41 
42  virtual ~ComponentObservable();
43 //-------------------------------------------------------------------------------------
44 
45 //METHODS -----------------------------------------------------------------------------
46 public:
52  void addObserver(sf::ui::ComponentObserver* observer);
53 
59  std::set<sf::ui::ComponentObserver*>::const_iterator getObserversBegin() const;
60 
66  std::set<sf::ui::ComponentObserver*>::const_iterator getObserversEnd() const;
67 
73  int countObservers();
74 
83 
89  void removeAllObservers();
90 
91 protected:
99  void triggerEvent(const sf::ui::ComponentEvent &event);
100 //-------------------------------------------------------------------------------------
101 
102 //GETTERS - SETTERS -------------------------------------------------------------------
103 
104 //-------------------------------------------------------------------------------------
105 
106 //FIELDS ------------------------------------------------------------------------------
107 protected:
108  std::set<sf::ui::ComponentObserver*> m_observers;
109 //-------------------------------------------------------------------------------------
110 };
111 
112 } /* namespace ui */
113 } /* namespace sf */
114 #endif /* COMPONENTOBSERVABLE_H_ */
115 
std::set< sf::ui::ComponentObserver * >::const_iterator getObserversEnd() const
void addObserver(sf::ui::ComponentObserver *observer)
Add an observer.
The class who call the observers.
void triggerEvent(const sf::ui::ComponentEvent &event)
Triggers the event and notify all observers.
An event generate by a component.
void removeObserver(sf::ui::ComponentObserver *observer)
Remove the observer at the given index.
ComponentObservable()
The default constructor.
void removeAllObservers()
Remove all the observers.
A object updated each time a ComponentObservable change.
std::set< sf::ui::ComponentObserver * >::const_iterator getObserversBegin() const