SeqAn3
uint.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 
53 #pragma once
54 
55 #include <limits>
56 
57 #include <meta/meta.hpp>
58 
61 
62 namespace seqan3::detail
63 {
66 
68 using uint_adaptations = meta::list<uint8_t,
69  uint16_t,
70  uint32_t>;
72 using uint_adaptations_char_types = meta::list<char,
73  char16_t,
74  char32_t>;
75 
77 template <typename type_in_list>
78  requires meta::in<uint_adaptations, type_in_list>::value
79 struct is_uint_adaptation<type_in_list> :
80  std::true_type
81 {};
82 
84 } // namespace seqan3::detail
85 
86 namespace seqan3
87 {
88 
91 
92 // ------------------------------------------------------------------
93 // type metafunctions
94 // ------------------------------------------------------------------
95 
101 template <typename uint_type>
103  requires detail::is_uint_adaptation_v<uint_type>
105 struct underlying_char<uint_type>
106 {
108  using type = meta::at<detail::uint_adaptations_char_types,
109  meta::find_index<detail::uint_adaptations, uint_type>>;
110 };
111 
117 template <typename uint_type>
119  requires detail::is_uint_adaptation_v<uint_type>
121 struct underlying_rank<uint_type>
122 {
124  using type = uint_type;
125 };
126 
127 // ------------------------------------------------------------------
128 // value metafunctions
129 // ------------------------------------------------------------------
130 
136 template <typename uint_type>
138  requires detail::is_uint_adaptation_v<uint_type>
140 struct alphabet_size<uint_type>
141 {
143  using type = detail::min_viable_uint_t<static_cast<uint64_t>(std::numeric_limits<uint_type>::max()) + 1 -
144  std::numeric_limits<uint_type>::lowest()>;
146  static constexpr type value =
147  static_cast<type>(std::numeric_limits<uint_type>::max()) + 1 - std::numeric_limits<uint_type>::lowest();
148 };
149 
150 // ------------------------------------------------------------------
151 // free functions
152 // ------------------------------------------------------------------
153 
165 template <typename uint_type>
166 constexpr underlying_char_t<uint_type> to_char(uint_type const intgr)
167  requires detail::is_uint_adaptation_v<uint_type>
168 {
169  return intgr;
170 }
171 
177 template <typename uint_type>
178 constexpr underlying_rank_t<uint_type> to_rank(uint_type const intgr)
179  requires detail::is_uint_adaptation_v<uint_type>
180 {
181  return intgr;
182 }
183 
190 template <typename uint_type>
191 constexpr uint_type & assign_char(uint_type & intgr, underlying_char_t<uint_type> const chr)
192  requires detail::is_uint_adaptation_v<uint_type>
193 {
194  return intgr = chr;
195 }
196 
206 template <typename uint_type>
207 constexpr uint_type && assign_char(uint_type && intgr, underlying_char_t<uint_type> const chr)
208  requires detail::is_uint_adaptation_v<std::remove_reference_t<uint_type>>
209 {
210  return std::move(intgr = chr);
211 }
212 
219 template <typename uint_type>
220 constexpr uint_type & assign_rank(uint_type & intgr, underlying_rank_t<uint_type> const intgr2)
221  requires detail::is_uint_adaptation_v<uint_type>
222 {
223  return intgr = intgr2;
224 }
225 
235 template <typename uint_type>
236 constexpr uint_type && assign_rank(uint_type && intgr, underlying_rank_t<uint_type> const intgr2)
237  requires detail::is_uint_adaptation_v<std::remove_reference_t<uint_type>>
238 {
239  return std::move(intgr = intgr2);
240 }
243 
244 } // namespace seqan3
245 
246 // concept tests in alphabet/adaptation.hpp because of include order constraints
meta::at< detail::uint_adaptations_char_types, meta::find_index< detail::uint_adaptations, uint_type > > type
The character type of the same size as uint_type.
Definition: uint.hpp:109
The rank_type of the semi_alphabet. [type metafunction base template].
Definition: concept_pre.hpp:80
typename underlying_rank< semi_alphabet_type >::type underlying_rank_t
The rank_type of the semi_alphabet. [type metafunction shortcut].
Definition: concept_pre.hpp:88
Contains metaprogramming utilities for integer types.
constexpr uint_type && assign_char(uint_type &&intgr, underlying_char_t< uint_type > const chr) requires detail
Assign from a character type via implicit or explicit cast.
Definition: uint.hpp:207
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
seqan3::alphabet_concept metafunction base classes.
detail::min_viable_uint_t< static_cast< uint64_t >(std::numeric_limits< uint_type >::max())+1 - std::numeric_limits< uint_type >::lowest()> type
Smallest unsigned integral type that can hold value;.
Definition: uint.hpp:144
uint_type type
The same as uint_type.
Definition: uint.hpp:124
constexpr uint_type & assign_char(uint_type &intgr, underlying_char_t< uint_type > const chr) requires detail
Assign from a character type via implicit or explicit cast.
Definition: uint.hpp:191
The size of the alphabet. [value metafunction base template].
Definition: concept_pre.hpp:104
Definition: aligned_sequence_concept.hpp:288
constexpr underlying_char_t< uint_type > to_char(uint_type const intgr) requires detail
Converting uint to char casts to a character type of same size.
Definition: uint.hpp:166
The char_type of the alphabet. [type metafunction base template].
Definition: concept_pre.hpp:164
typename underlying_char< alphabet_type >::type underlying_char_t
The char_type of the alphabet. [type metafunction shortcut].
Definition: concept_pre.hpp:172
constexpr uint_type & assign_rank(uint_type &intgr, underlying_rank_t< uint_type > const intgr2) requires detail
Assign a rank to to the uint (same as calling =).
Definition: uint.hpp:220
constexpr uint_type && assign_rank(uint_type &&intgr, underlying_rank_t< uint_type > const intgr2) requires detail
Assign a rank to to the uint (same as calling =).
Definition: uint.hpp:236
constexpr underlying_rank_t< uint_type > to_rank(uint_type const intgr) requires detail
Converting uint to rank is a no-op (it will just return the value you pass in).
Definition: uint.hpp:178