Main MRPT website > C++ reference for 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); }
mrpt::system::mrptEvent
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
system-precomp.h
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrpt::system::CObserver::observeBegin
void observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Definition: CObserver.cpp:26
mrpt::system::CObserver::~CObserver
virtual ~CObserver()
Definition: CObserver.cpp:19
CObservable.h
mrpt::system::CObserver::observeEnd
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
CObserver.h
mrpt::system::CObserver::CObserver
CObserver()
Definition: CObserver.cpp:18
mrpt::system::CObservable
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition: CObservable.h:33
mrpt::system::CObserver::internal_on_event
void internal_on_event(const mrptEvent &e)
Definition: CObserver.cpp:47
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