Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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 { 0 }
19 #endif
20 
21 struct XsTimeStamp;
22 struct XsUtcTime;
23 
25 XSTYPES_DLL_API double XsTimeStamp_timeOfDay(const struct XsTimeStamp* thisPtr);
33 XSTYPES_DLL_API int64_t XsTimeStamp_fromUtcTime(struct XsTimeStamp* thisPtr, const struct XsUtcTime* utc);
34 XSTYPES_DLL_API void XsTimeStamp_toUtcTime(struct XsTimeStamp* thisPtr, struct XsUtcTime* utc);
35 
36 #ifdef __cplusplus
37 } // extern "C"
38 #endif
39 
40 /*! \struct XsTimeStamp
41  \brief Class for managing timestamps in a unified way.
42 */
43 struct XsTimeStamp {
44 #ifdef __cplusplus
45  /*! \brief Construct a timestamp with \a t as the time in milliseconds. */
46  inline XsTimeStamp(int64_t t = 0) : m_msTime(t) {}
47 
48  /*! \brief Construct a timestamp with \a t as the time in milliseconds. */
49  inline XsTimeStamp(int t) : m_msTime(t) {}
50 
51  /*! \brief Construct a copy of \a other. */
52  inline XsTimeStamp(const XsTimeStamp& other) : m_msTime(other.m_msTime) {}
53 
54  /*! \brief Construct from \a utc */
55  inline XsTimeStamp(const XsUtcTime& utc)
56  {
57  XsTimeStamp_fromUtcTime(this, &utc);
58  }
59 
60  /*! \brief Convert this timestamp to UTC time \a utc */
61  inline void toUtcTime(XsUtcTime& utc)
62  {
63  XsTimeStamp_toUtcTime(this, &utc);
64  }
65 
66  /*! \brief Assign the contents of the \a other timestamp to this timestamp. */
67  inline XsTimeStamp& operator = (const XsTimeStamp& other)
68  {
69  m_msTime = other.m_msTime;
70  return *this;
71  }
72 
73  /*! \brief Get the stored time as milliseconds. */
74  inline int64_t msTime(void) const
75  { return m_msTime; }
76 
77  /*! \brief Set the stored time to \a t milliseconds. */
78  inline void setMsTime(int64_t t)
79  { m_msTime = t; }
80 
81  /*! \brief Get the time of day component of the stored timestamp in seconds as a double precision value.
82  */
83  inline double timeOfDay() const
84  { return XsTimeStamp_timeOfDay(this); }
85 
86  /*! \brief Get the time of day component of the stored timestamp in milliseconds
87  */
88  inline int64_t msTimeOfDay() const
89  { return m_msTime % (24*60*60*1000); }
90 
91  /*! \brief Return the time as seconds */
92  inline double secTime() const
93  { return ((double)m_msTime)*0.001; }
94 
95  /*! \brief Set the time as seconds */
96  inline void setSecTime(double t)
97  { m_msTime = (int64_t) (t*1000.0); }
98 
99  /*! \brief Get the sum of the current and the given \a other timestamp. \param other The value to add to this \returns The added timestamp values */
100  inline XsTimeStamp operator + (const XsTimeStamp& other) const
101  { return XsTimeStamp(m_msTime + other.m_msTime); }
102 
103  /*! \brief Get the current minus the given \a other timestamp. \param other The value to subtract from this \returns The subtracted timestamp values */
104  inline XsTimeStamp operator - (const XsTimeStamp& other) const
105  { return XsTimeStamp(m_msTime - other.m_msTime); }
106 
107  /*! \brief Get the result of adding the given \a other timestamp to the current timestamp. */
108  inline XsTimeStamp& operator += (const XsTimeStamp& other)
109  { m_msTime += other.m_msTime; return *this; }
110 
111  /*! \brief Get the result of subtracting the given \a other timestamp from the current timestamp. */
112  inline XsTimeStamp& operator -= (const XsTimeStamp& d)
113  { m_msTime -= d.m_msTime; return *this; }
114 
115  /*! \brief Test if the given \a other timestamp is smaller than the current timestamp. */
116  inline bool operator < (const XsTimeStamp& other) const
117  { return m_msTime < other.m_msTime; }
118 
119  /*! \brief Test if the given \a other timestamp is smaller than or equal to the current timestamp. */
120  inline bool operator <= (const XsTimeStamp& other) const
121  { return m_msTime <= other.m_msTime; }
122 
123  /*! \brief Test if the given \a other timestamp is equal to the current timestamp. */
124  inline bool operator == (const XsTimeStamp& other) const
125  { return m_msTime == other.m_msTime; }
126 
127  /*! \brief Test if the given \a other timestamp is larger than the current timestamp. */
128  inline bool operator > (const XsTimeStamp& other) const
129  { return m_msTime > other.m_msTime; }
130 
131  /*! \brief Test if the given \a other timestamp is larger than or equal to the current timestamp. */
132  inline bool operator >= (const XsTimeStamp& other) const
133  { return m_msTime >= other.m_msTime; }
134 
135  /*! \brief Test if the given \a other timestamp is not equal to the current timestamp. */
136  inline bool operator != (const XsTimeStamp& other) const
137  { return m_msTime != other.m_msTime; }
138 
139  /*! \brief Test if the given \a other is smaller than the current timestamp. */
140  inline bool operator < (int other) const
141  { return m_msTime < other; }
142 
143  /*! \brief Test if the given \a other is smaller than or equal to the current timestamp. */
144  inline bool operator <= (int other) const
145  { return m_msTime <= other; }
146 
147  /*! \brief Test if the given \a other is equal to the current timestamp. */
148  inline bool operator == (int other) const
149  { return m_msTime == other; }
150 
151  /*! \brief Test if the given \a other is larger than the current timestamp. */
152  inline bool operator > (int other) const
153  { return m_msTime > other; }
154 
155  /*! \brief Test if the given \a other is larger than or equal to the current timestamp. */
156  inline bool operator >= (int other) const
157  { return m_msTime >= other; }
158 
159  /*! \brief Test if the given \a other is not equal to the current timestamp. */
160  inline bool operator != (int other) const
161  { return m_msTime != other; }
162 
163  /*! \brief Returns the number of seconds elapsed since the epoch as stored in the XsTimeStamp */
164  inline int64_t secondTime() const
165  { return m_msTime/1000; }
166 
167  /*! \brief Returns the millisecond part of the time (in the range 0-999) */
168  inline int32_t milliSecondPart() const
169  { return (int32_t) (m_msTime % 1000); }
170 
171  /*! \brief Returns the seconds part of the time (in the range 0-59) */
172  inline int32_t secondPart() const
173  { return (int32_t) ((m_msTime/(1000))%60); }
174 
175  /*! \brief Returns the minutes part of the time (in the range 0-59) */
176  inline int32_t minutePart() const
177  { return (int32_t) ((m_msTime/(60*1000))%60); }
178 
179  /*! \brief Returns the hours part of the time (in the range 0-23) */
180  inline int32_t hourPart() const
181  { return (int32_t) ((m_msTime/(60*60*1000))%24); }
182 
183  /*! \brief Returns the current time in ms since the epoch (Jan 1st 1970) */
184  inline static XsTimeStamp now()
185  {
186  XsTimeStamp tmp;
187  XsTimeStamp_now(&tmp);
188  return tmp;
189  }
190 
191  /*! \brief Returns the current time in ms since the epoch (Jan 1st 1970) */
192  inline static int64_t nowMs()
193  {
194  XsTimeStamp tmp;
195  XsTimeStamp_now(&tmp);
196  return tmp.msTime();
197  }
198 
199  /*! \brief Returns the maximum value of an %XsTimeStamp */
200  inline static XsTimeStamp maxValue()
201  {
202  return XsTimeStamp(int64_t(9223372036854775807LL)); //INT64_MAX
203  }
204 
205  /*! \brief Increment the timestamp by one ms, prefix */
207  { return XsTimeStamp(++m_msTime); }
208 
209  /*! \brief Increment the timestamp by one ms, postfix */
211  { return XsTimeStamp(m_msTime++); }
212 
213  /*! \brief Decrement the timestamp by one ms, prefix */
214  XsTimeStamp operator--()
215  { return XsTimeStamp(--m_msTime); }
216 
217  /*! \brief Decrement the timestamp by one ms, postfix */
218  XsTimeStamp operator--(int)
219  { return XsTimeStamp(m_msTime--); }
220 
221 private:
222 #endif
223 
224  int64_t m_msTime; //!< The timestamp value
225 };
226 
227 typedef struct XsTimeStamp XsTimeStamp;
228 
229 #endif // file guard
bool operator==(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
GLdouble GLdouble t
Definition: glext.h:3610
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:97
bool operator!=(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
XSTYPES_DLL_API int64_t XsTimeStamp_now(struct XsTimeStamp *thisPtr)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:70
XSTYPES_DLL_API void XsTimeStamp_setMilliSecondTime(struct XsTimeStamp *thisPtr, int64_t t)
std::vector< T1 > operator+(const std::vector< T1 > &a, const std::vector< T2 > &b)
a+b (element-wise sum)
Definition: ops_vectors.h:89
XSTYPES_DLL_API int32_t XsTimeStamp_secondPart(const struct XsTimeStamp *thisPtr)
XSTYPES_DLL_API int64_t XsTimeStamp_maxValue()
__int64 int64_t
Definition: rptypes.h:51
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:70
XSTYPES_DLL_API int64_t XsTimeStamp_secondTime(const struct XsTimeStamp *thisPtr)
int64_t m_msTime
The timestamp value.
Definition: xstimestamp.h:224
struct XsTimeStamp XsTimeStamp
Definition: xstimestamp.h:227
Class for managing timestamps in a unified way.
Definition: xstimestamp.h:43
bool operator>(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:289
XSTYPES_DLL_API int32_t XsTimeStamp_hourPart(const struct XsTimeStamp *thisPtr)
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
__int32 int32_t
Definition: rptypes.h:48
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)
bool operator<=(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:293
XSTYPES_DLL_API void XsTimeStamp_toUtcTime(struct XsTimeStamp *thisPtr, struct XsUtcTime *utc)
bool operator<(const CPoint< DERIVEDCLASS > &a, const CPoint< DERIVEDCLASS > &b)
Used by STL algorithms.
Definition: CPoint.h:116
TPoint3D operator-(const TPoint3D &p1)
Unary minus operator for 3D points.
XSTYPES_DLL_API int64_t XsTimeStamp_fromUtcTime(struct XsTimeStamp *thisPtr, const struct XsUtcTime *utc)
bool operator>=(const CArray< T, N > &x, const CArray< T, N > &y)
Definition: CArray.h:297
XSTYPES_DLL_API int32_t XsTimeStamp_milliSecondPart(const struct XsTimeStamp *thisPtr)



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019