Main MRPT website > C++ reference for MRPT 1.9.9
CObserver.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CObserver_H
10 #define CObserver_H
11 
12 #include <mrpt/utils/utils_defs.h>
13 #include <mrpt/utils/mrptEvent.h>
14 #include <set>
15 
16 namespace mrpt
17 {
18 namespace utils
19 {
20 class CObservable;
21 
22 /** Inherit from this class to get notified about events from any CObservable
23  * object after subscribing to it.
24  *
25  * The main methods in this class are:
26  * - observeBegin(): To be called to start listening at a given object.
27  * - OnEvent(): Virtual functions to be implemented in your child class to
28  * receive all the notifications.
29  *
30  * Note that if custom (child) mrptEvent classes are used, you can tell
31  * between them in runtime with "dynamic_cast<>()".
32  *
33  * \note The pairs CObservable / CObserver automatically notify each other the
34  * destruction of any of them, effectively ending the subscription of events.
35  * \ingroup mrpt_base_grp
36  * \sa CObservable, mrptEvent
37  */
38 class CObserver
39 {
40  friend class CObservable;
41 
42  public:
43  CObserver();
44  virtual ~CObserver();
45 
46  /** Starts the subscription of this observer to the given object. \sa
47  * observeEnd */
49 
50  /** Ends the subscription of this observer to the given object (note that
51  there is no need to call this method, since the destruction of the first
52  of observer/observed will put an end to the process
53  \sa observeBegin */
54  void observeEnd(CObservable& obj);
55 
56  private:
57  std::set<CObservable*> m_subscribed;
58  void internal_on_event(const mrptEvent& e);
59 
60  protected:
61  /** This virtual function will be called upon receive of any event after
62  * starting listening at any CObservable object.
63  */
64  virtual void OnEvent(const mrptEvent& e) = 0;
65 
66 }; // End of class def.
67 
68 } // End of namespace
69 } // end of namespace
70 #endif
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:34
virtual void OnEvent(const mrptEvent &e)=0
This virtual function will be called upon receive of any event after starting listening at any CObser...
void observeEnd(CObservable &obj)
Ends the subscription of this observer to the given object (note that there is no need to call this m...
Definition: CObserver.cpp:36
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
std::set< CObservable * > m_subscribed
Definition: CObserver.h:57
void internal_on_event(const mrptEvent &e)
Definition: CObserver.cpp:47
void observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Definition: CObserver.cpp:26
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:38
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:35



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019