cat3d
A tiny OpenGL 3D engine library written in and for C++.
clock.hpp
1 #pragma once
2 
3 #include <chrono>
4 
5 namespace cat3d::util {
6 
11 class time {
12 public:
14  time();
15 
22  static time seconds(float s);
29  static time milliseconds(unsigned long ms);
36  static time minutes(float m);
37 
43  float as_seconds() const;
49  unsigned long as_milliseconds() const;
55  float as_minutes() const;
56 
58  time operator+(const time& other);
60  time operator-(const time& other);
62  time& operator+=(const time& other);
64  time& operator-=(const time& other);
65 
67  bool operator>(const time& other);
69  bool operator<(const time& other);
71  bool operator>=(const time& other);
73  bool operator<=(const time& other);
74 
76  bool operator==(const time& other);
78  bool operator!=(const time& other);
79 
80 private:
82  time(unsigned long ms);
83 
85  unsigned long m_ms;
86 };
87 
92 class clock {
93 public:
98  clock();
99 
111  time elapsed() const;
112 
113 private:
115  std::chrono::time_point<std::chrono::steady_clock> m_start;
116 };
117 
118 }
cat3d::util::time::operator<=
bool operator<=(const time &other)
Check if one duration is smaller than or equal to another.
cat3d::util::time::as_milliseconds
unsigned long as_milliseconds() const
Convert this time duration into milliseconds.
cat3d::util::time::seconds
static time seconds(float s)
Create a new time duration given seconds.
cat3d::util::time::operator!=
bool operator!=(const time &other)
Check if two durations aren't exactly equal.
cat3d::util::clock
Class to measure the passage of time.
Definition: clock.hpp:92
cat3d::util::time::time
time()
By default, initializes to length 0.
cat3d::util::time::minutes
static time minutes(float m)
Create a new time duration, given minutes.
cat3d::util::clock::restart
time restart()
Restart the clock.
cat3d::util::time::operator-
time operator-(const time &other)
Subtract two time durations.
cat3d::util::time::operator+
time operator+(const time &other)
Add two times together.
cat3d::util::time::as_seconds
float as_seconds() const
Convert this time duration into seconds.
cat3d::util::time::operator>
bool operator>(const time &other)
Check if one duration is larger than another.
cat3d::util::time
Class representing a duration of time.
Definition: clock.hpp:11
cat3d::util::time::milliseconds
static time milliseconds(unsigned long ms)
Create a new time duration, given milliseconds.
cat3d::util::time::operator<
bool operator<(const time &other)
Check if one duration is smaller than another.
cat3d::util::time::operator>=
bool operator>=(const time &other)
Check if one duration is greater than or equal to another.
cat3d::util::time::operator+=
time & operator+=(const time &other)
Add one duration to this.
cat3d::util::time::operator-=
time & operator-=(const time &other)
Subtract a duration of time from this.
cat3d::util::time::as_minutes
float as_minutes() const
Convert this time duration into minutes.
cat3d::util::time::operator==
bool operator==(const time &other)
Check if two durations are exactly equal.
cat3d::util::clock::elapsed
time elapsed() const
Get the elapsed time since the last restart()
cat3d::util::clock::clock
clock()