SystemClock.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_SYSTEMCLOCK_H_
36 #define _BLAZE_UTIL_SYSTEMCLOCK_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <ctime>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
75 class SystemClock : private Singleton<SystemClock>
76 {
77  private:
78  //**Constructors********************************************************************************
81  explicit SystemClock();
83  //**********************************************************************************************
84 
85  public:
86  //**Destructor**********************************************************************************
89  ~SystemClock();
91  //**********************************************************************************************
92 
93  //**Utility functions***************************************************************************
96  inline time_t start () const;
97  inline time_t now () const;
98  inline time_t elapsed() const;
100  //**********************************************************************************************
101 
102  private:
103  //**Member variables****************************************************************************
106  static time_t start_;
107 
108  //**********************************************************************************************
109 
110  //**Friend declarations*************************************************************************
112  friend SystemClockID theSystemClock();
115  //**********************************************************************************************
116 };
117 //*************************************************************************************************
118 
119 
120 
121 
122 //=================================================================================================
123 //
124 // SYSTEM CLOCK SETUP FUNCTIONS
125 //
126 //=================================================================================================
127 
128 //*************************************************************************************************
133 //*************************************************************************************************
134 
135 
136 //*************************************************************************************************
143 {
144  return SystemClock::instance();
145 }
146 //*************************************************************************************************
147 
148 
149 
150 
151 //=================================================================================================
152 //
153 // UTILITY FUNCTIONS
154 //
155 //=================================================================================================
156 
157 //*************************************************************************************************
162 inline time_t SystemClock::start() const
163 {
164  return start_;
165 }
166 //*************************************************************************************************
167 
168 
169 //*************************************************************************************************
174 inline time_t SystemClock::now() const
175 {
176  return time( nullptr );
177 }
178 //*************************************************************************************************
179 
180 
181 //*************************************************************************************************
186 inline time_t SystemClock::elapsed() const
187 {
188  return std::time( nullptr ) - start_;
189 }
190 //*************************************************************************************************
191 
192 } // namespace blaze
193 
194 #endif
std::shared_ptr< SystemClock > SystemClockID
Handle for the system clock of the Blaze library.
Definition: SystemClockID.h:54
static time_t start_
Timestamp for the start of the process.
Definition: SystemClock.h:106
Implementation of a smart SystemClock handle.
#define BLAZE_BEFRIEND_SINGLETON
Friendship declaration for the Singleton class template.This macro has to be used in order to declare...
Definition: Singleton.h:404
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the Singleton class.
SystemClockID theSystemClock()
Returns a handle to the Blaze system clock.
Definition: SystemClock.h:142
SystemClock()
Constructor for the SystemClock class.
Definition: SystemClock.cpp:72
time_t now() const
Returns the current timestamp.
Definition: SystemClock.h:174
Base class for all lifetime managed singletons.The Singleton class represents the base class for all ...
Definition: Singleton.h:563
~SystemClock()
Destructor for the SystemClock class.
Definition: SystemClock.cpp:89
time_t elapsed() const
Returns the elapsed time since the start of the process (in seconds).
Definition: SystemClock.h:186
System clock of the Blaze library.The SystemClock class represents the system clock of the Blaze libr...
Definition: SystemClock.h:75
time_t start() const
Returns the timestamp for the start of the process.
Definition: SystemClock.h:162