xrpld
Loading...
Searching...
No Matches
ReadViewFwdRange.h
1#pragma once
2
3#include <cstddef>
4#include <iterator>
5#include <memory>
6#include <optional>
7#include <type_traits>
8
9namespace xrpl {
10
11class ReadView;
12
13namespace detail {
14
15// A type-erased ForwardIterator
16//
17template <class ValueType>
19{
20public:
22
23 using value_type = ValueType;
24
25 ReadViewFwdIter() = default;
28 operator=(ReadViewFwdIter const&) = default;
29
30 virtual ~ReadViewFwdIter() = default;
31
32 [[nodiscard]] virtual std::unique_ptr<ReadViewFwdIter>
33 copy() const = 0;
34
35 [[nodiscard]] virtual bool
36 equal(ReadViewFwdIter const& impl) const = 0;
37
38 virtual void
39 increment() = 0;
40
41 [[nodiscard]] virtual value_type
42 dereference() const = 0;
43};
44
45// A range using type-erased ForwardIterator
46//
47template <class ValueType>
49{
50public:
52
53 static_assert(
55 "ReadViewFwdRange move and move assign constructors should be "
56 "noexcept");
57
59 {
60 public:
61 using value_type = ValueType;
62
63 using pointer = value_type const*;
64
65 using reference = value_type const&;
66
68
70
71 Iterator() = default;
72
73 Iterator(Iterator const& other);
74 Iterator(Iterator&& other) noexcept;
75
76 // Used by the implementation
77 explicit Iterator(ReadView const* view, std::unique_ptr<iter_base> impl);
78
80 operator=(Iterator const& other);
81
83 operator=(Iterator&& other) noexcept;
84
85 bool
86 operator==(Iterator const& other) const;
87
88 // Can throw
90 operator*() const;
91
92 // Can throw
94 operator->() const;
95
98
101
102 private:
103 ReadView const* view_ = nullptr;
106 };
107
110
112
113 using value_type = ValueType;
114
118 operator=(ReadViewFwdRange const&) = default;
119
120 explicit ReadViewFwdRange(ReadView const& view) : view_(&view)
121 {
122 }
123
124protected:
126};
127
128} // namespace detail
129} // namespace xrpl
A view into a ledger.
Definition ReadView.h:41
virtual ~ReadViewFwdIter()=default
virtual value_type dereference() const =0
ReadViewFwdIter(ReadViewFwdIter const &)=default
virtual std::unique_ptr< ReadViewFwdIter > copy() const =0
ReadViewFwdIter & operator=(ReadViewFwdIter const &)=default
virtual bool equal(ReadViewFwdIter const &impl) const =0
bool operator==(Iterator const &other) const
Iterator(Iterator &&other) noexcept
std::forward_iterator_tag iterator_category
Iterator(ReadView const *view, std::unique_ptr< iter_base > impl)
Iterator & operator=(Iterator const &other)
Iterator & operator=(Iterator &&other) noexcept
ReadViewFwdRange & operator=(ReadViewFwdRange const &)=default
ReadViewFwdIter< ValueType > iter_base
ReadViewFwdRange(ReadViewFwdRange const &)=default
ReadViewFwdRange(ReadView const &view)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5