Skip to content
Daniel Esambu
Work
Work
Projects
Things I've built
Leka
A C++20 matching engine
Latency Lab
(opens in a new tab)
A C++ course I wrote
Resume
The formal version
Writing
Writing
Poetry
Poems, shelved by what they're about
Essays
Notes and essays
Math
Math
Notes
Notes I've written up
IB papers
Worked exam questions
Calculus lessons
(opens in a new tab)
On YouTube
Life
Life
Photos
Things I stopped to look at
Training
Reps, not phases
Modeling
Measurements and photos
Resume
Say hi
Say hi
Resume
Menu
Leka
A low-latency C++20 price-time-priority limit order book and matching engine
Replay viewer
Toggle main menu visibility
Loading...
Searching...
No Matches
timestamp.hpp
1
#ifndef TIMESTAMP_HPP
2
#define TIMESTAMP_HPP
3
4
#include <cstdint>
5
#include <compare>
6
7
namespace
lob {
8
9
/** @brief Nanoseconds since the Unix epoch; zero is reserved as invalid. */
10
class
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
lob::Timestamp::isValid
bool isValid() const
Returns whether the timestamp is nonzero.
Definition
timestamp.hpp:25
lob::Timestamp::operator<=>
auto operator<=>(const Timestamp &other) const =default
Compares timestamps chronologically.
lob::Timestamp::Timestamp
Timestamp()
Constructs an invalid, zero-valued timestamp.
Definition
timestamp.hpp:16
lob::Timestamp::getTimestamp
std::uint64_t getTimestamp() const
Returns nanoseconds since the Unix epoch.
Definition
timestamp.hpp:22
lob::Timestamp::Timestamp
Timestamp(std::uint64_t timestamp)
Constructs a timestamp from nanoseconds since the Unix epoch.
Definition
timestamp.hpp:19
include
lob
types
timestamp.hpp
Generated by
1.18.0