Main MRPT website > C++ reference for MRPT 1.4.0
mrptEvent.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, 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#ifndef mrptEvent_H
10#define mrptEvent_H
11
13
14namespace mrpt
15{
16 namespace utils
17 {
18 class CObservable;
19
20 /** The basic event type for the observer-observable pattern in MRPT.
21 * You can sub-class this base class to create custom event types, then
22 * tell between them in runtime with isOfType<T>(), for example:
23 * \code
24 * if (e.isOfType<mrptEventOnDestroy>())
25 * {
26 * const mrptEventOnDestroy* ev = e.getAs<mrptEventOnDestroy>();
27 * ev-> ...
28 * }
29 * \endcode
30 *
31 * \sa CObserver, CObservable
32 * \ingroup mrpt_base_grp
33 */
35 {
36 protected:
37 virtual void do_nothing() { } //!< Just to allow this class to be polymorphic
38 public:
39 /** Default ctor */
40 inline mrptEvent() : timestamp(mrpt::system::now()) { }
41
42 template <class EVENTTYPE>
43 inline bool isOfType() const { return dynamic_cast<const EVENTTYPE*>(this)!=NULL; }
44
45 template <class EVENTTYPE>
46 inline const EVENTTYPE* getAs() const { return dynamic_cast<const EVENTTYPE*>(this); }
47
48 template <class EVENTTYPE>
49 inline EVENTTYPE* getAsNonConst() const { return const_cast<EVENTTYPE*>(dynamic_cast<const EVENTTYPE*>(this)); }
50
52
53 }; // End of class def.
54
55 /** An event sent by any CObservable object (automatically) just before being destroyed and telling its observers to unsubscribe.
56 * \ingroup mrpt_base_grp
57 */
59 {
60 protected:
61 void do_nothing() MRPT_OVERRIDE { } //!< Just to allow this class to be polymorphic
62 public:
63 inline mrptEventOnDestroy(const CObservable *obj) : source_object(obj) { }
64
66
67 }; // End of class def.
68
69 } // End of namespace
70} // end of namespace
71#endif
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition CObservable.h:34
The basic event type for the observer-observable pattern in MRPT.
Definition mrptEvent.h:35
const EVENTTYPE * getAs() const
Definition mrptEvent.h:46
EVENTTYPE * getAsNonConst() const
Definition mrptEvent.h:49
mrptEvent()
Default ctor.
Definition mrptEvent.h:40
mrpt::system::TTimeStamp timestamp
Definition mrptEvent.h:51
virtual void do_nothing()
Just to allow this class to be polymorphic.
Definition mrptEvent.h:37
bool isOfType() const
Definition mrptEvent.h:43
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition mrptEvent.h:59
mrptEventOnDestroy(const CObservable *obj)
Definition mrptEvent.h:63
void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
Definition mrptEvent.h:61
const CObservable * source_object
Definition mrptEvent.h:65
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition datetime.h:30
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition mrpt_macros.h:28
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.8 for MRPT 1.4.0 SVN: at Wed Dec 6 15:06:50 UTC 2023