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



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019