Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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 
12 #include <mrpt/system/datetime.h>
13 
14 namespace 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  */
34 class mrptEvent
35 {
36  protected:
37  /** Just to allow this class to be polymorphic */
38  virtual void do_nothing() {}
39  public:
40  /** Default ctor */
41  inline mrptEvent() : timestamp(mrpt::system::now()) {}
42  template <class EVENTTYPE>
43  inline bool isOfType() const
44  {
45  return dynamic_cast<const EVENTTYPE*>(this) != nullptr;
46  }
47 
48  template <class EVENTTYPE>
49  inline const EVENTTYPE* getAs() const
50  {
51  return dynamic_cast<const EVENTTYPE*>(this);
52  }
53 
54  template <class EVENTTYPE>
55  inline EVENTTYPE* getAsNonConst() const
56  {
57  return const_cast<EVENTTYPE*>(dynamic_cast<const EVENTTYPE*>(this));
58  }
59 
61 
62 }; // End of class def.
63 
64 /** An event sent by any CObservable object (automatically) just before being
65  * destroyed and telling its observers to unsubscribe.
66  * \ingroup mrpt_base_grp
67  */
69 {
70  protected:
71  /** Just to allow this class to be polymorphic */
72  void do_nothing() override {}
73  public:
76 
77 }; // End of class def.
78 
79 } // End of namespace
80 } // end of namespace
81 #endif
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
void do_nothing() override
Just to allow this class to be polymorphic.
Definition: mrptEvent.h:72
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:34
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:76
const EVENTTYPE * getAs() const
Definition: mrptEvent.h:49
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrptEvent()
Default ctor.
Definition: mrptEvent.h:41
bool isOfType() const
Definition: mrptEvent.h:43
mrpt::system::TTimeStamp timestamp
Definition: mrptEvent.h:60
virtual void do_nothing()
Just to allow this class to be polymorphic.
Definition: mrptEvent.h:38
mrptEventOnDestroy(const CObservable *obj)
Definition: mrptEvent.h:74
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:68
EVENTTYPE * getAsNonConst() const
Definition: mrptEvent.h:55
const CObservable * source_object
Definition: mrptEvent.h:75
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:35



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019