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 }
mrpt::system::mrptEvent
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
exceptions.h
mrpt::system::CObservable::~CObservable
virtual ~CObservable()
Definition: CObservable.cpp:20
s
GLdouble s
Definition: glext.h:3676
mrpt::system::CObservable::publishEvent
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
system-precomp.h
mrpt::system::CObservable::internal_observer_begin
void internal_observer_begin(CObserver *)
Definition: CObservable.cpp:29
mrpt::system::CObservable::CObservable
CObservable()
Definition: CObservable.cpp:19
CObservable.h
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::system::mrptEventOnDestroy
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:67
mrpt::system::CObservable::internal_observer_end
void internal_observer_end(CObserver *)
Definition: CObservable.cpp:34
CObserver.h
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
mrpt::system::CObserver
Inherit from this class to get notified about events from any CObservable object after subscribing to...
Definition: CObserver.h:36
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST