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 <iterator>
25#include <memory>
26#include <optional>
27
28namespace ripple {
29
30class ReadView;
31
32namespace detail {
33
34// A type-erased ForwardIterator
35//
36template <class ValueType>
38{
39public:
41
42 using value_type = ValueType;
43
44 ReadViewFwdIter() = default;
47 operator=(ReadViewFwdIter const&) = default;
48
49 virtual ~ReadViewFwdIter() = default;
50
52 copy() const = 0;
53
54 virtual bool
55 equal(ReadViewFwdIter const& impl) const = 0;
56
57 virtual void
58 increment() = 0;
59
60 virtual value_type
61 dereference() const = 0;
62};
63
64// A range using type-erased ForwardIterator
65//
66template <class ValueType>
68{
69public:
71
72 static_assert(
74 "ReadViewFwdRange move and move assign constructors should be "
75 "noexcept");
76
78 {
79 public:
80 using value_type = ValueType;
81
82 using pointer = value_type const*;
83
84 using reference = value_type const&;
85
87
89
90 iterator() = default;
91
92 iterator(iterator const& other);
93 iterator(iterator&& other) noexcept;
94
95 // Used by the implementation
96 explicit iterator(
97 ReadView const* view,
99
100 iterator&
101 operator=(iterator const& other);
102
103 iterator&
104 operator=(iterator&& other) noexcept;
105
106 bool
107 operator==(iterator const& other) const;
108
109 bool
110 operator!=(iterator const& other) const;
111
112 // Can throw
114 operator*() const;
115
116 // Can throw
117 pointer
118 operator->() const;
119
120 iterator&
122
125
126 private:
127 ReadView const* view_ = nullptr;
130 };
131
134
136
137 using value_type = ValueType;
138
142 operator=(ReadViewFwdRange const&) = default;
143
144 explicit ReadViewFwdRange(ReadView const& view) : view_(&view)
145 {
146 }
147
148protected:
150};
151
152} // namespace detail
153} // namespace ripple
154
155#endif
A view into a ledger.
Definition: ReadView.h:55
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:26