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-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 #pragma once
10 
11 #include <mrpt/system/datetime.h>
12 
13 namespace mrpt
14 {
15 namespace system
16 {
17 class CObservable;
18 
19 /** The basic event type for the observer-observable pattern in MRPT.
20  * You can sub-class this base class to create custom event types, then
21  * tell between them in runtime with isOfType<T>(), for example:
22  * \code
23  * if (e.isOfType<mrptEventOnDestroy>())
24  * {
25  * const mrptEventOnDestroy* ev = e.getAs<mrptEventOnDestroy>();
26  * ev-> ...
27  * }
28  * \endcode
29  *
30  * \sa CObserver, CObservable
31  * \ingroup mrpt_system_grp
32  */
33 class mrptEvent
34 {
35  protected:
36  /** Just to allow this class to be polymorphic */
37  virtual void do_nothing() {}
38  public:
39  /** Default ctor */
40  inline mrptEvent() : timestamp(mrpt::system::now()) {}
41  template <class EVENTTYPE>
42  inline bool isOfType() const
43  {
44  return dynamic_cast<const EVENTTYPE*>(this) != nullptr;
45  }
46 
47  template <class EVENTTYPE>
48  inline const EVENTTYPE* getAs() const
49  {
50  return dynamic_cast<const EVENTTYPE*>(this);
51  }
52 
53  template <class EVENTTYPE>
54  inline EVENTTYPE* getAsNonConst() const
55  {
56  return const_cast<EVENTTYPE*>(dynamic_cast<const EVENTTYPE*>(this));
57  }
58 
60 
61 }; // End of class def.
62 
63 /** An event sent by any CObservable object (automatically) just before being
64  * destroyed and telling its observers to unsubscribe.
65  * \ingroup mrpt_base_grp
66  */
68 {
69  protected:
70  /** Just to allow this class to be polymorphic */
71  void do_nothing() override {}
72  public:
75 
76 }; // End of class def.
77 
78 } // namespace system
79 } // namespace mrpt
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:33
void do_nothing() override
Just to allow this class to be polymorphic.
Definition: mrptEvent.h:71
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:75
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
EVENTTYPE * getAsNonConst() const
Definition: mrptEvent.h:54
virtual void do_nothing()
Just to allow this class to be polymorphic.
Definition: mrptEvent.h:37
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:67
const EVENTTYPE * getAs() const
Definition: mrptEvent.h:48
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:33
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::system::TTimeStamp timestamp
Definition: mrptEvent.h:59
bool isOfType() const
Definition: mrptEvent.h:42
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:31
const CObservable * source_object
Definition: mrptEvent.h:74
mrptEventOnDestroy(const CObservable *obj)
Definition: mrptEvent.h:73
mrptEvent()
Default ctor.
Definition: mrptEvent.h:40



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019