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>
44 #include <blaze/util/Null.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // CLASS DEFINITION
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
76 class SystemClock : private Singleton<SystemClock>
77 {
78  private:
79  //**Constructors********************************************************************************
82  explicit SystemClock();
84  //**********************************************************************************************
85 
86  public:
87  //**Destructor**********************************************************************************
90  ~SystemClock();
92  //**********************************************************************************************
93 
94  //**Utility functions***************************************************************************
97  inline time_t start () const;
98  inline time_t now () const;
99  inline time_t elapsed() const;
101  //**********************************************************************************************
102 
103  private:
104  //**Member variables****************************************************************************
107  static time_t start_;
108 
109  //**********************************************************************************************
110 
111  //**Friend declarations*************************************************************************
113  friend SystemClockID theSystemClock();
116  //**********************************************************************************************
117 };
118 //*************************************************************************************************
119 
120 
121 
122 
123 //=================================================================================================
124 //
125 // SYSTEM CLOCK SETUP FUNCTIONS
126 //
127 //=================================================================================================
128 
129 //*************************************************************************************************
134 //*************************************************************************************************
135 
136 
137 //*************************************************************************************************
144 {
145  return SystemClock::instance();
146 }
147 //*************************************************************************************************
148 
149 
150 
151 
152 //=================================================================================================
153 //
154 // UTILITY FUNCTIONS
155 //
156 //=================================================================================================
157 
158 //*************************************************************************************************
163 inline time_t SystemClock::start() const
164 {
165  return start_;
166 }
167 //*************************************************************************************************
168 
169 
170 //*************************************************************************************************
175 inline time_t SystemClock::now() const
176 {
177  return time( NULL );
178 }
179 //*************************************************************************************************
180 
181 
182 //*************************************************************************************************
187 inline time_t SystemClock::elapsed() const
188 {
189  return std::time( NULL ) - start_;
190 }
191 //*************************************************************************************************
192 
193 } // namespace blaze
194 
195 #endif
static time_t start_
Timestamp for the start of the process.
Definition: SystemClock.h:107
Implementation of a smart SystemClock handle.
boost::shared_ptr< SystemClock > SystemClockID
Handle for the system clock of the Blaze library.
Definition: SystemClockID.h:54
#define BLAZE_BEFRIEND_SINGLETON
Friendship declaration for the Singleton class template.This macro has to be used in order to declare...
Definition: Singleton.h:447
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:143
SystemClock()
Constructor for the SystemClock class.
Definition: SystemClock.cpp:73
time_t now() const
Returns the current timestamp.
Definition: SystemClock.h:175
Base class for all lifetime managed singletons.The Singleton class represents the base class for all ...
Definition: Singleton.h:606
~SystemClock()
Destructor for the SystemClock class.
Definition: SystemClock.cpp:90
time_t elapsed() const
Returns the elapsed time since the start of the process (in seconds).
Definition: SystemClock.h:187
System clock of the Blaze library.The SystemClock class represents the system clock of the Blaze libr...
Definition: SystemClock.h:76
time_t start() const
Returns the timestamp for the start of the process.
Definition: SystemClock.h:163
Header file for a safe C++ NULL pointer implementation.