Loading...
Searching...
No Matches
algorithm_result_generator_range.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <cassert>
#include <concepts>
#include <memory>
#include <ranges>
#include <seqan3/core/platform.hpp>
namespace seqan3
{
template <typename algorithm_executor_type>
class algorithm_result_generator_range
{
static_assert(!std::is_const_v<algorithm_executor_type>, "Cannot create an algorithm stream over a const buffer.");
using optional_type = decltype(std::declval<algorithm_executor_type>().next_result());
using algorithm_result_type = typename optional_type::value_type;
class algorithm_range_iterator;
friend class algorithm_range_iterator;
public:
algorithm_result_generator_range() = default;
algorithm_result_generator_range(algorithm_result_generator_range const &) = delete;
algorithm_result_generator_range(algorithm_result_generator_range &&) = default;
algorithm_result_generator_range &
operator=(algorithm_result_generator_range const &) = delete;
algorithm_result_generator_range & operator=(algorithm_result_generator_range &&) = default;
~algorithm_result_generator_range() = default;
explicit algorithm_result_generator_range(algorithm_executor_type const & algorithm_executor) = delete;
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START(-Warray-bounds)
explicit algorithm_result_generator_range(algorithm_executor_type && algorithm_executor) :
algorithm_executor_ptr{std::make_unique<algorithm_executor_type>(std::move(algorithm_executor))}
{}
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
constexpr algorithm_range_iterator begin()
{
return algorithm_range_iterator{*this};
}
algorithm_range_iterator begin() const = delete;
constexpr std::default_sentinel_t end() noexcept
{
return std::default_sentinel;
}
constexpr std::default_sentinel_t end() const = delete;
protected:
bool next()
{
if (!algorithm_executor_ptr)
throw std::runtime_error{"No algorithm execution buffer available."};
if (auto opt = algorithm_executor_ptr->next_result(); opt.has_value())
{
cache = std::move(*opt);
return true;
}
return false;
}
private:
std::unique_ptr<algorithm_executor_type> algorithm_executor_ptr{};
algorithm_result_type cache{};
};
template <typename algorithm_executor_type>
algorithm_result_generator_range(algorithm_executor_type &&)
-> algorithm_result_generator_range<std::remove_reference_t<algorithm_executor_type>>;
template <typename algorithm_executor_type>
class algorithm_result_generator_range<algorithm_executor_type>::algorithm_range_iterator
{
public:
using difference_type = std::ptrdiff_t;
using value_type = algorithm_result_type;
using reference = std::add_lvalue_reference_t<value_type>;
using pointer = std::add_pointer_t<value_type>;
using iterator_category = std::input_iterator_tag;
constexpr algorithm_range_iterator() noexcept = default;
constexpr algorithm_range_iterator(algorithm_range_iterator const &) noexcept = default;
constexpr algorithm_range_iterator(algorithm_range_iterator &&) noexcept = default;
constexpr algorithm_range_iterator & operator=(algorithm_range_iterator const &) noexcept = default;
constexpr algorithm_range_iterator & operator=(algorithm_range_iterator &&) noexcept = default;
~algorithm_range_iterator() = default;
explicit constexpr algorithm_range_iterator(algorithm_result_generator_range & range) :
range_ptr(std::addressof(range))
{
++(*this); // Fetch the next element.
}
reference operator*() const noexcept
{
return range_ptr->cache;
}
pointer operator->() const noexcept
{
return &range_ptr->cache;
}
algorithm_range_iterator & operator++(/*pre*/)
{
assert(range_ptr != nullptr);
at_end = !range_ptr->next();
return *this;
}
void operator++(int /*post*/)
{
++(*this);
}
friend constexpr bool operator==(algorithm_range_iterator const & lhs, std::default_sentinel_t const &) noexcept
{
return lhs.at_end;
}
friend constexpr bool operator==(std::default_sentinel_t const & lhs, algorithm_range_iterator const & rhs) noexcept
{
return rhs == lhs;
}
friend constexpr bool operator!=(algorithm_range_iterator const & lhs, std::default_sentinel_t const & rhs) noexcept
{
return !(lhs == rhs);
}
friend constexpr bool operator!=(std::default_sentinel_t const & lhs, algorithm_range_iterator const & rhs) noexcept
{
return rhs != lhs;
}
private:
algorithm_result_generator_range * range_ptr{};
bool at_end{true};
};
} // namespace seqan3
std::add_pointer_t
std::add_lvalue_reference_t
cassert
seqan3::algorithm_result_generator_range::algorithm_range_iterator
The iterator of seqan3::detail::algorithm_result_generator_range.
Definition algorithm_result_generator_range.hpp:170
seqan3::algorithm_result_generator_range::algorithm_range_iterator::iterator_category
std::input_iterator_tag iterator_category
Sets iterator category as input iterator.
Definition algorithm_result_generator_range.hpp:184
seqan3::algorithm_result_generator_range::algorithm_range_iterator::algorithm_range_iterator
constexpr algorithm_range_iterator() noexcept=default
Defaulted.
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator++
algorithm_range_iterator & operator++()
Increments the iterator by one.
Definition algorithm_result_generator_range.hpp:229
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator==
friend constexpr bool operator==(algorithm_range_iterator const &lhs, std::default_sentinel_t const &) noexcept
Checks whether lhs is equal to the sentinel.
Definition algorithm_result_generator_range.hpp:248
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator++
void operator++(int)
Returns an iterator incremented by one.
Definition algorithm_result_generator_range.hpp:238
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator*
reference operator*() const noexcept
Access the pointed-to element.
Definition algorithm_result_generator_range.hpp:213
seqan3::algorithm_result_generator_range::algorithm_range_iterator::pointer
std::add_pointer_t< value_type > pointer
Pointer type is pointer of container element type.
Definition algorithm_result_generator_range.hpp:182
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator==
friend constexpr bool operator==(std::default_sentinel_t const &lhs, algorithm_range_iterator const &rhs) noexcept
Checks whether lhs is equal to rhs.
Definition algorithm_result_generator_range.hpp:254
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator!=
friend constexpr bool operator!=(std::default_sentinel_t const &lhs, algorithm_range_iterator const &rhs) noexcept
Checks whether lhs is not equal to rhs.
Definition algorithm_result_generator_range.hpp:266
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator!=
friend constexpr bool operator!=(algorithm_range_iterator const &lhs, std::default_sentinel_t const &rhs) noexcept
Checks whether *this is not equal to the sentinel.
Definition algorithm_result_generator_range.hpp:260
seqan3::algorithm_result_generator_range::algorithm_range_iterator::difference_type
std::ptrdiff_t difference_type
Type for distances between iterators.
Definition algorithm_result_generator_range.hpp:176
seqan3::algorithm_result_generator_range::algorithm_range_iterator::value_type
algorithm_result_type value_type
Value type of container elements.
Definition algorithm_result_generator_range.hpp:178
seqan3::algorithm_result_generator_range::algorithm_range_iterator::reference
std::add_lvalue_reference_t< value_type > reference
Use reference type defined by container.
Definition algorithm_result_generator_range.hpp:180
seqan3::algorithm_result_generator_range::algorithm_range_iterator::operator->
pointer operator->() const noexcept
Returns a pointer to the current algorithm result.
Definition algorithm_result_generator_range.hpp:219
seqan3::algorithm_result_generator_range::end
constexpr std::default_sentinel_t end() noexcept
Returns a sentinel signaling the end of the algorithm range.
Definition algorithm_result_generator_range.hpp:115
seqan3::algorithm_result_generator_range::end
constexpr std::default_sentinel_t end() const =delete
This range is not const-iterable.
seqan3::algorithm_result_generator_range::algorithm_result_generator_range
algorithm_result_generator_range(algorithm_executor_type const &algorithm_executor)=delete
Explicit deletion to forbid copy construction of the underlying executor.
seqan3::algorithm_result_generator_range::operator=
algorithm_result_generator_range & operator=(algorithm_result_generator_range &&)=default
Defaulted.
seqan3::algorithm_result_generator_range::algorithm_result_generator_range
algorithm_result_generator_range(algorithm_result_generator_range &&)=default
Defaulted.
seqan3::algorithm_result_generator_range::algorithm_result_generator_range
algorithm_result_generator_range(algorithm_result_generator_range const &)=delete
This is a move-only type.
seqan3::algorithm_result_generator_range::operator=
algorithm_result_generator_range & operator=(algorithm_result_generator_range const &)=delete
This is a move-only type.
seqan3::algorithm_result_generator_range::next
bool next()
Receives the next algorithm result from the executor buffer.
Definition algorithm_result_generator_range.hpp:133
seqan3::algorithm_result_generator_range::begin
algorithm_range_iterator begin() const =delete
This range is not const-iterable.
seqan3::algorithm_result_generator_range::algorithm_result_generator_range
algorithm_result_generator_range()=default
Defaulted.
seqan3::algorithm_result_generator_range::begin
constexpr algorithm_range_iterator begin()
Returns an iterator to the first element of the algorithm range.
Definition algorithm_result_generator_range.hpp:99
seqan3::algorithm_result_generator_range::algorithm_result_generator_range
algorithm_result_generator_range(algorithm_executor_type &&) -> algorithm_result_generator_range< std::remove_reference_t< algorithm_executor_type > >
Deduces from the passed algorithm_executor_type.
seqan3::algorithm_result_generator_range::~algorithm_result_generator_range
~algorithm_result_generator_range()=default
Defaulted.
std::declval
T declval(T... args)
std::is_const_v
T is_const_v
std::input_iterator_tag
std::make_unique
T make_unique(T... args)
memory
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
std
SeqAn specific customisations in the standard namespace.
platform.hpp
Provides platform and dependency checks.
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START
#define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START(...)
Denotes the start of a block where diagnostics are ignored.
Definition platform.hpp:268
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
#define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
Denotes the end of a block where diagnostics are ignored.
Definition platform.hpp:277
std::ptrdiff_t
std::runtime_error
std::unique_ptr
Hide me