iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Time.H
Go to the documentation of this file.
1 /*! @file
2  @author Laurent Itti
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #ifndef INCLUDE_NRT_CORE_TYPING_TIME_H
36 #define INCLUDE_NRT_CORE_TYPING_TIME_H
37 
38 #include <chrono>
41 
42 /*! \defgroup time Time measurement definitions and classes
43 
44  The NRT Time definitions wrap commonly used std::chrono types and provide a simple Timer class
45 
46  \ingroup typing */
47 
48 namespace nrt
49 {
50  //! The standard clock used by NRT (high-resolution clock from std::chrono)
51  /*! \ingroup time */
52  typedef std::chrono::high_resolution_clock Clock;
53 
54  //! Typedef for the NRT standard time point
55  /*! \ingroup time */
56  typedef nrt::Clock::time_point Time;
57 
58  //! Standard NRT duration
59  /*! \ingroup time */
60  typedef nrt::Clock::duration Duration;
61 
62  //! Duration in seconds
63  /*! \ingroup time */
64  typedef std::chrono::duration<double> DurationSeconds;
65 
66  //! Now represented in nrt::Time
67  /*! \ingroup time */
68  Time now();
69 
70  //! Forever duration
71  /*! Note that this is not exactly forever, but lots and lots of hours...
72  \ingroup time */
73  Duration forev();
74 
75  //! Zero duration
76  /*! \ingroup time */
78 
79  //! A simple timer class
80  /*! \ingroup time */
81  class Timer
82  {
83  public:
84  //! Construct and start timing
85  Timer();
86 
87  //! Get the absolute time of construction or last reset
88  Time const & epoch() const;
89 
90  //! Reset our internal time stamp to now (zero timed duration) and start timing, return time of reset
91  Time const & reset();
92 
93  //! Return duration since last reset, in seconds
94  DurationSeconds get() const;
95 
96  //! Return duration since last reset, in seconds, and reset the timer
98 
99  private:
100  nrt::Time itsTime;
101  };
102 
103  //! The NRT central timer (relative time since start() of the NRT Manager)
104  /*! This timer is reset once at construction (which typically would be the first time it is used, since it is a
105  singleton) and at each start() of the Manager. Hence, durations returned by get() are since start(), if your
106  program has a manager, otherwise, since construction. Only the Manager can reset the CentralTimer, all others can
107  only get the duration elapsed since last reset. To access the CentralTimer, use:
108 
109  @code
110  nrt::DurationSeconds seconds_since_start = nrt::CentralTimer::instance().get();
111  @endcode
112 
113  \ingroup time */
114  class CentralTimer : public Singleton<CentralTimer>
115  {
116  public:
117  // Return epoch, i.e., absolute time of construction or of last start()
118  nrt::Time const & epoch() const;
119 
120  //! Return duration since start(), in seconds
121  DurationSeconds get() const;
122 
123  private:
124  friend class Singleton<CentralTimer>;
125  friend class Manager;
126  CentralTimer();
127  Timer itsTimer;
128  };
129 }
130 
131 //! Include details of no interest to the user
133 
134 
135 #endif // INCLUDE_NRT_CORE_TYPING_TIME_H