Files
rippled/include/xrpl/ledger/detail/ReadViewFwdRange.h
Bart 1d42c4f6de refactor: Remove unnecessary copyright notices already covered by LICENSE.md (#5929)
Per XLS-0095, we are taking steps to rename ripple(d) to xrpl(d).

This change specifically removes all copyright notices referencing Ripple, XRPLF, and certain affiliated contributors upon mutual agreement, so the notice in the LICENSE.md file applies throughout. Copyright notices referencing external contributions remain as-is. Duplicate verbiage is also removed.
2025-11-04 08:33:42 +00:00

136 lines
2.8 KiB
C++

#ifndef XRPL_LEDGER_READVIEWFWDRANGE_H_INCLUDED
#define XRPL_LEDGER_READVIEWFWDRANGE_H_INCLUDED
#include <cstddef>
#include <memory>
#include <optional>
namespace ripple {
class ReadView;
namespace detail {
// A type-erased ForwardIterator
//
template <class ValueType>
class ReadViewFwdIter
{
public:
using base_type = ReadViewFwdIter;
using value_type = ValueType;
ReadViewFwdIter() = default;
ReadViewFwdIter(ReadViewFwdIter const&) = default;
ReadViewFwdIter&
operator=(ReadViewFwdIter const&) = default;
virtual ~ReadViewFwdIter() = default;
virtual std::unique_ptr<ReadViewFwdIter>
copy() const = 0;
virtual bool
equal(ReadViewFwdIter const& impl) const = 0;
virtual void
increment() = 0;
virtual value_type
dereference() const = 0;
};
// A range using type-erased ForwardIterator
//
template <class ValueType>
class ReadViewFwdRange
{
public:
using iter_base = ReadViewFwdIter<ValueType>;
static_assert(
std::is_nothrow_move_constructible<ValueType>{},
"ReadViewFwdRange move and move assign constructors should be "
"noexcept");
class iterator
{
public:
using value_type = ValueType;
using pointer = value_type const*;
using reference = value_type const&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
iterator() = default;
iterator(iterator const& other);
iterator(iterator&& other) noexcept;
// Used by the implementation
explicit iterator(
ReadView const* view,
std::unique_ptr<iter_base> impl);
iterator&
operator=(iterator const& other);
iterator&
operator=(iterator&& other) noexcept;
bool
operator==(iterator const& other) const;
bool
operator!=(iterator const& other) const;
// Can throw
reference
operator*() const;
// Can throw
pointer
operator->() const;
iterator&
operator++();
iterator
operator++(int);
private:
ReadView const* view_ = nullptr;
std::unique_ptr<iter_base> impl_;
std::optional<value_type> mutable cache_;
};
static_assert(std::is_nothrow_move_constructible<iterator>{}, "");
static_assert(std::is_nothrow_move_assignable<iterator>{}, "");
using const_iterator = iterator;
using value_type = ValueType;
ReadViewFwdRange() = delete;
ReadViewFwdRange(ReadViewFwdRange const&) = default;
ReadViewFwdRange&
operator=(ReadViewFwdRange const&) = default;
explicit ReadViewFwdRange(ReadView const& view) : view_(&view)
{
}
protected:
ReadView const* view_;
};
} // namespace detail
} // namespace ripple
#endif