Main MRPT website > C++ reference for MRPT 1.9.9
CObservable.cpp
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 
10 #include "base-precomp.h" // Precompiled headers
11 
12 #include <mrpt/utils/CObserver.h>
13 #include <mrpt/utils/CObservable.h>
14 
15 using namespace mrpt::utils;
16 using namespace std;
17 
20 {
21  // Notify my destruction:
22  this->publishEvent(mrptEventOnDestroy(this));
23 
24  // Tell observers to unsubscribe:
25  while (!m_subscribers.empty()) (*m_subscribers.begin())->observeEnd(*this);
26 }
27 
29 {
30  m_subscribers.insert(o);
31 }
32 
34 {
36  auto it = m_subscribers.find(o);
37  ASSERTMSG_(
38  it != m_subscribers.end(),
39  "Ending subscription from an observer not subscribed to this object!")
40  m_subscribers.erase(it);
41  MRPT_END
42 }
43 
44 /** Called when you want this object to emit an event to all the observers
45  * currently subscribed to this object.
46 */
48 {
50  for (auto& s : m_subscribers)
51  if (s) s->internal_on_event(e);
52  MRPT_END
53 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:34
STL namespace.
void internal_observer_begin(CObserver *)
Definition: CObservable.cpp:28
GLdouble s
Definition: glext.h:3676
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...
Definition: CObservable.cpp:47
#define MRPT_END
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:68
#define MRPT_START
void internal_observer_end(CObserver *)
Definition: CObservable.cpp:33
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:38
#define ASSERTMSG_(f, __ERROR_MSG)



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