Timestamp.cpp
Go to the documentation of this file.
1 
28  /*
29  * Timestamp.cpp
30  *
31  * Created on: 14.01.2011
32  * Author: Thomas Wiemann
33  */
34 
35 #include "lvr2/io/Timestamp.hpp"
36 
37 #if defined(_MSC_VER)
38 #include <time.h>
39 #include <Windows.h>
40 
41 const __int64 DELTA_EPOCH_IN_MICROSECS = 11644473600000000;
42 
43 /* IN UNIX the use of the timezone struct is obsolete;
44 I don't know why you use it. See http://linux.about.com/od/commands/l/blcmdl2_gettime.htm
45 But if you want to use this structure to know about GMT(UTC) diffrence from your local time
46 it will be next: tz_minuteswest is the real diffrence in minutes from GMT(UTC) and a tz_dsttime is a flag
47 indicates whether daylight is now in use
48 */
49 struct timezone
50 {
51  __int32 tz_minuteswest; /* minutes W of Greenwich */
52  bool tz_dsttime; /* type of dst correction */
53 };
54 
55 
56 int gettimeofday(struct timeval *tv/*in*/, struct timezone *tz/*in*/)
57 {
58  FILETIME ft;
59  __int64 tmpres = 0;
60  TIME_ZONE_INFORMATION tz_winapi;
61  int rez = 0;
62 
63  ZeroMemory(&ft, sizeof(ft));
64  ZeroMemory(&tz_winapi, sizeof(tz_winapi));
65 
66  GetSystemTimeAsFileTime(&ft);
67 
68  tmpres = ft.dwHighDateTime;
69  tmpres <<= 32;
70  tmpres |= ft.dwLowDateTime;
71 
72  /*converting file time to unix epoch*/
73  tmpres /= 10; /*convert into microseconds*/
74  tmpres -= DELTA_EPOCH_IN_MICROSECS;
75  tv->tv_sec = (__int32)(tmpres*0.000001);
76  tv->tv_usec = (tmpres % 1000000);
77 
78 
79  //_tzset(),don't work properly, so we use GetTimeZoneInformation
80  /*
81  rez = GetTimeZoneInformation(&tz_winapi);
82  tz->tz_dsttime = (rez == 2) ? true : false;
83  tz->tz_minuteswest = tz_winapi.Bias + ((rez == 2) ? tz_winapi.DaylightBias : 0); */
84 
85  return 0;
86 }
87 #else
88 #include <sys/time.h>
89 #include <unistd.h>
90 #endif
91 
92 
93 
94 #include <cstddef>
95 #include <cstdlib>
96 #include <cstdio>
97 
98 #include <iostream>
99 using namespace std;
100 
101 namespace lvr2 {
102 
103 Timestamp::Timestamp(): m_nullStream(&m_nullBuffer)
104 {
105  resetTimer();
106 }
107 
108 
109 unsigned long Timestamp::getCurrentTimeInMs() const
110 {
111  static struct timeval tv;
112  gettimeofday( &tv, NULL );
113  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
114 }
115 
116 unsigned long Timestamp::getElapsedTimeInMs() const
117 {
118  return getCurrentTimeInMs() - m_startTime;
119 }
120 
122 {
123  return (double) getCurrentTimeInMs() / 1000.0;
124 }
125 
127 {
128  return (double) getElapsedTimeInMs() / 1000.0;
129 }
130 
132 {
134 }
135 
137 {
138  unsigned long time = getElapsedTimeInMs();
139  unsigned long hours = time / 3600000;
140  unsigned long mins = ( time % 3600000 ) / 60000;
141  unsigned long secs = ( time % 60000 ) / 1000;
142  unsigned long msecs = time % 1000;
143 
144  char times[512];
145 
146  sprintf( times, "[%02lu:%02lu:%02lu %03lu] ", hours, mins, secs, msecs);
147  string result( times );
148 
149  return result;
150 }
151 
152 } // namespace lvr
153 
154 
155 
lvr2::Timestamp::getElapsedTimeInS
double getElapsedTimeInS() const
Returns the time since instantiation in seconds.
Definition: Timestamp.cpp:126
scripts.normalize.mins
mins
Definition: normalize.py:36
lvr2::Timestamp::getCurrentTimeinS
double getCurrentTimeinS() const
Returns the current system time in seconds.
Definition: Timestamp.cpp:121
lvr2::Timestamp::getElapsedTime
string getElapsedTime() const
Returns a string representation of the current timer value.
Definition: Timestamp.cpp:136
NULL
#define NULL
Definition: mydefs.hpp:141
lvr2::Timestamp::getElapsedTimeInMs
unsigned long getElapsedTimeInMs() const
Returns the milliseconds since object creation.
Definition: Timestamp.cpp:116
lvr2::Timestamp::resetTimer
void resetTimer()
Resets the internal timer.
Definition: Timestamp.cpp:131
std
Definition: HalfEdge.hpp:124
lvr2
Definition: BaseBufferManipulators.hpp:39
Timestamp.hpp
lvr2::Timestamp::m_startTime
unsigned long m_startTime
The system at object instantiation.
Definition: Timestamp.hpp:109
lvr2::Timestamp::getCurrentTimeInMs
unsigned long getCurrentTimeInMs() const
Returns the current system time in milliseconds.
Definition: Timestamp.cpp:109


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:25