SeqAn3  3.0.1
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 
17 #include <range/v3/range_fwd.hpp>
18 
19 #include <seqan3/core/platform.hpp>
20 
21 #include <seqan3/std/ranges>
22 
23 namespace seqan3::detail
24 {
25 
42 template <typename file_type>
43 class in_file_iterator
44 {
45  static_assert(!std::is_const_v<file_type>,
46  "You cannot iterate over const files, because the iterator changes the file.");
47 public:
53  using value_type = typename file_type::value_type;
56  using reference = typename file_type::reference;
58  using const_reference = typename file_type::reference;
60  using size_type = typename file_type::size_type;
62  using difference_type = typename file_type::difference_type;
64  using pointer = typename file_type::value_type *;
66  using iterator_category = std::input_iterator_tag;
68 
72  constexpr in_file_iterator() = default;
75  constexpr in_file_iterator(in_file_iterator const &) = default;
77  constexpr in_file_iterator & operator=(in_file_iterator const &) = default;
79  constexpr in_file_iterator (in_file_iterator &&) = default;
81  constexpr in_file_iterator & operator=(in_file_iterator &&) = default;
83  ~in_file_iterator() = default;
84 
86  constexpr in_file_iterator(file_type & _host) noexcept :
87  host{&_host}
88  {}
90 
94  in_file_iterator & operator++()
96  {
97  assert(host != nullptr);
98  host->read_next_record();
99  return *this;
100  }
101 
103  void operator++(int)
104  {
105  assert(host != nullptr);
106  ++(*this);
107  }
108 
110  reference operator*() noexcept
111  {
112  assert(host != nullptr);
113  return host->record_buffer;
114  }
115 
117  reference operator*() const noexcept
118  {
119  assert(host != nullptr);
120  return host->record_buffer;
121  }
123 
129  constexpr bool operator==(std::ranges::default_sentinel_t const &) const noexcept
131  {
132  assert(host != nullptr);
133  return host->at_end;
134  }
135 
137  constexpr bool operator!=(std::ranges::default_sentinel_t const &) const noexcept
138  {
139  assert(host != nullptr);
140  return !host->at_end;
141  }
142 
144  constexpr friend bool operator==(std::ranges::default_sentinel_t const &,
145  in_file_iterator const & it) noexcept
146  {
147  return (it == std::ranges::default_sentinel);
148  }
149 
151  constexpr friend bool operator!=(std::ranges::default_sentinel_t const &,
152  in_file_iterator const & it) noexcept
153  {
154  return (it != std::ranges::default_sentinel);
155  }
157 
158 private:
160  file_type * host{};
161 };
162 
163 } // 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