MRPT
2.0.4
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
12
#include <
mrpt/system/CObservable.h
>
13
#include <
mrpt/system/CObserver.h
>
14
15
using namespace
mrpt::system
;
16
using namespace
std;
17
18
CObserver::CObserver
() =
default
;
19
CObserver::~CObserver
()
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 */
26
void
CObserver::observeBegin
(
CObservable
& obj)
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 */
36
void
CObserver::observeEnd
(
CObservable
& obj)
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:32
system-precomp.h
mrpt::system::CObserver::observeBegin
void observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Definition:
CObserver.cpp:26
mrpt::system::CObservable::internal_observer_begin
void internal_observer_begin(CObserver *)
Definition:
CObservable.cpp:38
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()
mrpt::system::CObservable
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition:
CObservable.h:32
mrpt::system::CObserver::internal_on_event
void internal_on_event(const mrptEvent &e)
Definition:
CObserver.cpp:47
mrpt::system
Definition:
backtrace.h:15
Page generated by
Doxygen 1.8.18
for MRPT 2.0.4 at Thu Sep 24 07:14:18 UTC 2020