Leka
A low-latency C++20 price-time-priority limit order book and matching engine
▶ Replay viewer
Loading...
Searching...
No Matches
timestamp.hpp
1#ifndef TIMESTAMP_HPP
2#define TIMESTAMP_HPP
3
4#include <cstdint>
5#include <compare>
6
7namespace lob {
8
9/** @brief Nanoseconds since the Unix epoch; zero is reserved as invalid. */
10class Timestamp {
11 private:
12 std::uint64_t timestamp;
13
14 public:
15 /** Constructs an invalid, zero-valued timestamp. */
16 Timestamp(): timestamp(0){}
17
18 /** Constructs a timestamp from nanoseconds since the Unix epoch. */
19 explicit Timestamp(std::uint64_t timestamp): timestamp(timestamp){}
20
21 /** Returns nanoseconds since the Unix epoch. */
22 std::uint64_t getTimestamp() const { return timestamp; }
23
24 /** Returns whether the timestamp is nonzero. */
25 bool isValid() const {
26 return timestamp != 0;
27 }
28
29 /** Compares timestamps chronologically. */
30 auto operator<=>(const Timestamp &other) const = default;
31};
32
33} // namespace lob
34
35#endif // TIMESTAMP_HPP
bool isValid() const
Returns whether the timestamp is nonzero.
Definition timestamp.hpp:25
auto operator<=>(const Timestamp &other) const =default
Compares timestamps chronologically.
Timestamp()
Constructs an invalid, zero-valued timestamp.
Definition timestamp.hpp:16
std::uint64_t getTimestamp() const
Returns nanoseconds since the Unix epoch.
Definition timestamp.hpp:22
Timestamp(std::uint64_t timestamp)
Constructs a timestamp from nanoseconds since the Unix epoch.
Definition timestamp.hpp:19