SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
advanceable_alignment_coordinate.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, 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 <concepts>
16#include <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:
73 using difference_type = std::make_signed_t<size_t>;
75
79 constexpr advanceable_alignment_coordinate() noexcept = default;
81 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate const &) noexcept = default;
82 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate &&) noexcept = default;
84 constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate const &) noexcept = default;
86 constexpr advanceable_alignment_coordinate & operator=(advanceable_alignment_coordinate &&) noexcept = default;
87 ~advanceable_alignment_coordinate() noexcept = default;
88
90 template <advanceable_alignment_coordinate_state other_state>
91 requires (other_state != state)
92 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> const & other) :
93 first{other.first},
94 second{other.second}
95 {}
96
98 template <advanceable_alignment_coordinate_state other_state>
99 requires (other_state != state)
100 constexpr advanceable_alignment_coordinate(advanceable_alignment_coordinate<other_state> && other) :
101 first{std::move(other.first)},
102 second{std::move(other.second)}
103 {}
104
109 constexpr advanceable_alignment_coordinate(column_index_type<size_t> const c_idx,
110 row_index_type<size_t> const r_idx) noexcept :
111 first{c_idx.get()},
112 second{r_idx.get()}
113 {}
115
117 constexpr friend bool operator==(advanceable_alignment_coordinate const & lhs,
118 advanceable_alignment_coordinate const & rhs) noexcept
119 {
120 return std::tie(lhs.first, lhs.second) == std::tie(rhs.first, rhs.second);
121 }
122
123 constexpr friend bool operator!=(advanceable_alignment_coordinate const & lhs,
124 advanceable_alignment_coordinate const & rhs) noexcept
125 {
126 return std::tie(lhs.first, lhs.second) != std::tie(rhs.first, rhs.second);
127 }
128
129 constexpr friend bool operator<=(advanceable_alignment_coordinate const & lhs,
130 advanceable_alignment_coordinate const & rhs) noexcept
131 {
132 return std::tie(lhs.first, lhs.second) <= std::tie(rhs.first, rhs.second);
133 }
134
135 constexpr friend bool operator<(advanceable_alignment_coordinate const & lhs,
136 advanceable_alignment_coordinate const & rhs) noexcept
137 {
138 return std::tie(lhs.first, lhs.second) < std::tie(rhs.first, rhs.second);
139 }
140
141 constexpr friend bool operator>=(advanceable_alignment_coordinate const & lhs,
142 advanceable_alignment_coordinate const & rhs) noexcept
143 {
144 return std::tie(lhs.first, lhs.second) >= std::tie(rhs.first, rhs.second);
145 }
146
147 constexpr friend bool operator>(advanceable_alignment_coordinate const & lhs,
148 advanceable_alignment_coordinate const & rhs) noexcept
149 {
150 return std::tie(lhs.first, lhs.second) > std::tie(rhs.first, rhs.second);
151 }
153
164 constexpr advanceable_alignment_coordinate & operator++(/*pre-increment*/) noexcept
165 requires (state != advanceable_alignment_coordinate_state::none)
166 {
167 if constexpr (state == advanceable_alignment_coordinate_state::column)
168 ++this->first;
169 else
170 ++this->second;
171 return *this;
172 }
173
177 constexpr advanceable_alignment_coordinate operator++(int /*post-increment*/) noexcept
178 requires (state != advanceable_alignment_coordinate_state::none)
179 {
180 advanceable_alignment_coordinate tmp{*this};
181 ++(*this);
182 return tmp;
183 }
184
188 constexpr advanceable_alignment_coordinate & operator--(/*pre-decrement*/) noexcept
189 requires (state != advanceable_alignment_coordinate_state::none)
190 {
191 if constexpr (state == advanceable_alignment_coordinate_state::column)
192 --this->first;
193 else
194 --this->second;
195 return *this;
196 }
197
201 constexpr advanceable_alignment_coordinate operator--(int /*post-decrement*/) noexcept
202 requires (state != advanceable_alignment_coordinate_state::none)
203 {
204 advanceable_alignment_coordinate tmp{*this};
205 --(*this);
206 return tmp;
207 }
208
213 constexpr advanceable_alignment_coordinate & operator+=(difference_type const offset) noexcept
214 requires (state != advanceable_alignment_coordinate_state::none)
215 {
216 if constexpr (state == advanceable_alignment_coordinate_state::column)
217 this->first += offset;
218 else
219 this->second += offset;
220 return *this;
221 }
222
227 constexpr advanceable_alignment_coordinate & operator-=(difference_type const offset) noexcept
228 requires (state != advanceable_alignment_coordinate_state::none)
229 {
230 if constexpr (state == advanceable_alignment_coordinate_state::column)
231 this->first -= offset;
232 else
233 this->second -= offset;
234 return *this;
235 }
236
241 constexpr advanceable_alignment_coordinate operator+(difference_type const offset) const noexcept
242 requires (state != advanceable_alignment_coordinate_state::none)
243 {
244 advanceable_alignment_coordinate tmp{*this};
245 tmp += offset;
246 return tmp;
247 }
248
253 constexpr advanceable_alignment_coordinate operator-(difference_type const offset) const noexcept
254 requires (state != advanceable_alignment_coordinate_state::none)
255 {
256 advanceable_alignment_coordinate tmp{*this};
257 tmp -= offset;
258 return tmp;
259 }
260
265 constexpr difference_type operator-(advanceable_alignment_coordinate const & other) const noexcept
266 requires (state != advanceable_alignment_coordinate_state::none)
267 {
268 if constexpr (state == advanceable_alignment_coordinate_state::column)
269 return this->first - other.first;
270 else
271 return this->second - other.second;
272 }
274
277
281 constexpr friend advanceable_alignment_coordinate operator+(difference_type const offset,
282 advanceable_alignment_coordinate const & me) noexcept
283 requires (state != advanceable_alignment_coordinate_state::none)
284 {
285 return me + offset;
286 }
288
290 size_t first{};
292 size_t second{};
293};
294
295} // namespace seqan3::detail
296
297namespace seqan3
298{
299
310template <typename char_t, typename coordinate_type>
311 requires detail::is_value_specialisation_of_v<std::remove_cvref_t<coordinate_type>,
312 detail::advanceable_alignment_coordinate>
313inline debug_stream_type<char_t> & operator<<(debug_stream_type<char_t> & s, coordinate_type && c)
314{
315 s << std::tie(c.first, c.second);
316 return s;
317}
318
319} // 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:110
@ none
No flag is set.
Definition: debug_stream_type.hpp:32
@ 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:29
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.