SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
advanceable_alignment_coordinate.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <concepts>
13#include <iterator>
14#include <type_traits>
15
21
22namespace seqan3::detail
23{
24
36enum struct advanceable_alignment_coordinate_state : uint8_t
37{
39 none,
41 column,
43 row
44};
45
61template <advanceable_alignment_coordinate_state state = advanceable_alignment_coordinate_state::none>
62class advanceable_alignment_coordinate
63{
64public:
70 using difference_type = std::make_signed_t<size_t>;
72
76 constexpr advanceable_alignment_coordinate() noexcept = default;
78 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate const &) noexcept = default;
79 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate &&) noexcept = default;
81 constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate const &) noexcept = default;
83 constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate &&) noexcept = default;
84 ~advanceable_alignment_coordinate() noexcept = default;
85
87 template <advanceable_alignment_coordinate_state other_state>
88 requires (other_state != state)
89 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> const & other) :
90 first{other.first},
91 second{other.second}
92 {}
93
95 template <advanceable_alignment_coordinate_state other_state>
96 requires (other_state != state)
97 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> && other) :
98 first{std::move(other.first)},
99 second{std::move(other.second)}
100 {}
101
106 constexpr advanceable_alignment_coordinate(column_index_type<size_t> const c_idx,
107 row_index_type<size_t> const r_idx) noexcept :
108 first{c_idx.get()},
109 second{r_idx.get()}
110 {}
112
114 constexpr friend bool operator==(advanceable_alignment_coordinate const & lhs,
115 advanceable_alignment_coordinate const & rhs) noexcept
116 {
117 return std::tie(lhs.first, lhs.second) == std::tie(rhs.first, rhs.second);
118 }
119
120 constexpr friend bool operator!=(advanceable_alignment_coordinate const & lhs,
121 advanceable_alignment_coordinate const & rhs) noexcept
122 {
123 return std::tie(lhs.first, lhs.second) != std::tie(rhs.first, rhs.second);
124 }
125
126 constexpr friend bool operator<=(advanceable_alignment_coordinate const & lhs,
127 advanceable_alignment_coordinate const & rhs) noexcept
128 {
129 return std::tie(lhs.first, lhs.second) <= std::tie(rhs.first, rhs.second);
130 }
131
132 constexpr friend bool operator<(advanceable_alignment_coordinate const & lhs,
133 advanceable_alignment_coordinate const & rhs) noexcept
134 {
135 return std::tie(lhs.first, lhs.second) < std::tie(rhs.first, rhs.second);
136 }
137
138 constexpr friend bool operator>=(advanceable_alignment_coordinate const & lhs,
139 advanceable_alignment_coordinate const & rhs) noexcept
140 {
141 return std::tie(lhs.first, lhs.second) >= std::tie(rhs.first, rhs.second);
142 }
143
144 constexpr friend bool operator>(advanceable_alignment_coordinate const & lhs,
145 advanceable_alignment_coordinate const & rhs) noexcept
146 {
147 return std::tie(lhs.first, lhs.second) > std::tie(rhs.first, rhs.second);
148 }
150
161 constexpr advanceable_alignment_coordinate & operator++(/*pre-increment*/) noexcept
162 requires (state != advanceable_alignment_coordinate_state::none)
163 {
164 if constexpr (state == advanceable_alignment_coordinate_state::column)
165 ++this->first;
166 else
167 ++this->second;
168 return *this;
169 }
170
174 constexpr advanceable_alignment_coordinate operator++(int /*post-increment*/) noexcept
175 requires (state != advanceable_alignment_coordinate_state::none)
176 {
177 advanceable_alignment_coordinate tmp{*this};
178 ++(*this);
179 return tmp;
180 }
181
185 constexpr advanceable_alignment_coordinate & operator--(/*pre-decrement*/) noexcept
186 requires (state != advanceable_alignment_coordinate_state::none)
187 {
188 if constexpr (state == advanceable_alignment_coordinate_state::column)
189 --this->first;
190 else
191 --this->second;
192 return *this;
193 }
194
198 constexpr advanceable_alignment_coordinate operator--(int /*post-decrement*/) noexcept
199 requires (state != advanceable_alignment_coordinate_state::none)
200 {
201 advanceable_alignment_coordinate tmp{*this};
202 --(*this);
203 return tmp;
204 }
205
210 constexpr advanceable_alignment_coordinate & operator+=(difference_type const offset) noexcept
211 requires (state != advanceable_alignment_coordinate_state::none)
212 {
213 if constexpr (state == advanceable_alignment_coordinate_state::column)
214 this->first += offset;
215 else
216 this->second += offset;
217 return *this;
218 }
219
224 constexpr advanceable_alignment_coordinate & operator-=(difference_type const offset) noexcept
225 requires (state != advanceable_alignment_coordinate_state::none)
226 {
227 if constexpr (state == advanceable_alignment_coordinate_state::column)
228 this->first -= offset;
229 else
230 this->second -= offset;
231 return *this;
232 }
233
238 constexpr advanceable_alignment_coordinate operator+(difference_type const offset) const noexcept
239 requires (state != advanceable_alignment_coordinate_state::none)
240 {
241 advanceable_alignment_coordinate tmp{*this};
242 tmp += offset;
243 return tmp;
244 }
245
250 constexpr advanceable_alignment_coordinate operator-(difference_type const offset) const noexcept
251 requires (state != advanceable_alignment_coordinate_state::none)
252 {
253 advanceable_alignment_coordinate tmp{*this};
254 tmp -= offset;
255 return tmp;
256 }
257
262 constexpr difference_type operator-(advanceable_alignment_coordinate const & other) const noexcept
263 requires (state != advanceable_alignment_coordinate_state::none)
264 {
265 if constexpr (state == advanceable_alignment_coordinate_state::column)
266 return this->first - other.first;
267 else
268 return this->second - other.second;
269 }
271
274
278 constexpr friend advanceable_alignment_coordinate operator+(difference_type const offset,
279 advanceable_alignment_coordinate const & me) noexcept
280 requires (state != advanceable_alignment_coordinate_state::none)
281 {
282 return me + offset;
283 }
285
287 size_t first{};
289 size_t second{};
290};
291
292} // namespace seqan3::detail
293
294namespace seqan3
295{
296
307template <typename char_t, typename coordinate_type>
308 requires detail::is_value_specialisation_of_v<std::remove_cvref_t<coordinate_type>,
309 detail::advanceable_alignment_coordinate>
310inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, coordinate_type && c)
311{
312 s << std::tie(c.first, c.second);
313 return s;
314}
315
316} // namespace seqan3
Provides seqan3::debug_stream and related types.
debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &stream, alignment_t &&alignment)
Stream operator for alignments, which are represented as tuples of aligned sequences.
Definition debug_stream_alignment.hpp:107
@ none
No flag is set.
Definition debug_stream_type.hpp:29
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
T operator!=(T... args)
Provides basic data structure for strong types.
Provides type traits for working with templates.
T tie(T... args)
Provides seqan3::debug_stream and related types.
Hide me