All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SystemClock.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_UTIL_SYSTEMCLOCK_H_
23 #define _BLAZE_UTIL_SYSTEMCLOCK_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <ctime>
31 #include <blaze/util/Null.h>
34 
35 
36 namespace blaze {
37 
38 //=================================================================================================
39 //
40 // CLASS DEFINITION
41 //
42 //=================================================================================================
43 
44 //*************************************************************************************************
63 class SystemClock : private Singleton<SystemClock>
64 {
65  private:
66  //**Constructors********************************************************************************
69  explicit SystemClock();
71  //**********************************************************************************************
72 
73  public:
74  //**Destructor**********************************************************************************
77  ~SystemClock();
79  //**********************************************************************************************
80 
81  //**Utility functions***************************************************************************
84  inline time_t start () const;
85  inline time_t now () const;
86  inline time_t elapsed() const;
88  //**********************************************************************************************
89 
90  private:
91  //**Member variables****************************************************************************
94  static time_t start_;
95 
96  //**********************************************************************************************
97 
98  //**Friend declarations*************************************************************************
100  friend SystemClockID theSystemClock();
103  //**********************************************************************************************
104 };
105 //*************************************************************************************************
106 
107 
108 
109 
110 //=================================================================================================
111 //
112 // SYSTEM CLOCK SETUP FUNCTIONS
113 //
114 //=================================================================================================
115 
116 //*************************************************************************************************
121 //*************************************************************************************************
122 
123 
124 //*************************************************************************************************
131 {
132  return SystemClock::instance();
133 }
134 //*************************************************************************************************
135 
136 
137 
138 
139 //=================================================================================================
140 //
141 // UTILITY FUNCTIONS
142 //
143 //=================================================================================================
144 
145 //*************************************************************************************************
150 inline time_t SystemClock::start() const
151 {
152  return start_;
153 }
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
162 inline time_t SystemClock::now() const
163 {
164  return time( NULL );
165 }
166 //*************************************************************************************************
167 
168 
169 //*************************************************************************************************
174 inline time_t SystemClock::elapsed() const
175 {
176  return std::time( NULL ) - start_;
177 }
178 //*************************************************************************************************
179 
180 } // namespace blaze
181 
182 #endif