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
quantity.hpp
1
#ifndef QUANTITY_HPP
2
#define QUANTITY_HPP
3
#include <cstdint>
4
#include <compare>
5
6
namespace
lob {
7
/** @brief Type-safe unsigned order quantity; zero represents a filled state. */
8
class
Quantity
{
9
private
:
10
std::uint64_t quantity;
11
12
public
:
13
/** Constructs a zero quantity. */
14
Quantity
(): quantity(0){}
15
16
/** Constructs a quantity from its numeric value. */
17
Quantity
(std::uint64_t quantity): quantity(quantity){}
18
19
/** Returns the underlying numeric quantity. */
20
std::uint64_t
getQuantity
()
const
{
return
quantity;};
21
22
/** Returns whether the quantity is valid for a submitted order. */
23
bool
isValid
()
const
{
24
return
quantity != 0;
25
};
26
27
/** Compares quantities by numeric value. */
28
auto
operator<=>
(
const
Quantity
&other)
const
=
default
;
29
/** Adds quantities while preserving the Quantity type. */
30
Quantity
operator+
(
const
Quantity
&other)
const
{
31
return
Quantity
{this->quantity + other.quantity};
32
};
33
34
};
35
}
// namespace lob
36
#endif
lob::Quantity::Quantity
Quantity()
Constructs a zero quantity.
Definition
quantity.hpp:14
lob::Quantity::isValid
bool isValid() const
Returns whether the quantity is valid for a submitted order.
Definition
quantity.hpp:23
lob::Quantity::Quantity
Quantity(std::uint64_t quantity)
Constructs a quantity from its numeric value.
Definition
quantity.hpp:17
lob::Quantity::operator+
Quantity operator+(const Quantity &other) const
Adds quantities while preserving the Quantity type.
Definition
quantity.hpp:30
lob::Quantity::getQuantity
std::uint64_t getQuantity() const
Returns the underlying numeric quantity.
Definition
quantity.hpp:20
lob::Quantity::operator<=>
auto operator<=>(const Quantity &other) const =default
Compares quantities by numeric value.
include
lob
types
quantity.hpp
Generated by
1.18.0