Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
14#include <set>
15
16namespace 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:
40 virtual ~CObserver();
41
42 /** Starts the subscription of this observer to the given object. \sa observeEnd */
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 */
48
49 private:
50 std::set<CObservable*> m_subscribed;
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
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition CObservable.h:34
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition CObserver.h:35
std::set< CObservable * > m_subscribed
Definition CObserver.h:50
void internal_on_event(const mrptEvent &e)
void observeEnd(CObservable &obj)
Ends the subscription of this observer to the given object (note that there is no need to call this m...
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.
The basic event type for the observer-observable pattern in MRPT.
Definition mrptEvent.h:35
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.7 for MRPT 1.4.0 SVN: at Tue Jun 27 15:23:24 UTC 2023