From bcdce9633dc351d3bc7f347a165348b8fab87cd9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 15 Feb 2022 12:33:52 +0100 Subject: refactor: reorganize files & improve classes --- src/std/time.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/std/time.hpp (limited to 'src/std/time.hpp') diff --git a/src/std/time.hpp b/src/std/time.hpp new file mode 100644 index 0000000..a544a5a --- /dev/null +++ b/src/std/time.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include + +constexpr double MICROS_TO_SECS = 0.000001; +constexpr double MICROS_TO_MILLIS = 0.001; + +/** + * A representation of time. + */ +class Time +{ +public: + /** + * A representation of time. + * + * @param time_micros Time in microseconds + */ + explicit Time(uint64_t time_micros); + + /** + * Updates the time to the current time. + */ + void update(); + + /** + * Returns the difference between two points in time. + * + * @param prev_time A previous point in time + */ + Time diff(Time prev_time) const; + + /** + * Returns the time in seconds. + */ + double secs() const; + + /** + * Returns the time in milliseconds. + */ + double millisecs() const; + + /** + * Returns the time in microseconds. + */ + uint64_t microsecs() const; + +private: + uint64_t _time_micros; +}; + +/** + * Returns a time object for the time since the program started. + */ +Time time_now(); -- cgit v1.2.3-18-g5258