xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
ledger
BookDirs.cpp
1
#include <xrpl/ledger/BookDirs.h>
2
3
#include <xrpl/beast/utility/Zero.h>
4
#include <xrpl/beast/utility/instrumentation.h>
5
#include <xrpl/ledger/ReadView.h>
6
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
7
#include <xrpl/protocol/Book.h>
8
#include <xrpl/protocol/Indexes.h>
9
10
#include <
optional
>
11
12
namespace
xrpl
{
13
14
BookDirs::BookDirs
(
ReadView
const
& view,
Book
const
& book)
15
:
view_
(&view)
16
,
root_
(
keylet
::page(
getBookBase
(book)).key)
17
,
nextQuality_
(
getQualityNext
(
root_
))
18
,
key_
(
view_
->succ(
root_
,
nextQuality_
).value_or(
beast
::kZero))
19
{
20
XRPL_ASSERT(
root_
!=
beast::kZero
,
"xrpl::BookDirs::BookDirs : nonzero root"
);
21
if
(
key_
!=
beast::kZero
)
22
{
23
if
(!
cdirFirst
(*
view_
,
key_
,
sle_
,
entry_
,
index_
))
24
{
25
// LCOV_EXCL_START
26
UNREACHABLE(
"xrpl::BookDirs::BookDirs : directory is empty"
);
27
// LCOV_EXCL_STOP
28
}
29
}
30
}
31
32
auto
33
BookDirs::begin
() const ->
BookDirs
::
const_iterator
34
{
35
auto
it =
BookDirs::const_iterator
(*
view_
,
root_
,
key_
);
36
if
(
key_
!=
beast::kZero
)
37
{
38
it.nextQuality_ =
nextQuality_
;
39
it.sle_ =
sle_
;
40
it.entry_ =
entry_
;
41
it.index_ =
index_
;
42
}
43
return
it;
44
}
45
46
auto
47
BookDirs::end
() const ->
BookDirs
::
const_iterator
48
{
49
return
BookDirs::const_iterator
(*
view_
,
root_
,
key_
);
50
}
51
52
bool
53
BookDirs::const_iterator::operator==
(
BookDirs::const_iterator
const
& other)
const
54
{
55
if
(
view_
==
nullptr
|| other.
view_
==
nullptr
)
56
return
false
;
57
58
XRPL_ASSERT(
59
view_
== other.
view_
&&
root_
== other.
root_
,
60
"xrpl::BookDirs::const_iterator::operator== : views and roots are "
61
"matching"
);
62
return
entry_
== other.
entry_
&&
curKey_
== other.
curKey_
&&
index_
== other.
index_
;
63
}
64
65
BookDirs::const_iterator::reference
66
BookDirs::const_iterator::operator*
()
const
67
{
68
XRPL_ASSERT(
69
index_
!=
beast::kZero
,
"xrpl::BookDirs::const_iterator::operator* : nonzero index"
);
70
if
(!
cache_
)
71
cache_
=
view_
->read(
keylet::offer
(
index_
));
72
return
*
cache_
;
73
}
74
75
BookDirs::const_iterator
&
76
BookDirs::const_iterator::operator++
()
77
{
78
using
beast::kZero
;
79
80
XRPL_ASSERT(
index_
!= kZero,
"xrpl::BookDirs::const_iterator::operator++ : nonzero index"
);
81
if
(!
cdirNext
(*
view_
,
curKey_
,
sle_
,
entry_
,
index_
))
82
{
83
if
(
index_
== 0)
84
curKey_
=
view_
->succ(++
curKey_
,
nextQuality_
).value_or(kZero);
85
86
if
(
index_
!= 0 ||
curKey_
== kZero)
87
{
88
curKey_
=
key_
;
89
entry_
= 0;
90
index_
= kZero;
91
}
92
else
if
(!
cdirFirst
(*
view_
,
curKey_
,
sle_
,
entry_
,
index_
))
93
{
94
// LCOV_EXCL_START
95
UNREACHABLE(
"xrpl::BookDirs::const_iterator::operator++ : directory is empty"
);
96
// LCOV_EXCL_STOP
97
}
98
}
99
100
cache_
= std::nullopt;
101
return
*
this
;
102
}
103
104
BookDirs::const_iterator
105
BookDirs::const_iterator::operator++
(
int
)
106
{
107
XRPL_ASSERT(
108
index_
!=
beast::kZero
,
"xrpl::BookDirs::const_iterator::operator++(int) : nonzero index"
);
109
const_iterator
tmp(*
this
);
110
++(*this);
111
return
tmp;
112
}
113
114
}
// namespace xrpl
xrpl::BookDirs::const_iterator
Definition
BookDirs.h:39
xrpl::BookDirs::const_iterator::nextQuality_
UInt256 nextQuality_
Definition
BookDirs.h:77
xrpl::BookDirs::const_iterator::cache_
std::optional< value_type > cache_
Definition
BookDirs.h:83
xrpl::BookDirs::const_iterator::root_
UInt256 root_
Definition
BookDirs.h:76
xrpl::BookDirs::const_iterator::curKey_
UInt256 curKey_
Definition
BookDirs.h:79
xrpl::BookDirs::const_iterator::const_iterator
const_iterator()=default
xrpl::BookDirs::const_iterator::sle_
SLE::const_pointer sle_
Definition
BookDirs.h:80
xrpl::BookDirs::const_iterator::entry_
unsigned int entry_
Definition
BookDirs.h:81
xrpl::BookDirs::const_iterator::index_
UInt256 index_
Definition
BookDirs.h:82
xrpl::BookDirs::const_iterator::key_
UInt256 key_
Definition
BookDirs.h:78
xrpl::BookDirs::const_iterator::view_
ReadView const * view_
Definition
BookDirs.h:75
xrpl::BookDirs::sle_
SLE::const_pointer sle_
Definition
BookDirs.h:21
xrpl::BookDirs::BookDirs
BookDirs(ReadView const &, Book const &)
Definition
BookDirs.cpp:14
xrpl::BookDirs::index_
UInt256 index_
Definition
BookDirs.h:23
xrpl::BookDirs::key_
UInt256 const key_
Definition
BookDirs.h:20
xrpl::BookDirs::entry_
unsigned int entry_
Definition
BookDirs.h:22
xrpl::BookDirs::nextQuality_
UInt256 const nextQuality_
Definition
BookDirs.h:19
xrpl::BookDirs::end
const_iterator end() const
Definition
BookDirs.cpp:47
xrpl::BookDirs::begin
const_iterator begin() const
Definition
BookDirs.cpp:33
xrpl::BookDirs::view_
ReadView const * view_
Definition
BookDirs.h:17
xrpl::BookDirs::root_
UInt256 const root_
Definition
BookDirs.h:18
xrpl::Book
Specifies an order book.
Definition
Book.h:28
xrpl::Dir::ConstIterator::operator++
ConstIterator & operator++()
Definition
Dir.cpp:71
xrpl::Dir::ConstIterator::reference
value_type const & reference
Definition
Dir.h:55
xrpl::Dir::ConstIterator::operator*
reference operator*() const
Definition
Dir.cpp:62
xrpl::Dir::ConstIterator::operator==
bool operator==(ConstIterator const &other) const
Definition
Dir.cpp:50
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
beast
Definition
base_uint.h:697
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl::keylet
Keylet computation functions.
Definition
Indexes.h:40
xrpl::keylet::offer
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Definition
Indexes.cpp:298
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::cdirFirst
bool cdirFirst(ReadView const &view, UInt256 const &root, SLE::const_pointer &page, unsigned int &index, UInt256 &entry)
Returns the first entry in the directory, advancing the index.
Definition
DirectoryHelpers.cpp:41
xrpl::getBookBase
UInt256 getBookBase(Book const &book)
Definition
Indexes.cpp:123
xrpl::getQualityNext
UInt256 getQualityNext(UInt256 const &uBase)
Definition
Indexes.cpp:186
xrpl::cdirNext
bool cdirNext(ReadView const &view, UInt256 const &root, SLE::const_pointer &page, unsigned int &index, UInt256 &entry)
Returns the next entry in the directory, advancing the index.
Definition
DirectoryHelpers.cpp:52
optional
Generated by
1.17.0