SeqAn3 3.1.0
The Modern C++ library for sequence analysis.
advanceable_alignment_coordinate.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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 <seqan3/std/concepts>
16#include <seqan3/std/iterator>
17#include <type_traits>
18
24
25namespace seqan3::detail
26{
27
39enum struct advanceable_alignment_coordinate_state : uint8_t
40{
42 none,
44 column,
46 row
47};
48
64template <advanceable_alignment_coordinate_state state = advanceable_alignment_coordinate_state::none>
65class advanceable_alignment_coordinate
66{
67public:
68
74 using difference_type = std::make_signed_t<size_t>;
76
80 constexpr advanceable_alignment_coordinate() noexcept = default;
82 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate const &) noexcept = default;
83 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate &&) noexcept = default;
85 constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate const &) noexcept = default;
87 constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate &&) noexcept = default;
88 ~advanceable_alignment_coordinate() noexcept = default;
89
91 template <advanceable_alignment_coordinate_state other_state>
93 requires (other_state != state)
95 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> const & other) :
96 first{other.first},
97 second{other.second}
98 {}
99
101 template <advanceable_alignment_coordinate_state other_state>
103 requires (other_state != state)
105 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> && other) :
106 first{std::move(other.first)},
107 second{std::move(other.second)}
108 {}
109
114 constexpr advanceable_alignment_coordinate(column_index_type<size_t> const c_idx,
115 row_index_type<size_t> const r_idx) noexcept :
116 first{c_idx.get()},
117 second{r_idx.get()}
118 {}
120
122 constexpr friend bool operator==(advanceable_alignment_coordinate const & lhs,
123 advanceable_alignment_coordinate const & rhs) noexcept
124 {
125 return std::tie(lhs.first, lhs.second) == std::tie(rhs.first, rhs.second);
126 }
127
128 constexpr friend bool operator!=(advanceable_alignment_coordinate const & lhs,
129 advanceable_alignment_coordinate const & rhs) noexcept
130 {
131 return std::tie(lhs.first, lhs.second) != std::tie(rhs.first, rhs.second);
132 }
133
134 constexpr friend bool operator<=(advanceable_alignment_coordinate const & lhs,
135 advanceable_alignment_coordinate const & rhs) noexcept
136 {
137 return std::tie(lhs.first, lhs.second) <= std::tie(rhs.first, rhs.second);
138 }
139
140 constexpr friend bool operator< (advanceable_alignment_coordinate const & lhs,
141 advanceable_alignment_coordinate const & rhs) noexcept
142 {
143 return std::tie(lhs.first, lhs.second) < std::tie(rhs.first, rhs.second);
144 }
145
146 constexpr friend bool operator>=(advanceable_alignment_coordinate const & lhs,
147 advanceable_alignment_coordinate const & rhs) noexcept
148 {
149 return std::tie(lhs.first, lhs.second) >= std::tie(rhs.first, rhs.second);
150 }
151
152 constexpr friend bool operator> (advanceable_alignment_coordinate const & lhs,
153 advanceable_alignment_coordinate const & rhs) noexcept
154 {
155 return std::tie(lhs.first, lhs.second) > std::tie(rhs.first, rhs.second);
156 }
158
169 constexpr advanceable_alignment_coordinate & operator++(/*pre-increment*/) noexcept
171 requires (state != advanceable_alignment_coordinate_state::none)
173 {
174 if constexpr (state == advanceable_alignment_coordinate_state::column)
175 ++this->first;
176 else
177 ++this->second;
178 return *this;
179 }
180
184 constexpr advanceable_alignment_coordinate operator++(int /*post-increment*/) noexcept
186 requires (state != advanceable_alignment_coordinate_state::none)
188 {
189 advanceable_alignment_coordinate tmp{*this};
190 ++(*this);
191 return tmp;
192 }
193
197 constexpr advanceable_alignment_coordinate & operator--(/*pre-decrement*/) noexcept
199 requires (state != advanceable_alignment_coordinate_state::none)
201 {
202 if constexpr (state == advanceable_alignment_coordinate_state::column)
203 --this->first;
204 else
205 --this->second;
206 return *this;
207 }
208
212 constexpr advanceable_alignment_coordinate operator--(int /*post-decrement*/) noexcept
214 requires (state != advanceable_alignment_coordinate_state::none)
216 {
217 advanceable_alignment_coordinate tmp{*this};
218 --(*this);
219 return tmp;
220 }
221
226 constexpr advanceable_alignment_coordinate & operator+=(difference_type const offset) noexcept
228 requires (state != advanceable_alignment_coordinate_state::none)
230 {
231 if constexpr (state == advanceable_alignment_coordinate_state::column)
232 this->first += offset;
233 else
234 this->second += offset;
235 return *this;
236 }
237
242 constexpr advanceable_alignment_coordinate & operator-=(difference_type const offset) noexcept
244 requires (state != advanceable_alignment_coordinate_state::none)
246 {
247 if constexpr (state == advanceable_alignment_coordinate_state::column)
248 this->first -= offset;
249 else
250 this->second -= offset;
251 return *this;
252 }
253
258 constexpr advanceable_alignment_coordinate operator+(difference_type const offset) const noexcept
260 requires (state != advanceable_alignment_coordinate_state::none)
262 {
263 advanceable_alignment_coordinate tmp{*this};
264 tmp += offset;
265 return tmp;
266 }
267
272 constexpr advanceable_alignment_coordinate operator-(difference_type const offset) const noexcept
274 requires (state != advanceable_alignment_coordinate_state::none)
276 {
277 advanceable_alignment_coordinate tmp{*this};
278 tmp -= offset;
279 return tmp;
280 }
281
286 constexpr difference_type operator-(advanceable_alignment_coordinate const & other) const noexcept
288 requires (state != advanceable_alignment_coordinate_state::none)
290 {
291 if constexpr (state == advanceable_alignment_coordinate_state::column)
292 return this->first - other.first;
293 else
294 return this->second - other.second;
295 }
297
300
304 constexpr friend advanceable_alignment_coordinate operator+(difference_type const offset,
305 advanceable_alignment_coordinate const & me) noexcept
307 requires (state != advanceable_alignment_coordinate_state::none)
309 {
310 return me + offset;
311 }
313
315 size_t first{};
317 size_t second{};
318};
319
320} // namespace seqan3::detail
321
322namespace seqan3
323{
324
335template <typename char_t, typename coordinate_type>
337 requires detail::is_value_specialisation_of_v<std::remove_cvref_t<coordinate_type>,
338 detail::advanceable_alignment_coordinate>
340inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, coordinate_type && c)
341{
342 s << std::tie(c.first, c.second);
343 return s;
344}
345
346} // namespace seqan3
The <concepts> header from C++20's standard library.
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:101
@ none
No flag is set.
Definition: debug_stream_type.hpp:32
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
The <iterator> header from C++20's standard library.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The main SeqAn3 namespace.
Definition: cigar_operation_table.hpp:2
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.