[Positioner] Timestamp: elapsed() & owl_timestamp()

New functions added in Timestamp:
  - elapsed()
  - elapsed(Timestamp)
  - operator owl_imestamp()
This commit is contained in:
Matteo Cypriani 2011-12-28 12:58:20 +01:00
parent 9c1fc429c9
commit 35265e75c2
2 changed files with 44 additions and 1 deletions

View File

@ -92,6 +92,31 @@ bool Timestamp::now()
}
/**
* @returns A Timestamp containing the time elapsed, or an empty
* Timestamp in case of error.
*/
Timestamp Timestamp::elapsed() const
{
Timestamp now ;
if (! now.now())
return Timestamp() ;
return elapsed(now) ;
}
Timestamp Timestamp::elapsed(const Timestamp &source) const
{
owl_timestamp
d1 = *this,
d2 = source,
elapsed ;
owl_time_elapsed(&d1, &d2, &elapsed) ;
return elapsed ;
}
/**
* #timestamp nanosecond field precision is set to ms, but the value
* is still in ns.
@ -178,6 +203,15 @@ std::ostream& operator<<(std::ostream &os, const Timestamp &t)
}
inline Timestamp::operator owl_timestamp(void) const
{
owl_timestamp ret ;
ret.tv_sec = timestamp.tv_sec ;
ret.tv_nsec = timestamp.tv_nsec ;
return ret ;
}
size_t hash_value(const Timestamp &source)
{

View File

@ -61,11 +61,18 @@ public:
~Timestamp(void) {}
/** @name Operations */
//@{
/// \brief Initialises #timestamp at the current time whith a
/// nanosecond precision
bool now(void) ;
/// Returns the time elapsed until now
Timestamp elapsed(void) const ;
/// Returns the time elapsed since or until \em source
Timestamp elapsed(const Timestamp &source) const ;
/// Resets #timestamp
void clear(void) ;
//@}
/** @name Operators */
//@{
@ -94,6 +101,8 @@ public:
operator const struct timespec&(void) const ;
/// Casts to milliseconds
operator uint64_t(void) const ;
/// Casts to the owl_timestamp type from libowlps
operator owl_timestamp(void) const ;
//@}
/// Displays a Timestamp