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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020