MRPT  1.9.9
CObservable.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "system-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/exceptions.h>
14 #include <mrpt/system/CObserver.h>
15 
16 using namespace mrpt::system;
17 using namespace std;
18 
19 CObservable::CObservable() = default;
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:241
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:31
STL namespace.
GLdouble s
Definition: glext.h:3682
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:34
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:66
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:108
void internal_observer_begin(CObserver *)
Definition: CObservable.cpp:29
#define MRPT_END
Definition: exceptions.h:245
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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019