Imported Upstream version 0.12.7
[bowtie.git] / SeqAn-1.1 / seqan / basic / basic_converter.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_converter.h,v 1.1 2008/08/25 16:20:01 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_BASIC_CONVERTER_H
22 #define SEQAN_HEADER_BASIC_CONVERTER_H
23
24 namespace SEQAN_NAMESPACE_MAIN
25 {
26
27 //////////////////////////////////////////////////////////////////////////////
28 //Convert
29 //////////////////////////////////////////////////////////////////////////////
30
31 //gibt den Typ an, in den TSource konvertiert werden kann (TTarget oder TTarget &)
32
33 /**
34 .Metafunction.Convert:
35 ..summary:Return type of a conversion. 
36 ..signature:Convert<Target, Source>::Type
37 ..param.Target:Type the object should be converted to.
38 ..param.Source:Type of the object that should be converted to $Target$.
39 ..returns.param.Type:Type that is returned by @Function.convert@.
40 ...remarks:This is either $Target$ or $Target &$:
41 If instances of $Source: /fs/szdevel/src/cvsroot/bowtie/SeqAn-1.1/seqan/basic/basic_converter.h,v $ can be re-interpreted as instances of $Target$,
42 than this metafunction returns a reference, otherwise it returns $Target$, 
43 that is @Function.convert@ returns a temporary.
44 ..remarks:A constant instance of $Convert$ is (ab)used as tag argument of @Function.convertImpl@.
45 */
46 template <typename TTarget, typename TSource = void>
47 struct Convert
48 {
49         typedef TTarget Type;
50         
51 };
52
53 //////////////////////////////////////////////////////////////////////////////
54 //convertImpl
55 //////////////////////////////////////////////////////////////////////////////
56 /**
57 .Function.convertImpl:
58 ..hidefromindex
59 ..cat:Alphabets
60 ..summary:Implements @Function.convert@.
61 ..signature:Convert convertImpl(convert, source)
62 ..param.convert:Object that specifies the conversion.
63 ...type:Metafunction.Convert
64 ...remarks:A constant instance of @Metafunction.Convert@ is used to specify the conversion target.
65 ..param.source:An object that should be converted.
66 ..returns:$source$ converted to the type specified by convert.
67 ...metafunction:Metafunction.Convert
68 ..remarks:This function implements @Function.convert@. 
69 It is recommended to use @Function.convert@ rather than $convertImpl$.
70 */
71 //??? Spezialisiere convertImpl, verwende convert
72 //??? Konversion eines einzelnen Zeichens in ein einzelnes Zeichen. Konversion von Sequenzen in Sequenzen finden wo anders statt.
73 //??? Kann entweder kopieren oder re-interpretieren, je nach Convert::Type
74 template <typename TTarget, typename T, typename TSource>
75 inline typename Convert<TTarget, TSource>::Type
76 convertImpl(Convert<TTarget, T> const,
77                         TSource & source)
78 {
79         return source;
80 }
81 template <typename TTarget, typename T, typename TSource>
82 inline typename Convert<TTarget, TSource const>::Type
83 convertImpl(Convert<TTarget, T> const,
84                         TSource const & source)
85 {
86         return source;
87 }
88
89 //////////////////////////////////////////////////////////////////////////////
90 //convert
91 //////////////////////////////////////////////////////////////////////////////
92 /**
93 .Function.convert:
94 ..cat:Alphabets
95 ..summary:Converts a value into another value.
96 ..signature:Convert convert<Target>(source)
97 ..param.Target:The type $source$ is converted to.
98 ..param.source:An object that is converted to $Target$.
99 ..returns:$source$ converted to $Target$.
100 ...remarks:If $source$ can be re-interpreted as instance of $Target$, then a reference is returned.
101 Otherwise the function returns a temporary object. 
102 ...metafunction:Metafunction.Convert
103 ..remarks:This function is implemented in @Function.convertImpl@. 
104 Do not specialize $convert$, specialize @Function.convertImpl@ instead.
105 ..see:Function.convertImpl
106 */
107 template <typename TTarget, typename TSource>
108 inline typename Convert<TTarget, TSource>::Type
109 convert(TSource const & source)
110 {
111         return convertImpl(Convert<TTarget, TSource>(), source);
112 }
113
114 //////////////////////////////////////////////////////////////////////////////
115 }// namespace SEQAN_NAMESPACE_MAIN
116
117 #endif //#ifndef SEQAN_HEADER_...