1 /*==========================================================================
2 SeqAn - The Library for Sequence Analysis
4 ============================================================================
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 ============================================================================
18 $Id: basic_alphabet_trait_basic.h,v 1.2 2009/02/19 01:51:23 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_BASIC_ALPHABET_TRAIT_BASIC_H
22 #define SEQAN_HEADER_BASIC_ALPHABET_TRAIT_BASIC_H
24 namespace SEQAN_NAMESPACE_MAIN
27 //////////////////////////////////////////////////////////////////////////////
29 //////////////////////////////////////////////////////////////////////////////
31 template<typename TIterator>
33 _arrayConstruct_Pointer(TIterator,
40 template<typename TIterator>
42 _arrayConstruct_Pointer(TIterator begin_,
47 _arrayConstruct_Default(begin_, end_);
49 template<typename TValue>
51 arrayConstruct(TValue * begin_,
55 _arrayConstruct_Pointer(begin_, end_, typename IsSimple<TValue>::Type() );
58 //____________________________________________________________________________
60 template<typename TIterator, typename TParam>
62 _arrayConstruct_Pointer(TIterator begin_,
64 TParam const & param_,
68 arrayFill(begin_, end_, param_);
70 template<typename TIterator, typename TParam>
72 _arrayConstruct_Pointer(TIterator begin_,
74 TParam const & param_,
78 _arrayConstruct_Default(begin_, end_, param_);
80 template<typename TValue, typename TParam>
82 arrayConstruct(TValue * begin_,
84 TParam const & param_)
87 _arrayConstruct_Pointer(begin_, end_, param_, typename IsSimple<TValue>::Type() );
90 //////////////////////////////////////////////////////////////////////////////
92 //////////////////////////////////////////////////////////////////////////////
94 template<typename TValue>
96 _arrayConstructCopy_Pointer(TValue * source_begin,
98 TValue * target_begin,
102 arrayCopyForward(source_begin, source_end, target_begin);
104 template<typename TValue>
106 _arrayConstructCopy_Pointer(TValue * source_begin,
108 TValue * target_begin,
112 _arrayConstructCopy_Default(source_begin, source_end, target_begin);
114 template<typename TValue>
116 arrayConstructCopy(TValue * source_begin,
118 TValue * target_begin)
121 _arrayConstructCopy_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
124 //////////////////////////////////////////////////////////////////////////////
126 //////////////////////////////////////////////////////////////////////////////
128 template<typename TValue>
130 _arrayConstructMove_Pointer(TValue * source_begin,
132 TValue * target_begin,
136 arrayMoveForward(source_begin, source_end, target_begin);
138 template<typename TValue>
140 _arrayConstructMove_Pointer(TValue * source_begin,
142 TValue * target_begin,
146 _arrayConstructMove_Default(source_begin, source_end, target_begin);
148 template<typename TValue>
150 arrayConstructMove(TValue * source_begin,
152 TValue * target_begin)
155 _arrayConstructMove_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
158 //////////////////////////////////////////////////////////////////////////////
160 //////////////////////////////////////////////////////////////////////////////
162 template<typename TValue>
164 _arrayDestruct_Pointer(TValue * /*begin_*/,
171 template<typename TValue>
173 _arrayDestruct_Pointer(TValue * begin_,
178 _arrayDestruct_Default(begin_, end_);
180 template<typename TValue>
182 arrayDestruct(TValue * begin_,
186 _arrayDestruct_Pointer(begin_, end_, typename IsSimple<TValue>::Type() );
189 //////////////////////////////////////////////////////////////////////////////
191 //////////////////////////////////////////////////////////////////////////////
193 //no specializiation for pointer to simple
195 //////////////////////////////////////////////////////////////////////////////
197 //////////////////////////////////////////////////////////////////////////////
199 template<typename TValue>
201 _arrayCopyForward_Pointer(TValue * source_begin,
203 TValue * target_begin,
207 memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
209 template<typename TValue>
211 _arrayCopyForward_Pointer(TValue * source_begin,
213 TValue * target_begin,
217 _arrayCopyForward_Default(source_begin, source_end, target_begin);
219 template<typename TValue>
221 arrayCopyForward(TValue * source_begin,
223 TValue * target_begin)
226 _arrayCopyForward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
229 //////////////////////////////////////////////////////////////////////////////
231 //////////////////////////////////////////////////////////////////////////////
233 template <typename TValue>
235 _arrayCopyBackward_Pointer(TValue * source_begin,
237 TValue * target_begin,
241 memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
243 template <typename TValue>
245 _arrayCopyBackward_Pointer(TValue * source_begin,
247 TValue * target_begin,
251 _arrayCopyBackward_Default(source_begin, source_end, target_begin);
253 template<typename TValue>
255 arrayCopyBackward(TValue * source_begin,
257 TValue * target_begin)
260 _arrayCopyBackward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
263 //////////////////////////////////////////////////////////////////////////////
265 //////////////////////////////////////////////////////////////////////////////
267 template<typename TValue>
269 _arrayMoveForward_Pointer(TValue * source_begin,
271 TValue * target_begin,
275 memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
277 template<typename TValue>
279 _arrayMoveForward_Pointer(TValue * source_begin,
281 TValue * target_begin,
285 _arrayMoveForward_Default(source_begin, source_end, target_begin);
287 template<typename TValue>
289 arrayMoveForward(TValue * source_begin,
291 TValue * target_begin)
294 _arrayMoveForward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
297 //////////////////////////////////////////////////////////////////////////////
299 //////////////////////////////////////////////////////////////////////////////
301 template <typename TValue>
303 _arrayMoveBackward_Pointer(TValue * source_begin,
305 TValue * target_begin,
309 memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
311 template <typename TValue>
313 _arrayMoveBackward_Pointer(TValue * source_begin,
315 TValue * target_begin,
319 _arrayMoveBackward_Default(source_begin, source_end, target_begin);
321 template<typename TValue>
323 arrayMoveBackward(TValue * source_begin,
325 TValue * target_begin)
328 _arrayMoveBackward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
331 //////////////////////////////////////////////////////////////////////////////
333 //////////////////////////////////////////////////////////////////////////////
335 template <typename TValue>
337 _arrayClearSpace_Pointer(TValue * array_begin,
343 if (keep_from == move_to) return;
345 arrayMove(array_begin + keep_from, array_begin + array_length, array_begin + move_to);
347 template <typename TValue>
349 _arrayClearSpace_Pointer(TValue * array_begin,
355 _arrayClearSpace_Default(array_begin, array_length, keep_from, move_to);
357 template <typename TValue>
358 void arrayClearSpace(TValue * array_begin,
363 _arrayClearSpace_Pointer(array_begin, array_length, keep_from, move_to, typename IsSimple<TValue>::Type() );
368 //////////////////////////////////////////////////////////////////////////////
369 // IsSimple specializations
370 //////////////////////////////////////////////////////////////////////////////
373 template <> struct _IsSimple< bool > { typedef True Type; };
374 template <> struct _IsSimple< char > { typedef True Type; };
376 template <> struct _IsSimple< unsigned char > { typedef True Type; };
377 template <> struct _IsSimple< unsigned short > { typedef True Type; };
378 template <> struct _IsSimple< unsigned int > { typedef True Type; };
379 template <> struct _IsSimple< unsigned long > { typedef True Type; };
381 template <> struct _IsSimple< signed char > { typedef True Type; };
382 template <> struct _IsSimple< signed short > { typedef True Type; };
383 template <> struct _IsSimple< signed int > { typedef True Type; };
384 template <> struct _IsSimple< signed long > { typedef True Type; };
386 template <> struct _IsSimple< float > { typedef True Type; };
387 template <> struct _IsSimple< double > { typedef True Type; };
388 template <> struct _IsSimple< long double > { typedef True Type; };
390 // user defined types (re-specializations are allowed here)
391 template <> struct IsSimple< wchar_t > { typedef True Type; };
392 template <> struct IsSimple< __int64 > { typedef True Type; };
394 //////////////////////////////////////////////////////////////////////////////
396 //////////////////////////////////////////////////////////////////////////////
402 static char const _gap = '-';
406 gapValueImpl(char const *)
409 static char const _gap = '-';
413 //////////////////////////////////////////////////////////////////////////////
414 // generic extreme values
415 //////////////////////////////////////////////////////////////////////////////
417 template <typename T>
419 supremumValueImpl(T *)
422 return SupremumValue<T>::VALUE;
424 template <typename T>
426 infimumValueImpl(T *)
429 return InfimumValue<T>::VALUE;
432 //////////////////////////////////////////////////////////////////////////////
434 //////////////////////////////////////////////////////////////////////////////
436 template <> struct BitsPerValue< bool > { enum { VALUE = 1 }; };
439 //////////////////////////////////////////////////////////////////////////////
441 //////////////////////////////////////////////////////////////////////////////
444 supremumValueImpl(char *)
447 static char const _value = (char) 127;
451 infimumValueImpl(char *)
454 static char const _value = (char) -128;
458 //////////////////////////////////////////////////////////////////////////////
460 //////////////////////////////////////////////////////////////////////////////
462 inline signed char const &
463 supremumValueImpl(signed char *)
466 static signed char const _value = 127;
469 inline signed char const &
470 infimumValueImpl(signed char *)
473 static signed char const _value = -128;
477 //////////////////////////////////////////////////////////////////////////////
479 //////////////////////////////////////////////////////////////////////////////
481 inline unsigned char const &
482 supremumValueImpl(unsigned char *)
485 static unsigned char const _value = 255;
488 inline unsigned char const &
489 infimumValueImpl(unsigned char *)
492 static unsigned char const _value = 0;
496 //////////////////////////////////////////////////////////////////////////////
498 //////////////////////////////////////////////////////////////////////////////
500 inline wchar_t const &
501 supremumValueImpl(wchar_t *)
504 static wchar_t const _value = 1UL << (BitsPerValue<wchar_t>::VALUE) - 1;
507 inline wchar_t const &
508 infimumValueImpl(wchar_t *)
511 static wchar_t const _value = 0;
515 //////////////////////////////////////////////////////////////////////////////
517 //////////////////////////////////////////////////////////////////////////////
519 inline signed short const &
520 supremumValueImpl(signed short *)
523 static signed short const _value = (((1 << (BitsPerValue<signed short>::VALUE - 2)) - 1) << 1) + 1;
526 inline signed short const &
527 infimumValueImpl(signed short *dummy)
530 static signed short const _value = -supremumValueImpl(dummy) - 1;
534 //////////////////////////////////////////////////////////////////////////////
536 //////////////////////////////////////////////////////////////////////////////
538 inline unsigned short const &
539 supremumValueImpl(unsigned short *)
542 static unsigned short const _value = (((1 << (BitsPerValue<unsigned short>::VALUE - 1)) - 1) << 1) + 1;
545 inline unsigned short const &
546 infimumValueImpl(unsigned short *)
549 static unsigned short const _value = 0;
553 //////////////////////////////////////////////////////////////////////////////
555 //////////////////////////////////////////////////////////////////////////////
557 inline signed int const &
558 supremumValueImpl(signed int *)
561 static signed int const _value = (((1 << (BitsPerValue<signed int>::VALUE - 2)) - 1) << 1) + 1;
564 inline signed int const &
565 infimumValueImpl(signed int *dummy)
568 static signed int const _value = -supremumValueImpl(dummy) - 1;
572 //////////////////////////////////////////////////////////////////////////////
574 //////////////////////////////////////////////////////////////////////////////
576 inline unsigned int const &
577 supremumValueImpl(unsigned int *)
580 static unsigned int const _value = ~0ul;
583 inline unsigned int const &
584 infimumValueImpl(unsigned int *)
587 static unsigned int const _value = 0;
591 //////////////////////////////////////////////////////////////////////////////
593 //////////////////////////////////////////////////////////////////////////////
595 inline signed long const &
596 supremumValueImpl(signed long *)
599 static signed long const _value = (((1 << (BitsPerValue<signed long>::VALUE - 2)) - 1) << 1) + 1;
602 inline signed long const &
603 infimumValueImpl(signed long *dummy)
606 static signed long const _value = -supremumValueImpl(dummy) - 1;
610 //////////////////////////////////////////////////////////////////////////////
612 //////////////////////////////////////////////////////////////////////////////
614 inline unsigned long const &
615 supremumValueImpl(unsigned long *)
618 static unsigned long const _value = ~0ul;
621 inline unsigned long const &
622 infimumValueImpl(unsigned long *)
625 static unsigned long const _value = 0;
629 //////////////////////////////////////////////////////////////////////////////
630 // signed 64bit int (cannot use long long <- no ISO C++)
631 //////////////////////////////////////////////////////////////////////////////
633 inline __int64 const &
634 supremumValueImpl(__int64 *)
637 static __int64 const _value = ((((__int64)1 << (BitsPerValue<__int64>::VALUE - 2)) - 1) << 1) + 1;
640 inline __int64 const &
641 infimumValueImpl(__int64 *dummy)
644 static __int64 const _value = -supremumValueImpl(dummy) - 1;
649 //////////////////////////////////////////////////////////////////////////////
651 //////////////////////////////////////////////////////////////////////////////
654 supremumValueImpl(float *)
657 #ifdef PLATFORM_WINDOWS
658 static float const _value = ::std::numeric_limits<float>::infinity( );
660 static float const _value = 3.40282347e+38F;
665 infimumValueImpl(float *)
668 #ifdef PLATFORM_WINDOWS
669 static float const _value = -::std::numeric_limits<float>::infinity( );
671 static float const _value = -3.40282347e+38F;
676 //////////////////////////////////////////////////////////////////////////////
678 //////////////////////////////////////////////////////////////////////////////
680 inline double const &
681 supremumValueImpl(double *)
684 #ifdef PLATFORM_WINDOWS
685 static double const _value = ::std::numeric_limits<double>::infinity( );
687 static double const _value = 1.7976931348623157e+308;
691 inline double const &
692 infimumValueImpl(double *)
695 #ifdef PLATFORM_WINDOWS
696 static double const _value = -::std::numeric_limits<double>::infinity( );
698 static double const _value = -1.7976931348623157e+308;
703 //////////////////////////////////////////////////////////////////////////////
705 //////////////////////////////////////////////////////////////////////////////
707 inline long double const &
708 supremumValueImpl(long double *)
711 #ifdef PLATFORM_WINDOWS
712 static long double const _value = ::std::numeric_limits<long double>::infinity( );
714 static long double const _value = 1.7976931348623157e+308;
718 inline long double const &
719 infimumValueImpl(long double *)
722 #ifdef PLATFORM_WINDOWS
723 static long double const _value = -::std::numeric_limits<long double>::infinity( );
725 static long double const _value = -1.7976931348623157e+308;
730 //////////////////////////////////////////////////////////////////////////////
731 }// namespace SEQAN_NAMESPACE_MAIN
733 #endif //#ifndef SEQAN_HEADER_...