rippled
RawStateTable.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_LEDGER_RAWSTATETABLE_H_INCLUDED
21 #define RIPPLE_LEDGER_RAWSTATETABLE_H_INCLUDED
22 
23 #include <ripple/basics/qalloc.h>
24 #include <ripple/ledger/RawView.h>
25 #include <ripple/ledger/ReadView.h>
26 #include <map>
27 #include <utility>
28 
29 namespace ripple {
30 namespace detail {
31 
32 // Helper class that buffers raw modifications
34 {
35 public:
37 
38  RawStateTable() = default;
39  RawStateTable(RawStateTable const&) = default;
40  RawStateTable(RawStateTable&&) = default;
41 
43  operator=(RawStateTable&&) = delete;
45  operator=(RawStateTable const&) = delete;
46 
47  void
48  apply(RawView& to) const;
49 
50  bool
51  exists(ReadView const& base, Keylet const& k) const;
52 
53  boost::optional<key_type>
54  succ(
55  ReadView const& base,
56  key_type const& key,
57  boost::optional<key_type> const& last) const;
58 
59  void
60  erase(std::shared_ptr<SLE> const& sle);
61 
62  void
63  insert(std::shared_ptr<SLE> const& sle);
64 
65  void
66  replace(std::shared_ptr<SLE> const& sle);
67 
69  read(ReadView const& base, Keylet const& k) const;
70 
71  void
72  destroyXRP(XRPAmount const& fee);
73 
75  slesBegin(ReadView const& base) const;
76 
78  slesEnd(ReadView const& base) const;
79 
81  slesUpperBound(ReadView const& base, uint256 const& key) const;
82 
83 private:
84  enum class Action {
85  erase,
86  insert,
87  replace,
88  };
89 
90  class sles_iter_impl;
91 
92  using items_t = std::map<
93  key_type,
98  false>>;
99 
102 };
103 
104 } // namespace detail
105 } // namespace ripple
106 
107 #endif
ripple::detail::RawStateTable::dropsDestroyed_
XRPAmount dropsDestroyed_
Definition: RawStateTable.h:101
ripple::detail::RawStateTable::items_t
std::map< key_type, std::pair< Action, std::shared_ptr< SLE > >, std::less< key_type >, qalloc_type< std::pair< key_type const, std::pair< Action, std::shared_ptr< SLE > >>, false > > items_t
Definition: RawStateTable.h:98
ripple::detail::RawStateTable::operator=
RawStateTable & operator=(RawStateTable &&)=delete
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
std::shared_ptr
STL class.
utility
std::pair
ripple::ReadView::key_type
uint256 key_type
Definition: ReadView.h:194
ripple::detail::RawStateTable::Action::erase
@ erase
ripple::detail::RawStateTable::RawStateTable
RawStateTable()=default
ripple::detail::RawStateTable::read
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
Definition: RawStateTable.cpp:303
ripple::detail::RawStateTable::Action::replace
@ replace
std::less
ripple::qalloc_type
Definition: qalloc.h:90
ripple::base_uint< 256 >
ripple::RawView
Interface for ledger entry changes.
Definition: RawView.h:37
ripple::detail::RawStateTable::slesUpperBound
std::unique_ptr< ReadView::sles_type::iter_base > slesUpperBound(ReadView const &base, uint256 const &key) const
Definition: RawStateTable.cpp:339
ripple::detail::RawStateTable::Action::insert
@ insert
ripple::detail::RawStateTable::slesBegin
std::unique_ptr< ReadView::sles_type::iter_base > slesBegin(ReadView const &base) const
Definition: RawStateTable.cpp:325
ripple::detail::RawStateTable::Action
Action
Definition: RawStateTable.h:84
ripple::detail::RawStateTable::erase
void erase(std::shared_ptr< SLE > const &sle)
Definition: RawStateTable.cpp:230
map
ripple::detail::RawStateTable::exists
bool exists(ReadView const &base, Keylet const &k) const
Definition: RawStateTable.cpp:176
ripple::detail::RawStateTable::succ
boost::optional< key_type > succ(ReadView const &base, key_type const &key, boost::optional< key_type > const &last) const
Definition: RawStateTable.cpp:195
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:188
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::detail::RawStateTable::apply
void apply(RawView &to) const
Definition: RawStateTable.cpp:154
ripple::detail::RawStateTable::items_
items_t items_
Definition: RawStateTable.h:100
ripple::detail::RawStateTable::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition: RawStateTable.cpp:319
ripple::detail::RawStateTable::insert
void insert(std::shared_ptr< SLE > const &sle)
Definition: RawStateTable.cpp:256
ripple::detail::RawStateTable
Definition: RawStateTable.h:33
ripple::detail::RawStateTable::replace
void replace(std::shared_ptr< SLE > const &sle)
Definition: RawStateTable.cpp:281
ripple::detail::RawStateTable::key_type
ReadView::key_type key_type
Definition: RawStateTable.h:36
ripple::detail::RawStateTable::slesEnd
std::unique_ptr< ReadView::sles_type::iter_base > slesEnd(ReadView const &base) const
Definition: RawStateTable.cpp:332
std::unique_ptr
STL class.
ripple::XRPAmount
Definition: XRPAmount.h:46