[Positioning] Timestamp: enable ns precision

Do not round to millisecond precision anymore, we now keep nanosecond
precision.
This commit is contained in:
Matteo Cypriani 2011-03-16 11:23:24 +01:00
parent 3782ca9012
commit cbd2ba3ca1
2 changed files with 18 additions and 29 deletions

View File

@ -16,7 +16,6 @@ Timestamp::Timestamp()
Timestamp::Timestamp(const struct timespec &source)
{
set(source) ;
round_to_ms() ;
}
@ -54,16 +53,6 @@ inline void Timestamp::set(const uint64_t source_ms)
bool Timestamp::now()
{
if (! now_ns())
return false ;
round_to_ms() ;
return true ;
}
inline bool Timestamp::now_ns()
{
return clock_gettime(CLOCK_REALTIME, &timestamp) == 0 ;
}
@ -94,7 +83,9 @@ bool Timestamp::equals(const struct timespec &source) const
bool Timestamp::equals(const uint64_t source) const
{
Timestamp tmp(source) ;
return equals(tmp.timestamp) ;
Timestamp me(*this) ;
me.round_to_ms() ;
return me == tmp ;
}
@ -148,7 +139,7 @@ bool Timestamp::operator==(const Timestamp &source) const
std::ostream& operator<<(std::ostream &os, const Timestamp &t)
{
os << static_cast<uint64_t>(t) ;
os << t.timestamp.tv_sec << '.' << t.timestamp.tv_nsec ;
return os ;
}

View File

@ -5,7 +5,7 @@
#include <stdint.h> // <cstdint> is not C++ 98 compliant
#include <ostream>
/// Represents a timestamp with a millisecond precision
/// Represents a timestamp with a nanosecond precision
/**
* This class boxes <em>struct timespec</em> from ctime (time.h) to
* integrate time manipulation functions.
@ -19,13 +19,14 @@ protected:
/** @name Internal accessors */
//@{
void set(const struct timespec &source) ;
/// Initialises the Timestamp with a value in milliseconds
/// Initialises the Timestamp with a value in milliseconds (deprecated)
void set(const uint64_t source_ms) ;
//@}
/** @name Comparison functions */
//@{
bool equals(const struct timespec &source) const ;
/// Compare to a millisecond value (deprecated)
bool equals(const uint64_t source) const ;
bool less_than(const struct timespec &source) const ;
bool greater_than(const struct timespec &source) const ;
@ -33,10 +34,7 @@ protected:
/** @name Operations */
//@{
/// \brief Initialises #timestamp at the current time whith a
/// nanosecond precision
bool now_ns(void) ;
/// Lowers the precision of #timestamp to ms
/// Lowers the precision of #timestamp to ms (deprecated)
void round_to_ms(void) ;
//@}
@ -44,14 +42,14 @@ protected:
public:
Timestamp(void) ;
Timestamp(const struct timespec &source) ;
/// Constructs a Timsestamp from a value in milliseconds
/// Constructs a Timsestamp from a value in milliseconds (deprecated)
Timestamp(const uint64_t source) ;
Timestamp(const Timestamp &source) ;
~Timestamp(void) {}
/// \brief Initialises #timestamp to the current time with a
/// millisecond precision
/// \brief Initialises #timestamp at the current time whith a
/// nanosecond precision
bool now(void) ;
void clear(void) ;
@ -60,25 +58,25 @@ public:
//@{
const Timestamp& operator=(const Timestamp &source) ;
const Timestamp& operator=(const struct timespec &source) ;
const Timestamp& operator=(const uint64_t source) ;
const Timestamp& operator=(const uint64_t source) ; //< deprecated
bool operator==(const Timestamp &source) const ;
bool operator==(const struct timespec &source) const ;
bool operator==(const uint64_t source) const ;
bool operator==(const uint64_t source) const ; //< deprecated
bool operator!=(const Timestamp &source) const ;
bool operator!=(const struct timespec &source) const ;
bool operator!=(const uint64_t source) const ;
bool operator!=(const uint64_t source) const ; //< deprecated
bool operator<(const Timestamp &source) const ;
bool operator<(const struct timespec &source) const ;
bool operator<(const uint64_t source) const ;
bool operator<(const uint64_t source) const ; //< deprecated
bool operator>(const Timestamp &source) const ;
bool operator>(const struct timespec &source) const ;
bool operator>(const uint64_t source) const ;
bool operator>(const uint64_t source) const ; //< deprecated
bool operator<=(const Timestamp &source) const ;
bool operator<=(const struct timespec &source) const ;
bool operator<=(const uint64_t source) const ;
bool operator<=(const uint64_t source) const ; //< deprecated
bool operator>=(const Timestamp &source) const ;
bool operator>=(const struct timespec &source) const ;
bool operator>=(const uint64_t source) const ;
bool operator>=(const uint64_t source) const ; //< deprecated
operator bool(void) const ;
operator const struct timespec&(void) const ;
/// Cast to milliseconds