SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
in_file_iterator.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <cassert>
16 #include <seqan3/std/ranges>
17 
18 #include <seqan3/core/platform.hpp>
19 
20 namespace seqan3::detail
21 {
22 
39 template <typename file_type>
40 class in_file_iterator
41 {
42  static_assert(!std::is_const_v<file_type>,
43  "You cannot iterate over const files, because the iterator changes the file.");
44 public:
50  using value_type = typename file_type::value_type;
53  using reference = typename file_type::reference;
55  using const_reference = typename file_type::reference;
57  using size_type = typename file_type::size_type;
59  using difference_type = typename file_type::difference_type;
61  using pointer = typename file_type::value_type *;
63  using iterator_category = std::input_iterator_tag;
65 
69  constexpr in_file_iterator() = default;
72  constexpr in_file_iterator(in_file_iterator const &) = default;
74  constexpr in_file_iterator & operator=(in_file_iterator const &) = default;
76  constexpr in_file_iterator (in_file_iterator &&) = default;
78  constexpr in_file_iterator & operator=(in_file_iterator &&) = default;
80  ~in_file_iterator() = default;
81 
83  constexpr in_file_iterator(file_type & _host) noexcept :
84  host{&_host}
85  {}
87 
91  in_file_iterator & operator++()
93  {
94  assert(host != nullptr);
95  host->read_next_record();
96  return *this;
97  }
98 
100  void operator++(int)
101  {
102  assert(host != nullptr);
103  ++(*this);
104  }
105 
107  reference operator*() noexcept
108  {
109  assert(host != nullptr);
110  return host->record_buffer;
111  }
112 
114  reference operator*() const noexcept
115  {
116  assert(host != nullptr);
117  return host->record_buffer;
118  }
120 
126  constexpr bool operator==(std::default_sentinel_t const &) const noexcept
128  {
129  assert(host != nullptr);
130  return host->at_end;
131  }
132 
134  constexpr bool operator!=(std::default_sentinel_t const &) const noexcept
135  {
136  assert(host != nullptr);
137  return !host->at_end;
138  }
139 
141  constexpr friend bool operator==(std::default_sentinel_t const &,
142  in_file_iterator const & it) noexcept
143  {
144  return (it == std::default_sentinel);
145  }
146 
148  constexpr friend bool operator!=(std::default_sentinel_t const &,
149  in_file_iterator const & it) noexcept
150  {
151  return (it != std::default_sentinel);
152  }
154 
155 private:
157  file_type * host{};
158 };
159 
160 } // namespace seqan3::detail
std::rel_ops::operator!=
T operator!=(T... args)
std::input_iterator_tag
ranges
Adaptations of concepts from the Ranges TS.
platform.hpp
Provides platform and dependency checks.
cassert