xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
protocol
SeqProxy.h
1
#pragma once
2
3
#include <
cstdint
>
4
#include <
ostream
>
5
6
namespace
xrpl
{
7
36
class
SeqProxy
37
{
38
public
:
39
enum class
Type
:
std::uint8_t
{
Seq
= 0,
Ticket
};
40
41
private
:
42
std::uint32_t
value_
;
43
Type
type_
;
44
45
public
:
46
constexpr
explicit
SeqProxy
(
Type
t,
std::uint32_t
v) :
value_
{v},
type_
{t}
47
{
48
}
49
50
SeqProxy
(
SeqProxy
const
& other) =
default
;
51
52
SeqProxy
&
53
operator=
(
SeqProxy
const
& other) =
default
;
54
61
static
constexpr
SeqProxy
62
rawSequence
(
std::uint32_t
v)
63
{
64
return
SeqProxy
{
Type::Seq
, v};
65
}
66
73
static
constexpr
SeqProxy
74
rawTicket
(
std::uint32_t
v)
75
{
76
return
SeqProxy
{
Type::Ticket
, v};
77
}
78
79
[[nodiscard]]
constexpr
std::uint32_t
80
value
()
const
81
{
82
return
value_
;
83
}
84
85
[[nodiscard]]
constexpr
bool
86
isSeq
()
const
87
{
88
return
type_
==
Type::Seq
;
89
}
90
91
[[nodiscard]]
constexpr
bool
92
isTicket
()
const
93
{
94
return
type_
==
Type::Ticket
;
95
}
96
97
// Occasionally it is convenient to be able to increase the value_
98
// of a SeqProxy. But it's unusual. So, rather than putting in an
99
// addition operator, you must invoke the method by name. That makes
100
// if more difficult to invoke accidentally.
101
SeqProxy
&
102
advanceBy
(
std::uint32_t
amount)
103
{
104
value_
+= amount;
105
return
*
this
;
106
}
107
108
// Comparison
109
//
110
// The comparison is designed specifically so _all_ Sequence
111
// representations sort in front of Ticket representations. This
112
// is true even if the Ticket value() is less that the Sequence
113
// value().
114
//
115
// This somewhat surprising sort order has benefits for transaction
116
// processing. It guarantees that transactions creating Tickets are
117
// sorted in from of transactions that consume Tickets.
118
friend
constexpr
bool
119
operator==
(
SeqProxy
lhs,
SeqProxy
rhs)
120
{
121
if
(lhs.
type_
!= rhs.
type_
)
122
return
false
;
123
return
(lhs.
value
() == rhs.
value
());
124
}
125
126
friend
constexpr
bool
127
operator<
(
SeqProxy
lhs,
SeqProxy
rhs)
128
{
129
if
(lhs.
type_
!= rhs.
type_
)
130
return
lhs.
type_
< rhs.
type_
;
131
return
lhs.
value
() < rhs.
value
();
132
}
133
134
friend
constexpr
bool
135
operator>
(
SeqProxy
lhs,
SeqProxy
rhs)
136
{
137
return
rhs < lhs;
138
}
139
140
friend
constexpr
bool
141
operator>=
(
SeqProxy
lhs,
SeqProxy
rhs)
142
{
143
return
!(lhs < rhs);
144
}
145
146
friend
constexpr
bool
147
operator<=
(
SeqProxy
lhs,
SeqProxy
rhs)
148
{
149
return
!(lhs > rhs);
150
}
151
152
friend
std::ostream
&
153
operator<<
(
std::ostream
& os,
SeqProxy
seqProx)
154
{
155
os << (seqProx.
isSeq
() ?
"sequence "
:
"ticket "
);
156
os << seqProx.
value
();
157
return
os;
158
}
159
};
160
}
// namespace xrpl
std::ostream
xrpl::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition
SeqProxy.h:37
xrpl::SeqProxy::Type
Type
Definition
SeqProxy.h:39
xrpl::SeqProxy::Type::Seq
@ Seq
Definition
SeqProxy.h:39
xrpl::SeqProxy::Type::Ticket
@ Ticket
Definition
SeqProxy.h:39
xrpl::SeqProxy::operator<
friend constexpr bool operator<(SeqProxy lhs, SeqProxy rhs)
Definition
SeqProxy.h:127
xrpl::SeqProxy::value_
std::uint32_t value_
Definition
SeqProxy.h:42
xrpl::SeqProxy::operator>
friend constexpr bool operator>(SeqProxy lhs, SeqProxy rhs)
Definition
SeqProxy.h:135
xrpl::SeqProxy::rawSequence
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition
SeqProxy.h:62
xrpl::SeqProxy::SeqProxy
constexpr SeqProxy(Type t, std::uint32_t v)
Definition
SeqProxy.h:46
xrpl::SeqProxy::operator=
SeqProxy & operator=(SeqProxy const &other)=default
xrpl::SeqProxy::operator>=
friend constexpr bool operator>=(SeqProxy lhs, SeqProxy rhs)
Definition
SeqProxy.h:141
xrpl::SeqProxy::operator==
friend constexpr bool operator==(SeqProxy lhs, SeqProxy rhs)
Definition
SeqProxy.h:119
xrpl::SeqProxy::SeqProxy
SeqProxy(SeqProxy const &other)=default
xrpl::SeqProxy::type_
Type type_
Definition
SeqProxy.h:43
xrpl::SeqProxy::isTicket
constexpr bool isTicket() const
Definition
SeqProxy.h:92
xrpl::SeqProxy::operator<<
friend std::ostream & operator<<(std::ostream &os, SeqProxy seqProx)
Definition
SeqProxy.h:153
xrpl::SeqProxy::advanceBy
SeqProxy & advanceBy(std::uint32_t amount)
Definition
SeqProxy.h:102
xrpl::SeqProxy::rawTicket
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
Definition
SeqProxy.h:74
xrpl::SeqProxy::operator<=
friend constexpr bool operator<=(SeqProxy lhs, SeqProxy rhs)
Definition
SeqProxy.h:147
xrpl::SeqProxy::value
constexpr std::uint32_t value() const
Definition
SeqProxy.h:80
xrpl::SeqProxy::isSeq
constexpr bool isSeq() const
Definition
SeqProxy.h:86
cstdint
std::uint8_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
ostream
Generated by
1.17.0