Main MRPT website > C++ reference
MRPT logo
mrptEvent.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef mrptEvent_H
29 #define mrptEvent_H
30 
31 #include <mrpt/utils/utils_defs.h>
32 #include <mrpt/system/datetime.h>
33 
34 namespace mrpt
35 {
36  namespace utils
37  {
38  class CObservable;
39 
40  /** The basic event type for the observer-observable pattern in MRPT.
41  * You can sub-class this base class to create custom event types, then
42  * tell between them in runtime with isOfType<T>(), for example:
43  * \code
44  * if (e.isOfType<mrptEventOnDestroy>())
45  * {
46  * const mrptEventOnDestroy* ev = e.getAs<mrptEventOnDestroy>();
47  * ev-> ...
48  * }
49  * \endcode
50  *
51  * \sa CObserver, CObservable
52  * \ingroup mrpt_base_grp
53  */
55  {
56  protected:
57  virtual void do_nothing() { } //!< Just to allow this class to be polymorphic
58  public:
59  /** Default ctor */
60  inline mrptEvent() : timestamp(mrpt::system::now()) { }
61 
62  template <class EVENTTYPE>
63  inline bool isOfType() const { return dynamic_cast<const EVENTTYPE*>(this)!=NULL; }
64 
65  template <class EVENTTYPE>
66  inline const EVENTTYPE* getAs() const { return dynamic_cast<const EVENTTYPE*>(this); }
67 
68  template <class EVENTTYPE>
69  inline EVENTTYPE* getAsNonConst() const { return const_cast<EVENTTYPE*>(dynamic_cast<const EVENTTYPE*>(this)); }
70 
72 
73  }; // End of class def.
74 
75  /** An event sent by any CObservable object (automatically) just before being destroyed and telling its observers to unsubscribe.
76  * \ingroup mrpt_base_grp
77  */
79  {
80  protected:
81  virtual void do_nothing() { } //!< Just to allow this class to be polymorphic
82  public:
83  inline mrptEventOnDestroy(const CObservable *obj) : source_object(obj) { }
84 
86 
87  }; // End of class def.
88 
89  } // End of namespace
90 } // end of namespace
91 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013