rippled
Loading...
Searching...
No Matches
RawStateTable.h
1#pragma once
2
3#include <xrpl/ledger/RawView.h>
4#include <xrpl/ledger/ReadView.h>
5
6#include <boost/container/pmr/monotonic_buffer_resource.hpp>
7#include <boost/container/pmr/polymorphic_allocator.hpp>
8
9#include <map>
10#include <utility>
11
12namespace xrpl {
13namespace detail {
14
15// Helper class that buffers raw modifications
17{
18public:
20 // Initial size for the monotonic_buffer_resource used for allocations
21 // The size was chosen from the old `qalloc` code (which this replaces).
22 // It is unclear how the size initially chosen in qalloc.
23 static constexpr size_t initialBufferSize = kilobytes(256);
24
27 std::make_unique<boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
29
32 std::make_unique<boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
35
37
41 operator=(RawStateTable const&) = delete;
42
43 void
44 apply(RawView& to) const;
45
46 bool
47 exists(ReadView const& base, Keylet const& k) const;
48
50 succ(ReadView const& base, key_type const& key, std::optional<key_type> const& last) const;
51
52 void
53 erase(std::shared_ptr<SLE> const& sle);
54
55 void
56 insert(std::shared_ptr<SLE> const& sle);
57
58 void
59 replace(std::shared_ptr<SLE> const& sle);
60
62 read(ReadView const& base, Keylet const& k) const;
63
64 void
65 destroyXRP(XRPAmount const& fee);
66
68 slesBegin(ReadView const& base) const;
69
71 slesEnd(ReadView const& base) const;
72
74 slesUpperBound(ReadView const& base, uint256 const& key) const;
75
76private:
77 enum class Action {
78 erase,
79 insert,
80 replace,
81 };
82
83 class sles_iter_impl;
84
85 struct sleAction
86 {
89
90 // Constructor needed for emplacement in std::map
91 sleAction(Action action_, std::shared_ptr<SLE> const& sle_) : action(action_), sle(sle_)
92 {
93 }
94 };
95
96 // Use boost::pmr functionality instead of the std::pmr
97 // functions b/c clang does not support pmr yet (as-of 9/2020)
100 sleAction,
102 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, sleAction>>>;
103 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
104 // easily moved.
107
109};
110
111} // namespace detail
112} // namespace xrpl
Interface for ledger entry changes.
Definition RawView.h:14
A view into a ledger.
Definition ReadView.h:31
uint256 key_type
Definition ReadView.h:35
RawStateTable & operator=(RawStateTable const &)=delete
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
static constexpr size_t initialBufferSize
bool exists(ReadView const &base, Keylet const &k) const
RawStateTable & operator=(RawStateTable &&)=delete
std::unique_ptr< ReadView::sles_type::iter_base > slesBegin(ReadView const &base) const
void apply(RawView &to) const
ReadView::key_type key_type
RawStateTable(RawStateTable const &rhs)
void destroyXRP(XRPAmount const &fee)
std::unique_ptr< ReadView::sles_type::iter_base > slesUpperBound(ReadView const &base, uint256 const &key) const
RawStateTable(RawStateTable &&)=default
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
std::unique_ptr< ReadView::sles_type::iter_base > slesEnd(ReadView const &base) const
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
constexpr auto kilobytes(T value) noexcept
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
sleAction(Action action_, std::shared_ptr< SLE > const &sle_)