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-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 
10 #include "system-precomp.h" // Precompiled headers
11 
12 #include <mrpt/system/CObserver.h>
14 #include <mrpt/core/exceptions.h>
15 
16 using namespace mrpt::system;
17 using namespace std;
18 
21 {
22  // Notify my destruction:
23  this->publishEvent(mrptEventOnDestroy(this));
24 
25  // Tell observers to unsubscribe:
26  while (!m_subscribers.empty()) (*m_subscribers.begin())->observeEnd(*this);
27 }
28 
30 {
31  m_subscribers.insert(o);
32 }
33 
35 {
37  auto it = m_subscribers.find(o);
38  ASSERTMSG_(
39  it != m_subscribers.end(),
40  "Ending subscription from an observer not subscribed to this object!");
41  m_subscribers.erase(it);
42  MRPT_END
43 }
44 
45 /** Called when you want this object to emit an event to all the observers
46  * currently subscribed to this object.
47  */
49 {
51  for (auto& s : m_subscribers)
52  if (s) s->internal_on_event(e);
53  MRPT_END
54 }
void internal_observer_end(CObserver *)
Definition: CObservable.cpp:34
#define MRPT_START
Definition: exceptions.h:262
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:25
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
STL namespace.
GLdouble s
Definition: glext.h:3676
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:36
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:67
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
void internal_observer_begin(CObserver *)
Definition: CObservable.cpp:29
#define MRPT_END
Definition: exceptions.h:266
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:48



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