File: TimeStamp.h

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (62 lines) | stat: -rw-r--r-- 1,791 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "Clock.h"

namespace nCine
{
	/// Represents a point in time or a duration
	class TimeStamp
	{
	public:
		TimeStamp();

		/// Returns a new time stamp initialized to the current clock value
		inline static TimeStamp now() {
			return TimeStamp(clock().now());
		}

		bool operator>(const TimeStamp& other) const;
		bool operator<(const TimeStamp& other) const;
		TimeStamp& operator+=(const TimeStamp& other);
		TimeStamp& operator-=(const TimeStamp& other);
		TimeStamp operator+(const TimeStamp& other) const;
		TimeStamp operator-(const TimeStamp& other) const;

		/// Returns a new time stamp with the time elapsed since this one
		TimeStamp timeSince() const;

		/// Returns the time elapsed since the timestamp, as seconds in a `float` number
		float secondsSince() const;

		/// Returns the time elapsed since the timestamp, as milliseconds in a `float` number
		float millisecondsSince() const;

		/// Returns the time elapsed since the timestamp, as microseconds in a `float` number
		float microsecondsSince() const;

		/// Returns the time elapsed since the timestamp, as seconds in a `nanoseconds` number
		float nanosecondsSince() const;

		// Returns the number of elapsed ticks
		inline std::uint64_t ticks() const {
			return _counter;
		}

		/// Returns the timestamp counter value as seconds in a `float` number
		float seconds() const;

		/// Returns the timestamp counter value as milliseconds in a `float` number
		float milliseconds() const;

		/// Returns the timestamp counter value as microseconds in a `float` number
		float microseconds() const;

		/// Returns the timestamp counter value as nanoseconds in a `float` number
		float nanoseconds() const;

	private:
		std::uint64_t _counter;

		explicit TimeStamp(std::uint64_t counter);
	};
}