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
order_id.hpp
1
// include/lob/types/order_id.hpp
2
#ifndef ORDER_ID_HPP
3
#define ORDER_ID_HPP
4
#include <cstdint>
5
#include <functional>
6
7
namespace
lob {
8
9
/** @brief Type-safe identifier for an order; zero is reserved as invalid. */
10
class
OrderId
{
11
private
:
12
std::uint64_t id;
13
14
public
:
15
/** Constructs an invalid, zero-valued identifier. */
16
OrderId
(): id(0){}
17
18
/** Constructs an identifier from its numeric value. */
19
OrderId
(std::uint64_t
id
): id(id){}
20
21
/** Returns the underlying numeric identifier. */
22
std::uint64_t
getId
()
const
{
return
id; }
23
24
// Overload the equality operator to compare two OrderID objects
25
bool
operator==(
const
OrderId
&other)
const
{
26
return
this->
id
== other.id;
27
};
28
29
/** Returns whether the identifier is nonzero. */
30
bool
isValid
()
const
{
31
return
id
!= 0;
32
};
33
34
// Overload the less than operator to compare two OrderID objects
35
// bool operator<(const OrderId &other) const {
36
// return this->id < other.id;
37
// };
38
39
// // Overload the greater than operator to compare two OrderID objects
40
// bool operator>(const OrderId &other) const {
41
// return this->id > other.id;
42
// };
43
44
};
45
46
}
// namespace lob
47
48
namespace
std {
49
template
<>
50
struct
hash<lob::OrderId> {
51
std::size_t operator()(
const
lob::OrderId
&orderId)
const
noexcept
{
52
return
std::hash<std::uint64_t>{}(orderId.
getId
());
53
}
54
};
55
}
56
57
#endif
// ORDER_ID_HPP
lob::OrderId
Type-safe identifier for an order; zero is reserved as invalid.
Definition
order_id.hpp:10
lob::OrderId::OrderId
OrderId(std::uint64_t id)
Constructs an identifier from its numeric value.
Definition
order_id.hpp:19
lob::OrderId::getId
std::uint64_t getId() const
Returns the underlying numeric identifier.
Definition
order_id.hpp:22
lob::OrderId::OrderId
OrderId()
Constructs an invalid, zero-valued identifier.
Definition
order_id.hpp:16
lob::OrderId::isValid
bool isValid() const
Returns whether the identifier is nonzero.
Definition
order_id.hpp:30
include
lob
types
order_id.hpp
Generated by
1.18.0