35 #ifndef ROS_TIME_IMPL_H_INCLUDED 36 #define ROS_TIME_IMPL_H_INCLUDED 47 #include <boost/date_time/posix_time/posix_time.hpp> 54 #include <sys/timeb.h> 62 template<
class T,
class D>
70 sec =
static_cast<uint32_t
>(sec64);
71 nsec =
static_cast<uint32_t
>(nsec64);
73 return *
static_cast<T*
>(
this);
76 template<
class T,
class D>
78 int64_t sec64 =
static_cast<int64_t
>(floor(t));
79 if (sec64 < 0 || sec64 > std::numeric_limits<uint32_t>::max())
80 throw std::runtime_error(
"Time is out of dual 32-bit range");
81 sec =
static_cast<uint32_t
>(sec64);
82 nsec =
static_cast<uint32_t
>(boost::math::round((t-sec) * 1e9));
84 sec += (nsec / 1000000000ul);
86 return *
static_cast<T*
>(
this);
89 template<
class T,
class D>
93 return d.fromNSec(toNSec() - rhs.toNSec());
96 template<
class T,
class D>
99 return *
static_cast<const T*
>(
this) + ( -rhs);
102 template<
class T,
class D>
105 int64_t sec_sum =
static_cast<uint64_t
>(sec) + static_cast<uint64_t>(rhs.sec);
106 int64_t nsec_sum =
static_cast<uint64_t
>(nsec) + static_cast<uint64_t>(rhs.nsec);
112 return T(static_cast<uint32_t>(sec_sum), static_cast<uint32_t>(nsec_sum));
115 template<
class T,
class D>
119 return *
static_cast<T*
>(
this);
122 template<
class T,
class D>
126 return *
static_cast<T*
>(
this);
129 template<
class T,
class D>
132 return sec == rhs.sec && nsec == rhs.nsec;
135 template<
class T,
class D>
140 else if (sec == rhs.sec && nsec < rhs.nsec)
145 template<
class T,
class D>
150 else if (sec == rhs.sec && nsec > rhs.nsec)
155 template<
class T,
class D>
160 else if (sec == rhs.sec && nsec <= rhs.nsec)
165 template<
class T,
class D>
170 else if (sec == rhs.sec && nsec >= rhs.nsec)
175 template<
class T,
class D>
176 boost::posix_time::ptime
180 #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) 181 return pt::from_time_t(sec) + pt::nanoseconds(nsec);
183 return pt::from_time_t(sec) + pt::microseconds(nsec/1000);
188 #endif // ROS_IMPL_TIME_H_INCLUDED bool operator>(const T &rhs) const
T & operator-=(const D &rhs)
T & operator+=(const D &rhs)
T operator+(const D &rhs) const
ROSTIME_DECL void normalizeSecNSecUnsigned(int64_t &sec, int64_t &nsec)
bool operator==(const T &rhs) const
bool operator<=(const T &rhs) const
bool operator>=(const T &rhs) const
bool operator<(const T &rhs) const
D operator-(const T &rhs) const
ROSTIME_DECL void normalizeSecNSec(uint64_t &sec, uint64_t &nsec)
boost::posix_time::ptime toBoost() const