V-ART
time.cpp
Go to the documentation of this file.
1 
5 #include "vart/time.h"
6 
7 #ifdef __linux__ // compiling on a Linux system?
8 #include <sys/time.h>
9 #endif
10 
11 #ifdef WIN32
12 #include <windows.h>
13 #endif
14 
15 using namespace std;
16 
18 {
19 }
20 
21 VART::Time::Time(const Time& t) : seconds(t.seconds)
22 {
23 }
24 
25 VART::Time::Time(double newSeconds) : seconds(newSeconds)
26 {
27 }
28 
29 unsigned int VART::Time::WholeMicroseconds() const
30 {
31  return static_cast<unsigned int>(seconds * 1000000);
32 }
33 
34 unsigned int VART::Time::WholeMilliseconds() const
35 {
36  return static_cast<unsigned int>(seconds * 1000);
37 }
38 
39 unsigned int VART::Time::WholeSeconds() const
40 {
41  return static_cast<unsigned int>(seconds);
42 }
43 
44 VART::Time VART::Time::operator-(const VART::Time& initialTime) const
45 {
46  return VART::Time(seconds - initialTime.seconds);
47 }
48 
50 {
51 #ifdef __linux__
52  static timeval temp;
53  gettimeofday(&temp, NULL);
54  seconds = static_cast<double>(temp.tv_sec) + (static_cast<double>(temp.tv_usec)/1000000.0f);
55 #endif
56 
57 #ifdef WIN32
58  LARGE_INTEGER perfCounter;
59  LARGE_INTEGER perfFrequency;
60 
61  QueryPerformanceFrequency(&perfFrequency);
62 
63  QueryPerformanceCounter(&perfCounter);
64  seconds = (((double)perfCounter.QuadPart) / ((double) perfFrequency.QuadPart));
65 #endif
66 }
67 
69 // static method
70 {
71  static VART::Time time;
72  time.Set();
73  return time;
74 }
75 
76 namespace VART {
77  ostream& operator<<(ostream& output, const Time& t)
78  {
79  output << t.seconds;
80  return output;
81  }
82 }
Time operator-(const Time &initialTime) const
Definition: time.cpp:44
static const Time & NOW()
Returns current time.
Definition: time.cpp:68
Time()
Creates an unitialized object.
Definition: time.cpp:17
Header file for V-ART class "Time".
std::ostream & operator<<(std::ostream &output, const Joint::DofID &dofId)
void Set()
Set to current time.
Definition: time.cpp:49
double seconds
Number of seconds in elapsed time.
Definition: time.h:57
unsigned int WholeMicroseconds() const
Returns the number of whole microseconds in elapsed time.
Definition: time.cpp:29
unsigned int WholeSeconds() const
Returns the number of whole seconds in elapsed time.
Definition: time.cpp:39
unsigned int WholeMilliseconds() const
Returns the number of whole miliseconds in elapsed time.
Definition: time.cpp:34
Elapsed time representation.
Definition: time.h:15