timestamp_base.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_TIME_TIMESTAMP_BASE_HPP_
13 #define ECL_TIME_TIMESTAMP_BASE_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <cstdlib>
20 #include <ecl/time_lite/types.hpp>
21 #include <ecl/config/macros.hpp>
22 #include <ecl/exceptions/standard_exception.hpp>
23 #include "macros.hpp"
24 
25 /*****************************************************************************
26 ** Namespaces
27 *****************************************************************************/
28 
29 namespace ecl {
30 
31 /*****************************************************************************
32 ** Implementation
33 *****************************************************************************/
40 class ecl_time_PUBLIC TimeStampBase {
41 public:
42  /*********************
43  ** Constructors
44  **********************/
45  explicit TimeStampBase() {};
56  explicit TimeStampBase (const double& decimal_time_value) ecl_assert_throw_decl(StandardException);
66  TimeStampBase (const time_t &seconds, const long &nanoseconds) ecl_assert_throw_decl(StandardException);
67 
68  virtual ~TimeStampBase() {}
69 
70  /******************************************
71  ** Stamps
72  *******************************************/
83  const TimeStampBase& stamp (const double& decimal_time_value) ecl_assert_throw_decl(StandardException);
94  const TimeStampBase& stamp (const time_t &seconds, const long &nanoseconds) ecl_assert_throw_decl(StandardException);
95 
96  /******************************************
97  ** Accessors
98  *******************************************/
105  long sec() const { return time.tv_sec; }
112  long msec() const { return time.tv_nsec/1000000L; }
119  long usec() const { return time.tv_nsec/1000; }
126  long nsec() const { return time.tv_nsec; }
127 
134  operator double() const { return ( time.tv_sec + time.tv_nsec*0.000000001); }
135 
136  /******************************************
137  ** Comparison Operators
138  *******************************************/
144  bool operator==(const TimeStampBase& time_stamp);
150  bool operator!=(const TimeStampBase& time_stamp);
156  bool operator<=(const TimeStampBase& time_stamp);
162  bool operator>=(const TimeStampBase& time_stamp);
168  bool operator<(const TimeStampBase& time_stamp);
174  bool operator>(const TimeStampBase& time_stamp);
175 
176  /******************************************
177  ** Mathematical Operators
178  *******************************************/
184  TimeStampBase operator+(const TimeStampBase& time_stamp );
189  void operator+=(const TimeStampBase& time_stamp);
199  TimeStampBase operator-(const TimeStampBase& time_stamp ) ecl_assert_throw_decl(StandardException);
208  void operator-=(const TimeStampBase& time_stamp) ecl_assert_throw_decl(StandardException);
209 
210  /******************************************
211  ** Insertion Operator
212  *******************************************/
213  template <typename OutputStream>
214  friend OutputStream& operator << ( OutputStream &ostream , const TimeStampBase& time_stamp );
215 
216 protected:
217  TimeStructure time;
218 };
219 
220 
221 /*****************************************************************************
222 ** Implementation [Insertion Operator]
223 *****************************************************************************/
224 
225 template <typename OutputStream>
226 OutputStream& operator <<( OutputStream &ostream , const TimeStampBase& time_stamp )
227 {
228  if ( ( time_stamp.time.tv_sec == 0 ) && (time_stamp.time.tv_nsec < 0 ) ) {
229  ostream << "-";
230  }
231  ostream << time_stamp.time.tv_sec << ".";
232  long nanoseconds = std::abs(time_stamp.time.tv_nsec);
233  if ( nanoseconds < 10 ) {
234  ostream << "00000000";
235  } else if ( nanoseconds < 100 ) {
236  ostream << "0000000";
237  } else if ( nanoseconds < 1000 ) {
238  ostream << "000000";
239  } else if ( nanoseconds < 10000 ) {
240  ostream << "00000";
241  } else if ( nanoseconds < 100000 ) {
242  ostream << "0000";
243  } else if ( nanoseconds < 1000000 ) {
244  ostream << "000";
245  } else if ( nanoseconds < 10000000 ) {
246  ostream << "00";
247  } else if ( nanoseconds < 100000000 ) {
248  ostream << "0";
249  }
250  ostream << nanoseconds;
251  return ostream;
252 }
253 
254 } // namespace ecl
255 
256 #endif /* ECL_TIME_TIMESTAMP_BASE_HPP_ */
257 
258 
259 
TFSIMD_FORCE_INLINE Quaternion operator-(const Quaternion &q)
bool operator>(const TransformStorage &lhs, const TransformStorage &rhs)
#define ecl_time_PUBLIC
Definition: time/macros.hpp:37
OutputStream & operator<<(OutputStream &ostream, const Void void_object)
Output stream operator for Void objects.
Definition: void.hpp:76
This class provides common functionality across platforms for the timestamps.
stamp
TFSIMD_FORCE_INLINE Vector3 & operator-=(const Vector3 &v)
bool operator==(const GTEST_10_TUPLE_(T)&t, const GTEST_10_TUPLE_(U)&u)
TFSIMD_FORCE_INLINE Vector3 & operator+=(const Vector3 &v)
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
TFSIMD_FORCE_INLINE Vector3 operator+(const Vector3 &v1, const Vector3 &v2)
bool operator!=(const GTEST_10_TUPLE_(T)&t, const GTEST_10_TUPLE_(U)&u)


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13