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
26 : monotonic_resource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
28
30 : monotonic_resource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(initialBufferSize)}
33
35
39 operator=(RawStateTable const&) = delete;
40
41 void
42 apply(RawView& to) const;
43
44 bool
45 exists(ReadView const& base, Keylet const& k) const;
46
48 succ(ReadView const& base, key_type const& key, std::optional<key_type> const& last) const;
49
50 void
51 erase(std::shared_ptr<SLE> const& sle);
52
53 void
54 insert(std::shared_ptr<SLE> const& sle);
55
56 void
57 replace(std::shared_ptr<SLE> const& sle);
58
60 read(ReadView const& base, Keylet const& k) const;
61
62 void
63 destroyXRP(XRPAmount const& fee);
64
66 slesBegin(ReadView const& base) const;
67
69 slesEnd(ReadView const& base) const;
70
72 slesUpperBound(ReadView const& base, uint256 const& key) const;
73
74private:
75 enum class Action {
76 erase,
77 insert,
78 replace,
79 };
80
81 class sles_iter_impl;
82
83 struct sleAction
84 {
87
88 // Constructor needed for emplacement in std::map
89 sleAction(Action action_, std::shared_ptr<SLE> const& sle_) : action(action_), sle(sle_)
90 {
91 }
92 };
93
94 // Use boost::pmr functionality instead of the std::pmr
95 // functions b/c clang does not support pmr yet (as-of 9/2020)
100 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, sleAction>>>;
101 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
102 // easily moved.
105
107};
108
109} // namespace detail
110} // 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_)