summaryrefslogtreecommitdiff
path: root/src/time_utils.hpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-12-24 20:07:16 +0100
committerHampusM <hampus@hampusmat.com>2021-12-26 20:36:34 +0100
commite5b34cbb3d6764cc9a7d3e6d4c27da468f16246f (patch)
treedd6da3fb64a9a8f355ad819061efcdaa8aa305a3 /src/time_utils.hpp
parent8969ebfa45b593e0c59f6998fdf8bde42324089f (diff)
refactor: improve whole project
Diffstat (limited to 'src/time_utils.hpp')
-rw-r--r--src/time_utils.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/time_utils.hpp b/src/time_utils.hpp
new file mode 100644
index 0000000..f8f2eb3
--- /dev/null
+++ b/src/time_utils.hpp
@@ -0,0 +1,53 @@
+#ifndef TIME_UTILS_HPP
+#define TIME_UTILS_HPP
+
+/**
+ * A representation of time.
+ */
+class Time
+{
+public:
+ /**
+ * A representation of time.
+ *
+ * @param time_micros Time in microseconds
+ */
+ Time(unsigned long 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);
+
+ /**
+ * Returns the time in seconds.
+ */
+ float secs();
+
+ /**
+ * Returns the time in milliseconds.
+ */
+ unsigned long millisecs();
+
+ /**
+ * Returns the time in microseconds.
+ */
+ unsigned long microsecs();
+
+private:
+ unsigned long _time_micros;
+};
+
+/**
+ * Returns a time object for the time since the program started.
+ */
+Time time_now();
+
+#endif