Commit patch to not break on spaces.
[bowtie.git] / SeqAn-1.1 / seqan / basic / basic_alphabet_trait_basic.h
1  /*==========================================================================
2                 SeqAn - The Library for Sequence Analysis
3                           http://www.seqan.de
4  ============================================================================
5   Copyright (C) 2007
6
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.
11
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.
16
17  ============================================================================
18   $Id: basic_alphabet_trait_basic.h,v 1.2 2009/02/19 01:51:23 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_BASIC_ALPHABET_TRAIT_BASIC_H
22 #define SEQAN_HEADER_BASIC_ALPHABET_TRAIT_BASIC_H
23
24 namespace SEQAN_NAMESPACE_MAIN
25 {
26
27 //////////////////////////////////////////////////////////////////////////////
28 //arrayConstruct
29 //////////////////////////////////////////////////////////////////////////////
30
31 template<typename TIterator>
32 inline void
33 _arrayConstruct_Pointer(TIterator,
34                                                 TIterator,
35                                                 True)
36 {
37 SEQAN_CHECKPOINT
38         //nothing to do
39 }
40 template<typename TIterator>
41 inline void
42 _arrayConstruct_Pointer(TIterator begin_,
43                                                 TIterator end_,
44                                                 False)
45 {
46 SEQAN_CHECKPOINT
47         _arrayConstruct_Default(begin_, end_);
48 }
49 template<typename TValue>
50 inline void
51 arrayConstruct(TValue * begin_,
52                            TValue * end_)
53 {
54 SEQAN_CHECKPOINT
55         _arrayConstruct_Pointer(begin_, end_, typename IsSimple<TValue>::Type() );
56 }
57
58 //____________________________________________________________________________
59
60 template<typename TIterator, typename TParam>
61 inline void
62 _arrayConstruct_Pointer(TIterator begin_,
63                                                 TIterator end_,
64                                                 TParam const & param_,
65                                                 True)
66 {
67 SEQAN_CHECKPOINT
68         arrayFill(begin_, end_, param_);
69 }
70 template<typename TIterator, typename TParam>
71 inline void
72 _arrayConstruct_Pointer(TIterator begin_,
73                                                 TIterator end_,
74                                                 TParam const & param_,
75                                                 False)
76 {
77 SEQAN_CHECKPOINT
78         _arrayConstruct_Default(begin_, end_, param_);
79 }
80 template<typename TValue, typename TParam>
81 inline void
82 arrayConstruct(TValue * begin_,
83                            TValue * end_,
84                            TParam const & param_)
85 {
86 SEQAN_CHECKPOINT
87         _arrayConstruct_Pointer(begin_, end_, param_, typename IsSimple<TValue>::Type() );
88 }
89
90 //////////////////////////////////////////////////////////////////////////////
91 //arrayConstructCopy
92 //////////////////////////////////////////////////////////////////////////////
93
94 template<typename TValue>
95 inline void
96 _arrayConstructCopy_Pointer(TValue * source_begin,
97                                                         TValue * source_end,
98                                                         TValue * target_begin,
99                                                         True)
100 {
101 SEQAN_CHECKPOINT
102         arrayCopyForward(source_begin, source_end, target_begin);
103 }
104 template<typename TValue>
105 inline void
106 _arrayConstructCopy_Pointer(TValue * source_begin,
107                                                         TValue * source_end,
108                                                         TValue * target_begin,
109                                                         False)
110 {
111 SEQAN_CHECKPOINT
112         _arrayConstructCopy_Default(source_begin, source_end, target_begin);
113 }
114 template<typename TValue>
115 inline void
116 arrayConstructCopy(TValue * source_begin,
117                                    TValue * source_end,
118                                    TValue * target_begin)
119 {
120 SEQAN_CHECKPOINT
121         _arrayConstructCopy_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
122 }
123
124 //////////////////////////////////////////////////////////////////////////////
125 //arrayConstructMove
126 //////////////////////////////////////////////////////////////////////////////
127
128 template<typename TValue>
129 inline void
130 _arrayConstructMove_Pointer(TValue * source_begin,
131                                                         TValue * source_end,
132                                                         TValue * target_begin,
133                                                         True)
134 {
135 SEQAN_CHECKPOINT
136         arrayMoveForward(source_begin, source_end, target_begin);
137 }
138 template<typename TValue>
139 inline void
140 _arrayConstructMove_Pointer(TValue * source_begin,
141                                                         TValue * source_end,
142                                                         TValue * target_begin,
143                                                         False)
144 {
145 SEQAN_CHECKPOINT
146         _arrayConstructMove_Default(source_begin, source_end, target_begin);
147 }
148 template<typename TValue>
149 inline void
150 arrayConstructMove(TValue * source_begin,
151                                    TValue * source_end,
152                                    TValue * target_begin)
153 {
154 SEQAN_CHECKPOINT
155         _arrayConstructMove_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
156 }
157
158 //////////////////////////////////////////////////////////////////////////////
159 //arrayDestruct
160 //////////////////////////////////////////////////////////////////////////////
161
162 template<typename TValue>
163 inline void
164 _arrayDestruct_Pointer(TValue * /*begin_*/,
165                                            TValue * /*end_*/,
166                                            True)
167 {
168 SEQAN_CHECKPOINT
169         //do nothing
170 }
171 template<typename TValue>
172 inline void
173 _arrayDestruct_Pointer(TValue * begin_,
174                                            TValue * end_,
175                                            False)
176 {
177 SEQAN_CHECKPOINT
178         _arrayDestruct_Default(begin_, end_);
179 }
180 template<typename TValue>
181 inline void
182 arrayDestruct(TValue * begin_,
183                           TValue * end_)
184 {
185 SEQAN_CHECKPOINT
186         _arrayDestruct_Pointer(begin_, end_, typename IsSimple<TValue>::Type() );
187 }
188
189 //////////////////////////////////////////////////////////////////////////////
190 //arrayFill
191 //////////////////////////////////////////////////////////////////////////////
192
193 //no specializiation for pointer to simple
194
195 //////////////////////////////////////////////////////////////////////////////
196 //arrayCopyForward
197 //////////////////////////////////////////////////////////////////////////////
198
199 template<typename TValue>
200 inline void
201 _arrayCopyForward_Pointer(TValue * source_begin,
202                                                   TValue * source_end,
203                                                   TValue * target_begin,
204                                                   True)
205 {
206 SEQAN_CHECKPOINT
207         memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
208 }
209 template<typename TValue>
210 inline void
211 _arrayCopyForward_Pointer(TValue * source_begin,
212                                                   TValue * source_end,
213                                                   TValue * target_begin,
214                                                   False)
215 {
216 SEQAN_CHECKPOINT
217         _arrayCopyForward_Default(source_begin, source_end, target_begin);
218 }
219 template<typename TValue>
220 inline void
221 arrayCopyForward(TValue * source_begin,
222                                  TValue * source_end,
223                                  TValue * target_begin)
224 {
225 SEQAN_CHECKPOINT
226         _arrayCopyForward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
227 }
228
229 //////////////////////////////////////////////////////////////////////////////
230 //arrayCopyBackward
231 //////////////////////////////////////////////////////////////////////////////
232
233 template <typename TValue>
234 inline void
235 _arrayCopyBackward_Pointer(TValue * source_begin,
236                                                    TValue * source_end,
237                                                    TValue * target_begin,
238                                                    True)
239 {
240 SEQAN_CHECKPOINT
241         memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
242 }
243 template <typename TValue>
244 inline void
245 _arrayCopyBackward_Pointer(TValue * source_begin,
246                                                    TValue * source_end,
247                                                    TValue * target_begin,
248                                                    False)
249 {
250 SEQAN_CHECKPOINT
251         _arrayCopyBackward_Default(source_begin, source_end, target_begin);
252 }
253 template<typename TValue>
254 inline void
255 arrayCopyBackward(TValue * source_begin,
256                                   TValue * source_end,
257                                   TValue * target_begin)
258 {
259 SEQAN_CHECKPOINT
260         _arrayCopyBackward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
261 }
262
263 //////////////////////////////////////////////////////////////////////////////
264 //arrayMoveForward
265 //////////////////////////////////////////////////////////////////////////////
266
267 template<typename TValue>
268 inline void
269 _arrayMoveForward_Pointer(TValue * source_begin,
270                                                   TValue * source_end,
271                                                   TValue * target_begin,
272                                                   True)
273 {
274 SEQAN_CHECKPOINT
275         memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
276 }
277 template<typename TValue>
278 inline void
279 _arrayMoveForward_Pointer(TValue * source_begin,
280                                                   TValue * source_end,
281                                                   TValue * target_begin,
282                                                   False)
283 {
284 SEQAN_CHECKPOINT
285         _arrayMoveForward_Default(source_begin, source_end, target_begin);
286 }
287 template<typename TValue>
288 inline void
289 arrayMoveForward(TValue * source_begin,
290                                  TValue * source_end,
291                                  TValue * target_begin)
292 {
293 SEQAN_CHECKPOINT
294         _arrayMoveForward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
295 }
296
297 //////////////////////////////////////////////////////////////////////////////
298 //arrayMoveBackward
299 //////////////////////////////////////////////////////////////////////////////
300
301 template <typename TValue>
302 inline void
303 _arrayMoveBackward_Pointer(TValue * source_begin,
304                                                    TValue * source_end,
305                                                    TValue * target_begin,
306                                                    True)
307 {
308 SEQAN_CHECKPOINT
309         memmove(target_begin, source_begin, (source_end - source_begin) * sizeof(TValue));
310 }
311 template <typename TValue>
312 inline void
313 _arrayMoveBackward_Pointer(TValue * source_begin,
314                                                    TValue * source_end,
315                                                    TValue * target_begin,
316                                                    False)
317 {
318 SEQAN_CHECKPOINT
319         _arrayMoveBackward_Default(source_begin, source_end, target_begin);
320 }
321 template<typename TValue>
322 inline void
323 arrayMoveBackward(TValue * source_begin,
324                                   TValue * source_end,
325                                   TValue * target_begin)
326 {
327 SEQAN_CHECKPOINT
328         _arrayMoveBackward_Pointer(source_begin, source_end, target_begin, typename IsSimple<TValue>::Type() );
329 }
330
331 //////////////////////////////////////////////////////////////////////////////
332 //arrayClearSpace
333 //////////////////////////////////////////////////////////////////////////////
334
335 template <typename TValue>
336 inline void
337 _arrayClearSpace_Pointer(TValue * array_begin,
338                                                 size_t array_length,
339                                                 size_t keep_from,
340                                                 size_t move_to,
341                                                 True)
342 {
343         if (keep_from == move_to) return;
344 SEQAN_CHECKPOINT
345         arrayMove(array_begin + keep_from, array_begin + array_length, array_begin + move_to);
346 }
347 template <typename TValue>
348 inline void
349 _arrayClearSpace_Pointer(TValue * array_begin,
350                                                 size_t array_length,
351                                                 size_t keep_from,
352                                                 size_t move_to,
353                                                 False)
354 {
355         _arrayClearSpace_Default(array_begin, array_length, keep_from, move_to);
356 }
357 template <typename TValue>
358 void arrayClearSpace(TValue * array_begin,
359                                          size_t array_length,
360                                          size_t keep_from,
361                                          size_t move_to)
362 {
363         _arrayClearSpace_Pointer(array_begin, array_length, keep_from, move_to, typename IsSimple<TValue>::Type() );
364 }
365
366
367
368 //////////////////////////////////////////////////////////////////////////////
369 // IsSimple specializations
370 //////////////////////////////////////////////////////////////////////////////
371
372 // standard types
373 template <> struct _IsSimple< bool > { typedef True Type; };
374 template <> struct _IsSimple< char > { typedef True Type; };
375
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; };
380
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; };
385
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; };
389
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; };
393
394 //////////////////////////////////////////////////////////////////////////////
395 // gapValue
396 //////////////////////////////////////////////////////////////////////////////
397
398 inline char const &
399 gapValueImpl(char *)
400 {
401 SEQAN_CHECKPOINT
402         static char const _gap = '-';
403         return _gap;
404 }
405 inline char const &
406 gapValueImpl(char const *)
407 {
408 SEQAN_CHECKPOINT
409         static char const _gap = '-';
410         return _gap;
411 }
412
413 //////////////////////////////////////////////////////////////////////////////
414 // generic extreme values
415 //////////////////////////////////////////////////////////////////////////////
416
417 template <typename T>
418 inline T const &
419 supremumValueImpl(T *)
420 {
421 SEQAN_CHECKPOINT
422         return SupremumValue<T>::VALUE;
423 }
424 template <typename T>
425 inline T const &
426 infimumValueImpl(T *)
427 {
428 SEQAN_CHECKPOINT
429         return InfimumValue<T>::VALUE;
430 }
431
432 //////////////////////////////////////////////////////////////////////////////
433 // bool
434 //////////////////////////////////////////////////////////////////////////////
435
436 template <> struct BitsPerValue< bool > { enum { VALUE = 1 }; };
437
438 /*
439 //////////////////////////////////////////////////////////////////////////////
440 // char
441 //////////////////////////////////////////////////////////////////////////////
442
443 inline char const &
444 supremumValueImpl(char *)
445 {
446 SEQAN_CHECKPOINT
447         static char const _value = (char) 127;
448         return _value;
449 }
450 inline char const &
451 infimumValueImpl(char *)
452 {
453 SEQAN_CHECKPOINT
454         static char const _value = (char) -128;
455         return _value;
456 }
457
458 //////////////////////////////////////////////////////////////////////////////
459 // signed char
460 //////////////////////////////////////////////////////////////////////////////
461
462 inline signed char const &
463 supremumValueImpl(signed char *)
464 {
465 SEQAN_CHECKPOINT
466         static signed char const _value = 127;
467         return _value;
468 }
469 inline signed char const &
470 infimumValueImpl(signed char *)
471 {
472 SEQAN_CHECKPOINT
473         static signed char const _value = -128;
474         return _value;
475 }
476
477 //////////////////////////////////////////////////////////////////////////////
478 // unsigned char
479 //////////////////////////////////////////////////////////////////////////////
480
481 inline unsigned char const &
482 supremumValueImpl(unsigned char *)
483 {
484 SEQAN_CHECKPOINT
485         static unsigned char const _value = 255;
486         return _value;
487 }
488 inline unsigned char const &
489 infimumValueImpl(unsigned char *)
490 {
491 SEQAN_CHECKPOINT
492         static unsigned char const _value = 0;
493         return _value;
494 }
495
496 //////////////////////////////////////////////////////////////////////////////
497 // wchar_t
498 //////////////////////////////////////////////////////////////////////////////
499
500 inline wchar_t const &
501 supremumValueImpl(wchar_t *)
502 {
503 SEQAN_CHECKPOINT
504         static wchar_t const _value = 1UL << (BitsPerValue<wchar_t>::VALUE) - 1;
505         return _value;
506 }
507 inline wchar_t const &
508 infimumValueImpl(wchar_t *)
509 {
510 SEQAN_CHECKPOINT
511         static wchar_t const _value = 0;
512         return _value;
513 }
514
515 //////////////////////////////////////////////////////////////////////////////
516 // signed short
517 //////////////////////////////////////////////////////////////////////////////
518
519 inline signed short const &
520 supremumValueImpl(signed short *)
521 {
522 SEQAN_CHECKPOINT
523         static signed short const _value = (((1 << (BitsPerValue<signed short>::VALUE - 2)) - 1) << 1) + 1;
524         return _value;
525 }
526 inline signed short const &
527 infimumValueImpl(signed short *dummy)
528 {
529 SEQAN_CHECKPOINT
530         static signed short const _value = -supremumValueImpl(dummy) - 1;
531         return _value;
532 }
533
534 //////////////////////////////////////////////////////////////////////////////
535 // unsigned short
536 //////////////////////////////////////////////////////////////////////////////
537
538 inline unsigned short const &
539 supremumValueImpl(unsigned short *)
540 {
541 SEQAN_CHECKPOINT
542         static unsigned short const _value = (((1 << (BitsPerValue<unsigned short>::VALUE - 1)) - 1) << 1) + 1;
543         return _value;
544 }
545 inline unsigned short const &
546 infimumValueImpl(unsigned short *)
547 {
548 SEQAN_CHECKPOINT
549         static unsigned short const _value = 0;
550         return _value;
551 }
552
553 //////////////////////////////////////////////////////////////////////////////
554 // signed int
555 //////////////////////////////////////////////////////////////////////////////
556
557 inline signed int const &
558 supremumValueImpl(signed int *)
559 {
560 SEQAN_CHECKPOINT
561         static signed int const _value = (((1 << (BitsPerValue<signed int>::VALUE - 2)) - 1) << 1) + 1;
562         return _value;
563 }
564 inline signed int const &
565 infimumValueImpl(signed int *dummy)
566 {
567 SEQAN_CHECKPOINT
568         static signed int const _value = -supremumValueImpl(dummy) - 1;
569         return _value;
570 }
571
572 //////////////////////////////////////////////////////////////////////////////
573 // unsigned int
574 //////////////////////////////////////////////////////////////////////////////
575
576 inline unsigned int const &
577 supremumValueImpl(unsigned int *)
578 {
579 SEQAN_CHECKPOINT
580         static unsigned int const _value = ~0ul;
581         return _value;
582 }
583 inline unsigned int const &
584 infimumValueImpl(unsigned int *)
585 {
586 SEQAN_CHECKPOINT
587         static unsigned int const _value = 0;
588         return _value;
589 }
590
591 //////////////////////////////////////////////////////////////////////////////
592 // signed long
593 //////////////////////////////////////////////////////////////////////////////
594
595 inline signed long const &
596 supremumValueImpl(signed long *)
597 {
598 SEQAN_CHECKPOINT
599         static signed long const _value = (((1 << (BitsPerValue<signed long>::VALUE - 2)) - 1) << 1) + 1;
600         return _value;
601 }
602 inline signed long const &
603 infimumValueImpl(signed long *dummy)
604 {
605 SEQAN_CHECKPOINT
606         static signed long const _value = -supremumValueImpl(dummy) - 1;
607         return _value;
608 }
609
610 //////////////////////////////////////////////////////////////////////////////
611 // unsigned long
612 //////////////////////////////////////////////////////////////////////////////
613
614 inline unsigned long const &
615 supremumValueImpl(unsigned long *)
616 {
617 SEQAN_CHECKPOINT
618         static unsigned long const _value = ~0ul;
619         return _value;
620 }
621 inline unsigned long const &
622 infimumValueImpl(unsigned long *)
623 {
624 SEQAN_CHECKPOINT
625         static unsigned long const _value = 0;
626         return _value;
627 }
628
629 //////////////////////////////////////////////////////////////////////////////
630 // signed 64bit int (cannot use long long <- no ISO C++)
631 //////////////////////////////////////////////////////////////////////////////
632
633 inline __int64 const &
634 supremumValueImpl(__int64 *)
635 {
636 SEQAN_CHECKPOINT
637         static __int64 const _value = ((((__int64)1 << (BitsPerValue<__int64>::VALUE - 2)) - 1) << 1) + 1;
638         return _value;
639 }
640 inline __int64 const &
641 infimumValueImpl(__int64 *dummy)
642 {
643 SEQAN_CHECKPOINT
644         static __int64 const _value = -supremumValueImpl(dummy) - 1;
645         return _value;
646 }
647 */
648
649 //////////////////////////////////////////////////////////////////////////////
650 // float
651 //////////////////////////////////////////////////////////////////////////////
652
653 inline float const &
654 supremumValueImpl(float *)
655 {
656 SEQAN_CHECKPOINT
657 #ifdef PLATFORM_WINDOWS
658         static float const _value = ::std::numeric_limits<float>::infinity( );
659 #else
660         static float const _value = 3.40282347e+38F;
661 #endif
662         return _value;
663 }
664 inline float const &
665 infimumValueImpl(float *)
666 {
667 SEQAN_CHECKPOINT
668 #ifdef PLATFORM_WINDOWS
669         static float const _value = -::std::numeric_limits<float>::infinity( );
670 #else
671         static float const _value = -3.40282347e+38F;
672 #endif
673         return _value;
674 }
675
676 //////////////////////////////////////////////////////////////////////////////
677 // double
678 //////////////////////////////////////////////////////////////////////////////
679
680 inline double const &
681 supremumValueImpl(double *)
682 {
683 SEQAN_CHECKPOINT
684 #ifdef PLATFORM_WINDOWS
685         static double const _value = ::std::numeric_limits<double>::infinity( );
686 #else
687         static double const _value = 1.7976931348623157e+308;
688 #endif
689         return _value;
690 }
691 inline double const &
692 infimumValueImpl(double *)
693 {
694 SEQAN_CHECKPOINT
695 #ifdef PLATFORM_WINDOWS
696         static double const _value = -::std::numeric_limits<double>::infinity( );
697 #else
698         static double const _value = -1.7976931348623157e+308;
699 #endif
700         return _value;
701 }
702
703 //////////////////////////////////////////////////////////////////////////////
704 // long double
705 //////////////////////////////////////////////////////////////////////////////
706
707 inline long double const &
708 supremumValueImpl(long double *)
709 {
710 SEQAN_CHECKPOINT
711 #ifdef PLATFORM_WINDOWS
712         static long double const _value = ::std::numeric_limits<long double>::infinity( );
713 #else
714         static long double const _value = 1.7976931348623157e+308;
715 #endif
716         return _value;
717 }
718 inline long double const &
719 infimumValueImpl(long double *)
720 {
721 SEQAN_CHECKPOINT
722 #ifdef PLATFORM_WINDOWS
723         static long double const _value = -::std::numeric_limits<long double>::infinity( );
724 #else
725         static long double const _value = -1.7976931348623157e+308;
726 #endif
727         return _value;
728 }
729
730 //////////////////////////////////////////////////////////////////////////////
731 }// namespace SEQAN_NAMESPACE_MAIN
732
733 #endif //#ifndef SEQAN_HEADER_...