Commit patch to not break on spaces.
[bowtie.git] / SeqAn-1.1 / seqan / basic / basic_alphabet_simple.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_simple.h,v 1.1 2008/08/25 16:20:02 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_BASIC_ALPHABET_SIMPLE_H
22 #define SEQAN_HEADER_BASIC_ALPHABET_SIMPLE_H
23
24 namespace SEQAN_NAMESPACE_MAIN
25 {
26
27 //////////////////////////////////////////////////////////////////////////////
28 //Class that is used for various simple value types
29 //////////////////////////////////////////////////////////////////////////////
30
31 /**
32 .Class.SimpleType:
33 ..cat:Basic
34 ..summary:Implementation for "simple" types.
35 ..signature:SimpleType<TValue, TSpec>
36 ..param.TValue:Type that stores the values of an instance.
37 ...remarks:TValue must be a simple type.
38 ...metafunction:Metafunction.Value
39 ..param.TSpec:Specialization tag.
40 ...metafunction:Metafunction.Spec
41 ..remarks:
42 ...text:A "simple type" is a C++ type that can be constructed without constructor,
43 destructed without destructor and copied without copy constructor or assignment operator.
44 All basic types (like $char$, $int$ or $float$) are simple. Pointers, references and arrays of
45 simple types are simple.
46 POD types ("plain old data types"), that are - simplified spoken - C++-types that already existed in C,
47 are simple too. 
48 ...text:Arrays of simple types can be copied very fast by memory manipulation routines, 
49 but the default implementation of functions like @Function.arrayCopyForward@ and @Function.arrayCopy@
50 are not optimized for simple types this way.
51 But for classes derived from $SimpleType$, optimized variants of array manipulation functions are applied. 
52 ...text:Note that simple types need not to be derived or specialized from $SimpleType$, but
53 it could be convenient to do so.
54 ..implements:Concept.Simple Type
55 */
56 template <typename TValue, typename TSpec>
57 struct SimpleType
58 {
59 //____________________________________________________________________________
60
61         TValue value;
62
63 //____________________________________________________________________________
64
65         SimpleType() 
66         {
67 SEQAN_CHECKPOINT
68         }
69
70 //____________________________________________________________________________
71
72         SimpleType(SimpleType const & other)
73         {
74 SEQAN_CHECKPOINT
75                 assign(*this, other);
76         }
77
78         template <typename T> 
79         SimpleType(T const & other) 
80         {
81 SEQAN_CHECKPOINT
82                 assign(*this, other);
83         }
84
85
86 //____________________________________________________________________________
87
88         SimpleType & operator=(SimpleType const & other) 
89         { 
90 SEQAN_CHECKPOINT
91                 assign(*this, other);
92                 return *this;
93         }
94         template <typename T>
95         SimpleType & operator=(T const & other) 
96         { 
97 SEQAN_CHECKPOINT
98                 assign(*this, other);
99                 return *this;
100         }
101 //____________________________________________________________________________
102
103         ~SimpleType()
104         {
105 SEQAN_CHECKPOINT
106         }
107 //____________________________________________________________________________
108
109         //this cannot be a template since a template would be in conflict to
110         //the template c'tor
111
112
113         operator long() const
114         {
115 SEQAN_CHECKPOINT
116                 long c;
117                 assign(c, *this);
118                 return c;
119         }
120         operator unsigned long() const
121         {
122 SEQAN_CHECKPOINT
123                 unsigned long c;
124                 assign(c, *this);
125                 return c;
126         }
127         operator int() const
128         {
129 SEQAN_CHECKPOINT
130                 int c;
131                 assign(c, *this);
132                 return c;
133         }
134         operator unsigned int() const
135         {
136 SEQAN_CHECKPOINT
137                 unsigned int c;
138                 assign(c, *this);
139                 return c;
140         }
141         operator short() const
142         {
143 SEQAN_CHECKPOINT
144                 short c;
145                 assign(c, *this);
146                 return c;
147         }
148         operator unsigned short() const
149         {
150 SEQAN_CHECKPOINT
151                 unsigned short c;
152                 assign(c, *this);
153                 return c;
154         }
155         operator char() const
156         {
157 SEQAN_CHECKPOINT
158                 char c;
159                 assign(c, *this);
160                 return c;
161         }
162         operator signed char() const
163         {
164 SEQAN_CHECKPOINT
165                 signed char c;
166                 assign(c, *this);
167                 return c;
168         }
169         operator unsigned char() const
170         {
171 SEQAN_CHECKPOINT
172                 unsigned char c;
173                 assign(c, *this);
174                 return c;
175         }
176
177 //____________________________________________________________________________
178 };
179
180 //////////////////////////////////////////////////////////////////////////////
181 // METAFUNCTIONS
182 //////////////////////////////////////////////////////////////////////////////
183
184 ///.Metafunction.IsSimple.param.T.type:Class.SimpleType
185
186 template <typename TValue, typename TSpec>
187 struct IsSimple<SimpleType<TValue, TSpec> >
188 {
189         typedef True Type;
190 };
191
192 //////////////////////////////////////////////////////////////////////////////
193
194 ///.Metafunction.Value.param.T.type:Class.SimpleType
195 template <typename TValue, typename TSpec>
196 struct Value<SimpleType<TValue, TSpec> >
197 {
198         typedef TValue Type;
199 };
200
201 template <typename TValue, typename TSpec>
202 struct Value<SimpleType<TValue, TSpec> const >
203 {
204         typedef TValue const Type;
205 };
206
207 //////////////////////////////////////////////////////////////////////////////
208
209 ///.Metafunction.Spec.param.T.type:Class.SimpleType
210 template <typename TValue, typename TSpec>
211 struct Spec<SimpleType<TValue, TSpec> >
212 {
213         typedef TSpec Type;
214 };
215
216 template <typename TValue, typename TSpec>
217 struct Spec<SimpleType<TValue, TSpec> const >
218 {
219         typedef TSpec Type;
220 };
221
222 //////////////////////////////////////////////////////////////////////////////
223
224 template <typename TValue, typename TSpec>
225 struct Iterator<SimpleType<TValue, TSpec>, Standard>
226 {
227         typedef SimpleType<TValue, TSpec> * Type;
228 //      typedef Iter<SimpleType<TValue, TSpec>, SimpleIterator> * Type;
229 };
230
231 template <typename TValue, typename TSpec>
232 struct Iterator<SimpleType<TValue, TSpec> const, Standard>
233 {
234         typedef SimpleType<TValue, TSpec> const * Type;
235 //      typedef Iter<SimpleType<TValue, TSpec> const, SimpleIterator> * Type;
236 };
237
238
239 //////////////////////////////////////////////////////////////////////////////
240 // FUNCTIONS
241 //////////////////////////////////////////////////////////////////////////////
242
243 template <typename TTarget, typename T, typename TSourceValue, typename TSourceSpec>
244 inline typename _RemoveConst<TTarget>::Type
245 convertImpl(Convert<TTarget, T> const,
246                         SimpleType<TSourceValue, TSourceSpec> const & source_)
247 {
248 SEQAN_CHECKPOINT
249         typename _RemoveConst<TTarget>::Type target_;
250         assign(target_, source_);
251         return target_;
252 }
253
254
255
256 //////////////////////////////////////////////////////////////////////////////
257
258 template <typename TStream, typename TValue, typename TSpec>
259 inline TStream &
260 operator << (TStream & stream, 
261                          SimpleType<TValue, TSpec> const & data)
262 {
263 SEQAN_CHECKPOINT
264         stream << convert<char>(data);
265         return stream;
266 }
267
268 //////////////////////////////////////////////////////////////////////////////
269
270 template <typename TStream, typename TValue, typename TSpec>
271 inline TStream &
272 operator >> (TStream & stream, 
273                          SimpleType<TValue, TSpec> & data)
274 {
275 SEQAN_CHECKPOINT
276         char c;
277         stream >> c;
278         assign(data, c);
279         return stream;
280 }
281
282 //////////////////////////////////////////////////////////////////////////////
283 // assign
284 //////////////////////////////////////////////////////////////////////////////
285
286 ///.Function.assign.param.target.type:Class.SimpleType
287 ///.Function.assign.param.source.type:Class.SimpleType
288
289
290 template <typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TSourceSpec>
291 inline void 
292 assign(SimpleType<TTargetValue, TTargetSpec> & target, 
293            SimpleType<TSourceValue, TSourceSpec> & source)
294 {
295 SEQAN_CHECKPOINT
296         target.value = source.value;
297 }
298 template <typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TSourceSpec>
299 inline void 
300 assign(SimpleType<TTargetValue, TTargetSpec> & target, 
301            SimpleType<TSourceValue, TSourceSpec> const & source)
302 {
303 SEQAN_CHECKPOINT
304         target.value = source.value;
305 }
306
307 //____________________________________________________________________________
308
309 template <typename TTargetValue, typename TTargetSpec, typename TSource>
310 inline void 
311 assign(SimpleType<TTargetValue, TTargetSpec> & target, 
312            TSource & source)
313 {
314 SEQAN_CHECKPOINT
315         target.value = source;
316 }
317 template <typename TTargetValue, typename TTargetSpec, typename TSource>
318 inline void 
319 assign(SimpleType<TTargetValue, TTargetSpec> & target, 
320            TSource const & source)
321 {
322 SEQAN_CHECKPOINT
323         target.value = source;
324 }
325
326 //____________________________________________________________________________
327 // Assign Proxy to SimpleType 
328 //??? Diese Funktionen wurden noetig wegen eines seltsamen VC++-Verhaltens
329
330 template <typename TTargetValue, typename TTargetSpec, typename TSourceSpec>
331 inline void 
332 assign(SimpleType<TTargetValue, TTargetSpec> & target, 
333            Proxy<TSourceSpec> & source)
334 {
335 SEQAN_CHECKPOINT
336         target.value = getValue(source);
337 }
338
339 template <typename TTargetValue, typename TTargetSpec, typename TSourceSpec>
340 inline void 
341 assign(SimpleType<TTargetValue, TTargetSpec> & target, 
342            Proxy<TSourceSpec> const & source)
343 {
344 SEQAN_CHECKPOINT
345         target.value = getValue(source);
346 }
347
348 //____________________________________________________________________________
349 //INTEGRAL TYPES
350 //note: it is not possible to write a single function here since "assign"
351 //must be specialized for the first argument at the first place
352
353 //int
354 template <typename TValue, typename TSpec>
355 inline void 
356 assign(int & c_target, 
357            SimpleType<TValue, TSpec> & source)
358 {
359 SEQAN_CHECKPOINT
360         c_target = source.value;
361 }
362 template <typename TValue, typename TSpec>
363 inline void 
364 assign(int & c_target, 
365            SimpleType<TValue, TSpec> const & source)
366 {
367 SEQAN_CHECKPOINT
368         c_target = source.value;
369 }
370
371 //unsigned int
372 template <typename TValue, typename TSpec>
373 inline void 
374 assign(unsigned int & c_target, 
375            SimpleType<TValue, TSpec> & source)
376 {
377 SEQAN_CHECKPOINT
378         c_target = source.value;
379 }
380 template <typename TValue, typename TSpec>
381 inline void 
382 assign(unsigned int & c_target, 
383            SimpleType<TValue, TSpec> const & source)
384 {
385 SEQAN_CHECKPOINT
386         c_target = source.value;
387 }
388
389 //short
390 template <typename TValue, typename TSpec>
391 inline void 
392 assign(short & c_target, 
393            SimpleType<TValue, TSpec> & source)
394 {
395 SEQAN_CHECKPOINT
396         c_target = source.value;
397 }
398 template <typename TValue, typename TSpec>
399 inline void 
400 assign(short & c_target, 
401            SimpleType<TValue, TSpec> const & source)
402 {
403 SEQAN_CHECKPOINT
404         c_target = source.value;
405 }
406
407 //unsigned short
408 template <typename TValue, typename TSpec>
409 inline void 
410 assign(unsigned short & c_target, 
411            SimpleType<TValue, TSpec> & source)
412 {
413 SEQAN_CHECKPOINT
414         c_target = source.value;
415 }
416 template <typename TValue, typename TSpec>
417 inline void 
418 assign(unsigned short & c_target, 
419            SimpleType<TValue, TSpec> const & source)
420 {
421 SEQAN_CHECKPOINT
422         c_target = source.value;
423 }
424
425 //char
426 template <typename TValue, typename TSpec>
427 inline void 
428 assign(char & c_target, 
429            SimpleType<TValue, TSpec> & source)
430 {
431 SEQAN_CHECKPOINT
432         c_target = source.value;
433 }
434 template <typename TValue, typename TSpec>
435 inline void 
436 assign(char & c_target, 
437            SimpleType<TValue, TSpec> const & source)
438 {
439 SEQAN_CHECKPOINT
440         c_target = source.value;
441 }
442
443 //signed char
444 template <typename TValue, typename TSpec>
445 inline void 
446 assign(signed char & c_target, 
447            SimpleType<TValue, TSpec> & source)
448 {
449 SEQAN_CHECKPOINT
450         c_target = source.value;
451 }
452 template <typename TValue, typename TSpec>
453 inline void 
454 assign(signed char & c_target, 
455            SimpleType<TValue, TSpec> const & source)
456 {
457 SEQAN_CHECKPOINT
458         c_target = source.value;
459 }
460
461 //unsigned char
462 template <typename TValue, typename TSpec>
463 inline void 
464 assign(unsigned char & c_target, 
465            SimpleType<TValue, TSpec> & source)
466 {
467 SEQAN_CHECKPOINT
468         c_target = source.value;
469 }
470 template <typename TValue, typename TSpec>
471 inline void 
472 assign(unsigned char & c_target, 
473            SimpleType<TValue, TSpec> const & source)
474 {
475 SEQAN_CHECKPOINT
476         c_target = source.value;
477 }
478
479 //////////////////////////////////////////////////////////////////////////////
480 //////////////////////////////////////////////////////////////////////////////
481 // CompareType
482 //////////////////////////////////////////////////////////////////////////////
483
484 /**.Metafunction.CompareType:
485 ..summary:Type to convert other types for comparisons.
486 ..signature:CompareType<TLeft, TRight>::Type
487 ..param.TLeft:Type of the left operand of a comparison.
488 ..param.TRight:Type of the right operand of a comparison.
489 ..return.Type:The Type in which the arguments are converted in order to compare them.
490 ..remarks:Comparisons are for example operators like $==$ or $<$.
491 ..remarks.text:Note that there is no rule that guarantees that $CompareType<T1, T2>::Type$
492 is the same as $CompareType<T2, T1>::Type$. It is also possible, that only one of these
493 two types is defined.
494 ..remarks.text:This metafunction is used for the implementation of
495 comparisons that involve @Class.SimpleType@.
496 */
497 //???TODO: muss geprueft werden, ob diese Metafunktion noch ausgeweitet oder aber versteckt wird.
498
499 template <typename TLeft, typename TRight>
500 struct CompareType;
501
502 template <typename T>
503 struct CompareType<T, T>
504 {
505         typedef T Type;
506 };
507
508 //____________________________________________________________________________
509
510 template <typename TValue, typename TSpec, typename TRight>
511 struct CompareType<SimpleType<TValue, TSpec>, TRight>
512 {
513         typedef TRight Type;
514 };
515
516 //////////////////////////////////////////////////////////////////////////////
517 // operator ==
518
519 template <typename TValue, typename TSpec, typename TRight>
520 inline bool
521 operator == (SimpleType<TValue, TSpec> const & left_, 
522                          TRight const & right_)
523 {
524 SEQAN_CHECKPOINT
525         typedef SimpleType<TValue, TSpec> TLeft;
526         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
527         return convert<TCompareType>(left_) == convert<TCompareType>(right_);
528 }
529
530 template <typename TLeft, typename TValue, typename TSpec>
531 inline bool
532 operator == (TLeft const & left_, 
533                          SimpleType<TValue, TSpec> const & right_)
534 {
535 SEQAN_CHECKPOINT
536         typedef SimpleType<TValue, TSpec> TRight;
537         typedef typename CompareType<TRight, TLeft>::Type TCompareType;
538         return convert<TCompareType>(left_) == convert<TCompareType>(right_);
539 }
540
541 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
542 inline bool
543 operator == (SimpleType<TLeftValue, TLeftSpec> const & left_, 
544                          SimpleType<TRightValue, TRightSpec> const & right_)
545 {
546 SEQAN_CHECKPOINT
547         typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
548         typedef SimpleType<TRightValue, TRightSpec> TRight;
549         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
550         return convert<TCompareType>(left_) == convert<TCompareType>(right_);
551 }
552
553 template <typename TValue, typename TSpec>
554 inline bool
555 operator == (SimpleType<TValue, TSpec> const & left_, 
556                          SimpleType<TValue, TSpec> const & right_)
557 {
558 SEQAN_CHECKPOINT
559         return convert<TValue>(left_) == convert<TValue>(right_);
560 }
561
562
563 template <typename TSpec, typename TValue, typename TSpec2>
564 inline bool
565 operator == (Proxy<TSpec> const & left_, 
566                          SimpleType<TValue, TSpec2> const & right_)
567 {
568 SEQAN_CHECKPOINT
569         typedef Proxy<TSpec> TLeft;
570         typedef SimpleType<TValue, TSpec> TRight;
571         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
572         return convert<TCompareType>(left_) == convert<TCompareType>(right_);
573 }
574 template <typename TSpec, typename TValue, typename TSpec2>
575 inline bool
576 operator == (SimpleType<TValue, TSpec2> const & left_,
577                          Proxy<TSpec> const & right_)
578 {
579 SEQAN_CHECKPOINT
580         typedef SimpleType<TValue, TSpec> TLeft;
581         typedef Proxy<TSpec> TRight;
582         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
583         return convert<TCompareType>(left_) == convert<TCompareType>(right_);
584 }
585
586
587 //____________________________________________________________________________
588 // operator !=
589
590 template <typename TValue, typename TSpec, typename TRight>
591 inline bool
592 operator != (SimpleType<TValue, TSpec> const & left_, 
593                          TRight const & right_)
594 {
595 SEQAN_CHECKPOINT
596         typedef SimpleType<TValue, TSpec> TLeft;
597         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
598         return convert<TCompareType>(left_) != convert<TCompareType>(right_);
599 }
600
601 template <typename TLeft, typename TValue, typename TSpec>
602 inline bool
603 operator != (TLeft const & left_, 
604                          SimpleType<TValue, TSpec> const & right_)
605 {
606 SEQAN_CHECKPOINT
607         typedef SimpleType<TValue, TSpec> TRight;
608         typedef typename CompareType<TRight, TLeft>::Type TCompareType;
609         return convert<TCompareType>(left_) != convert<TCompareType>(right_);
610 }
611
612 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
613 inline bool
614 operator != (SimpleType<TLeftValue, TLeftSpec> const & left_, 
615                          SimpleType<TRightValue, TRightSpec> const & right_)
616 {
617 SEQAN_CHECKPOINT
618         typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
619         typedef SimpleType<TRightValue, TRightSpec> TRight;
620         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
621         return convert<TCompareType>(left_) != convert<TCompareType>(right_);
622 }
623
624 template <typename TValue, typename TSpec>
625 inline bool
626 operator != (SimpleType<TValue, TSpec> const & left_, 
627                          SimpleType<TValue, TSpec> const & right_)
628 {
629 SEQAN_CHECKPOINT
630         return convert<TValue>(left_) != convert<TValue>(right_);
631 }
632
633
634 template <typename TSpec, typename TValue, typename TSpec2>
635 inline bool
636 operator != (Proxy<TSpec> const & left_, 
637                          SimpleType<TValue, TSpec2> const & right_)
638 {
639 SEQAN_CHECKPOINT
640         typedef Proxy<TSpec> TLeft;
641         typedef SimpleType<TValue, TSpec> TRight;
642         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
643         return convert<TCompareType>(left_) != convert<TCompareType>(right_);
644 }
645 template <typename TSpec, typename TValue, typename TSpec2>
646 inline bool
647 operator != (SimpleType<TValue, TSpec2> const & left_,
648                          Proxy<TSpec> const & right_)
649 {
650 SEQAN_CHECKPOINT
651         typedef SimpleType<TValue, TSpec> TLeft;
652         typedef Proxy<TSpec> TRight;
653         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
654         return convert<TCompareType>(left_) != convert<TCompareType>(right_);
655 }
656
657
658 //____________________________________________________________________________
659 // operator <
660
661 template <typename TValue, typename TSpec, typename TRight>
662 inline bool
663 operator < (SimpleType<TValue, TSpec> const & left_, 
664                         TRight const & right_)
665 {
666 SEQAN_CHECKPOINT
667         typedef SimpleType<TValue, TSpec> TLeft;
668         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
669         return convert<TCompareType>(left_) < convert<TCompareType>(right_);
670 }
671
672 template <typename TLeft, typename TValue, typename TSpec>
673 inline bool
674 operator < (TLeft const & left_, 
675                         SimpleType<TValue, TSpec> const & right_)
676 {
677 SEQAN_CHECKPOINT
678         typedef SimpleType<TValue, TSpec> TRight;
679         typedef typename CompareType<TRight, TLeft>::Type TCompareType;
680         return convert<TCompareType>(left_) < convert<TCompareType>(right_);
681 }
682
683 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
684 inline bool
685 operator < (SimpleType<TLeftValue, TLeftSpec> const & left_, 
686                         SimpleType<TRightValue, TRightSpec> const & right_)
687 {
688 SEQAN_CHECKPOINT
689         typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
690         typedef SimpleType<TRightValue, TRightSpec> TRight;
691         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
692         return convert<TCompareType>(left_) < convert<TCompareType>(right_);
693 }
694
695 template <typename TValue, typename TSpec>
696 inline bool
697 operator < (SimpleType<TValue, TSpec> const & left_, 
698                         SimpleType<TValue, TSpec> const & right_)
699 {
700 SEQAN_CHECKPOINT
701         return convert<TValue>(left_) < convert<TValue>(right_);
702 }
703
704
705 template <typename TSpec, typename TValue, typename TSpec2>
706 inline bool
707 operator < (Proxy<TSpec> const & left_, 
708                          SimpleType<TValue, TSpec2> const & right_)
709 {
710 SEQAN_CHECKPOINT
711         typedef Proxy<TSpec> TLeft;
712         typedef SimpleType<TValue, TSpec> TRight;
713         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
714         return convert<TCompareType>(left_) < convert<TCompareType>(right_);
715 }
716 template <typename TSpec, typename TValue, typename TSpec2>
717 inline bool
718 operator < (SimpleType<TValue, TSpec2> const & left_,
719                          Proxy<TSpec> const & right_)
720 {
721 SEQAN_CHECKPOINT
722         typedef SimpleType<TValue, TSpec> TLeft;
723         typedef Proxy<TSpec> TRight;
724         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
725         return convert<TCompareType>(left_) < convert<TCompareType>(right_);
726 }
727
728
729 //____________________________________________________________________________
730 // operator <=
731
732 template <typename TValue, typename TSpec, typename TRight>
733 inline bool
734 operator <= (SimpleType<TValue, TSpec> const & left_, 
735                          TRight const & right_)
736 {
737 SEQAN_CHECKPOINT
738         typedef SimpleType<TValue, TSpec> TLeft;
739         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
740         return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
741 }
742
743 template <typename TLeft, typename TValue, typename TSpec>
744 inline bool
745 operator <= (TLeft const & left_, 
746                          SimpleType<TValue, TSpec> const & right_)
747 {
748 SEQAN_CHECKPOINT
749         typedef SimpleType<TValue, TSpec> TRight;
750         typedef typename CompareType<TRight, TLeft>::Type TCompareType;
751         return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
752 }
753
754 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
755 inline bool
756 operator <= (SimpleType<TLeftValue, TLeftSpec> const & left_, 
757                          SimpleType<TRightValue, TRightSpec> const & right_)
758 {
759 SEQAN_CHECKPOINT
760         typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
761         typedef SimpleType<TRightValue, TRightSpec> TRight;
762         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
763         return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
764 }
765
766 template <typename TValue, typename TSpec>
767 inline bool
768 operator <= (SimpleType<TValue, TSpec> const & left_, 
769                          SimpleType<TValue, TSpec> const & right_)
770 {
771 SEQAN_CHECKPOINT
772         return convert<TValue>(left_) <= convert<TValue>(right_);
773 }
774
775
776 template <typename TSpec, typename TValue, typename TSpec2>
777 inline bool
778 operator <= (Proxy<TSpec> const & left_, 
779                          SimpleType<TValue, TSpec2> const & right_)
780 {
781 SEQAN_CHECKPOINT
782         typedef Proxy<TSpec> TLeft;
783         typedef SimpleType<TValue, TSpec> TRight;
784         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
785         return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
786 }
787 template <typename TSpec, typename TValue, typename TSpec2>
788 inline bool
789 operator <= (SimpleType<TValue, TSpec2> const & left_,
790                          Proxy<TSpec> const & right_)
791 {
792 SEQAN_CHECKPOINT
793         typedef SimpleType<TValue, TSpec> TLeft;
794         typedef Proxy<TSpec> TRight;
795         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
796         return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
797 }
798
799
800
801 //____________________________________________________________________________
802 // operator >
803
804 template <typename TValue, typename TSpec, typename TRight>
805 inline bool
806 operator > (SimpleType<TValue, TSpec> const & left_, 
807                         TRight const & right_)
808 {
809 SEQAN_CHECKPOINT
810         typedef SimpleType<TValue, TSpec> TLeft;
811         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
812         return convert<TCompareType>(left_) > convert<TCompareType>(right_);
813 }
814
815 template <typename TLeft, typename TValue, typename TSpec>
816 inline bool
817 operator > (TLeft const & left_, 
818                         SimpleType<TValue, TSpec> const & right_)
819 {
820 SEQAN_CHECKPOINT
821         typedef SimpleType<TValue, TSpec> TRight;
822         typedef typename CompareType<TRight, TLeft>::Type TCompareType;
823         return convert<TCompareType>(left_) > convert<TCompareType>(right_);
824 }
825
826 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
827 inline bool
828 operator > (SimpleType<TLeftValue, TLeftSpec> const & left_, 
829                         SimpleType<TRightValue, TRightSpec> const & right_)
830 {
831 SEQAN_CHECKPOINT
832         typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
833         typedef SimpleType<TRightValue, TRightSpec> TRight;
834         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
835         return convert<TCompareType>(left_) > convert<TCompareType>(right_);
836 }
837
838 template <typename TValue, typename TSpec>
839 inline bool
840 operator > (SimpleType<TValue, TSpec> const & left_, 
841                         SimpleType<TValue, TSpec> const & right_)
842 {
843 SEQAN_CHECKPOINT
844         return convert<TValue>(left_) > convert<TValue>(right_);
845 }
846
847
848 template <typename TSpec, typename TValue, typename TSpec2>
849 inline bool
850 operator > (Proxy<TSpec> const & left_, 
851                          SimpleType<TValue, TSpec2> const & right_)
852 {
853 SEQAN_CHECKPOINT
854         typedef Proxy<TSpec> TLeft;
855         typedef SimpleType<TValue, TSpec> TRight;
856         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
857         return convert<TCompareType>(left_) > convert<TCompareType>(right_);
858 }
859 template <typename TSpec, typename TValue, typename TSpec2>
860 inline bool
861 operator > (SimpleType<TValue, TSpec2> const & left_,
862                          Proxy<TSpec> const & right_)
863 {
864 SEQAN_CHECKPOINT
865         typedef SimpleType<TValue, TSpec> TLeft;
866         typedef Proxy<TSpec> TRight;
867         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
868         return convert<TCompareType>(left_) > convert<TCompareType>(right_);
869 }
870
871
872 //____________________________________________________________________________
873 // operator >=
874
875 template <typename TValue, typename TSpec, typename TRight>
876 inline bool
877 operator >= (SimpleType<TValue, TSpec> const & left_, 
878                          TRight const & right_)
879 {
880 SEQAN_CHECKPOINT
881         typedef SimpleType<TValue, TSpec> TLeft;
882         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
883         return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
884 }
885
886 template <typename TLeft, typename TValue, typename TSpec>
887 inline bool
888 operator >= (TLeft const & left_, 
889                          SimpleType<TValue, TSpec> const & right_)
890 {
891 SEQAN_CHECKPOINT
892         typedef SimpleType<TValue, TSpec> TRight;
893         typedef typename CompareType<TRight, TLeft>::Type TCompareType;
894         return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
895 }
896
897 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
898 inline bool
899 operator >= (SimpleType<TLeftValue, TLeftSpec> const & left_, 
900                          SimpleType<TRightValue, TRightSpec> const & right_)
901 {
902 SEQAN_CHECKPOINT
903         typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
904         typedef SimpleType<TRightValue, TRightSpec> TRight;
905         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
906         return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
907 }
908
909 template <typename TValue, typename TSpec>
910 inline bool
911 operator >= (SimpleType<TValue, TSpec> const & left_, 
912                          SimpleType<TValue, TSpec> const & right_)
913 {
914 SEQAN_CHECKPOINT
915         return convert<TValue>(left_) >= convert<TValue>(right_);
916 }
917
918
919 template <typename TSpec, typename TValue, typename TSpec2>
920 inline bool
921 operator >= (Proxy<TSpec> const & left_, 
922                          SimpleType<TValue, TSpec2> const & right_)
923 {
924 SEQAN_CHECKPOINT
925         typedef Proxy<TSpec> TLeft;
926         typedef SimpleType<TValue, TSpec> TRight;
927         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
928         return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
929 }
930 template <typename TSpec, typename TValue, typename TSpec2>
931 inline bool
932 operator >= (SimpleType<TValue, TSpec2> const & left_,
933                          Proxy<TSpec> const & right_)
934 {
935 SEQAN_CHECKPOINT
936         typedef SimpleType<TValue, TSpec> TLeft;
937         typedef Proxy<TSpec> TRight;
938         typedef typename CompareType<TLeft, TRight>::Type TCompareType;
939         return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
940 }
941
942
943 //////////////////////////////////////////////////////////////////////////////
944
945 template<typename _T, typename TSpec> 
946 inline
947 bool lexLess(SimpleType<_T, TSpec> const &_Left, SimpleType<_T, TSpec> const &_Right)
948 {       // return lexicographical _Left < _Right
949         typedef typename _MakeUnsigned<_T>::Type TUnsigned;
950     return (TUnsigned)(_Left.value) < (TUnsigned)(_Right.value);
951 }
952
953 //////////////////////////////////////////////////////////////////////////////
954
955 template <typename TValue, typename TSpec>
956 inline SimpleType<TValue, TSpec> &
957 operator ++ (SimpleType<TValue, TSpec> & me)
958 {
959         ++me.value;
960         return me;
961 }
962 template <typename TValue, typename TSpec>
963 inline SimpleType<TValue, TSpec>
964 operator ++ (SimpleType<TValue, TSpec> & me,
965                          int)
966 {
967         SimpleType<TValue, TSpec> dummy = me;
968         ++me.value;
969         return dummy;
970 }
971
972 //////////////////////////////////////////////////////////////////////////////
973
974 template <typename TValue, typename TSpec>
975 inline SimpleType<TValue, TSpec> &
976 operator -- (SimpleType<TValue, TSpec> & me)
977 {
978         --me.value;
979         return me;
980 }
981 template <typename TValue, typename TSpec>
982 inline SimpleType<TValue, TSpec>
983 operator -- (SimpleType<TValue, TSpec> & me,
984                          int)
985 {
986         SimpleType<TValue, TSpec> dummy = me;
987         --me.value;
988         return dummy;
989 }
990
991 //////////////////////////////////////////////////////////////////////////////
992 //////////////////////////////////////////////////////////////////////////////
993
994 /**
995 .Spec.Dna:
996 ..cat:Alphabets
997 ..summary:Alphabet for DNA.
998 ..general:Class.SimpleType
999 ..signature:Dna
1000 ..remarks:
1001 ...text:The @Metafunction.ValueSize@ of $Dna$ is 4. 
1002 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'T' = 3$.
1003 ...text:Objects of type $Dna$ can be converted to various other types and vice versa. 
1004 An object that has a value not in ${'A', 'C', 'G', 'T'}$ is converted to $'A'$.
1005 ...text:$Dna$ is typedef for $SimpleType<char,_Dna>$, while $_Dna$ is a helper
1006 specialization tag class.
1007 ..see:Metafunction.ValueSize
1008 ..see:Spec.Dna5
1009 */
1010 struct _Dna {};
1011 typedef SimpleType<unsigned char,_Dna> Dna;
1012
1013 template <> struct ValueSize< Dna > { enum { VALUE = 4 }; };
1014 template <> struct BitsPerValue< Dna > { enum { VALUE = 2 }; };
1015
1016 //____________________________________________________________________________
1017
1018 /**
1019 .Spec.Dna5:
1020 ..cat:Alphabets
1021 ..summary:Alphabet for DNA including 'N' character.
1022 ..general:Class.SimpleType
1023 ..signature:Dna5
1024 ..remarks:
1025 ...text:The @Metafunction.ValueSize@ of $Dna5$ is 5. 
1026 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'T' = 3$. 
1027 The 'N' character ("unkown nucleotide") is encoded by 4.
1028 ...text:Objects of type $Dna5$ can be converted to various other types and vice versa. 
1029 An object that has a value not in ${'A', 'C', 'G', 'T'}$ is converted to $'N'$.
1030 ...text:$Dna5$ is typedef for $SimpleType<char,_Dna5>$, while $_Dna5$ is a helper
1031 specialization tag class.
1032 ..see:Metafunction.ValueSize
1033 */
1034 struct _Dna5 {};
1035 typedef SimpleType<unsigned char, _Dna5> Dna5;
1036
1037 template <> struct ValueSize< Dna5 > { enum { VALUE = 5 }; };
1038 template <> struct BitsPerValue< Dna5 > { enum { VALUE = 3 }; };
1039
1040 //____________________________________________________________________________
1041
1042 /**
1043 .Spec.Iupac:
1044 ..cat:Alphabets
1045 ..summary:Iupac code for DNA.
1046 ..general:Class.SimpleType
1047 ..signature:Iupac
1048 ..remarks:
1049 ...text:The @Metafunction.ValueSize@ of $Iupac$ is 16. 
1050 The nucleotides are enumerated from 0 to 15 in this order: 
1051 'U'=0, 'T', 'A', 'W', 'C', 'Y', 'M', 'H', 'G', 'K', 'R', 'D', 'S', 'B', 'V', 'N'=15. 
1052 ...text:Objects of type $Iupac$ can be converted to various other types and vice versa. 
1053 Unkown values are converted to $'N'$.
1054 ...text:$Iupac$ is typedef for $SimpleType<char,_Iupac>$, while $_Iupac$ is a helper
1055 specialization tag class.
1056 ..see:Metafunction.ValueSize
1057 */
1058 struct _Iupac {};
1059 typedef SimpleType<unsigned char, _Iupac> Iupac;
1060
1061 template <> struct ValueSize< Iupac > { enum { VALUE = 16 }; };
1062 template <> struct BitsPerValue< Iupac > { enum { VALUE = 4 }; };
1063
1064
1065 //____________________________________________________________________________
1066
1067 /**
1068 .Spec.AminoAcid:
1069 ..cat:Alphabets
1070 ..summary:Iupac code for amino acids.
1071 ..general:Class.SimpleType
1072 ..signature:AminoAcid
1073 ..remarks:
1074 ...text:The @Metafunction.ValueSize@ of $AminoAcid$ is 24. 
1075 ...text:The amino acids are enumerated from 0 to 15 in this order: 
1076 ...text:'A'=0, 'R', 'N', 'D', 'C', 'Q', 'E', 'G', 'H', 'I', 'L', 'K', 'M', 'F', 'P', 'S', 'T', 'W', 'Y', 'V'=19.
1077 ...text:The remaining 4 symbols are:
1078 ...text: 'B'=20 (Aspartic Acid, Asparagine), 'Z'=21 (Glutamic Acid, Glutamine), 'X'=22 (unknown), '*'=23 (terminator)
1079 ...text:Objects of type $AminoAcid$ can be converted to $char$ and vice versa. 
1080 Unkown values are converted to $'X'$.
1081 ...text:$AminoAcid$ is typedef for $SimpleType<char,_AminoAcid>$, while $_AminoAcid$ is a helper
1082 specialization tag class.
1083 ..see:Metafunction.ValueSize
1084 */
1085 struct _AminoAcid {};
1086 typedef SimpleType<unsigned char, _AminoAcid> AminoAcid;
1087
1088 template <> struct ValueSize< AminoAcid > { enum { VALUE = 24 }; };
1089 template <> struct BitsPerValue< AminoAcid > { enum { VALUE = 5 }; };
1090
1091 //////////////////////////////////////////////////////////////////////////////
1092 //ASCII
1093
1094 inline void assign(Ascii & c_target, 
1095                                    Dna const & source)
1096 {
1097 SEQAN_CHECKPOINT
1098         c_target = _Translate_Table_Dna5_2_Ascii<>::VALUE[source.value];
1099 }
1100 //____________________________________________________________________________
1101
1102 inline void assign(Ascii & c_target, 
1103                                    Dna5 const & source)
1104 {
1105 SEQAN_CHECKPOINT
1106         c_target = _Translate_Table_Dna5_2_Ascii<>::VALUE[source.value];
1107 }
1108 //____________________________________________________________________________
1109
1110 inline void assign(Ascii & c_target, Iupac const & source)
1111 {
1112 SEQAN_CHECKPOINT
1113         c_target = _Translate_Table_Iupac_2_Ascii<>::VALUE[source.value];
1114 }
1115 //____________________________________________________________________________
1116
1117 inline void assign(Ascii & c_target, AminoAcid const & source)
1118 {
1119 SEQAN_CHECKPOINT
1120         c_target = _Translate_Table_AA_2_Ascii<>::VALUE[source.value];
1121 }
1122
1123 //////////////////////////////////////////////////////////////////////////////
1124 //DNA (4 letters)
1125
1126 template <>
1127 struct CompareType<Dna, Byte> { typedef Dna Type; };
1128 inline void assign(Dna & target, Byte c_source)
1129 {
1130 SEQAN_CHECKPOINT
1131         target.value = _Translate_Table_Byte_2_Dna<>::VALUE[c_source];
1132 }
1133 //____________________________________________________________________________
1134
1135 template <>
1136 struct CompareType<Dna, Ascii> { typedef Dna Type; };
1137 inline void assign(Dna & target, Ascii c_source)
1138 {
1139 SEQAN_CHECKPOINT
1140         target.value = _Translate_Table_Ascii_2_Dna<>::VALUE[(unsigned char)c_source];
1141 }
1142 //____________________________________________________________________________
1143
1144 template <>
1145 struct CompareType<Dna, Unicode> { typedef Dna Type; };
1146 inline void assign(Dna & target, Unicode c_source)
1147 {
1148 SEQAN_CHECKPOINT
1149         target.value = _Translate_Table_Ascii_2_Dna<>::VALUE[(unsigned char) c_source];
1150 }
1151 //____________________________________________________________________________
1152
1153 template <>
1154 struct CompareType<Dna, Dna5> { typedef Dna Type; };
1155 inline void assign(Dna & target, Dna5 const & c_source)
1156 {
1157 SEQAN_CHECKPOINT
1158         target.value = c_source.value & 0x03;
1159 }
1160 //____________________________________________________________________________
1161
1162 template <>
1163 struct CompareType<Dna, Iupac> { typedef Dna Type; };
1164 inline void assign(Dna & target, Iupac const & source)
1165 {
1166 SEQAN_CHECKPOINT
1167         target.value = _Translate_Table_Iupac_2_Dna<>::VALUE[source.value];
1168 }
1169
1170 //////////////////////////////////////////////////////////////////////////////
1171 //DNA (5 letters)
1172
1173 template <>
1174 struct CompareType<Dna5, Byte> { typedef Dna5 Type; };
1175 inline void assign(Dna5 & target, Byte c_source)
1176 {
1177 SEQAN_CHECKPOINT
1178         target.value = _Translate_Table_Byte_2_Dna5<>::VALUE[c_source];
1179 }
1180 //____________________________________________________________________________
1181
1182 template <>
1183 struct CompareType<Dna5, Ascii> { typedef Dna5 Type; };
1184 inline void assign(Dna5 & target, Ascii c_source)
1185 {
1186 SEQAN_CHECKPOINT
1187         target.value = _Translate_Table_Ascii_2_Dna5<>::VALUE[(unsigned char) c_source];
1188 }
1189 //____________________________________________________________________________
1190
1191 template <>
1192 struct CompareType<Dna5, Unicode> { typedef Dna5 Type; };
1193 inline void assign(Dna5 & target, Unicode c_source)
1194 {
1195 SEQAN_CHECKPOINT
1196         target.value = _Translate_Table_Ascii_2_Dna5<>::VALUE[(unsigned char) c_source];
1197 }
1198 //____________________________________________________________________________
1199
1200 template <>
1201 struct CompareType<Dna5, Iupac> { typedef Dna5 Type; };
1202 inline void assign(Dna5 & target, Iupac const & source)
1203 {
1204 SEQAN_CHECKPOINT
1205         target.value = _Translate_Table_Iupac_2_Dna5<>::VALUE[source.value];
1206 }
1207
1208 //____________________________________________________________________________
1209
1210 template <>
1211 struct CompareType<Dna5, Dna> { typedef Dna Type; };
1212 inline void assign(Dna5 & target, Dna const & c_source)
1213 {
1214 SEQAN_CHECKPOINT
1215         target.value = c_source.value;
1216 }
1217
1218 //////////////////////////////////////////////////////////////////////////////
1219 //IUPAC (4 bits)
1220
1221 template <>
1222 struct CompareType<Iupac, Byte> { typedef Iupac Type; };
1223 inline void assign(Iupac & target, Byte c_source)
1224 {
1225 SEQAN_CHECKPOINT
1226         target.value = _Translate_Table_Byte_2_Iupac<>::VALUE[c_source];
1227 }
1228 //____________________________________________________________________________
1229
1230 template <>
1231 struct CompareType<Iupac, Ascii> { typedef Iupac Type; };
1232 inline void assign(Iupac & target, Ascii c_source)
1233 {
1234 SEQAN_CHECKPOINT
1235         target.value = _Translate_Table_Ascii_2_Iupac<>::VALUE[(unsigned char) c_source];
1236 }
1237 //____________________________________________________________________________
1238
1239 template <>
1240 struct CompareType<Iupac, Unicode> { typedef Iupac Type; };
1241 inline void assign(Iupac & target, Unicode c_source)
1242 {
1243 SEQAN_CHECKPOINT
1244         target.value = _Translate_Table_Ascii_2_Iupac<>::VALUE[(unsigned char) c_source];
1245 }
1246 //____________________________________________________________________________
1247
1248 inline void assign(Iupac & target, Dna const & source)
1249 {
1250 SEQAN_CHECKPOINT
1251         target.value = _Translate_Table_Dna5_2_Iupac<>::VALUE[source.value];
1252 }
1253 //____________________________________________________________________________
1254
1255 inline void assign(Iupac & target, Dna5 const & source)
1256 {
1257 SEQAN_CHECKPOINT
1258         target.value = _Translate_Table_Dna5_2_Iupac<>::VALUE[source.value];
1259 }
1260
1261 //////////////////////////////////////////////////////////////////////////////
1262 //Amino Acid (5 bits)
1263
1264 template <>
1265 struct CompareType<AminoAcid, Byte> { typedef AminoAcid Type; };
1266 inline void assign(AminoAcid & target, Byte c_source)
1267 {
1268 SEQAN_CHECKPOINT
1269         target.value = _Translate_Table_Byte_2_AA<>::VALUE[c_source];
1270 }
1271 //____________________________________________________________________________
1272
1273 template <>
1274 struct CompareType<AminoAcid, Ascii> { typedef AminoAcid Type; };
1275 inline void assign(AminoAcid & target, Ascii c_source)
1276 {
1277 SEQAN_CHECKPOINT
1278         target.value = _Translate_Table_Ascii_2_AA<>::VALUE[(unsigned char) c_source];
1279 }
1280 //____________________________________________________________________________
1281
1282 template <>
1283 struct CompareType<AminoAcid, Unicode> { typedef AminoAcid Type; };
1284 inline void assign(AminoAcid & target, Unicode c_source)
1285 {
1286 SEQAN_CHECKPOINT
1287         target.value = _Translate_Table_Ascii_2_AA<>::VALUE[(unsigned char) c_source];
1288 }
1289
1290 //////////////////////////////////////////////////////////////////////////////
1291
1292
1293 //////////////////////////////////////////////////////////////////////////////
1294 }// namespace SEQAN_NAMESPACE_MAIN
1295
1296 #endif //#ifndef SEQAN_HEADER_...