MRPT  1.9.9
CObserver.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 
15 using namespace mrpt::system;
16 using namespace std;
17 
20 {
21  while (!m_subscribed.empty()) this->observeEnd(**m_subscribed.begin());
22 }
23 
24 /** Starts the subscription of this observer to the given object. \sa
25  * observeEnd */
27 {
28  m_subscribed.insert(&obj);
29  obj.internal_observer_begin(this);
30 }
31 
32 /** Ends the subscription of this observer to the given object (note that there
33 is no need to call this method, since the destruction of the first of
34 observer/observed will put an end to the process
35 \sa observeBegin */
37 {
38  auto it = m_subscribed.find(&obj);
39  if (it != m_subscribed.end())
40  {
41  (*it)->internal_observer_end(this);
42  m_subscribed.erase(it);
43  }
44 }
45 
46 // Redirect the notification to the user virtual method:
47 void CObserver::internal_on_event(const mrptEvent& e) { this->OnEvent(e); }
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:32
STL namespace.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
void observeEnd(CObservable &obj)
Ends the subscription of this observer to the given object (note that there is no need to call this m...
Definition: CObserver.cpp:36
void internal_on_event(const mrptEvent &e)
Definition: CObserver.cpp:47
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:31
void observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Definition: CObserver.cpp:26



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020