MRPT  1.9.9
xstimestamp.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef XSTIMESTAMP_H
10 #define XSTIMESTAMP_H
11 
12 #include "pstdint.h"
13 #include "xstypesconfig.h"
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #else
19 #define XSTIMESTAMP_INITIALIZER \
20  { \
21  0 \
22  }
23 #endif
24 
25  struct XsTimeStamp;
26  struct XsUtcTime;
27 
29  struct XsTimeStamp* thisPtr, int64_t t);
31  const struct XsTimeStamp* thisPtr);
33  XsTimeStamp_secondTime(const struct XsTimeStamp* thisPtr);
35  XsTimeStamp_milliSecondPart(const struct XsTimeStamp* thisPtr);
37  XsTimeStamp_secondPart(const struct XsTimeStamp* thisPtr);
39  XsTimeStamp_minutePart(const struct XsTimeStamp* thisPtr);
41  XsTimeStamp_hourPart(const struct XsTimeStamp* thisPtr);
45  struct XsTimeStamp* thisPtr, const struct XsUtcTime* utc);
47  struct XsTimeStamp* thisPtr, struct XsUtcTime* utc);
48 
49 #ifdef __cplusplus
50 } // extern "C"
51 #endif
52 
53 /*! \struct XsTimeStamp
54  \brief Class for managing timestamps in a unified way.
55 */
57 {
58 #ifdef __cplusplus
59  /*! \brief Construct a timestamp with \a t as the time in milliseconds. */
60  inline XsTimeStamp(int64_t t = 0) : m_msTime(t) {}
61  /*! \brief Construct a timestamp with \a t as the time in milliseconds. */
62  inline XsTimeStamp(int t) : m_msTime(t) {}
63  /*! \brief Construct a copy of \a other. */
64  inline XsTimeStamp(const XsTimeStamp& other) : m_msTime(other.m_msTime) {}
65  /*! \brief Construct from \a utc */
66  inline XsTimeStamp(const XsUtcTime& utc)
67  {
68  XsTimeStamp_fromUtcTime(this, &utc);
69  }
70 
71  /*! \brief Convert this timestamp to UTC time \a utc */
72  inline void toUtcTime(XsUtcTime& utc) { XsTimeStamp_toUtcTime(this, &utc); }
73  /*! \brief Assign the contents of the \a other timestamp to this timestamp.
74  */
75  inline XsTimeStamp& operator=(const XsTimeStamp& other)
76  {
77  m_msTime = other.m_msTime;
78  return *this;
79  }
80 
81  /*! \brief Get the stored time as milliseconds. */
82  inline int64_t msTime(void) const { return m_msTime; }
83  /*! \brief Set the stored time to \a t milliseconds. */
84  inline void setMsTime(int64_t t) { m_msTime = t; }
85  /*! \brief Get the time of day component of the stored timestamp in seconds
86  * as a double precision value.
87  */
88  inline double timeOfDay() const { return XsTimeStamp_timeOfDay(this); }
89  /*! \brief Get the time of day component of the stored timestamp in
90  * milliseconds
91  */
92  inline int64_t msTimeOfDay() const
93  {
94  return m_msTime % (24 * 60 * 60 * 1000);
95  }
96 
97  /*! \brief Return the time as seconds */
98  inline double secTime() const { return ((double)m_msTime) * 0.001; }
99  /*! \brief Set the time as seconds */
100  inline void setSecTime(double t) { m_msTime = (int64_t)(t * 1000.0); }
101  /*! \brief Get the sum of the current and the given \a other timestamp.
102  * \param other The value to add to this \returns The added timestamp values
103  */
104  inline XsTimeStamp operator+(const XsTimeStamp& other) const
105  {
106  return XsTimeStamp(m_msTime + other.m_msTime);
107  }
108 
109  /*! \brief Get the current minus the given \a other timestamp. \param other
110  * The value to subtract from this \returns The subtracted timestamp values
111  */
112  inline XsTimeStamp operator-(const XsTimeStamp& other) const
113  {
114  return XsTimeStamp(m_msTime - other.m_msTime);
115  }
116 
117  /*! \brief Get the result of adding the given \a other timestamp to the
118  * current timestamp. */
119  inline XsTimeStamp& operator+=(const XsTimeStamp& other)
120  {
121  m_msTime += other.m_msTime;
122  return *this;
123  }
124 
125  /*! \brief Get the result of subtracting the given \a other timestamp from
126  * the current timestamp. */
127  inline XsTimeStamp& operator-=(const XsTimeStamp& d)
128  {
129  m_msTime -= d.m_msTime;
130  return *this;
131  }
132 
133  /*! \brief Test if the given \a other timestamp is smaller than the current
134  * timestamp. */
135  inline bool operator<(const XsTimeStamp& other) const
136  {
137  return m_msTime < other.m_msTime;
138  }
139 
140  /*! \brief Test if the given \a other timestamp is smaller than or equal to
141  * the current timestamp. */
142  inline bool operator<=(const XsTimeStamp& other) const
143  {
144  return m_msTime <= other.m_msTime;
145  }
146 
147  /*! \brief Test if the given \a other timestamp is equal to the current
148  * timestamp. */
149  inline bool operator==(const XsTimeStamp& other) const
150  {
151  return m_msTime == other.m_msTime;
152  }
153 
154  /*! \brief Test if the given \a other timestamp is larger than the current
155  * timestamp. */
156  inline bool operator>(const XsTimeStamp& other) const
157  {
158  return m_msTime > other.m_msTime;
159  }
160 
161  /*! \brief Test if the given \a other timestamp is larger than or equal to
162  * the current timestamp. */
163  inline bool operator>=(const XsTimeStamp& other) const
164  {
165  return m_msTime >= other.m_msTime;
166  }
167 
168  /*! \brief Test if the given \a other timestamp is not equal to the current
169  * timestamp. */
170  inline bool operator!=(const XsTimeStamp& other) const
171  {
172  return m_msTime != other.m_msTime;
173  }
174 
175  /*! \brief Test if the given \a other is smaller than the current timestamp.
176  */
177  inline bool operator<(int other) const { return m_msTime < other; }
178  /*! \brief Test if the given \a other is smaller than or equal to the
179  * current timestamp. */
180  inline bool operator<=(int other) const { return m_msTime <= other; }
181  /*! \brief Test if the given \a other is equal to the current timestamp. */
182  inline bool operator==(int other) const { return m_msTime == other; }
183  /*! \brief Test if the given \a other is larger than the current timestamp.
184  */
185  inline bool operator>(int other) const { return m_msTime > other; }
186  /*! \brief Test if the given \a other is larger than or equal to the current
187  * timestamp. */
188  inline bool operator>=(int other) const { return m_msTime >= other; }
189  /*! \brief Test if the given \a other is not equal to the current timestamp.
190  */
191  inline bool operator!=(int other) const { return m_msTime != other; }
192  /*! \brief Returns the number of seconds elapsed since the epoch as stored
193  * in the XsTimeStamp */
194  inline int64_t secondTime() const { return m_msTime / 1000; }
195  /*! \brief Returns the millisecond part of the time (in the range 0-999) */
196  inline int32_t milliSecondPart() const
197  {
198  return (int32_t)(m_msTime % 1000);
199  }
200 
201  /*! \brief Returns the seconds part of the time (in the range 0-59) */
202  inline int32_t secondPart() const
203  {
204  return (int32_t)((m_msTime / (1000)) % 60);
205  }
206 
207  /*! \brief Returns the minutes part of the time (in the range 0-59) */
208  inline int32_t minutePart() const
209  {
210  return (int32_t)((m_msTime / (60 * 1000)) % 60);
211  }
212 
213  /*! \brief Returns the hours part of the time (in the range 0-23) */
214  inline int32_t hourPart() const
215  {
216  return (int32_t)((m_msTime / (60 * 60 * 1000)) % 24);
217  }
218 
219  /*! \brief Returns the current time in ms since the epoch (Jan 1st 1970) */
220  inline static XsTimeStamp now()
221  {
222  XsTimeStamp tmp;
223  XsTimeStamp_now(&tmp);
224  return tmp;
225  }
226 
227  /*! \brief Returns the current time in ms since the epoch (Jan 1st 1970) */
228  inline static int64_t nowMs()
229  {
230  XsTimeStamp tmp;
231  XsTimeStamp_now(&tmp);
232  return tmp.msTime();
233  }
234 
235  /*! \brief Returns the maximum value of an %XsTimeStamp */
236  inline static XsTimeStamp maxValue()
237  {
238  return XsTimeStamp(int64_t(9223372036854775807LL)); // INT64_MAX
239  }
240 
241  /*! \brief Increment the timestamp by one ms, prefix */
242  XsTimeStamp operator++() { return XsTimeStamp(++m_msTime); }
243  /*! \brief Increment the timestamp by one ms, postfix */
244  XsTimeStamp operator++(int) { return XsTimeStamp(m_msTime++); }
245  /*! \brief Decrement the timestamp by one ms, prefix */
246  XsTimeStamp operator--() { return XsTimeStamp(--m_msTime); }
247  /*! \brief Decrement the timestamp by one ms, postfix */
248  XsTimeStamp operator--(int) { return XsTimeStamp(m_msTime--); }
249 
250  private:
251 #endif
252 
253  /** The timestamp value */
255 };
256 
257 typedef struct XsTimeStamp XsTimeStamp;
258 
259 #endif // file guard
GLdouble GLdouble t
Definition: glext.h:3695
XSTYPES_DLL_API int64_t XsTimeStamp_now(struct XsTimeStamp *thisPtr)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:86
XSTYPES_DLL_API void XsTimeStamp_setMilliSecondTime(struct XsTimeStamp *thisPtr, int64_t t)
TColor operator+(const TColor &first, const TColor &second)
Pairwise addition of their corresponding RGBA members.
Definition: TColor.cpp:19
XSTYPES_DLL_API int32_t XsTimeStamp_secondPart(const struct XsTimeStamp *thisPtr)
XSTYPES_DLL_API int64_t XsTimeStamp_maxValue()
__int64 int64_t
Definition: rptypes.h:52
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:62
XSTYPES_DLL_API int64_t XsTimeStamp_secondTime(const struct XsTimeStamp *thisPtr)
int64_t m_msTime
The timestamp value.
Definition: xstimestamp.h:254
struct XsTimeStamp XsTimeStamp
Definition: xstimestamp.h:257
Class for managing timestamps in a unified way.
Definition: xstimestamp.h:56
XSTYPES_DLL_API int32_t XsTimeStamp_hourPart(const struct XsTimeStamp *thisPtr)
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:202
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
__int32 int32_t
Definition: rptypes.h:49
A structure for storing UTC Time values.
Definition: xsutctime.h:15
XSTYPES_DLL_API int32_t XsTimeStamp_minutePart(const struct XsTimeStamp *thisPtr)
XSTYPES_DLL_API double XsTimeStamp_timeOfDay(const struct XsTimeStamp *thisPtr)
TColor operator-(const TColor &first, const TColor &second)
Pairwise substraction of their corresponding RGBA members.
Definition: TColor.cpp:30
XSTYPES_DLL_API void XsTimeStamp_toUtcTime(struct XsTimeStamp *thisPtr, struct XsUtcTime *utc)
iterator operator++(int)
A thread-safe (ts) container which minimally emulates a std::map<>&#39;s [] and find() methods but which ...
Definition: ts_hash_map.h:157
bool operator<(const COccupancyGridMap2D::TPairLikelihoodIndex &e1, const COccupancyGridMap2D::TPairLikelihoodIndex &e2)
bool operator!=(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:209
XSTYPES_DLL_API int64_t XsTimeStamp_fromUtcTime(struct XsTimeStamp *thisPtr, const struct XsUtcTime *utc)
XSTYPES_DLL_API int32_t XsTimeStamp_milliSecondPart(const struct XsTimeStamp *thisPtr)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019