Loading...
Searching...
No Matches
in_file_iterator.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 <ios>
#include <ranges>
#include <seqan3/core/platform.hpp>
namespace seqan3::detail
{
template <typename file_type>
class in_file_iterator
{
static_assert(!std::is_const_v<file_type>,
"You cannot iterate over const files, because the iterator changes the file.");
public:
using value_type = typename file_type::value_type;
using reference = typename file_type::reference;
using const_reference = typename file_type::reference;
using size_type = typename file_type::size_type;
using difference_type = typename file_type::difference_type;
using pointer = typename file_type::value_type *;
using iterator_category = std::input_iterator_tag;
constexpr in_file_iterator() = default;
constexpr in_file_iterator(in_file_iterator const &) = default;
constexpr in_file_iterator & operator=(in_file_iterator const &) = default;
constexpr in_file_iterator(in_file_iterator &&) = default;
constexpr in_file_iterator & operator=(in_file_iterator &&) = default;
~in_file_iterator() = default;
constexpr in_file_iterator(file_type & _host) noexcept : host{&_host}
{}
in_file_iterator & operator++()
{
assert(host != nullptr);
host->read_next_record();
return *this;
}
void operator++(int)
{
assert(host != nullptr);
++(*this);
}
reference operator*() noexcept
{
assert(host != nullptr);
return host->record_buffer;
}
reference operator*() const noexcept
{
assert(host != nullptr);
return host->record_buffer;
}
constexpr bool operator==(std::default_sentinel_t const &) const noexcept
{
assert(host != nullptr);
return host->at_end;
}
constexpr bool operator!=(std::default_sentinel_t const &) const noexcept
{
assert(host != nullptr);
return !host->at_end;
}
constexpr friend bool operator==(std::default_sentinel_t const &, in_file_iterator const & it) noexcept
{
return (it == std::default_sentinel);
}
constexpr friend bool operator!=(std::default_sentinel_t const &, in_file_iterator const & it) noexcept
{
return (it != std::default_sentinel);
}
std::streampos file_position() const
{
assert(host != nullptr);
return host->position_buffer;
}
in_file_iterator & seek_to(std::streampos const & pos)
{
assert(host != nullptr);
host->secondary_stream->seekg(pos);
if (host->secondary_stream->fail())
{
throw std::runtime_error{"Seeking to file position failed!"};
}
host->at_end = false; // iterator will not be at end if seeking to a specific record
host->read_next_record();
return *this;
}
private:
file_type * host{};
};
} // namespace seqan3::detail
cassert
ios
std::is_const_v
T is_const_v
platform.hpp
Provides platform and dependency checks.
Hide me