Main MRPT website > C++ reference for MRPT 1.4.0
CObservable.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 CObservable_H
10#define CObservable_H
11
12#include <mrpt/config.h>
14#include <set>
15
16namespace mrpt
17{
18 namespace utils
19 {
20 class CObserver;
21 class mrptEvent;
22
23 /** Inherit from this class for those objects capable of being observed by a CObserver class.
24 *
25 * The only thing to do in your child class is to call CObservable::publishEvent() whenever needed and all the
26 * observer classes will be notified.
27 *
28 * \note The pairs CObservable / CObserver automatically notify each other the destruction of any of them, effectively ending the subscription of events.
29 *
30 * \sa CObserver, mrptEvent
31 * \ingroup mrpt_base_grp
32 */
34 {
35 friend class CObserver;
36
37 public:
39 virtual ~CObservable();
40
41 private:
42 std::set<CObserver*> m_subscribers;
45
46 protected:
47 /** Called when you want this object to emit an event to all the observers currently subscribed to this object. */
48 void publishEvent(const mrptEvent &e) const;
49
50 /** Can be called by a derived class before preparing an event for publishing with \a publishEvent to determine if there is no one
51 * subscribed, so it can save the wasted time preparing an event that will be not read. */
52 inline bool hasSubscribers() const { return !m_subscribers.empty(); }
53
54 }; // End of class def.
55
56 } // End of namespace
57} // end of namespace
58#endif
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition: CObservable.h:34
void internal_observer_begin(CObserver *)
void publishEvent(const mrptEvent &e) const
Called when you want this object to emit an event to all the observers currently subscribed to this o...
bool hasSubscribers() const
Can be called by a derived class before preparing an event for publishing with publishEvent to determ...
Definition: CObservable.h:52
void internal_observer_end(CObserver *)
std::set< CObserver * > m_subscribers
Definition: CObservable.h:42
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:35
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.4 for MRPT 1.4.0 SVN: at Sun Aug 14 11:34:44 UTC 2022