MRPT  2.0.1
CObserver.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-2020, 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 
13 #include <mrpt/system/CObserver.h>
14 
15 using namespace mrpt::system;
16 using namespace std;
17 
18 CObserver::CObserver() = default;
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:31
STL namespace.
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 internal_observer_begin(CObserver *)
Definition: CObservable.cpp:38
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 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020