Debian Codegraph @

3rdparty/xspublic/xstypes/xstime.h

raw
1
2 // Copyright (c) 2003-2019 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 #ifndef XSTIME_H
34 #define XSTIME_H
35
36 #include "xstypesconfig.h"
37 #ifdef _WIN32
38 #include <windows.h>
39 #endif
40
41 #include <time.h>
42 #include "pstdint.h"
43 #include "xstimestamp.h"
44
45 #ifdef __cplusplus
46 #include "xsstring.h"
47 extern "C" {
48 #endif
49
50 XSTYPES_DLL_API extern const XsTimeStamp XsTime_secPerDay;
51 XSTYPES_DLL_API extern const XsTimeStamp XsTime_milliSecPerDay;
52 XSTYPES_DLL_API extern const XsTimeStamp XsTime_timeStampMax;
53
54 XSTYPES_DLL_API uint32_t XsTime_getTimeOfDay(struct tm* date_, time_t* secs_);
55 XSTYPES_DLL_API int64_t XsTime_getDateTime(struct tm * date);
56 XSTYPES_DLL_API void XsTime_getDateAsString(char* dest, struct tm const* date);
57 XSTYPES_DLL_API void XsTime_getTimeAsString(char* dest, struct tm const* time);
58 XSTYPES_DLL_API void XsTime_getDateAsWString(wchar_t* dest, struct tm const* date);
59 XSTYPES_DLL_API void XsTime_getTimeAsWString(wchar_t* dest, struct tm const* time);
60 XSTYPES_DLL_API void XsTime_msleep(uint32_t ms);
61 XSTYPES_DLL_API void XsTime_udelay(uint64_t us);
62 XSTYPES_DLL_API int64_t XsTime_timeStampNow(XsTimeStamp* now);
63 XSTYPES_DLL_API void XsTime_initializeTime(void);
64 XSTYPES_DLL_API int64_t XsTime_utcToLocal();
65 XSTYPES_DLL_API int64_t XsTime_localToUtc();
66
67 #ifdef __cplusplus
68 } // extern "C"
69
70 namespace XsTime {
71 #ifdef __GNUC__
72 #pragma GCC diagnostic push
73 #pragma GCC diagnostic ignored "-Wunused-variable"
74 #endif
75 /*! \brief The number of seconds in a day */
76 static const XsTimeStamp& secPerDay = XsTime_secPerDay;
77 /*! \brief The number of milliseconds in a day */
78 static const XsTimeStamp& milliSecPerDay = XsTime_milliSecPerDay;
79 /*! \brief The maximum possible timestamp */
80 static const XsTimeStamp& timeStampMax = XsTime_timeStampMax;
81 #ifdef __GNUC__
82 #pragma GCC diagnostic pop
83 #endif
84
85 //! \copydoc XsTime_getTimeOfDay
86 inline uint32_t getTimeOfDay(tm* date_ = NULL, time_t* secs_ = NULL)
87 {
88 return XsTime_getTimeOfDay(date_ , secs_);
89 }
90
91 //! \copydoc XsTime_getDateTime
92 inline int64_t getDateTime(tm * date = 0)
93 {
94 return XsTime_getDateTime(date);
95 }
96
97 //! \copydoc XsTime_getDateAsString
98 inline void getDateAsString(char* dest, tm const* date = 0)
99 {
100 XsTime_getDateAsString(dest, date);
101 }
102
103 //! \copydoc XsTime_getTimeAsString
104 inline void getTimeAsString(char* dest, tm const* date = 0)
105 {
106 XsTime_getTimeAsString(dest, date);
107 }
108
109 /*! \brief Returns the date as a readable string
110 \param date to convert to string
111 \returns The date as a readable string
112 \sa XsTime_getDateAsWString
113 */
114 inline XsString getDateAsString(tm const* date = 0)
115 {
116 wchar_t wcharBuf[9];
117 XsTime_getDateAsWString(wcharBuf, date);
118 wcharBuf[8] = 0;
119 return XsString(wcharBuf);
120 }
121
122 /*! \brief Returns the time as a readable string
123 \param time to convert to string
124 \returns The time as a readable string
125 \sa XsTime_getTimeAsWString
126 */
127 inline XsString getTimeAsString(tm const* time = 0)
128 {
129 wchar_t wcharBuf[9];
130 XsTime_getTimeAsWString(wcharBuf, time);
131 wcharBuf[8] = 0;
132 return XsString(wcharBuf);
133 }
134
135 //! \copydoc XsTime_msleep
136 inline void msleep(uint32_t ms) noexcept
137 {
138 XsTime_msleep(ms);
139 }
140
141 //! \copydoc XsTime_udelay
142 inline void udelay(uint64_t us) noexcept
143 {
144 XsTime_udelay(us);
145 }
146
147 //! \copydoc XsTime_initializeTime
148 inline void initializeTime()
149 {
150 XsTime_initializeTime();
151 }
152
153 //! \copydoc XsTime_timeStampNow
154 inline int64_t timeStampNow(XsTimeStamp* now = 0)
155 {
156 return XsTime_timeStampNow(now);
157 }
158 }
159 #endif
160
161 #endif