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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020