xstimestamp.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef XSTIMESTAMP_H
66 #define XSTIMESTAMP_H
67 
68 #include "xstypesconfig.h"
69 #include "pstdint.h"
70 
71 #ifdef __cplusplus
72 #ifndef XSENS_NO_STL
73  #include "xsstring.h"
74 #endif
75 #include "xstimeinfo.h"
76 extern "C" {
77 #endif
78 #ifndef __cplusplus
79 #define XSTIMESTAMP_INITIALIZER { 0 }
80 #endif
81 
82 struct XsTimeStamp;
83 struct XsTimeInfo;
84 struct XsString;
85 
86 XSTYPES_DLL_API void XsTimeStamp_setMilliSecondTime(struct XsTimeStamp* thisPtr, int64_t t);
87 XSTYPES_DLL_API double XsTimeStamp_timeOfDay(const struct XsTimeStamp* thisPtr);
88 XSTYPES_DLL_API int64_t XsTimeStamp_secondTime(const struct XsTimeStamp* thisPtr);
93 XSTYPES_DLL_API int64_t XsTimeStamp_now(struct XsTimeStamp* thisPtr);
95 
96 XSTYPES_DLL_API int64_t XsTimeStamp_fromTimeInfo(struct XsTimeStamp* thisPtr, const struct XsTimeInfo* info);
97 XSTYPES_DLL_API void XsTimeStamp_toTimeInfo(struct XsTimeStamp const* thisPtr, struct XsTimeInfo* info);
98 #ifndef XSENS_NO_STL
99 XSTYPES_DLL_API void XsTimeStamp_toString(struct XsTimeStamp const* thisPtr, struct XsString* result);
100 #endif
101 XSTYPES_DLL_API void XsTimeStamp_utcToLocalTime(struct XsTimeStamp const* thisPtr, struct XsTimeStamp* local);
102 XSTYPES_DLL_API void XsTimeStamp_localToUtcTime(struct XsTimeStamp const* thisPtr, struct XsTimeStamp* utc);
103 XSTYPES_DLL_API void XsTimeStamp_utcToLocalTime2(struct XsTimeStamp const* thisPtr, struct XsTimeStamp* local, const struct XsTimeInfo* info);
104 XSTYPES_DLL_API void XsTimeStamp_localToUtcTime2(struct XsTimeStamp const* thisPtr, struct XsTimeStamp* utc, const struct XsTimeInfo* info);
105 XSTYPES_DLL_API void XsTimeStamp_utcToLocalTime_ms(struct XsTimeStamp const* thisPtr, struct XsTimeStamp* local, int64_t utcOffset);
106 XSTYPES_DLL_API void XsTimeStamp_localToUtcTime_ms(struct XsTimeStamp const* thisPtr, struct XsTimeStamp* utc, int64_t utcOffset);
107 
108 #ifdef __cplusplus
109 } // extern "C"
110 #endif
111 
116 {
117 #ifdef __cplusplus
118 
119  inline XsTimeStamp(int64_t t = 0) : m_msTime(t) {}
120 
122  inline XsTimeStamp(int t) : m_msTime(t) {}
123 
125  inline explicit XsTimeStamp(double t) : m_msTime((int64_t)(t * 1000.0)) {}
126 
128  inline XsTimeStamp(const XsTimeStamp& other) : m_msTime(other.m_msTime) {}
129 
131  inline XsTimeStamp(const XsTimeInfo& info)
132  {
133  XsTimeStamp_fromTimeInfo(this, &info);
134  }
135 
137  inline XsTimeInfo toTimeInfo() const
138  {
139  XsTimeInfo info;
140  XsTimeStamp_toTimeInfo(this, &info);
141  return info;
142  }
143 
145  inline void toTimeInfo(XsTimeInfo& info) const
146  {
147  XsTimeStamp_toTimeInfo(this, &info);
148  }
149 
150 #ifndef XSENS_NO_STL
151 
152  inline XsString toString() const
153  {
154  XsString result;
155  XsTimeStamp_toString(this, &result);
156  return result;
157  }
158 #endif
159 
161  inline XsTimeStamp& operator = (const XsTimeStamp& other)
162  {
163  m_msTime = other.m_msTime;
164  return *this;
165  }
166 
168  inline int64_t msTime(void) const
169  {
170  return m_msTime;
171  }
172 
174  inline void setMsTime(int64_t t)
175  {
176  m_msTime = t;
177  }
178 
181  inline double timeOfDay() const
182  {
183  return XsTimeStamp_timeOfDay(this);
184  }
185 
188  inline int64_t msTimeOfDay() const
189  {
190  return m_msTime % (24 * 60 * 60 * 1000);
191  }
192 
194  inline double secTime() const
195  {
196  return ((double)m_msTime) * 0.001;
197  }
198 
200  inline void setSecTime(double t)
201  {
202  m_msTime = (int64_t)(t * 1000.0);
203  }
204 
206  inline XsTimeStamp operator + (const XsTimeStamp& other) const
207  {
208  return XsTimeStamp(m_msTime + other.m_msTime);
209  }
210 
212  inline XsTimeStamp operator - (const XsTimeStamp& other) const
213  {
214  return XsTimeStamp(m_msTime - other.m_msTime);
215  }
216 
218  inline XsTimeStamp& operator += (const XsTimeStamp& other)
219  {
220  m_msTime += other.m_msTime;
221  return *this;
222  }
223 
225  inline XsTimeStamp& operator -= (const XsTimeStamp& d)
226  {
227  m_msTime -= d.m_msTime;
228  return *this;
229  }
230 
232  inline bool operator < (const XsTimeStamp& other) const
233  {
234  return m_msTime < other.m_msTime;
235  }
236 
238  inline bool operator <= (const XsTimeStamp& other) const
239  {
240  return m_msTime <= other.m_msTime;
241  }
242 
244  inline bool operator == (const XsTimeStamp& other) const
245  {
246  return m_msTime == other.m_msTime;
247  }
248 
250  inline bool operator > (const XsTimeStamp& other) const
251  {
252  return m_msTime > other.m_msTime;
253  }
254 
256  inline bool operator >= (const XsTimeStamp& other) const
257  {
258  return m_msTime >= other.m_msTime;
259  }
260 
262  inline bool operator != (const XsTimeStamp& other) const
263  {
264  return m_msTime != other.m_msTime;
265  }
266 
268  inline bool operator < (int other) const
269  {
270  return m_msTime < other;
271  }
272 
274  inline bool operator <= (int other) const
275  {
276  return m_msTime <= other;
277  }
278 
280  inline bool operator == (int other) const
281  {
282  return m_msTime == other;
283  }
284 
286  inline bool operator > (int other) const
287  {
288  return m_msTime > other;
289  }
290 
292  inline bool operator >= (int other) const
293  {
294  return m_msTime >= other;
295  }
296 
298  inline bool operator != (int other) const
299  {
300  return m_msTime != other;
301  }
302 
304  inline int64_t secondTime() const
305  {
306  return m_msTime / 1000;
307  }
308 
310  inline int32_t milliSecondPart() const
311  {
312  return (int32_t)(m_msTime % 1000);
313  }
314 
316  inline int32_t secondPart() const
317  {
318  return (int32_t)((m_msTime / (1000)) % 60);
319  }
320 
322  inline int32_t minutePart() const
323  {
324  return (int32_t)((m_msTime / (60 * 1000)) % 60);
325  }
326 
328  inline int32_t hourPart() const
329  {
330  return (int32_t)((m_msTime / (60 * 60 * 1000)) % 24);
331  }
332 
334  inline static XsTimeStamp now()
335  {
336  XsTimeStamp tmp;
337  XsTimeStamp_now(&tmp);
338  return tmp;
339  }
340 
342  inline static int64_t nowMs()
343  {
344  XsTimeStamp tmp;
345  XsTimeStamp_now(&tmp);
346  return tmp.msTime();
347  }
348 
350  inline int64_t elapsedToNow() const
351  {
352  return XsTimeStamp_now(0) - m_msTime;
353  }
354 
356  inline static XsTimeStamp maxValue()
357  {
358  return XsTimeStamp(int64_t(9223372036854775807LL)); //INT64_MAX
359  }
360 
362  XsTimeStamp& operator++()
363  {
364  ++m_msTime;
365  return *this;
366  }
367 
369  XsTimeStamp operator++(int)
370  {
371  return XsTimeStamp(m_msTime++);
372  }
373 
375  XsTimeStamp& operator--()
376  {
377  --m_msTime;
378  return *this;
379  }
380 
382  XsTimeStamp operator--(int)
383  {
384  return XsTimeStamp(m_msTime--);
385  }
386 
391  XsTimeStamp utcToLocalTime() const
392  {
393  XsTimeStamp local;
394  XsTimeStamp_utcToLocalTime(this, &local);
395  return local;
396  }
397 
402  XsTimeStamp localToUtcTime() const
403  {
404  XsTimeStamp utc;
405  XsTimeStamp_localToUtcTime(this, &utc);
406  return utc;
407  }
408 
413  XsTimeStamp utcToLocalTime(XsTimeInfo const& info) const
414  {
415  XsTimeStamp local;
416  XsTimeStamp_utcToLocalTime2(this, &local, &info);
417  return local;
418  }
419 
424  XsTimeStamp localToUtcTime(XsTimeInfo const& info) const
425  {
426  XsTimeStamp utc;
427  XsTimeStamp_localToUtcTime2(this, &utc, &info);
428  return utc;
429  }
430 
435  XsTimeStamp utcToLocalTime(int64_t utcOffset) const
436  {
437  XsTimeStamp local;
438  XsTimeStamp_utcToLocalTime_ms(this, &local, utcOffset);
439  return local;
440  }
441 
446  XsTimeStamp localToUtcTime(int64_t utcOffset) const
447  {
448  XsTimeStamp utc;
449  XsTimeStamp_localToUtcTime_ms(this, &utc, utcOffset);
450  return utc;
451  }
452 private:
453 #endif
454 
455  int64_t m_msTime;
456 };
457 
458 typedef struct XsTimeStamp XsTimeStamp;
459 
460 #endif
XsTimeStamp_utcToLocalTime_ms
XSTYPES_DLL_API void XsTimeStamp_utcToLocalTime_ms(struct XsTimeStamp const *thisPtr, struct XsTimeStamp *local, int64_t utcOffset)
Convert the supplied time from (assumed) UTC to local time, using the offset in utcOffset.
Definition: xstimestamp.c:309
XsTimeStamp::XsTimeStamp_now
int64_t XsTimeStamp_now(XsTimeStamp *dest)
Returns the current time in ms since the epoch (Jan 1st 1970)
Definition: xstimestamp.c:136
xsstring.h
XsTimeStamp_localToUtcTime2
XSTYPES_DLL_API void XsTimeStamp_localToUtcTime2(struct XsTimeStamp const *thisPtr, struct XsTimeStamp *utc, const struct XsTimeInfo *info)
Convert the supplied time from (assumed) local time to UTC, using the offset in info.
Definition: xstimestamp.c:300
XsTimeStamp::XsTimeStamp_timeOfDay
double XsTimeStamp_timeOfDay(const XsTimeStamp *thisPtr)
Get the time of day component of the stored timestamp in seconds as a double precision value.
Definition: xstimestamp.c:90
XsTimeStamp_localToUtcTime_ms
XSTYPES_DLL_API void XsTimeStamp_localToUtcTime_ms(struct XsTimeStamp const *thisPtr, struct XsTimeStamp *utc, int64_t utcOffset)
Convert the supplied time from (assumed) local time to UTC, using the offset in utcOffset.
Definition: xstimestamp.c:318
XsTimeStamp::XsTimeStamp_hourPart
int32_t XsTimeStamp_hourPart(const XsTimeStamp *thisPtr)
Returns the hours part of the time (in the range 0-23)
Definition: xstimestamp.c:125
XsTimeStamp::XsTimeStamp_minutePart
int32_t XsTimeStamp_minutePart(const XsTimeStamp *thisPtr)
Returns the minutes part of the time (in the range 0-59)
Definition: xstimestamp.c:118
XsTimeStamp::XsTimeStamp_maxValue
int64_t XsTimeStamp_maxValue(void)
Returns the maximum value of an XsTimeStamp.
Definition: xstimestamp.c:144
XsTimeStamp::XsTimeStamp_secondPart
int32_t XsTimeStamp_secondPart(const XsTimeStamp *thisPtr)
Returns the seconds part of the time (in the range 0-59)
Definition: xstimestamp.c:111
operator==
bool operator==(const XsFilterProfile &lhs, const XsFilterProfile &rhs)
Returns true if lhs has the same type as rhs.
Definition: scenariomatchpred.h:81
XsTimeStamp_utcToLocalTime
XSTYPES_DLL_API void XsTimeStamp_utcToLocalTime(struct XsTimeStamp const *thisPtr, struct XsTimeStamp *local)
Convert the supplied time from (assumed) UTC to local time, using the system's local time zone knowle...
Definition: xstimestamp.c:273
XsTimeStamp::XsTimeStamp_milliSecondPart
int32_t XsTimeStamp_milliSecondPart(const XsTimeStamp *thisPtr)
Returns the millisecond part of the time (in the range 0-999)
Definition: xstimestamp.c:104
XsTimeStamp::XsTimeStamp_toString
void XsTimeStamp_toString(struct XsTimeStamp const *thisPtr, struct XsString *result)
Converts the timestamp into an XsString object in format YYYY/MM/DD hh:mm:ss.nnn.
Definition: xstimestamp.c:241
d
d
XsTimeStamp_utcToLocalTime2
XSTYPES_DLL_API void XsTimeStamp_utcToLocalTime2(struct XsTimeStamp const *thisPtr, struct XsTimeStamp *local, const struct XsTimeInfo *info)
Convert the supplied time from (assumed) UTC to local time, using the offset in info.
Definition: xstimestamp.c:291
xstimeinfo.h
XsTimeStamp::XsTimeStamp_setMilliSecondTime
void XsTimeStamp_setMilliSecondTime(XsTimeStamp *thisPtr, int64_t t)
Set the stored time to miliseconds.
Definition: xstimestamp.c:84
XsTimeStamp::XsTimeStamp_secondTime
int64_t XsTimeStamp_secondTime(const XsTimeStamp *thisPtr)
Returns the number of seconds elapsed since the epoch as stored in the XsTimeStamp.
Definition: xstimestamp.c:97
xstypesconfig.h
pstdint.h
XsTimeStamp::XsTimeStamp_fromTimeInfo
int64_t XsTimeStamp_fromTimeInfo(struct XsTimeStamp *thisPtr, const struct XsTimeInfo *info)
Creates a (UTC) XsTimeStamp from an XsTimeInfo object.
Definition: xstimestamp.c:154
XsTimeStamp_localToUtcTime
XSTYPES_DLL_API void XsTimeStamp_localToUtcTime(struct XsTimeStamp const *thisPtr, struct XsTimeStamp *utc)
Convert the supplied time from (assumed) local time to UTC, using the system's local time zone knowle...
Definition: xstimestamp.c:282
XsTimeStamp::m_msTime
int64_t m_msTime
The timestamp value.
Definition: xstimestamp.h:455
XSTYPES_DLL_API
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:65
XsTimeStamp::XsTimeStamp_toTimeInfo
void XsTimeStamp_toTimeInfo(struct XsTimeStamp const *thisPtr, struct XsTimeInfo *info)
Converts the timestamp into an XsTimeInfo object.
Definition: xstimestamp.c:191
int32_t
signed int int32_t
Definition: pstdint.h:515
XsString
A 0-terminated managed string of characters.
XsTimeStamp
struct XsTimeStamp XsTimeStamp
Definition: xstimestamp.h:458
XsTimeStamp
This class contains method to set, retrieve and compare timestamps.
Definition: xstimestamp.h:115
XsTimeInfo
A structure for storing Time values.
Definition: xstimeinfo.h:87


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20