1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2010, 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-Doering <andreas.doering@mdc-berlin.de>
33 // ==========================================================================
34 // Implementation of SimpleType, the biological sequence types and conversion
35 // tables.
36 // ==========================================================================
37 
38 #ifndef SEQAN_HEADER_BASIC_ALPHABET_SIMPLE_H
39 #define SEQAN_HEADER_BASIC_ALPHABET_SIMPLE_H
40 
41 namespace SEQAN_NAMESPACE_MAIN
42 {
43 
44 //////////////////////////////////////////////////////////////////////////////
45 //Class that is used for various simple value types
46 //////////////////////////////////////////////////////////////////////////////
47 
48 /**
49 .Class.SimpleType:
50 ..cat:Basic
51 ..summary:Implementation for "simple" types.
52 ..signature:SimpleType<TValue, TSpec>
53 ..param.TValue:Type that stores the values of an instance.
54 ...remarks:TValue must be a simple type.
55 ...metafunction:Metafunction.Value
56 ..param.TSpec:Specialization tag.
57 ...metafunction:Metafunction.Spec
58 ..remarks:
59 ...text:A "simple type" is a C++ type that can be constructed without constructor,
60 destructed without destructor and copied without copy constructor or assignment operator.
61 All basic types (like $char$, $int$ or $float$) are simple. Pointers, references and arrays of
62 simple types are simple.
63 POD types ("plain old data types"), that are - simplified spoken - C++-types that already existed in C,
64 are simple too.
65 ...text:Arrays of simple types can be copied very fast by memory manipulation routines,
66 but the default implementation of functions like @Function.arrayCopyForward@ and @Function.arrayCopy@
67 are not optimized for simple types this way.
68 But for classes derived from $SimpleType$, optimized variants of array manipulation functions are applied.
69 ...text:Note that simple types need not to be derived or specialized from $SimpleType$, but
70 it could be convenient to do so.
71 ..implements:Concept.Simple Type
72 ..include:seqan/basic.h
73 */
74 // TODO(holtgrew): This should actually be a class.
75 template <typename TValue, typename TSpec>
76 struct SimpleType
77 {
78 //____________________________________________________________________________
79 
80 	TValue value;
81 
82 //____________________________________________________________________________
83 
SimpleTypeSimpleType84 	SimpleType()
85 	{
86 SEQAN_CHECKPOINT
87 	}
88 
89 //____________________________________________________________________________
90 
SimpleTypeSimpleType91 	SimpleType(SimpleType const & other)
92 	{
93 SEQAN_CHECKPOINT
94 		assign(*this, other);
95 	}
96 
97 	template <typename T>
SimpleTypeSimpleType98 	SimpleType(T const & other)
99 	{
100 SEQAN_CHECKPOINT
101 		assign(*this, other);
102 	}
103 
104 
105 //____________________________________________________________________________
106 
107 	SimpleType & operator=(SimpleType const & other)
108 	{
109 SEQAN_CHECKPOINT
110 		assign(*this, other);
111 		return *this;
112 	}
113 
114 	template <typename T>
115 	SimpleType & operator=(T const & other)
116 	{
117 SEQAN_CHECKPOINT
118 		assign(*this, other);
119 		return *this;
120 	}
121 //____________________________________________________________________________
122 
~SimpleTypeSimpleType123 	~SimpleType()
124 	{
125 SEQAN_CHECKPOINT
126 	}
127 //____________________________________________________________________________
128 
129 
130     // Class.SimpleType specifies type conversion operators for all built-in
131     // integer types since there is no way to extend the build-in types with
132     // copy and assignment constructors in C++.
133     //
134     // This cannot be a template since it would conflict to the template
135     // constructor.
136 
137     // TODO(holtgrew): These are candidates for breaking the style convention and simply write each function in one line.
138 
__int64SimpleType139 	operator __int64() const
140 	{
141 SEQAN_CHECKPOINT
142 		__int64 c;
143 		assign(c, *this);
144 		return c;
145 	}
146 
__uint64SimpleType147 	operator __uint64() const
148 	{
149 SEQAN_CHECKPOINT
150 		__uint64 c;
151 		assign(c, *this);
152 		return c;
153 	}
154 
155 
156 	operator int() const
157 	{
158 SEQAN_CHECKPOINT
159 		int c;
160 		assign(c, *this);
161 		return c;
162 	}
163 	operator unsigned int() const
164 	{
165 SEQAN_CHECKPOINT
166 		unsigned int c;
167 		assign(c, *this);
168 		return c;
169 	}
170 	operator short() const
171 	{
172 SEQAN_CHECKPOINT
173 		short c;
174 		assign(c, *this);
175 		return c;
176 	}
177 	operator unsigned short() const
178 	{
179 SEQAN_CHECKPOINT
180 		unsigned short c;
181 		assign(c, *this);
182 		return c;
183 	}
184 	operator char() const
185 	{
186 SEQAN_CHECKPOINT
187 		char c;
188 		assign(c, *this);
189 		return c;
190 	}
191 	operator signed char() const
192 	{
193 SEQAN_CHECKPOINT
194 		signed char c;
195 		assign(c, *this);
196 		return c;
197 	}
198 	operator unsigned char() const
199 	{
200 SEQAN_CHECKPOINT
201 		unsigned char c;
202 		assign(c, *this);
203 		return c;
204 	}
205 
206 //____________________________________________________________________________
207 };
208 
209 //////////////////////////////////////////////////////////////////////////////
210 // METAFUNCTIONS
211 //////////////////////////////////////////////////////////////////////////////
212 
213 ///.Metafunction.IsSimple.param.T.type:Class.SimpleType
214 
215 template <typename TValue, typename TSpec>
216 struct IsSimple<SimpleType<TValue, TSpec> >
217 {
218 	typedef True Type;
219 };
220 
221 //////////////////////////////////////////////////////////////////////////////
222 
223 ///.Metafunction.Value.param.T.type:Class.SimpleType
224 template <typename TValue, typename TSpec>
225 struct Value<SimpleType<TValue, TSpec> >
226 {
227 	typedef TValue Type;
228 };
229 
230 template <typename TValue, typename TSpec>
231 struct Value<SimpleType<TValue, TSpec> const >
232 {
233 	typedef TValue const Type;
234 };
235 
236 //////////////////////////////////////////////////////////////////////////////
237 
238 ///.Metafunction.Spec.param.T.type:Class.SimpleType
239 template <typename TValue, typename TSpec>
240 struct Spec<SimpleType<TValue, TSpec> >
241 {
242 	typedef TSpec Type;
243 };
244 
245 template <typename TValue, typename TSpec>
246 struct Spec<SimpleType<TValue, TSpec> const >
247 {
248 	typedef TSpec Type;
249 };
250 
251 //////////////////////////////////////////////////////////////////////////////
252 
253 template <typename TValue, typename TSpec>
254 struct Iterator<SimpleType<TValue, TSpec>, Standard>
255 {
256 	typedef SimpleType<TValue, TSpec> * Type;
257 //	typedef Iter<SimpleType<TValue, TSpec>, SimpleIterator> * Type;
258 };
259 
260 template <typename TValue, typename TSpec>
261 struct Iterator<SimpleType<TValue, TSpec> const, Standard>
262 {
263 	typedef SimpleType<TValue, TSpec> const * Type;
264 //	typedef Iter<SimpleType<TValue, TSpec> const, SimpleIterator> * Type;
265 };
266 
267 
268 //////////////////////////////////////////////////////////////////////////////
269 // FUNCTIONS
270 //////////////////////////////////////////////////////////////////////////////
271 
272 template <typename TTarget, typename T, typename TSourceValue, typename TSourceSpec>
273 inline typename RemoveConst_<TTarget>::Type
274 convertImpl(Convert<TTarget, T> const,
275 			SimpleType<TSourceValue, TSourceSpec> const & source_)
276 {
277 SEQAN_CHECKPOINT
278 	typename RemoveConst_<TTarget>::Type target_;
279 	assign(target_, source_);
280 	return target_;
281 }
282 
283 
284 
285 //////////////////////////////////////////////////////////////////////////////
286 
287 template <typename TStream, typename TValue, typename TSpec>
288 inline TStream &
289 operator << (TStream & stream,
290 			 SimpleType<TValue, TSpec> const & data)
291 {
292 SEQAN_CHECKPOINT
293 	stream << convert<char>(data);
294 	return stream;
295 }
296 
297 //////////////////////////////////////////////////////////////////////////////
298 
299 template <typename TStream, typename TValue, typename TSpec>
300 inline TStream &
301 operator >> (TStream & stream,
302 			 SimpleType<TValue, TSpec> & data)
303 {
304 SEQAN_CHECKPOINT
305 	char c;
306 	stream >> c;
307 	assign(data, c);
308 	return stream;
309 }
310 
311 //////////////////////////////////////////////////////////////////////////////
312 // assign
313 //////////////////////////////////////////////////////////////////////////////
314 
315 ///.Function.assign.param.target.type:Class.SimpleType
316 ///.Function.assign.param.source.type:Class.SimpleType
317 
318 
319 template <typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TSourceSpec>
320 inline void
321 assign(SimpleType<TTargetValue, TTargetSpec> & target,
322 	   SimpleType<TSourceValue, TSourceSpec> & source)
323 {
324 SEQAN_CHECKPOINT
325 	target.value = source.value;
326 }
327 template <typename TTargetValue, typename TTargetSpec, typename TSourceValue, typename TSourceSpec>
328 inline void
329 assign(SimpleType<TTargetValue, TTargetSpec> & target,
330 	   SimpleType<TSourceValue, TSourceSpec> const & source)
331 {
332 SEQAN_CHECKPOINT
333 	target.value = source.value;
334 }
335 
336 //____________________________________________________________________________
337 
338 template <typename TTargetValue, typename TTargetSpec, typename TSource>
339 inline void
340 assign(SimpleType<TTargetValue, TTargetSpec> & target,
341 	   TSource & source)
342 {
343 SEQAN_CHECKPOINT
344 	target.value = source;
345 }
346 template <typename TTargetValue, typename TTargetSpec, typename TSource>
347 inline void
348 assign(SimpleType<TTargetValue, TTargetSpec> & target,
349 	   TSource const & source)
350 {
351 SEQAN_CHECKPOINT
352 	target.value = source;
353 }
354 
355 //____________________________________________________________________________
356 // Assign Proxy to SimpleType
357 //??? Diese Funktionen wurden noetig wegen eines seltsamen VC++-Verhaltens
358 
359 template <typename TTargetValue, typename TTargetSpec, typename TSourceSpec>
360 inline void
361 assign(SimpleType<TTargetValue, TTargetSpec> & target,
362 	   Proxy<TSourceSpec> & source)
363 {
364 SEQAN_CHECKPOINT
365 	target.value = getValue(source);
366 }
367 
368 template <typename TTargetValue, typename TTargetSpec, typename TSourceSpec>
369 inline void
370 assign(SimpleType<TTargetValue, TTargetSpec> & target,
371 	   Proxy<TSourceSpec> const & source)
372 {
373 SEQAN_CHECKPOINT
374 	target.value = getValue(source);
375 }
376 
377 //____________________________________________________________________________
378 //INTEGRAL TYPES
379 //note: it is not possible to write a single function here since "assign"
380 //must be specialized for the first argument at the first place
381 
382 //__int64
383 template <typename TValue, typename TSpec>
384 inline void
385 assign(__int64 & c_target,
386 	   SimpleType<TValue, TSpec> & source)
387 {
388 SEQAN_CHECKPOINT
389 	c_target = source.value;
390 }
391 template <typename TValue, typename TSpec>
392 inline void
393 assign(__int64 & c_target,
394 	   SimpleType<TValue, TSpec> const & source)
395 {
396 SEQAN_CHECKPOINT
397 	c_target = source.value;
398 }
399 
400 //__uint64
401 template <typename TValue, typename TSpec>
402 inline void
403 assign(__uint64 & c_target,
404 	   SimpleType<TValue, TSpec> & source)
405 {
406 SEQAN_CHECKPOINT
407 	c_target = source.value;
408 }
409 template <typename TValue, typename TSpec>
410 inline void
411 assign(__uint64 & c_target,
412 	   SimpleType<TValue, TSpec> const & source)
413 {
414 SEQAN_CHECKPOINT
415 	c_target = source.value;
416 }
417 
418 //int
419 template <typename TValue, typename TSpec>
420 inline void
421 assign(int & c_target,
422 	   SimpleType<TValue, TSpec> & source)
423 {
424 SEQAN_CHECKPOINT
425 	c_target = source.value;
426 }
427 template <typename TValue, typename TSpec>
428 inline void
429 assign(int & c_target,
430 	   SimpleType<TValue, TSpec> const & source)
431 {
432 SEQAN_CHECKPOINT
433 	c_target = source.value;
434 }
435 
436 //unsigned int
437 template <typename TValue, typename TSpec>
438 inline void
439 assign(unsigned int & c_target,
440 	   SimpleType<TValue, TSpec> & source)
441 {
442 SEQAN_CHECKPOINT
443 	c_target = source.value;
444 }
445 template <typename TValue, typename TSpec>
446 inline void
447 assign(unsigned int & c_target,
448 	   SimpleType<TValue, TSpec> const & source)
449 {
450 SEQAN_CHECKPOINT
451 	c_target = source.value;
452 }
453 
454 //short
455 template <typename TValue, typename TSpec>
456 inline void
457 assign(short & c_target,
458 	   SimpleType<TValue, TSpec> & source)
459 {
460 SEQAN_CHECKPOINT
461 	c_target = source.value;
462 }
463 template <typename TValue, typename TSpec>
464 inline void
465 assign(short & c_target,
466 	   SimpleType<TValue, TSpec> const & source)
467 {
468 SEQAN_CHECKPOINT
469 	c_target = source.value;
470 }
471 
472 //unsigned short
473 template <typename TValue, typename TSpec>
474 inline void
475 assign(unsigned short & c_target,
476 	   SimpleType<TValue, TSpec> & source)
477 {
478 SEQAN_CHECKPOINT
479 	c_target = source.value;
480 }
481 template <typename TValue, typename TSpec>
482 inline void
483 assign(unsigned short & c_target,
484 	   SimpleType<TValue, TSpec> const & source)
485 {
486 SEQAN_CHECKPOINT
487 	c_target = source.value;
488 }
489 
490 //char
491 template <typename TValue, typename TSpec>
492 inline void
493 assign(char & c_target,
494 	   SimpleType<TValue, TSpec> & source)
495 {
496 SEQAN_CHECKPOINT
497 	c_target = source.value;
498 }
499 template <typename TValue, typename TSpec>
500 inline void
501 assign(char & c_target,
502 	   SimpleType<TValue, TSpec> const & source)
503 {
504 SEQAN_CHECKPOINT
505 	c_target = source.value;
506 }
507 
508 //signed char
509 template <typename TValue, typename TSpec>
510 inline void
511 assign(signed char & c_target,
512 	   SimpleType<TValue, TSpec> & source)
513 {
514 SEQAN_CHECKPOINT
515 	c_target = source.value;
516 }
517 template <typename TValue, typename TSpec>
518 inline void
519 assign(signed char & c_target,
520 	   SimpleType<TValue, TSpec> const & source)
521 {
522 SEQAN_CHECKPOINT
523 	c_target = source.value;
524 }
525 
526 //unsigned char
527 template <typename TValue, typename TSpec>
528 inline void
529 assign(unsigned char & c_target,
530 	   SimpleType<TValue, TSpec> & source)
531 {
532 SEQAN_CHECKPOINT
533 	c_target = source.value;
534 }
535 template <typename TValue, typename TSpec>
536 inline void
537 assign(unsigned char & c_target,
538 	   SimpleType<TValue, TSpec> const & source)
539 {
540 SEQAN_CHECKPOINT
541 	c_target = source.value;
542 }
543 
544 //////////////////////////////////////////////////////////////////////////////
545 //////////////////////////////////////////////////////////////////////////////
546 // CompareType
547 //////////////////////////////////////////////////////////////////////////////
548 
549 /**.Metafunction.CompareType:
550 ..summary:Type to convert other types for comparisons.
551 ..signature:CompareType<TLeft, TRight>::Type
552 ..param.TLeft:Type of the left operand of a comparison.
553 ..param.TRight:Type of the right operand of a comparison.
554 ..return.Type:The Type in which the arguments are converted in order to compare them.
555 ..remarks:Comparisons are for example operators like $==$ or $<$.
556 ..remarks.text:Note that there is no rule that guarantees that $CompareType<T1, T2>::Type$
557 is the same as $CompareType<T2, T1>::Type$. It is also possible, that only one of these
558 two types is defined.
559 ..remarks.text:This metafunction is used for the implementation of
560 comparisons that involve @Class.SimpleType@.
561 */
562 //???TODO: muss geprueft werden, ob diese Metafunktion noch ausgeweitet oder aber versteckt wird.
563 
564 template <typename TLeft, typename TRight>
565 struct CompareType;
566 
567 template <typename T>
568 struct CompareType<T, T>
569 {
570 	typedef T Type;
571 };
572 
573 //____________________________________________________________________________
574 
575 template <typename TValue, typename TSpec, typename TRight>
576 struct CompareType<SimpleType<TValue, TSpec>, TRight>
577 {
578 	typedef TRight Type;
579 };
580 
581 //////////////////////////////////////////////////////////////////////////////
582 // operator ==
583 
584 template <typename TValue, typename TSpec, typename TRight>
585 inline bool
586 operator == (SimpleType<TValue, TSpec> const & left_,
587 			 TRight const & right_)
588 {
589 SEQAN_CHECKPOINT
590 	typedef SimpleType<TValue, TSpec> TLeft;
591 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
592 	return convert<TCompareType>(left_) == convert<TCompareType>(right_);
593 }
594 
595 template <typename TLeft, typename TValue, typename TSpec>
596 inline bool
597 operator == (TLeft const & left_,
598 			 SimpleType<TValue, TSpec> const & right_)
599 {
600 SEQAN_CHECKPOINT
601 	typedef SimpleType<TValue, TSpec> TRight;
602 	typedef typename CompareType<TRight, TLeft>::Type TCompareType;
603 	return convert<TCompareType>(left_) == convert<TCompareType>(right_);
604 }
605 
606 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
607 inline bool
608 operator == (SimpleType<TLeftValue, TLeftSpec> const & left_,
609 			 SimpleType<TRightValue, TRightSpec> const & right_)
610 {
611 SEQAN_CHECKPOINT
612 	typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
613 	typedef SimpleType<TRightValue, TRightSpec> TRight;
614 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
615 	return convert<TCompareType>(left_) == convert<TCompareType>(right_);
616 }
617 
618 template <typename TValue, typename TSpec>
619 inline bool
620 operator == (SimpleType<TValue, TSpec> const & left_,
621 			 SimpleType<TValue, TSpec> const & right_)
622 {
623 SEQAN_CHECKPOINT
624 	return convert<TValue>(left_) == convert<TValue>(right_);
625 }
626 
627 
628 template <typename TSpec, typename TValue, typename TSpec2>
629 inline bool
630 operator == (Proxy<TSpec> const & left_,
631 			 SimpleType<TValue, TSpec2> const & right_)
632 {
633 SEQAN_CHECKPOINT
634 	typedef Proxy<TSpec> TLeft;
635 	typedef SimpleType<TValue, TSpec> TRight;
636 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
637 	return convert<TCompareType>(left_) == convert<TCompareType>(right_);
638 }
639 template <typename TSpec, typename TValue, typename TSpec2>
640 inline bool
641 operator == (SimpleType<TValue, TSpec2> const & left_,
642 			 Proxy<TSpec> const & right_)
643 {
644 SEQAN_CHECKPOINT
645 	typedef SimpleType<TValue, TSpec> TLeft;
646 	typedef Proxy<TSpec> TRight;
647 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
648 	return convert<TCompareType>(left_) == convert<TCompareType>(right_);
649 }
650 
651 
652 //____________________________________________________________________________
653 // operator !=
654 
655 template <typename TValue, typename TSpec, typename TRight>
656 inline bool
657 operator != (SimpleType<TValue, TSpec> const & left_,
658 			 TRight const & right_)
659 {
660 SEQAN_CHECKPOINT
661 	typedef SimpleType<TValue, TSpec> TLeft;
662 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
663 	return convert<TCompareType>(left_) != convert<TCompareType>(right_);
664 }
665 
666 template <typename TLeft, typename TValue, typename TSpec>
667 inline bool
668 operator != (TLeft const & left_,
669 			 SimpleType<TValue, TSpec> const & right_)
670 {
671 SEQAN_CHECKPOINT
672 	typedef SimpleType<TValue, TSpec> TRight;
673 	typedef typename CompareType<TRight, TLeft>::Type TCompareType;
674 	return convert<TCompareType>(left_) != convert<TCompareType>(right_);
675 }
676 
677 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
678 inline bool
679 operator != (SimpleType<TLeftValue, TLeftSpec> const & left_,
680 			 SimpleType<TRightValue, TRightSpec> const & right_)
681 {
682 SEQAN_CHECKPOINT
683 	typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
684 	typedef SimpleType<TRightValue, TRightSpec> TRight;
685 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
686 	return convert<TCompareType>(left_) != convert<TCompareType>(right_);
687 }
688 
689 template <typename TValue, typename TSpec>
690 inline bool
691 operator != (SimpleType<TValue, TSpec> const & left_,
692 			 SimpleType<TValue, TSpec> const & right_)
693 {
694 SEQAN_CHECKPOINT
695 	return convert<TValue>(left_) != convert<TValue>(right_);
696 }
697 
698 
699 template <typename TSpec, typename TValue, typename TSpec2>
700 inline bool
701 operator != (Proxy<TSpec> const & left_,
702 			 SimpleType<TValue, TSpec2> const & right_)
703 {
704 SEQAN_CHECKPOINT
705 	typedef Proxy<TSpec> TLeft;
706 	typedef SimpleType<TValue, TSpec> TRight;
707 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
708 	return convert<TCompareType>(left_) != convert<TCompareType>(right_);
709 }
710 template <typename TSpec, typename TValue, typename TSpec2>
711 inline bool
712 operator != (SimpleType<TValue, TSpec2> const & left_,
713 			 Proxy<TSpec> const & right_)
714 {
715 SEQAN_CHECKPOINT
716 	typedef SimpleType<TValue, TSpec> TLeft;
717 	typedef Proxy<TSpec> TRight;
718 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
719 	return convert<TCompareType>(left_) != convert<TCompareType>(right_);
720 }
721 
722 
723 //____________________________________________________________________________
724 // operator <
725 
726 template <typename TValue, typename TSpec, typename TRight>
727 inline bool
728 operator < (SimpleType<TValue, TSpec> const & left_,
729 			TRight const & right_)
730 {
731 SEQAN_CHECKPOINT
732 	typedef SimpleType<TValue, TSpec> TLeft;
733 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
734 	return convert<TCompareType>(left_) < convert<TCompareType>(right_);
735 }
736 
737 template <typename TLeft, typename TValue, typename TSpec>
738 inline bool
739 operator < (TLeft const & left_,
740 			SimpleType<TValue, TSpec> const & right_)
741 {
742 SEQAN_CHECKPOINT
743 	typedef SimpleType<TValue, TSpec> TRight;
744 	typedef typename CompareType<TRight, TLeft>::Type TCompareType;
745 	return convert<TCompareType>(left_) < convert<TCompareType>(right_);
746 }
747 
748 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
749 inline bool
750 operator < (SimpleType<TLeftValue, TLeftSpec> const & left_,
751 			SimpleType<TRightValue, TRightSpec> const & right_)
752 {
753 SEQAN_CHECKPOINT
754 	typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
755 	typedef SimpleType<TRightValue, TRightSpec> TRight;
756 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
757 	return convert<TCompareType>(left_) < convert<TCompareType>(right_);
758 }
759 
760 template <typename TValue, typename TSpec>
761 inline bool
762 operator < (SimpleType<TValue, TSpec> const & left_,
763 			SimpleType<TValue, TSpec> const & right_)
764 {
765 SEQAN_CHECKPOINT
766 	return convert<TValue>(left_) < convert<TValue>(right_);
767 }
768 
769 
770 template <typename TSpec, typename TValue, typename TSpec2>
771 inline bool
772 operator < (Proxy<TSpec> const & left_,
773 			 SimpleType<TValue, TSpec2> const & right_)
774 {
775 SEQAN_CHECKPOINT
776 	typedef Proxy<TSpec> TLeft;
777 	typedef SimpleType<TValue, TSpec> TRight;
778 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
779 	return convert<TCompareType>(left_) < convert<TCompareType>(right_);
780 }
781 template <typename TSpec, typename TValue, typename TSpec2>
782 inline bool
783 operator < (SimpleType<TValue, TSpec2> const & left_,
784 			 Proxy<TSpec> const & right_)
785 {
786 SEQAN_CHECKPOINT
787 	typedef SimpleType<TValue, TSpec> TLeft;
788 	typedef Proxy<TSpec> TRight;
789 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
790 	return convert<TCompareType>(left_) < convert<TCompareType>(right_);
791 }
792 
793 
794 //____________________________________________________________________________
795 // operator <=
796 
797 template <typename TValue, typename TSpec, typename TRight>
798 inline bool
799 operator <= (SimpleType<TValue, TSpec> const & left_,
800 			 TRight const & right_)
801 {
802 SEQAN_CHECKPOINT
803 	typedef SimpleType<TValue, TSpec> TLeft;
804 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
805 	return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
806 }
807 
808 template <typename TLeft, typename TValue, typename TSpec>
809 inline bool
810 operator <= (TLeft const & left_,
811 			 SimpleType<TValue, TSpec> const & right_)
812 {
813 SEQAN_CHECKPOINT
814 	typedef SimpleType<TValue, TSpec> TRight;
815 	typedef typename CompareType<TRight, TLeft>::Type TCompareType;
816 	return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
817 }
818 
819 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
820 inline bool
821 operator <= (SimpleType<TLeftValue, TLeftSpec> const & left_,
822 			 SimpleType<TRightValue, TRightSpec> const & right_)
823 {
824 SEQAN_CHECKPOINT
825 	typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
826 	typedef SimpleType<TRightValue, TRightSpec> TRight;
827 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
828 	return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
829 }
830 
831 template <typename TValue, typename TSpec>
832 inline bool
833 operator <= (SimpleType<TValue, TSpec> const & left_,
834 			 SimpleType<TValue, TSpec> const & right_)
835 {
836 SEQAN_CHECKPOINT
837 	return convert<TValue>(left_) <= convert<TValue>(right_);
838 }
839 
840 
841 template <typename TSpec, typename TValue, typename TSpec2>
842 inline bool
843 operator <= (Proxy<TSpec> const & left_,
844 			 SimpleType<TValue, TSpec2> const & right_)
845 {
846 SEQAN_CHECKPOINT
847 	typedef Proxy<TSpec> TLeft;
848 	typedef SimpleType<TValue, TSpec> TRight;
849 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
850 	return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
851 }
852 template <typename TSpec, typename TValue, typename TSpec2>
853 inline bool
854 operator <= (SimpleType<TValue, TSpec2> const & left_,
855 			 Proxy<TSpec> const & right_)
856 {
857 SEQAN_CHECKPOINT
858 	typedef SimpleType<TValue, TSpec> TLeft;
859 	typedef Proxy<TSpec> TRight;
860 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
861 	return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
862 }
863 
864 
865 
866 //____________________________________________________________________________
867 // operator >
868 
869 template <typename TValue, typename TSpec, typename TRight>
870 inline bool
871 operator > (SimpleType<TValue, TSpec> const & left_,
872 			TRight const & right_)
873 {
874 SEQAN_CHECKPOINT
875 	typedef SimpleType<TValue, TSpec> TLeft;
876 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
877 	return convert<TCompareType>(left_) > convert<TCompareType>(right_);
878 }
879 
880 template <typename TLeft, typename TValue, typename TSpec>
881 inline bool
882 operator > (TLeft const & left_,
883 			SimpleType<TValue, TSpec> const & right_)
884 {
885 SEQAN_CHECKPOINT
886 	typedef SimpleType<TValue, TSpec> TRight;
887 	typedef typename CompareType<TRight, TLeft>::Type TCompareType;
888 	return convert<TCompareType>(left_) > convert<TCompareType>(right_);
889 }
890 
891 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
892 inline bool
893 operator > (SimpleType<TLeftValue, TLeftSpec> const & left_,
894 			SimpleType<TRightValue, TRightSpec> const & right_)
895 {
896 SEQAN_CHECKPOINT
897 	typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
898 	typedef SimpleType<TRightValue, TRightSpec> TRight;
899 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
900 	return convert<TCompareType>(left_) > convert<TCompareType>(right_);
901 }
902 
903 template <typename TValue, typename TSpec>
904 inline bool
905 operator > (SimpleType<TValue, TSpec> const & left_,
906 			SimpleType<TValue, TSpec> const & right_)
907 {
908 SEQAN_CHECKPOINT
909 	return convert<TValue>(left_) > convert<TValue>(right_);
910 }
911 
912 
913 template <typename TSpec, typename TValue, typename TSpec2>
914 inline bool
915 operator > (Proxy<TSpec> const & left_,
916 			 SimpleType<TValue, TSpec2> const & right_)
917 {
918 SEQAN_CHECKPOINT
919 	typedef Proxy<TSpec> TLeft;
920 	typedef SimpleType<TValue, TSpec> TRight;
921 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
922 	return convert<TCompareType>(left_) > convert<TCompareType>(right_);
923 }
924 template <typename TSpec, typename TValue, typename TSpec2>
925 inline bool
926 operator > (SimpleType<TValue, TSpec2> const & left_,
927 			 Proxy<TSpec> const & right_)
928 {
929 SEQAN_CHECKPOINT
930 	typedef SimpleType<TValue, TSpec> TLeft;
931 	typedef Proxy<TSpec> TRight;
932 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
933 	return convert<TCompareType>(left_) > convert<TCompareType>(right_);
934 }
935 
936 
937 //____________________________________________________________________________
938 // operator >=
939 
940 template <typename TValue, typename TSpec, typename TRight>
941 inline bool
942 operator >= (SimpleType<TValue, TSpec> const & left_,
943 			 TRight const & right_)
944 {
945 SEQAN_CHECKPOINT
946 	typedef SimpleType<TValue, TSpec> TLeft;
947 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
948 	return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
949 }
950 
951 template <typename TLeft, typename TValue, typename TSpec>
952 inline bool
953 operator >= (TLeft const & left_,
954 			 SimpleType<TValue, TSpec> const & right_)
955 {
956 SEQAN_CHECKPOINT
957 	typedef SimpleType<TValue, TSpec> TRight;
958 	typedef typename CompareType<TRight, TLeft>::Type TCompareType;
959 	return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
960 }
961 
962 template <typename TLeftValue, typename TLeftSpec, typename TRightValue, typename TRightSpec>
963 inline bool
964 operator >= (SimpleType<TLeftValue, TLeftSpec> const & left_,
965 			 SimpleType<TRightValue, TRightSpec> const & right_)
966 {
967 SEQAN_CHECKPOINT
968 	typedef SimpleType<TLeftValue, TLeftSpec> TLeft;
969 	typedef SimpleType<TRightValue, TRightSpec> TRight;
970 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
971 	return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
972 }
973 
974 template <typename TValue, typename TSpec>
975 inline bool
976 operator >= (SimpleType<TValue, TSpec> const & left_,
977 			 SimpleType<TValue, TSpec> const & right_)
978 {
979 SEQAN_CHECKPOINT
980 	return convert<TValue>(left_) >= convert<TValue>(right_);
981 }
982 
983 
984 template <typename TSpec, typename TValue, typename TSpec2>
985 inline bool
986 operator >= (Proxy<TSpec> const & left_,
987 			 SimpleType<TValue, TSpec2> const & right_)
988 {
989 SEQAN_CHECKPOINT
990 	typedef Proxy<TSpec> TLeft;
991 	typedef SimpleType<TValue, TSpec> TRight;
992 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
993 	return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
994 }
995 template <typename TSpec, typename TValue, typename TSpec2>
996 inline bool
997 operator >= (SimpleType<TValue, TSpec2> const & left_,
998 			 Proxy<TSpec> const & right_)
999 {
1000 SEQAN_CHECKPOINT
1001 	typedef SimpleType<TValue, TSpec> TLeft;
1002 	typedef Proxy<TSpec> TRight;
1003 	typedef typename CompareType<TLeft, TRight>::Type TCompareType;
1004 	return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
1005 }
1006 
1007 
1008 //////////////////////////////////////////////////////////////////////////////
1009 
1010 template<typename T_, typename TSpec>
1011 inline
1012 bool lexLess(SimpleType<T_, TSpec> const &_Left, SimpleType<T_, TSpec> const &Right_)
1013 {	// return lexicographical _Left < Right_
1014 	typedef typename MakeUnsigned_<T_>::Type TUnsigned;
1015     return (TUnsigned)(_Left.value) < (TUnsigned)(Right_.value);
1016 }
1017 
1018 //////////////////////////////////////////////////////////////////////////////
1019 
1020 template <typename TValue, typename TSpec>
1021 inline SimpleType<TValue, TSpec> &
1022 operator ++ (SimpleType<TValue, TSpec> & me)
1023 {
1024 	++me.value;
1025 	return me;
1026 }
1027 template <typename TValue, typename TSpec>
1028 inline SimpleType<TValue, TSpec>
1029 operator ++ (SimpleType<TValue, TSpec> & me,
1030 			 int)
1031 {
1032 	SimpleType<TValue, TSpec> dummy = me;
1033 	++me.value;
1034 	return dummy;
1035 }
1036 
1037 //////////////////////////////////////////////////////////////////////////////
1038 
1039 template <typename TValue, typename TSpec>
1040 inline SimpleType<TValue, TSpec> &
1041 operator -- (SimpleType<TValue, TSpec> & me)
1042 {
1043 	--me.value;
1044 	return me;
1045 }
1046 template <typename TValue, typename TSpec>
1047 inline SimpleType<TValue, TSpec>
1048 operator -- (SimpleType<TValue, TSpec> & me,
1049 			 int)
1050 {
1051 	SimpleType<TValue, TSpec> dummy = me;
1052 	--me.value;
1053 	return dummy;
1054 }
1055 
1056 //////////////////////////////////////////////////////////////////////////////
1057 //////////////////////////////////////////////////////////////////////////////
1058 
1059 /**
1060 .Spec.Dna:
1061 ..cat:Alphabets
1062 ..summary:Alphabet for DNA.
1063 ..general:Class.SimpleType
1064 ..signature:Dna
1065 ..remarks:
1066 ...text:The @Metafunction.ValueSize@ of $Dna$ is 4.
1067 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'T' = 3$.
1068 ...text:Objects of type $Dna$ can be converted to various other types and vice versa.
1069 An object that has a value not in ${'A', 'C', 'G', 'T'}$ is converted to $'A'$.
1070 ...text:$Dna$ is typedef for $SimpleType<char,Dna_>$, while $Dna_$ is a helper
1071 specialization tag class.
1072 ..see:Metafunction.ValueSize
1073 ..see:Spec.Dna5
1074 ..include:seqan/basic.h
1075 */
1076 struct Dna_ {};
1077 typedef SimpleType<unsigned char,Dna_> Dna;
1078 
1079 template <> struct ValueSize< Dna > { enum { VALUE = 4 }; };
1080 template <> struct BitsPerValue< Dna > { enum { VALUE = 2 }; };
1081 
1082 //____________________________________________________________________________
1083 
1084 /**
1085 .Spec.Dna5:
1086 ..cat:Alphabets
1087 ..summary:Alphabet for DNA including 'N' character.
1088 ..general:Class.SimpleType
1089 ..signature:Dna5
1090 ..remarks:
1091 ...text:The @Metafunction.ValueSize@ of $Dna5$ is 5.
1092 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'T' = 3$.
1093 The 'N' character ("unkown nucleotide") is encoded by 4.
1094 ...text:Objects of type $Dna5$ can be converted to various other types and vice versa.
1095 An object that has a value not in ${'A', 'C', 'G', 'T'}$ is converted to $'N'$.
1096 ...text:$Dna5$ is typedef for $SimpleType<char,Dna5_>$, while $Dna5_$ is a helper
1097 specialization tag class.
1098 ..see:Metafunction.ValueSize
1099 ..include:seqan/basic.h
1100 */
1101 struct Dna5_ {};
1102 typedef SimpleType<unsigned char, Dna5_> Dna5;
1103 
1104 template <> struct ValueSize< Dna5 > { enum { VALUE = 5 }; };
1105 template <> struct BitsPerValue< Dna5 > { enum { VALUE = 3 }; };
1106 
1107 //____________________________________________________________________________
1108 
1109 /**
1110 .Spec.Rna:
1111 ..cat:Alphabets
1112 ..summary:Alphabet for RNA.
1113 ..general:Class.SimpleType
1114 ..signature:Rna
1115 ..remarks:
1116 ...text:The @Metafunction.ValueSize@ of $Rna$ is 4.
1117 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'U' = 3$.
1118 ...text:Objects of type $Rna$ can be converted to various other types and vice versa.
1119 An object that has a value not in ${'A', 'C', 'G', 'U'}$ is converted to $'A'$.
1120 ...text:$Rna$ is typedef for $SimpleType<char,Rna_>$, while $Rna_$ is a helper
1121 specialization tag class.
1122 ..see:Metafunction.ValueSize
1123 ..see:Spec.Rna5
1124 ..include:seqan/basic.h
1125 */
1126 struct Rna_ {};
1127 typedef SimpleType<unsigned char,Rna_> Rna;
1128 
1129 template <> struct ValueSize< Rna > { enum { VALUE = 4 }; };
1130 template <> struct BitsPerValue< Rna > { enum { VALUE = 2 }; };
1131 
1132 //____________________________________________________________________________
1133 
1134 /**
1135 .Spec.Rna5:
1136 ..cat:Alphabets
1137 ..summary:Alphabet for RNA including 'N' character.
1138 ..general:Class.SimpleType
1139 ..signature:Rna5
1140 ..remarks:
1141 ...text:The @Metafunction.ValueSize@ of $Rna5$ is 5.
1142 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'U' = 3$.
1143 The 'N' character ("unkown nucleotide") is encoded by 4.
1144 ...text:Objects of type $Rna5$ can be converted to various other types and vice versa.
1145 An object that has a value not in ${'A', 'C', 'G', 'U'}$ is converted to $'N'$.
1146 ...text:$Rna5$ is typedef for $SimpleType<char,Rna5_>$, while $Rna5_$ is a helper
1147 specialization tag class.
1148 ..see:Metafunction.ValueSize
1149 ..include:seqan/basic.h
1150 */
1151 struct Rna5_ {};
1152 typedef SimpleType<unsigned char, Rna5_> Rna5;
1153 
1154 template <> struct ValueSize< Rna5 > { enum { VALUE = 5 }; };
1155 template <> struct BitsPerValue< Rna5 > { enum { VALUE = 3 }; };
1156 
1157 //____________________________________________________________________________
1158 
1159 /**
1160 .Spec.Iupac:
1161 ..cat:Alphabets
1162 ..summary:Iupac code for DNA.
1163 ..general:Class.SimpleType
1164 ..signature:Iupac
1165 ..remarks:
1166 ...text:The @Metafunction.ValueSize@ of $Iupac$ is 16.
1167 The nucleotides are enumerated from 0 to 15 in this order:
1168 'U'=0, 'T', 'A', 'W', 'C', 'Y', 'M', 'H', 'G', 'K', 'R', 'D', 'S', 'B', 'V', 'N'=15.
1169 ...text:Objects of type $Iupac$ can be converted to various other types and vice versa.
1170 Unkown values are converted to $'N'$.
1171 ...text:$Iupac$ is typedef for $SimpleType<char,Iupac_>$, while $Iupac_$ is a helper
1172 specialization tag class.
1173 ..see:Metafunction.ValueSize
1174 ..include:seqan/basic.h
1175 */
1176 struct Iupac_ {};
1177 typedef SimpleType<unsigned char, Iupac_> Iupac;
1178 
1179 template <> struct ValueSize< Iupac > { enum { VALUE = 16 }; };
1180 template <> struct BitsPerValue< Iupac > { enum { VALUE = 4 }; };
1181 
1182 
1183 //____________________________________________________________________________
1184 
1185 /**
1186 .Spec.AminoAcid:
1187 ..cat:Alphabets
1188 ..summary:Iupac code for amino acids.
1189 ..general:Class.SimpleType
1190 ..signature:AminoAcid
1191 ..remarks:
1192 ...text:The @Metafunction.ValueSize@ of $AminoAcid$ is 24.
1193 ...text:The amino acids are enumerated from 0 to 15 in this order:
1194 ...text:'A'=0, 'R', 'N', 'D', 'C', 'Q', 'E', 'G', 'H', 'I', 'L', 'K', 'M', 'F', 'P', 'S', 'T', 'W', 'Y', 'V'=19.
1195 ...text:The remaining 4 symbols are:
1196 ...text: 'B'=20 (Aspartic Acid, Asparagine), 'Z'=21 (Glutamic Acid, Glutamine), 'X'=22 (unknown), '*'=23 (terminator)
1197 ...text:Objects of type $AminoAcid$ can be converted to $char$ and vice versa.
1198 Unkown values are converted to $'X'$.
1199 ...text:$AminoAcid$ is typedef for $SimpleType<char,AminoAcid_>$, while $AminoAcid_$ is a helper
1200 specialization tag class.
1201 ..see:Metafunction.ValueSize
1202 ..include:seqan/basic.h
1203 */
1204 struct AminoAcid_ {};
1205 typedef SimpleType<unsigned char, AminoAcid_> AminoAcid;
1206 
1207 template <> struct ValueSize< AminoAcid > { enum { VALUE = 24 }; };
1208 template <> struct BitsPerValue< AminoAcid > { enum { VALUE = 5 }; };
1209 
1210 //____________________________________________________________________________
1211 
1212 /**
1213 .Spec.Finite:
1214 ..cat:Alphabets
1215 ..summary:A finite alphabet of a fixed size.
1216 ..general:Class.SimpleType
1217 ..signature:SimpleType<TValue, Finite<SIZE> >
1218 ..param.TValue:The type that is use to store the values.
1219 ...default:$char$
1220 ..param.SIZE:The @Metafunction.ValueSize@ of the alphabet.
1221 ..see:Metafunction.ValueSize
1222 ..include:seqan/basic.h
1223 */
1224 template <unsigned SIZE>
1225 struct Finite;
1226 
1227 template <typename TValue, unsigned SIZE>
1228 struct ValueSize< SimpleType<TValue, Finite<SIZE> > > { enum { VALUE = SIZE }; };
1229 
1230 template <typename TValue, unsigned SIZE>
1231 struct BitsPerValue< SimpleType<TValue, Finite<SIZE> > >: Log2<SIZE> {};
1232 
1233 //////////////////////////////////////////////////////////////////////////////
1234 //ASCII
1235 
1236 inline void assign(Ascii & c_target,
1237 				   Dna const & source)
1238 {
1239 SEQAN_CHECKPOINT
1240 	c_target = TranslateTableDna5ToAscii_<>::VALUE[source.value];
1241 }
1242 //____________________________________________________________________________
1243 
1244 inline void assign(Ascii & c_target,
1245 				   Dna5 const & source)
1246 {
1247 SEQAN_CHECKPOINT
1248 	c_target = TranslateTableDna5ToAscii_<>::VALUE[source.value];
1249 }
1250 //____________________________________________________________________________
1251 
1252 inline void assign(Ascii& target,
1253 				   Rna const & source)
1254 {
1255 	SEQAN_CHECKPOINT
1256 	target = TranslateTableRna5ToAscii_<>::VALUE[source.value];
1257 }
1258 //____________________________________________________________________________
1259 
1260 inline void assign(Ascii& target,
1261 				   Rna5 const & source)
1262 {
1263 	SEQAN_CHECKPOINT
1264 	target = TranslateTableRna5ToAscii_<>::VALUE[source.value];
1265 }
1266 //____________________________________________________________________________
1267 
1268 inline void assign(Ascii & c_target, Iupac const & source)
1269 {
1270 SEQAN_CHECKPOINT
1271 	c_target = TranslateTableIupacToAscii_<>::VALUE[source.value];
1272 }
1273 //____________________________________________________________________________
1274 
1275 inline void assign(Ascii & c_target, AminoAcid const & source)
1276 {
1277 SEQAN_CHECKPOINT
1278 	c_target = TranslateTableAAToAscii_<>::VALUE[source.value];
1279 }
1280 
1281 //////////////////////////////////////////////////////////////////////////////
1282 //DNA (4 letters)
1283 
1284 template <>
1285 struct CompareType<Dna, __uint8> { typedef Dna Type; };
1286 inline void assign(Dna & target, __uint8 c_source)
1287 {
1288 SEQAN_CHECKPOINT
1289 	target.value = TranslateTableByteToDna_<>::VALUE[c_source];
1290 }
1291 //____________________________________________________________________________
1292 
1293 template <>
1294 struct CompareType<Dna, Ascii> { typedef Dna Type; };
1295 inline void assign(Dna & target, Ascii c_source)
1296 {
1297 SEQAN_CHECKPOINT
1298 	target.value = TranslateTableAsciiToDna_<>::VALUE[(unsigned char)c_source];
1299 }
1300 //____________________________________________________________________________
1301 
1302 template <>
1303 struct CompareType<Dna, Unicode> { typedef Dna Type; };
1304 inline void assign(Dna & target, Unicode c_source)
1305 {
1306 SEQAN_CHECKPOINT
1307 	target.value = TranslateTableAsciiToDna_<>::VALUE[(unsigned char) c_source];
1308 }
1309 //____________________________________________________________________________
1310 
1311 template <>
1312 struct CompareType<Dna, Dna5> { typedef Dna Type; };
1313 inline void assign(Dna & target, Dna5 const & c_source)
1314 {
1315 SEQAN_CHECKPOINT
1316 	target.value = c_source.value & 0x03;
1317 }
1318 //____________________________________________________________________________
1319 
1320 template <>
1321 struct CompareType<Dna, Iupac> { typedef Dna Type; };
1322 inline void assign(Dna & target, Iupac const & source)
1323 {
1324 SEQAN_CHECKPOINT
1325 	target.value = TranslateTableIupacToDna_<>::VALUE[source.value];
1326 }
1327 
1328 //////////////////////////////////////////////////////////////////////////////
1329 //DNA (5 letters)
1330 
1331 template <>
1332 struct CompareType<Dna5, __uint8> { typedef Dna5 Type; };
1333 inline void assign(Dna5 & target, __uint8 c_source)
1334 {
1335 SEQAN_CHECKPOINT
1336 	target.value = TranslateTableByteToDna5_<>::VALUE[c_source];
1337 }
1338 //____________________________________________________________________________
1339 
1340 template <>
1341 struct CompareType<Dna5, Ascii> { typedef Dna5 Type; };
1342 inline void assign(Dna5 & target, Ascii c_source)
1343 {
1344 SEQAN_CHECKPOINT
1345 	target.value = TranslateTableAsciiToDna5_<>::VALUE[(unsigned char) c_source];
1346 }
1347 //____________________________________________________________________________
1348 
1349 template <>
1350 struct CompareType<Dna5, Unicode> { typedef Dna5 Type; };
1351 inline void assign(Dna5 & target, Unicode c_source)
1352 {
1353 SEQAN_CHECKPOINT
1354 	target.value = TranslateTableAsciiToDna5_<>::VALUE[(unsigned char) c_source];
1355 }
1356 //____________________________________________________________________________
1357 
1358 template <>
1359 struct CompareType<Dna5, Iupac> { typedef Dna5 Type; };
1360 inline void assign(Dna5 & target, Iupac const & source)
1361 {
1362 SEQAN_CHECKPOINT
1363 	target.value = TranslateTableIupacToDna5_<>::VALUE[source.value];
1364 }
1365 //____________________________________________________________________________
1366 
1367 template <>
1368 struct CompareType<Dna5, Dna> { typedef Dna Type; };
1369 inline void assign(Dna5 & target, Dna const & c_source)
1370 {
1371 SEQAN_CHECKPOINT
1372 	target.value = c_source.value;
1373 }
1374 
1375 //////////////////////////////////////////////////////////////////////////////
1376 //RNA (4 letters)
1377 
1378 template <>
1379 struct CompareType<Rna, __uint8> { typedef Rna Type; };
1380 inline void assign(Rna & target, __uint8 c_source)
1381 {
1382 	SEQAN_CHECKPOINT
1383 	target.value = TranslateTableByteToRna_<>::VALUE[c_source];
1384 }
1385 //____________________________________________________________________________
1386 
1387 template <>
1388 struct CompareType<Rna, Ascii> { typedef Rna Type; };
1389 inline void assign(Rna & target, Ascii c_source)
1390 {
1391 	SEQAN_CHECKPOINT
1392 	target.value = TranslateTableAsciiToRna_<>::VALUE[(unsigned char)c_source];
1393 }
1394 //____________________________________________________________________________
1395 
1396 template <>
1397 struct CompareType<Rna, Unicode> { typedef Rna Type; };
1398 inline void assign(Rna & target, Unicode c_source)
1399 {
1400 	SEQAN_CHECKPOINT
1401 	target.value = TranslateTableAsciiToRna_<>::VALUE[(unsigned char) c_source];
1402 }
1403 //____________________________________________________________________________
1404 
1405 template <>
1406 struct CompareType<Rna, Rna5> { typedef Rna Type; };
1407 inline void assign(Rna & target, Rna5 const & c_source)
1408 {
1409 SEQAN_CHECKPOINT
1410 	target.value = c_source.value & 0x03;
1411 }
1412 
1413 //////////////////////////////////////////////////////////////////////////////
1414 //RNA (5 letters)
1415 
1416 template <>
1417 struct CompareType<Rna5, __uint8> { typedef Rna5 Type; };
1418 inline void assign(Rna5 & target, __uint8 c_source)
1419 {
1420 	SEQAN_CHECKPOINT
1421 	target.value = TranslateTableByteToRna5_<>::VALUE[c_source];
1422 }
1423 //____________________________________________________________________________
1424 
1425 template <>
1426 struct CompareType<Rna5, Ascii> { typedef Rna5 Type; };
1427 inline void assign(Rna5 & target, Ascii c_source)
1428 {
1429 	SEQAN_CHECKPOINT
1430 	target.value = TranslateTableAsciiToRna5_<>::VALUE[(unsigned char)c_source];
1431 }
1432 //____________________________________________________________________________
1433 
1434 template <>
1435 struct CompareType<Rna5, Unicode> { typedef Rna5 Type; };
1436 inline void assign(Rna5 & target, Unicode c_source)
1437 {
1438 	SEQAN_CHECKPOINT
1439 	target.value = TranslateTableAsciiToRna5_<>::VALUE[(unsigned char) c_source];
1440 }
1441 //____________________________________________________________________________
1442 
1443 template <>
1444 struct CompareType<Rna5, Rna> { typedef Dna Type; };
1445 inline void assign(Rna5 & target, Rna const & c_source)
1446 {
1447 SEQAN_CHECKPOINT
1448 	target.value = c_source.value;
1449 }
1450 
1451 //////////////////////////////////////////////////////////////////////////////
1452 //IUPAC (4 bits)
1453 
1454 template <>
1455 struct CompareType<Iupac, __uint8> { typedef Iupac Type; };
1456 inline void assign(Iupac & target, __uint8 c_source)
1457 {
1458 SEQAN_CHECKPOINT
1459 	target.value = TranslateTableByteToIupac_<>::VALUE[c_source];
1460 }
1461 //____________________________________________________________________________
1462 
1463 template <>
1464 struct CompareType<Iupac, Ascii> { typedef Iupac Type; };
1465 inline void assign(Iupac & target, Ascii c_source)
1466 {
1467 SEQAN_CHECKPOINT
1468 	target.value = TranslateTableAsciiToIupac_<>::VALUE[(unsigned char) c_source];
1469 }
1470 //____________________________________________________________________________
1471 
1472 template <>
1473 struct CompareType<Iupac, Unicode> { typedef Iupac Type; };
1474 inline void assign(Iupac & target, Unicode c_source)
1475 {
1476 SEQAN_CHECKPOINT
1477 	target.value = TranslateTableAsciiToIupac_<>::VALUE[(unsigned char) c_source];
1478 }
1479 //____________________________________________________________________________
1480 
1481 inline void assign(Iupac & target, Dna const & source)
1482 {
1483 SEQAN_CHECKPOINT
1484 	target.value = TranslateTableDna5ToIupac_<>::VALUE[source.value];
1485 }
1486 //____________________________________________________________________________
1487 
1488 inline void assign(Iupac & target, Dna5 const & source)
1489 {
1490 SEQAN_CHECKPOINT
1491 	target.value = TranslateTableDna5ToIupac_<>::VALUE[source.value];
1492 }
1493 
1494 //////////////////////////////////////////////////////////////////////////////
1495 //Amino Acid (5 bits)
1496 
1497 template <>
1498 struct CompareType<AminoAcid, __uint8> { typedef AminoAcid Type; };
1499 inline void assign(AminoAcid & target, __uint8 c_source)
1500 {
1501 SEQAN_CHECKPOINT
1502 	target.value = TranslateTableByteToAA_<>::VALUE[c_source];
1503 }
1504 //____________________________________________________________________________
1505 
1506 template <>
1507 struct CompareType<AminoAcid, Ascii> { typedef AminoAcid Type; };
1508 inline void assign(AminoAcid & target, Ascii c_source)
1509 {
1510 SEQAN_CHECKPOINT
1511 	target.value = TranslateTableAsciiToAA_<>::VALUE[(unsigned char) c_source];
1512 }
1513 //____________________________________________________________________________
1514 
1515 template <>
1516 struct CompareType<AminoAcid, Unicode> { typedef AminoAcid Type; };
1517 inline void assign(AminoAcid & target, Unicode c_source)
1518 {
1519 SEQAN_CHECKPOINT
1520 	target.value = TranslateTableAsciiToAA_<>::VALUE[(unsigned char) c_source];
1521 }
1522 
1523 //////////////////////////////////////////////////////////////////////////////
1524 
1525 template <typename TValue>
1526 struct BaseAlphabet
1527 {
1528 	typedef TValue Type;
1529 };
1530 
1531 //////////////////////////////////////////////////////////////////////////////
1532 
1533 // //DnaQ and Dna5Q
1534 
1535 /**
1536 .Spec.DnaQ:
1537 ..cat:Alphabets
1538 ..summary:Alphabet for DNA plus phred quality.
1539 ..general:Class.SimpleType
1540 ..signature:DnaQ
1541 ..remarks:
1542 ...text:The @Metafunction.ValueSize@ of $DnaQ$ is 4.
1543 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'T' = 3$.
1544 ...text:Objects of type $DnaQ$ can be converted to various other types and vice versa.
1545 ...text:$DnaQ$ is typedef for $SimpleType<char,DnaQ_>$, while $DnaQ_$ is a helper
1546 specialization tag class.
1547 ..see:Metafunction.ValueSize
1548 ..see:Spec.Dna5Q
1549 */
1550 struct DnaQ_ {};
1551 typedef SimpleType <unsigned char, DnaQ_> DnaQ;
1552 
1553 template <> struct ValueSize< DnaQ > { enum { VALUE = 4 }; };				// considering nucleotides
1554 template <> struct InternalValueSize_< DnaQ > { enum { VALUE = 252 }; };	// considering nucleotides x Quality 0..62
1555 template <> struct BitsPerValue< DnaQ > { enum { VALUE = 8 }; };
1556 
1557 template <>
1558 struct BaseAlphabet<DnaQ>
1559 {
1560 	typedef Dna Type;
1561 };
1562 
1563 //____________________________________________________________________________
1564 
1565 /**
1566 .Spec.Dna5Q:
1567 ..cat:Alphabets
1568 ..summary:Alphabet for DNA plus phred quality including 'N' character.
1569 ..general:Class.SimpleType
1570 ..signature:Dna5Q
1571 ..remarks:
1572 ...text:The @Metafunction.ValueSize@ of $Dna5Q$ is 5.
1573 The nucleotides are enumerated this way: $'A' = 0, 'C' = 1, 'G' = 2, 'T' = 3$.
1574 The 'N' character ("unkown nucleotide") is encoded by 4.
1575 ...text:Objects of type $Dna5$ can be converted to various other types and vice versa.
1576 ...text:$Dna5Q$ is typedef for $SimpleType<char,Dna5Q_>$, while $Dna5Q_$ is a helper
1577 specialization tag class.
1578 ..see:Metafunction.ValueSize
1579 */
1580 struct Dna5Q_ {};
1581 typedef SimpleType <unsigned char, Dna5Q_> Dna5Q;
1582 
1583 static const unsigned char Dna5QValueN_ = 252;								// value representing N
1584 
1585 template <> struct ValueSize< Dna5Q > { enum { VALUE = 5 }; };				// considering nucleotides + N
1586 template <> struct InternalValueSize_< Dna5Q > { enum { VALUE = 253 }; };	// considering (nucleotides x Quality 0..62) + N
1587 template <> struct BitsPerValue< Dna5Q > { enum { VALUE = 8 }; };
1588 
1589 template <>
1590 struct BaseAlphabet<Dna5Q>
1591 {
1592 	typedef Dna5 Type;
1593 };
1594 
1595 template <typename TValue>
1596 struct QualityValueSize {
1597 	enum { VALUE = ValueSize<TValue>::VALUE };
1598 };
1599 template <typename TValue>
1600 struct QualityValueSize<TValue const>:
1601 	public QualityValueSize<TValue> {};
1602 
1603 template <> struct QualityValueSize< DnaQ >  { enum { VALUE = 63 }; };		// 64 - 1 (N)
1604 template <> struct QualityValueSize< Dna5Q > { enum { VALUE = 63 }; };
1605 
1606 
1607 // template <typename TValue, typename TValue2>
1608 // struct CompareType<SimpleType<TValue,DnaQ_>, SimpleType<TValue2,Dna_> >
1609 // {
1610 // 	typedef SimpleType<TValue2,Dna_> Type;
1611 // };
1612 //
1613 // template <typename TValue, typename TValue2>
1614 // struct CompareType<SimpleType<TValue,Dna_>, SimpleType<TValue2,DnaQ_> >
1615 // {
1616 // 	typedef SimpleType<TValue,Dna_> Type;
1617 // };
1618 //
1619 //
1620 //
1621 // template <typename TValue, typename TValue2>
1622 // struct CompareType<SimpleType<TValue,Dna5Q_>, SimpleType<TValue2,Dna5_> >
1623 // {
1624 // 	typedef SimpleType<TValue2,Dna5_> Type;
1625 // };
1626 //
1627 // template <typename TValue, typename TValue2>
1628 // struct CompareType<SimpleType<TValue,Dna5_>, SimpleType<TValue2,Dna5Q_> >
1629 // {
1630 // 	typedef SimpleType<TValue,Dna5_> Type;
1631 // };
1632 
1633 
1634 template <>
1635 struct CompareType<Dna5Q, Dna5Q> { typedef Dna5 Type; };
1636 template <>
1637 struct CompareType<DnaQ, DnaQ> { typedef Dna Type; };
1638 
1639 //////////////////////////////////////////////////////////////////////////////
1640 //DNA (4 letters) with Qualities (0..60)
1641 
1642 
1643 template <>
1644 struct CompareType<DnaQ, Dna5Q> { typedef Dna Type; };
1645 inline void assign(DnaQ & target, Dna5Q const & source)
1646 {
1647     SEQAN_CHECKPOINT;
1648 
1649     // We perform the converstion from DNA5 to DNA5 with qualities by a simple
1650     // table lookup.  The lookup below is equivalent to the following line:
1651     //
1652 	// target.value = (source.value == Dna5QValueN_)? 0: source.value;
1653 
1654     static const unsigned table[] = {
1655           0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,
1656          16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,
1657          32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,
1658          48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,
1659          64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,
1660          80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,
1661          96,  97,  98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
1662         112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
1663         128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
1664         144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
1665         160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
1666         176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
1667         192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
1668         208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
1669         224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
1670         240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 0,   0,   0,   0
1671     };
1672     target.value = table[source.value];
1673 }
1674 //____________________________________________________________________________
1675 
1676 
1677 template <>
1678 struct CompareType<DnaQ, Dna> { typedef Dna Type; };
1679 inline void assign(DnaQ & target, Dna const & source)
1680 {
1681 SEQAN_CHECKPOINT
1682 	target.value = source.value | (60 << 2);
1683 }
1684 
1685 //////////////////////////////////////////////////////////////////////////////
1686 //DNA (5 letters)
1687 
1688 template <>
1689 struct CompareType<Dna5Q, DnaQ> { typedef Dna Type; };
1690 inline void assign(Dna5Q & target, DnaQ const & source)
1691 {
1692 SEQAN_CHECKPOINT
1693 	target.value = source.value;
1694 }
1695 
1696 //____________________________________________________________________________
1697 
1698 template <>
1699 struct CompareType<Dna5, Dna5Q> { typedef Dna5 Type; };
1700 inline void assign(Dna5 & target, Dna5Q const & source)
1701 {
1702     SEQAN_CHECKPOINT;
1703 
1704     // We perform the conversion from DNA5 to DNA5 with qualities by a simple
1705     // table lookup.  The lookup below is equivalent to the following line:
1706     //
1707 	// target.value = (source.value == Dna5QValueN_)? 4: source.value & 3;
1708 
1709     static const unsigned table[] = {
1710         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1711         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1712         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1713         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1714         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1715         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1716         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1717         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1718         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1719         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1720         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1721         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
1722         0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 4, 4, 4, 4 // <-- note the 4
1723     };
1724     target.value = table[source.value];
1725 }
1726 
1727 
1728 //____________________________________________________________________________
1729 
1730 template <>
1731 struct CompareType<Dna5Q, Dna5> { typedef Dna5 Type; };
1732 inline void assign(Dna5Q & target, Dna5 const & source)
1733 {
1734     SEQAN_CHECKPOINT;
1735 
1736     // We perform the conversion from DNA5 with qualities to DNA5 by a simple
1737     // table lookup.  The lookup below is equivalent to the following line:
1738     //
1739 	// target.value = (source.value == 4)? Dna5QValueN_ : source.value | (60 << 2);
1740 
1741     static const unsigned table[] = {
1742         (60 << 2) + 0, (60 << 2) + 1, (60 << 2) + 2, (60 << 2) + 3, Dna5QValueN_
1743     };
1744     target.value = table[source.value];
1745 }
1746 
1747 
1748 //____________________________________________________________________________
1749 
1750 template <>
1751 struct CompareType<Dna, DnaQ> { typedef Dna Type; };
1752 inline void assign(Dna & target, DnaQ const & source)
1753 {
1754 SEQAN_CHECKPOINT
1755 	target.value = source.value & 3;
1756 }
1757 
1758 //____________________________________________________________________________
1759 
1760 
1761 template <>
1762 struct CompareType<DnaQ, Iupac> { typedef Dna Type; };
1763 inline void assign(DnaQ & target, Iupac const & source)
1764 {
1765 SEQAN_CHECKPOINT
1766 	assign(target, (Dna) source);
1767 }
1768 
1769 //____________________________________________________________________________
1770 
1771 
1772 template <>
1773 struct CompareType<DnaQ, Dna5> { typedef Dna Type; };
1774 inline void assign(DnaQ & target, Dna5 const & source)
1775 {
1776 SEQAN_CHECKPOINT
1777 	assign(target, (Dna) source);
1778 }
1779 
1780 template <>
1781 struct CompareType<DnaQ, __uint8> { typedef Dna Type; };
1782 inline void assign(DnaQ & target, __uint8 c_source)
1783 {
1784 SEQAN_CHECKPOINT
1785 	assign(target, (Dna) c_source);
1786 }
1787 //____________________________________________________________________________
1788 
1789 template <>
1790 struct CompareType<DnaQ, Ascii> { typedef Dna Type; };
1791 inline void assign(DnaQ & target, Ascii c_source)
1792 {
1793 SEQAN_CHECKPOINT
1794 	assign(target, (Dna) c_source);
1795 }
1796 //____________________________________________________________________________
1797 
1798 template <>
1799 struct CompareType<DnaQ, Unicode> { typedef Dna Type; };
1800 inline void assign(DnaQ & target, Unicode c_source)
1801 {
1802 SEQAN_CHECKPOINT
1803 	assign(target, (Dna) c_source);
1804 }
1805 //____________________________________________________________________________
1806 
1807 inline void
1808 assign(DnaQ & target, DnaQ const & source)
1809 {
1810 SEQAN_CHECKPOINT
1811 	target.value = source.value;
1812 }
1813 
1814 template <typename TSource>
1815 inline void
1816 assign(DnaQ & target, TSource const & source)
1817 {
1818 SEQAN_CHECKPOINT
1819 	target.value = (Dna)source;
1820 }
1821 //____________________________________________________________________________
1822 
1823 
1824 template <>
1825 struct CompareType<Dna5Q, Dna> { typedef Dna Type; };
1826 inline void assign(Dna5Q & target, Dna const & source)
1827 {
1828 SEQAN_CHECKPOINT
1829 	assign(target, (DnaQ) source);
1830 }
1831 
1832 //____________________________________________________________________________
1833 
1834 
1835 template <>
1836 struct CompareType<Dna, Dna5Q> { typedef Dna Type; };
1837 inline void assign(Dna & target, Dna5Q const & source)
1838 {
1839 SEQAN_CHECKPOINT
1840 	assign(target, (Dna5)source);
1841 }
1842 
1843 //____________________________________________________________________________
1844 template <>
1845 struct CompareType<Dna5, DnaQ> { typedef Dna5 Type; };
1846 inline void assign(Dna5 & target, DnaQ const & source)
1847 {
1848 SEQAN_CHECKPOINT
1849 	assign(target, (Dna5Q)source);
1850 }
1851 //____________________________________________________________________________
1852 
1853 
1854 
1855 template <>
1856 struct CompareType<Dna5Q, __uint8> { typedef Dna5 Type; };
1857 inline void assign(Dna5Q & target, __uint8 c_source)
1858 {
1859 SEQAN_CHECKPOINT
1860 	assign(target, (Dna5)c_source);
1861 }
1862 //____________________________________________________________________________
1863 
1864 template <>
1865 struct CompareType<Dna5Q, Ascii> { typedef Dna5 Type; };
1866 inline void assign(Dna5Q & target, Ascii c_source)
1867 {
1868 SEQAN_CHECKPOINT
1869 	assign(target, (Dna5)c_source);
1870 }
1871 //____________________________________________________________________________
1872 
1873 template <>
1874 struct CompareType<Dna5Q, Unicode> { typedef Dna5 Type; };
1875 inline void assign(Dna5Q & target, Unicode c_source)
1876 {
1877 SEQAN_CHECKPOINT
1878 	assign(target, (Dna5)c_source);
1879 }
1880 //____________________________________________________________________________
1881 
1882 template <>
1883 struct CompareType<Dna5Q, Iupac> { typedef Dna5 Type; };
1884 inline void assign(Dna5Q & target, Iupac const & source)
1885 {
1886 SEQAN_CHECKPOINT
1887 	assign(target, (Dna5)source);
1888 }
1889 
1890 inline void
1891 assign(Dna5Q & target, Dna5Q const & source)
1892 {
1893 SEQAN_CHECKPOINT
1894 	target.value = source.value;
1895 }
1896 template <typename TSource>
1897 inline void
1898 assign(Dna5Q & target, TSource const & source)
1899 {
1900 SEQAN_CHECKPOINT
1901 	assign(target, (Dna5)source);
1902 }
1903 
1904 
1905 //____________________________________________________________________________
1906 
1907 
1908 
1909 //__int64
1910 
1911 inline void
1912 assign(__int64 & c_target,
1913 	   DnaQ & source)
1914 {
1915 SEQAN_CHECKPOINT
1916 	c_target = Dna(source);
1917 }
1918 
1919 inline void
1920 assign(__int64 & c_target,
1921 	   DnaQ const & source)
1922 {
1923 SEQAN_CHECKPOINT
1924 	c_target = Dna(source);
1925 }
1926 
1927 //__uint64
1928 
1929 inline void
1930 assign(__uint64 & c_target,
1931 	   DnaQ & source)
1932 {
1933 SEQAN_CHECKPOINT
1934 	c_target = Dna(source);
1935 }
1936 
1937 inline void
1938 assign(__uint64 & c_target,
1939 	   DnaQ const & source)
1940 {
1941 SEQAN_CHECKPOINT
1942 	c_target = Dna(source);
1943 }
1944 
1945 //int
1946 
1947 inline void
1948 assign(int & c_target,
1949 	   DnaQ & source)
1950 {
1951 SEQAN_CHECKPOINT
1952 	c_target = Dna(source);
1953 }
1954 
1955 inline void
1956 assign(int & c_target,
1957 	   DnaQ const & source)
1958 {
1959 SEQAN_CHECKPOINT
1960 	c_target = Dna(source);
1961 }
1962 
1963 //unsigned int
1964 
1965 inline void
1966 assign(unsigned int & c_target,
1967 	   DnaQ & source)
1968 {
1969 SEQAN_CHECKPOINT
1970 	c_target = Dna(source);
1971 }
1972 
1973 inline void
1974 assign(unsigned int & c_target,
1975 	   DnaQ const & source)
1976 {
1977 SEQAN_CHECKPOINT
1978 	c_target = Dna(source);
1979 }
1980 
1981 
1982 //short
1983 
1984 inline void
1985 assign(short & c_target,
1986 	   DnaQ & source)
1987 {
1988 SEQAN_CHECKPOINT
1989 	c_target = Dna(source);
1990 }
1991 
1992 inline void
1993 assign(short & c_target,
1994 	   DnaQ const & source)
1995 {
1996 SEQAN_CHECKPOINT
1997 	c_target = Dna(source);
1998 }
1999 
2000 //unsigned short
2001 
2002 inline void
2003 assign(unsigned short & c_target,
2004 	   DnaQ & source)
2005 {
2006 SEQAN_CHECKPOINT
2007 	c_target = Dna(source);
2008 }
2009 
2010 inline void
2011 assign(unsigned short & c_target,
2012 	   DnaQ const & source)
2013 {
2014 SEQAN_CHECKPOINT
2015 	c_target = Dna(source);
2016 }
2017 
2018 //char
2019 
2020 inline void
2021 assign(char & c_target,
2022 	   DnaQ & source)
2023 {
2024 SEQAN_CHECKPOINT
2025 	c_target = Dna(source);
2026 }
2027 
2028 inline void
2029 assign(char & c_target,
2030 	   DnaQ const & source)
2031 {
2032 SEQAN_CHECKPOINT
2033 	c_target = Dna(source);
2034 }
2035 
2036 //signed char
2037 
2038 inline void
2039 assign(signed char & c_target,
2040 	   DnaQ & source)
2041 {
2042 SEQAN_CHECKPOINT
2043 	c_target = Dna(source);
2044 }
2045 
2046 inline void
2047 assign(signed char & c_target,
2048 	   DnaQ const & source)
2049 {
2050 SEQAN_CHECKPOINT
2051 	c_target = Dna(source);
2052 }
2053 
2054 //unsigned char
2055 
2056 inline void
2057 assign(unsigned char & c_target,
2058 	   DnaQ & source)
2059 {
2060 SEQAN_CHECKPOINT
2061 	c_target = Dna(source);
2062 }
2063 
2064 inline void
2065 assign(unsigned char & c_target,
2066 	   DnaQ const & source)
2067 {
2068 SEQAN_CHECKPOINT
2069 	c_target = Dna(source);
2070 }
2071 
2072 
2073 //__int64
2074 
2075 inline void
2076 assign(__int64 & c_target,
2077 	   Dna5Q & source)
2078 {
2079 SEQAN_CHECKPOINT
2080 	c_target = Dna5(source);
2081 }
2082 
2083 inline void
2084 assign(__int64 & c_target,
2085 	   Dna5Q const & source)
2086 {
2087 SEQAN_CHECKPOINT
2088 	c_target = Dna5(source);
2089 }
2090 
2091 //__uint64
2092 
2093 inline void
2094 assign(__uint64 & c_target,
2095 	   Dna5Q & source)
2096 {
2097 SEQAN_CHECKPOINT
2098 	c_target = Dna5(source);
2099 }
2100 
2101 inline void
2102 assign(__uint64 & c_target,
2103 	   Dna5Q const & source)
2104 {
2105 SEQAN_CHECKPOINT
2106 	c_target = Dna5(source);
2107 }
2108 
2109 //int
2110 
2111 inline void
2112 assign(int & c_target,
2113 	   Dna5Q & source)
2114 {
2115 SEQAN_CHECKPOINT
2116 	c_target = Dna5(source);
2117 }
2118 
2119 inline void
2120 assign(int & c_target,
2121 	   Dna5Q const & source)
2122 {
2123 SEQAN_CHECKPOINT
2124 	c_target = Dna5(source);
2125 }
2126 
2127 //unsigned int
2128 
2129 inline void
2130 assign(unsigned int & c_target,
2131 	   Dna5Q & source)
2132 {
2133 SEQAN_CHECKPOINT
2134 	c_target = Dna5(source);
2135 }
2136 
2137 inline void
2138 assign(unsigned int & c_target,
2139 	   Dna5Q const & source)
2140 {
2141 SEQAN_CHECKPOINT
2142 	c_target = Dna5(source);
2143 }
2144 
2145 
2146 //short
2147 
2148 inline void
2149 assign(short & c_target,
2150 	   Dna5Q & source)
2151 {
2152 SEQAN_CHECKPOINT
2153 	c_target = Dna5(source);
2154 }
2155 
2156 inline void
2157 assign(short & c_target,
2158 	   Dna5Q const & source)
2159 {
2160 SEQAN_CHECKPOINT
2161 	c_target = Dna5(source);
2162 }
2163 
2164 //unsigned short
2165 
2166 inline void
2167 assign(unsigned short & c_target,
2168 	   Dna5Q & source)
2169 {
2170 SEQAN_CHECKPOINT
2171 	c_target = Dna5(source);
2172 }
2173 
2174 inline void
2175 assign(unsigned short & c_target,
2176 	   Dna5Q const & source)
2177 {
2178 SEQAN_CHECKPOINT
2179 	c_target = Dna5(source);
2180 }
2181 
2182 //char
2183 
2184 inline void
2185 assign(char & c_target,
2186 	   Dna5Q & source)
2187 {
2188 SEQAN_CHECKPOINT
2189 	c_target = Dna5(source);
2190 }
2191 
2192 inline void
2193 assign(char & c_target,
2194 	   Dna5Q const & source)
2195 {
2196 SEQAN_CHECKPOINT
2197 	c_target = Dna5(source);
2198 }
2199 
2200 //signed char
2201 
2202 inline void
2203 assign(signed char & c_target,
2204 	   Dna5Q & source)
2205 {
2206 SEQAN_CHECKPOINT
2207 	c_target = Dna5(source);
2208 }
2209 
2210 inline void
2211 assign(signed char & c_target,
2212 	   Dna5Q const & source)
2213 {
2214 SEQAN_CHECKPOINT
2215 	c_target = Dna5(source);
2216 }
2217 
2218 //unsigned char
2219 
2220 inline void
2221 assign(unsigned char & c_target,
2222 	   Dna5Q & source)
2223 {
2224 SEQAN_CHECKPOINT
2225 	c_target = Dna5(source);
2226 }
2227 
2228 inline void
2229 assign(unsigned char & c_target,
2230 	   Dna5Q const & source)
2231 {
2232 SEQAN_CHECKPOINT
2233 	c_target = Dna5(source);
2234 }
2235 
2236 inline int getQualityValue(DnaQ const &c)
2237 {
2238 	return c.value >> 2;
2239 }
2240 
2241 inline int getQualityValue(Dna5Q const &c)
2242 {
2243     // We use a lookup table to extract the qualities from DNA5Q.  The lookup
2244     // table based code is equivalent to the following line:
2245 	// return (c.value == Dna5QValueN_)? 0: c.value >> 2;
2246 
2247     static const unsigned table[] = {
2248          0,  0,  0,  0,  1,  1,  1,  1,  2,  2,  2,  2,  3,  3,  3,  3,  4,
2249          4,  4,  4,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,
2250          8,  8,  9,  9,  9,  9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12,
2251         12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
2252         17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21,
2253         21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25,
2254         25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29,
2255         29, 30, 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33,
2256         34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 36, 36, 37, 37, 37, 37, 38,
2257         38, 38, 38, 39, 39, 39, 39, 40, 40, 40, 40, 41, 41, 41, 41, 42, 42,
2258         42, 42, 43, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46,
2259         46, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50,
2260         51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55,
2261         55, 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59,
2262         59, 59, 60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62,
2263 		0,  0,  0,  0};
2264     return table[c.value];
2265 }
2266 
2267 inline
2268 void convertQuality(Ascii & c, int q)
2269 {
2270 	c = '!' + Ascii(q);
2271 }
2272 
2273 
2274 // TODO(holtgrew): What about different quality types? Guess scaling? Look at how other packages do this.
2275 /**
2276 .Function.assignQualityValue
2277 ..cat:Alphabets
2278 ..signature:assignQualityValue(c, q)
2279 ..summary:Assign quality to a character from an alphabet with integrated quality.
2280 ..param.c:Target character to assign quality to.
2281 ...type:Spec.DnaQ
2282 ..param.q:Quality to assign to the quality.
2283 ...type:nolink:int
2284 ...type:nolink:char
2285 ..remarks:If $q$ is a $char$ then $'!'$ is subtracted from $q$. This is useful for ASCII encoded PHRED scores.
2286  */
2287 //set quality value
2288 inline
2289 void assignQualityValue(DnaQ &c, int q)
2290 {
2291 	if (q < 0) q = 0;
2292     if (q >= QualityValueSize<DnaQ>::VALUE)
2293         q = QualityValueSize<DnaQ>::VALUE - 1;
2294 	c.value = (c.value & 3) | (q << 2);
2295 }
2296 
2297 ///.Function.assignQualityValue.param.c.type:Spec.Dna5Q
2298 inline
2299 void assignQualityValue(Dna5Q &c, int q)
2300 {
2301 	if (q < 0) q = 0;
2302     if (q >= QualityValueSize<Dna5Q>::VALUE)
2303         q = QualityValueSize<Dna5Q>::VALUE - 1;
2304 	if (c.value != Dna5QValueN_)
2305 		c.value = (c.value & 3) | (q << 2);
2306 }
2307 
2308 inline
2309 void assignQualityValue(DnaQ &c, Ascii q)
2310 {
2311     int q1 = static_cast<int>(q - '!');
2312 	if (q1 < 0) q1 = 0;
2313     if (q1 >= QualityValueSize<DnaQ>::VALUE)
2314         q1 = QualityValueSize<DnaQ>::VALUE - 1;
2315 	assignQualityValue(c, q1);
2316 }
2317 
2318 inline
2319 void assignQualityValue(Dna5Q &c, Ascii q)
2320 {
2321     int q1 = static_cast<int>(q - '!');
2322 	if (q1 < 0) q1 = 0;
2323 	if (q1 >= QualityValueSize<Dna5Q>::VALUE)
2324         q1 = QualityValueSize<Dna5Q>::VALUE - 1;
2325 	assignQualityValue(c, q1);
2326 }
2327 
2328 /**
2329 .Function.assignQualities
2330 ..cat:Alphabets
2331 ..summary:Assign quality value between strings.
2332 ..signature:assignQualities(target, source)
2333 ..param.target:Target string
2334 ...type:nolink:@Class.String@ of any alphabet with qualities, e.g. @Spec.DnaQ@, @Spec.Dna5Q@
2335 ..param.source:Source string.
2336 ...type:nolink:@Class.String@ of $int$ or $char$.
2337 ..remarks:This funciton calls @Function.assignQualityValue@ for all entries of $target$ and $source$, look at the documentation of @Function.assignQualityValue@ on how the values of $source$ are interpreted.
2338 ..see:Function.assignQualityValue
2339  */
2340 template <typename TDest, typename TSource>
2341 void assignQualities(TDest &dst, TSource const &src)
2342 {
2343 	typedef typename Iterator<TDest>::Type TDestIter;
2344 	typedef typename Iterator<TSource>::Type TSourceIter;
2345 
2346 	TDestIter itDst = begin(dst, Standard());
2347 	TDestIter itDstEnd = end(dst, Standard());
2348 	TSourceIter itSrcEnd = end(src, Standard());
2349 
2350 	for (TSourceIter itSrc = begin(src, Standard()); itDst != itDstEnd && itSrc != itSrcEnd; ++itDst, ++itSrc)
2351 		assignQualityValue(*itDst, *itSrc);
2352 }
2353 
2354 //////////////////////////////////////////////////////////////////////////////
2355 }// namespace SEQAN_NAMESPACE_MAIN
2356 
2357 #endif //#ifndef SEQAN_HEADER_...
2358