rippled
Loading...
Searching...
No Matches
ReadViewFwdRange.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_READVIEWFWDRANGE_H_INCLUDED
21#define RIPPLE_LEDGER_READVIEWFWDRANGE_H_INCLUDED
22
23#include <cstddef>
24#include <memory>
25#include <optional>
26
27namespace ripple {
28
29class ReadView;
30
31namespace detail {
32
33// A type-erased ForwardIterator
34//
35template <class ValueType>
37{
38public:
40
41 using value_type = ValueType;
42
43 ReadViewFwdIter() = default;
46 operator=(ReadViewFwdIter const&) = default;
47
48 virtual ~ReadViewFwdIter() = default;
49
51 copy() const = 0;
52
53 virtual bool
54 equal(ReadViewFwdIter const& impl) const = 0;
55
56 virtual void
57 increment() = 0;
58
59 virtual value_type
60 dereference() const = 0;
61};
62
63// A range using type-erased ForwardIterator
64//
65template <class ValueType>
67{
68public:
70
71 static_assert(
73 "ReadViewFwdRange move and move assign constructors should be "
74 "noexcept");
75
77 {
78 public:
79 using value_type = ValueType;
80
81 using pointer = value_type const*;
82
83 using reference = value_type const&;
84
86
88
89 iterator() = default;
90
91 iterator(iterator const& other);
92 iterator(iterator&& other) noexcept;
93
94 // Used by the implementation
95 explicit iterator(
96 ReadView const* view,
98
100 operator=(iterator const& other);
101
102 iterator&
103 operator=(iterator&& other) noexcept;
104
105 bool
106 operator==(iterator const& other) const;
107
108 bool
109 operator!=(iterator const& other) const;
110
111 // Can throw
113 operator*() const;
114
115 // Can throw
116 pointer
117 operator->() const;
118
119 iterator&
121
124
125 private:
126 ReadView const* view_ = nullptr;
129 };
130
133
135
136 using value_type = ValueType;
137
141 operator=(ReadViewFwdRange const&) = default;
142
143 explicit ReadViewFwdRange(ReadView const& view) : view_(&view)
144 {
145 }
146
147protected:
149};
150
151} // namespace detail
152} // namespace ripple
153
154#endif
A view into a ledger.
Definition ReadView.h:51
virtual value_type dereference() const =0
virtual std::unique_ptr< ReadViewFwdIter > copy() const =0
virtual ~ReadViewFwdIter()=default
ReadViewFwdIter(ReadViewFwdIter const &)=default
virtual bool equal(ReadViewFwdIter const &impl) const =0
ReadViewFwdIter & operator=(ReadViewFwdIter const &)=default
iterator(ReadView const *view, std::unique_ptr< iter_base > impl)
iterator & operator=(iterator const &other)
iterator & operator=(iterator &&other) noexcept
iterator(iterator &&other) noexcept
bool operator!=(iterator const &other) const
bool operator==(iterator const &other) const
ReadViewFwdRange(ReadViewFwdRange const &)=default
ReadViewFwdRange & operator=(ReadViewFwdRange const &)=default
ReadViewFwdRange(ReadView const &view)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25