Main MRPT website > C++ reference for MRPT 1.5.7
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  */
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
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:
The basic event type for the observer-observable pattern in MRPT.
Definition: mrptEvent.h:34
void do_nothing() MRPT_OVERRIDE
Just to allow this class to be polymorphic.
Definition: mrptEvent.h:61
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:70
const EVENTTYPE * getAs() const
Definition: mrptEvent.h:46
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
mrptEvent()
Default ctor.
Definition: mrptEvent.h:40
bool isOfType() const
Definition: mrptEvent.h:43
mrpt::system::TTimeStamp timestamp
Definition: mrptEvent.h:51
virtual void do_nothing()
Just to allow this class to be polymorphic.
Definition: mrptEvent.h:37
mrptEventOnDestroy(const CObservable *obj)
Definition: mrptEvent.h:63
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition: mrptEvent.h:58
EVENTTYPE * getAsNonConst() const
Definition: mrptEvent.h:49
const CObservable * source_object
Definition: mrptEvent.h:65
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:33



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019