From 0d527ec77d576942b559a4b52ee4a52b6e91aa0a Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 4 Jun 2012 18:07:47 +0200 Subject: [PATCH] [Positioner] Add Timestamp::current_time --- owlps-positioner/src/timestamp.cc | 23 +++++++++++++++++++++++ owlps-positioner/src/timestamp.hh | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/owlps-positioner/src/timestamp.cc b/owlps-positioner/src/timestamp.cc index 97b1d1b..70dcee6 100644 --- a/owlps-positioner/src/timestamp.cc +++ b/owlps-positioner/src/timestamp.cc @@ -11,6 +11,10 @@ +Timestamp Timestamp::current_time ; + + + /* *** Constructors *** */ @@ -86,6 +90,25 @@ inline void Timestamp::set(const uint64_t source_ms) /* *** Operations *** */ +Timestamp Timestamp::get_current_time() +{ + return current_time ; +} + + +/** + * @source A pointer to the new time. If NULL, #current_time is updated + * to the current time. + */ +void Timestamp::set_current_time(const Timestamp *const source) +{ + if (source) + current_time = *source ; + else + current_time.now() ; +} + + bool Timestamp::now() { return clock_gettime(CLOCK_REALTIME, ×tamp) == 0 ; diff --git a/owlps-positioner/src/timestamp.hh b/owlps-positioner/src/timestamp.hh index 84cb1e3..2b36244 100644 --- a/owlps-positioner/src/timestamp.hh +++ b/owlps-positioner/src/timestamp.hh @@ -21,6 +21,9 @@ */ class Timestamp { +private: + static Timestamp current_time ; + protected: /// Time data struct timespec timestamp ; @@ -63,6 +66,10 @@ public: /** @name Operations */ //@{ + /// Returns a Timestamp containing the current time + static Timestamp get_current_time(void) ; + /// Sets #current_time to a new timestamp + static void set_current_time(const Timestamp *const source = NULL) ; /// \brief Initialises #timestamp at the current time whith a /// nanosecond precision bool now(void) ;