xrpld
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::detail {
13
14// Helper class that buffers raw modifications
16{
17public:
19 // Initial size for the monotonic_buffer_resource used for allocations
20 // The size was chosen from the old `qalloc` code (which this replaces).
21 // It is unclear how the size initially chosen in qalloc.
22 static constexpr size_t kInitialBufferSize = kilobytes(256);
23
25 : monotonicResource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
28
30 : monotonicResource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
34
36
40 operator=(RawStateTable const&) = delete;
41
42 void
43 apply(RawView& to) const;
44
45 [[nodiscard]] bool
46 exists(ReadView const& base, Keylet const& k) const;
47
48 [[nodiscard]] std::optional<key_type>
49 succ(ReadView const& base, key_type const& key, std::optional<key_type> const& last) const;
50
51 void
52 erase(SLE::ref sle);
53
54 void
55 insert(SLE::ref sle);
56
57 void
58 replace(SLE::ref sle);
59
60 [[nodiscard]] SLE::const_pointer
61 read(ReadView const& base, Keylet const& k) const;
62
63 void
64 destroyXRP(XRPAmount const& fee);
65
67 slesBegin(ReadView const& base) const;
68
70 slesEnd(ReadView const& base) const;
71
73 slesUpperBound(ReadView const& base, uint256 const& key) const;
74
75private:
76 enum class Action {
80 };
81
82 class SlesIterImpl;
83
84 struct SleAction
85 {
88
89 // Constructor needed for emplacement in std::map
93 };
94
95 // Use boost::pmr functionality instead of the std::pmr
96 // functions b/c clang does not support pmr yet (as-of 9/2020)
101 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, SleAction>>>;
102 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
103 // easily moved.
106
108};
109
110} // namespace xrpl::detail
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
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const_pointer
RawStateTable & operator=(RawStateTable const &)=delete
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
bool exists(ReadView const &base, Keylet const &k) const
RawStateTable & operator=(RawStateTable &&)=delete
std::map< key_type, SleAction, std::less< key_type >, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, SleAction > > > items_t
SLE::const_pointer read(ReadView const &base, Keylet const &k) const
std::unique_ptr< ReadView::SlesType::iter_base > slesEnd(ReadView const &base) const
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonicResource_
static constexpr size_t kInitialBufferSize
void apply(RawView &to) const
std::unique_ptr< ReadView::SlesType::iter_base > slesBegin(ReadView const &base) const
ReadView::key_type key_type
RawStateTable(RawStateTable const &rhs)
std::unique_ptr< ReadView::SlesType::iter_base > slesUpperBound(ReadView const &base, uint256 const &key) const
void destroyXRP(XRPAmount const &fee)
RawStateTable(RawStateTable &&)=default
STL namespace.
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
BaseUInt< 256 > uint256
Definition base_uint.h:562
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
SleAction(Action action, SLE::pointer sle)