1 // ========================================================================== 2 // SeqAn - The Library for Sequence Analysis 3 // ========================================================================== 4 // Copyright (c) 2006-2018, Knut Reinert, FU Berlin 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions are met: 9 // 10 // * Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // * Redistributions in binary form must reproduce the above copyright 13 // notice, this list of conditions and the following disclaimer in the 14 // documentation and/or other materials provided with the distribution. 15 // * Neither the name of Knut Reinert or the FU Berlin nor the names of 16 // its contributors may be used to endorse or promote products derived 17 // from this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE 23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 // DAMAGE. 30 // 31 // ========================================================================== 32 // Author: Andreas Gogol-Döring <andreas.doering@mdc-berlin.de> 33 // ========================================================================== 34 // Adaptions of builting types such as bool, int, but also "builtin-level" 35 // user defined types such as wchar_t, int64_t, uint64_t to the alphabet 36 // concepts they are in. 37 // ========================================================================== 38 39 #ifndef SEQAN_INCLUDE_BASIC_ALPHABET_ADAPT_BUILTINS_H_ 40 #define SEQAN_INCLUDE_BASIC_ALPHABET_ADAPT_BUILTINS_H_ 41 42 #include <limits> 43 44 namespace seqan { 45 46 // ============================================================================ 47 // Forwards 48 // ============================================================================ 49 50 // ============================================================================ 51 // Tags, Classes, Enums 52 // ============================================================================ 53 54 // ============================================================================ 55 // Metafunctions 56 // ============================================================================ 57 58 // ---------------------------------------------------------------------------- 59 // Metafunctions MaxValue_, MinValue_ 60 // ---------------------------------------------------------------------------- 61 62 // We would want to have this here, however this is not possible with the 63 // current implementation. 64 65 // ---------------------------------------------------------------------------- 66 // Metafunction BitsPerValue 67 // ---------------------------------------------------------------------------- 68 69 template <> 70 struct BitsPerValue<bool> 71 { 72 typedef int Type; 73 enum { VALUE = 1 }; 74 }; 75 76 // ---------------------------------------------------------------------------- 77 // Metafunction IsCharType 78 // ---------------------------------------------------------------------------- 79 80 // TODO(holtgrew): This should probably become a concept. 81 82 /*! 83 * @mfn IsCharType 84 * @headerfile <seqan/basic.h> 85 * 86 * @brief Return whether the argument is <tt>char</tt>, <tt>wchar_t</tt>, <tt>char const</tt>, or <tt>wchar_t 87 * const</tt>. 88 * 89 * @signature IsCharType<T>::Type; 90 * @signature IsCharType<T>::VALUE; 91 * 92 * @tparam T Type to check type of. 93 * 94 * This metafunction is used to enable and disable templated adaptions of arrays to sequences for builtin character 95 * types only. 96 * 97 * The return value is <tt>True</tt>/<tt>true</tt> for <tt>char</tt>, <tt>wchar_t</tt>, <tt>char const</tt>, and 98 * <tt>wchar_t const</tt>. 99 */ 100 101 template <typename T> 102 struct IsCharType; 103 104 template <typename T> 105 struct IsCharType 106 { 107 typedef False Type; 108 enum { VALUE = 0 }; 109 }; 110 111 template <typename T> 112 struct IsCharType<T const> 113 : IsCharType<T> {}; 114 115 template <> 116 struct IsCharType<char> 117 { 118 typedef True Type; 119 enum { VALUE = 1 }; 120 }; 121 122 template <> 123 struct IsCharType<wchar_t> 124 { 125 typedef True Type; 126 enum { VALUE = 1 }; 127 }; 128 129 // ============================================================================ 130 // Functions 131 // ============================================================================ 132 133 // ---------------------------------------------------------------------------- 134 // Function gapValueImpl() [char] 135 // ---------------------------------------------------------------------------- 136 137 inline char const & 138 gapValueImpl(char *) 139 { 140 static char const _gap = '-'; 141 return _gap; 142 } 143 144 inline char const & 145 gapValueImpl(char const *) 146 { 147 static char const _gap = '-'; 148 return _gap; 149 } 150 151 // ---------------------------------------------------------------------------- 152 // Function unknownValueImpl() [char] 153 // ---------------------------------------------------------------------------- 154 155 inline char const & 156 unknownValueImpl(char *) 157 { 158 static char const _unknown = 'N'; 159 return _unknown; 160 } 161 162 inline char const & 163 unknownValueImpl(char const *) 164 { 165 static char const _unknown = 'N'; 166 return _unknown; 167 } 168 169 // ---------------------------------------------------------------------------- 170 // Function supremumValueImpl() 171 // ---------------------------------------------------------------------------- 172 173 template <typename T> 174 [[deprecated("Use std::numeric_limits<T>::max() instead.")]] 175 inline T const & 176 supremumValueImpl(T *) 177 { 178 static T const x = std::numeric_limits<T>::max(); 179 return x; 180 } 181 182 [[deprecated("Use std::numeric_limits<T>::max() instead.")]] 183 inline long double const & 184 supremumValueImpl(long double *) 185 { 186 static long double const _value = std::numeric_limits<long double>::infinity( ); 187 return _value; 188 } 189 190 [[deprecated("Use std::numeric_limits<T>::max() instead.")]] 191 inline double const & 192 supremumValueImpl(double *) 193 { 194 static double const _value = std::numeric_limits<double>::infinity( ); 195 return _value; 196 } 197 198 [[deprecated("Use std::numeric_limits<T>::max() instead.")]] 199 inline float const & 200 supremumValueImpl(float *) 201 { 202 static float const _value = std::numeric_limits<float>::infinity( ); 203 return _value; 204 } 205 206 // ---------------------------------------------------------------------------- 207 // Function infimumValueImpl() 208 // ---------------------------------------------------------------------------- 209 210 template <typename T> 211 [[deprecated("Use std::numeric_limits<T>::min() instead.")]] 212 inline T const & 213 infimumValueImpl(T *) 214 { 215 static T const x = std::numeric_limits<T>::min(); 216 return x; 217 } 218 219 [[deprecated("Use std::numeric_limits<T>::min() instead.")]] 220 inline float const & 221 infimumValueImpl(float *) 222 { 223 static float const _value = -std::numeric_limits<float>::infinity( ); 224 return _value; 225 } 226 227 [[deprecated("Use std::numeric_limits<T>::min() instead.")]] 228 inline double const & 229 infimumValueImpl(double *) 230 { 231 static double const _value = -std::numeric_limits<double>::infinity( ); 232 return _value; 233 } 234 235 [[deprecated("Use std::numeric_limits<T>::min() instead.")]] 236 inline long double const & 237 infimumValueImpl(long double *) 238 { 239 static long double const _value = -std::numeric_limits<long double>::infinity( ); 240 return _value; 241 } 242 243 } // namespace seqan 244 245 #endif // #ifndef SEQAN_INCLUDE_BASIC_ALPHABET_ADAPT_BUILTINS_H_ 246