simpletime.h
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 #ifndef SIMPLETIME_H_
31 #define SIMPLETIME_H_
32 
33 #include "sdhlibrary_settings.h"
34 
35 //----------------------------------------------------------------------
36 // System Includes - include with <>
37 //----------------------------------------------------------------------
38 
39 #if SDH_USE_VCC
40 #include <sys/timeb.h>
41 #include <time.h>
42 #else
43 # include <sys/time.h>
44 #endif
45 
46 //----------------------------------------------------------------------
47 // Project Includes - include with ""
48 //----------------------------------------------------------------------
49 
50 #include "sdhexception.h"
51 
52 //----------------------------------------------------------------------
53 // Defines, enums, unions, structs,
54 //----------------------------------------------------------------------
55 
57 
58 
59 //----------------------------------------------------------------------
60 // Global variables
61 //----------------------------------------------------------------------
62 
63 
64 //----------------------------------------------------------------------
65 // Function declarations
66 //----------------------------------------------------------------------
67 
68 
69 //----------------------------------------------------------------------
70 // Class declarations
71 //----------------------------------------------------------------------
72 
73 #if SDH_USE_VCC
74 typedef long tTimevalSec;
75 typedef long tTimevalUSec;
76 #else
77 typedef time_t tTimevalSec;
78 typedef suseconds_t tTimevalUSec;
79 #endif
80 
84 class VCC_EXPORT cSimpleTime
85 {
86 protected:
87 #if SDH_USE_VCC
88  struct _timeb timebuffer;
89 #else
90  struct timeval a_time;
91 #endif
92 
93 public:
96  {
97  StoreNow();
98  }
99  //----------------------------------------------------------------------
100 
101 
103  void StoreNow( void )
104  {
105 #if SDH_USE_VCC
106  _ftime64_s( &timebuffer );
107 
108 #else
109  gettimeofday( &a_time, NULL );
110 #endif
111  }
112  //----------------------------------------------------------------------
113 
115  double Elapsed( void ) const
116  {
117  cSimpleTime now;
118 
119  return Elapsed( now );
120  }
121  //----------------------------------------------------------------------
122 
123 
125  long Elapsed_us( void ) const
126  {
127  cSimpleTime now;
128 
129  return Elapsed_us( now );
130  }
131  //----------------------------------------------------------------------
132 
133 
134 #if SDH_USE_VCC
135  double Elapsed( cSimpleTime const& other ) const
137  {
138  double seconds = double( other.timebuffer.time - timebuffer.time);
139  double msec = double( other.timebuffer.millitm - timebuffer.millitm );
140 
141  return seconds + msec / 1000.0;
142  }
143  //----------------------------------------------------------------------
144 
146  long Elapsed_us( cSimpleTime const& other ) const
147  {
148  long seconds = long( other.timebuffer.time - timebuffer.time);
149  long msec = long( other.timebuffer.millitm - timebuffer.millitm );
150 
151  return seconds * 1000000 + msec * 1000;
152  }
153  //----------------------------------------------------------------------
154 #else
155  double Elapsed( cSimpleTime const& other ) const
157  {
158  double seconds = double( other.a_time.tv_sec - a_time.tv_sec );
159  double usec = double( other.a_time.tv_usec - a_time.tv_usec );
160 
161  return seconds + usec / 1000000.0;
162  }
163  //----------------------------------------------------------------------
164 
166  long Elapsed_us( cSimpleTime const& other ) const
167  {
168  long seconds = other.a_time.tv_sec - a_time.tv_sec;
169  long usec = other.a_time.tv_usec - a_time.tv_usec;
170 
171  return seconds * 1000000 + usec;
172  }
173  //----------------------------------------------------------------------
174 
175 
177  timeval Timeval( void )
178  {
179  return a_time;
180  }
181 #endif
182 };
183 
184 
186 
187 #endif
188 
189 
190 //======================================================================
191 /*
192  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
193  (e.g. to explicitely set C++ mode for *.h header files)
194 
195  Local Variables:
196  mode:C++
197  mode:ELSE
198  End:
199 */
200 //======================================================================
cSimpleTime::StoreNow
void StoreNow(void)
Store current time internally.
Definition: simpletime.h:103
cSimpleTime
Very simple class to measure elapsed time.
Definition: simpletime.h:84
NAMESPACE_SDH_END
#define NAMESPACE_SDH_END
Definition: sdhlibrary_settings.h:80
tTimevalSec
NAMESPACE_SDH_START typedef time_t tTimevalSec
Definition: simpletime.h:77
cSimpleTime::Elapsed
double Elapsed(void) const
Return time in seconds elapsed between the time stored in the object and now.
Definition: simpletime.h:115
cSimpleTime::Elapsed_us
long Elapsed_us(cSimpleTime const &other) const
Return time in micro seconds elapsed between the time stored in the object and other.
Definition: simpletime.h:166
NULL
#define NULL
Definition: getopt1.c:56
cSimpleTime::a_time
struct timeval a_time
Definition: simpletime.h:90
cSimpleTime::cSimpleTime
cSimpleTime()
Constructor: store current time ("now") internally.
Definition: simpletime.h:95
NAMESPACE_SDH_START
#define NAMESPACE_SDH_START
Definition: sdhlibrary_settings.h:79
cSimpleTime::Timeval
timeval Timeval(void)
Return the time stored as C struct timeval.
Definition: simpletime.h:177
sdhexception.h
Interface of the exception base class #SDH::cSDHLibraryException and #SDH::cMsg.
cSimpleTime::Elapsed_us
long Elapsed_us(void) const
Return time in micro seconds elapsed between the time stored in the object and now.
Definition: simpletime.h:125
tTimevalUSec
suseconds_t tTimevalUSec
Definition: simpletime.h:78
sdhlibrary_settings.h
This file contains settings to make the SDHLibrary compile on differen systems:


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:58