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