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-2018, 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 #pragma once
10 
11 #include <mrpt/system/mrptEvent.h>
12 #include <set>
13 
14 namespace mrpt
15 {
16 namespace system
17 {
18 class CObservable;
19 
20 /** Inherit from this class to get notified about events from any CObservable
21  * object after subscribing to it.
22  *
23  * The main methods in this class are:
24  * - observeBegin(): To be called to start listening at a given object.
25  * - OnEvent(): Virtual functions to be implemented in your child class to
26  * receive all the notifications.
27  *
28  * Note that if custom (child) mrptEvent classes are used, you can tell
29  * between them in runtime with "dynamic_cast<>()".
30  *
31  * \note The pairs CObservable / CObserver automatically notify each other the
32  * destruction of any of them, effectively ending the subscription of events.
33  * \ingroup mrpt_system_grp
34  * \sa CObservable, mrptEvent
35  */
36 class CObserver
37 {
38  friend class CObservable;
39 
40  public:
41  CObserver();
42  virtual ~CObserver();
43 
44  /** Starts the subscription of this observer to the given object. \sa
45  * observeEnd */
47 
48  /** Ends the subscription of this observer to the given object (note that
49  there is no need to call this method, since the destruction of the first
50  of observer/observed will put an end to the process
51  \sa observeBegin */
52  void observeEnd(CObservable& obj);
53 
54  private:
55  std::set<CObservable*> m_subscribed;
56  void internal_on_event(const mrptEvent& e);
57 
58  protected:
59  /** This virtual function will be called upon receive of any event after
60  * starting listening at any CObservable object.
61  */
62  virtual void OnEvent(const mrptEvent& e) = 0;
63 
64 }; // End of class def.
65 
66 } // namespace system
67 } // namespace mrpt
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:36
std::set< CObservable * > m_subscribed
Definition: CObserver.h:55
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
void internal_on_event(const mrptEvent &e)
Definition: CObserver.cpp:47
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:33
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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 observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Definition: CObserver.cpp:26



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019