SeqAn3
concept.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <type_traits>
43 
44 #include <sdsl/suffix_arrays.hpp>
45 
48 #include <seqan3/range/concept.hpp>
49 
50 namespace seqan3::detail
51 {
52 
57  // ============================================================================
58  // sdsl_index_concept
59  // ============================================================================
60 
64 template <typename t>
66 concept sdsl_index_concept = requires (t sdsl_index)
67 {
68  typename t::size_type;
69 
70  { sdsl_index.size() } -> typename t::size_type;
71  { sdsl_index[0] }; // suffix array access
72  { sdsl_index.comp2char[0] } -> uint8_t;
73  { sdsl_index.char2comp[0] } -> uint8_t;
74  { sdsl_index.sigma };
75  { sdsl_index.C[0] };
76 
77  requires requires (t sdsl_index, typename t::char_type const c, typename t::size_type const lb,
78  typename t::size_type const rb, sdsl::int_vector<8> const text)
79  {
80  { sdsl_index.bwt.rank(lb, c) };
81  { sdsl_index.wavelet_tree.lex_count(lb, rb, c) };
82  { sdsl::construct_im(sdsl_index, text, 0) };
83  };
84 };
86 
100 
102 } // namespace seqan3::detail
103 
104 namespace seqan3
105 {
106 
111 // ============================================================================
112 // fm_index_traits_concept
113 // ============================================================================
114 
120 template <typename t>
122 concept fm_index_traits_concept = requires (t v)
123 {
124  typename t::sdsl_index_type;
125 
126  requires detail::sdsl_index_concept<typename t::sdsl_index_type>;
127 };
129 
141 // ============================================================================
142 // fm_index_concept
143 // ============================================================================
144 
150 template <typename t>
152 concept fm_index_concept = std::Semiregular<t> && requires (t index)
153 {
154  typename t::text_type;
155  typename t::char_type;
156  typename t::size_type;
157  typename t::iterator_type;
158 
159  // NOTE: circular dependency
160  // requires fm_index_iterator_concept<typename t::iterator_type>;
161 
162  requires requires (t index, std::vector<typename t::char_type> const text)
163  {
164  { t(text) };
165  { index.construct(text) } -> void;
166  };
167 
168  { index.begin() } -> typename t::iterator_type;
169 
170  { index.size() } -> typename t::size_type;
171  { index.empty() } -> bool;
172 
173  { index.load(std::string{}) } -> bool;
174  { index.store(std::string{}) } -> bool;
175 };
177 
203 // ============================================================================
204 // fm_index_iterator_concept
205 // ============================================================================
206 
212 template <typename t>
214 concept fm_index_iterator_concept = std::Semiregular<t> && requires (t it)
215 {
216  typename t::index_type;
217  typename t::size_type;
218 
219  requires fm_index_concept<typename t::index_type>;
220 
221  requires requires (typename t::index_type const index) { { t(index) } };
222 
223  requires requires (t it, typename t::index_type::char_type const c,
224  std::vector<typename t::index_type::char_type> const seq)
225  {
226  { it.extend_right() } -> bool;
227  { it.extend_right(c) } -> bool;
228  { it.extend_right(seq) } -> bool;
229  { it.cycle_back() } -> bool;
230  };
231 
232  { it.last_char() } -> typename t::index_type::char_type;
233  { it.query_length() } -> typename t::size_type;
234  { it.query() } -> auto;
235  { *it } -> auto;
236  { it.count() } -> typename t::size_type;
237  { it.locate() } -> std::vector<typename t::size_type>;
238  { it.lazy_locate() } -> auto;
239 };
241 
259 // ============================================================================
260 // bi_fm_index_traits_concept
261 // ============================================================================
262 
268 template <typename t>
270 concept bi_fm_index_traits_concept = requires (t v)
271 {
272  requires fm_index_traits_concept<typename t::fm_index_traits>;
273  requires fm_index_traits_concept<typename t::rev_fm_index_traits>;
274 
275  requires std::Same<typename t::fm_index_traits::sdsl_index_type::size_type,
276  typename t::rev_fm_index_traits::sdsl_index_type::size_type>;
277 };
279 
297 // ============================================================================
298 // bi_fm_index_concept
299 // ============================================================================
300 
306 template <typename t>
308 concept bi_fm_index_concept = fm_index_concept<t> && requires (t index)
309 {
310  typename t::iterator_type; // already required by fm_index_concept but has a different documentation
311  typename t::fwd_iterator_type;
312  typename t::rev_iterator_type;
313 
314  // NOTE: circular dependency
315  // requires bi_fm_index_iterator_concept<typename t::iterator_type>;
316 
317  { index.fwd_begin() } -> typename t::fwd_iterator_type;
318  { index.rev_begin() } -> typename t::rev_iterator_type;
319 };
321 
343 // ============================================================================
344 // bi_fm_index_iterator_concept
345 // ============================================================================
346 
352 template <typename t>
354 concept bi_fm_index_iterator_concept = fm_index_iterator_concept<t> && requires (t it)
355 {
356  requires bi_fm_index_concept<typename t::index_type>;
357 
358  requires requires (typename t::index_type const index) { { t(index) } };
359 
360  requires requires (t it, typename t::index_type::char_type const c,
361  std::vector<typename t::index_type::char_type> const seq)
362  {
363  { it.extend_left() } -> bool;
364  { it.extend_left(c) } -> bool;
365  { it.extend_left(seq) } -> bool;
366  { it.cycle_front() } -> bool;
367  };
368 
369 };
371 
390 
392 } // namespace seqan3
Subsumes std::Copyable and std::DefaultConstructible.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Additional non-standard concepts for ranges.
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
Definition: aligned_sequence_concept.hpp:288
Provides C++20 additions to the type_traits header.
Provides various metafunctions used by the range module.
Contains seqan3::dna4, container aliases and string literals.