LibMultiSense
LibMultiSense Documentation
TimeStamp.hh
Go to the documentation of this file.
1 
42 #ifndef CRL_MULTISENSE_TIMESTAMP_HH
43 #define CRL_MULTISENSE_TIMESTAMP_HH
44 
45 #if defined(WIN32)
46 #ifndef WIN32_LEAN_AND_MEAN
47 #define WIN32_LEAN_AND_MEAN 1
48 #endif
49 
50 #include <windows.h>
51 #include <winsock2.h> // Provides a declaration for struct timeval
52 #else
53 #include <sys/time.h>
54 #endif
55 #include <stdint.h>
56 
57 #include "utility/Portability.hh"
58 
59 namespace crl {
60 namespace multisense {
61 namespace details {
62 namespace utility {
63 
64 //
65 // This is a simple class that helps manage time for the rest of the system,
66 // abstracting it away into something that is more usable.
67 //
68 
70 {
71 private:
72 
73  //
74  // The stored time.
75  //
76 
77  struct timeval time;
78 
79 #if defined (WIN32)
80  static ULARGE_INTEGER offsetSecondsSince1970;
81 #endif
82 
83 public:
84 
85  //
86  // Static routines, for the singleton version of the TimeStamp.
87  //
88 
89  static TimeStamp getCurrentTime();
90 
91  //
92  // Public constructor. Initializes from a timestamp.
93  //
94 
95  TimeStamp();
96  TimeStamp(int32_t seconds, int32_t microSeconds);
97  TimeStamp(int64_t nanoseconds);
98  TimeStamp(const struct timeval& value);
99 
100  //
101  // For setting the timestamp.
102  //
103 
104  void set(const struct timeval& value);
105  void set(int32_t seconds, int32_t microSeconds);
106 
107  //
108  // Get the seconds portion of the underlying timeval
109  // For getting precise values from the timestamp.
110  //
111 
112  int32_t getSeconds() const;
113 
114  //
115  // Get the microseconds portion of the underlying timeval
116  // For getting precise values from the timestamp.
117  //
118 
119  int32_t getMicroSeconds() const;
120 
121  //
122  // Get the time in nanoseconds, aggregates seconds and microseconds
123  //
124 
125  int64_t getNanoSeconds() const;
126 
127  //
128  // Operator overloads, for working with time.
129  //
130 
131  TimeStamp operator+(TimeStamp const& other) const;
132  TimeStamp operator-(TimeStamp const& other) const;
133  TimeStamp& operator+=(TimeStamp const& other);
134  TimeStamp& operator-=(TimeStamp const& other);
135 
136 };
137 
138 }}}} // namespaces
139 
140 #endif /* #ifndef CRL_MULTISENSE_TIMESTAMP_HH */
MULTISENSE_API
#define MULTISENSE_API
Definition: MultiSenseTypes.hh:57
Portability.hh
crl
Definition: BufferStream.hh:51
crl::multisense::details::utility::TimeStamp
Definition: TimeStamp.hh:69
multisense
Definition: MultiSenseChannel.hh:44