Imported Upstream version 0.12.7
[bowtie.git] / SeqAn-1.1 / seqan / basic / basic_iterator_base.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_iterator_base.h,v 1.1 2008/08/25 16:20:01 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_BASIC_ITERATOR_BASE_H
22 #define SEQAN_HEADER_BASIC_ITERATOR_BASE_H
23
24 namespace SEQAN_NAMESPACE_MAIN
25 {
26 //////////////////////////////////////////////////////////////////////////////
27 // Iter
28 //////////////////////////////////////////////////////////////////////////////
29 /**
30 .Class.Iter:
31 ..cat:Basic
32 ..summary:Iterator that is used to traverse containers.
33 ..signature:Iter<TContainer, TSpec>
34 ..param.TContainer:Type of the container that can be iterated by $Iter$.
35 ...metafunction:Metafunction.Container
36 ..param.TSpec:The specializing type.
37 ...metafunction:Metafunction.Spec
38 ..implements:Concept.Iterator
39 */
40 template <typename TContainer, typename TSpec>
41 class Iter;
42
43 //////////////////////////////////////////////////////////////////////////////
44 ///.Metafunction.Spec.param.T.type:Class.Iter
45
46 template <typename TContainer, typename TSpec>
47 struct Spec<Iter<TContainer, TSpec> >
48 {
49         typedef TSpec Type;
50 };
51 template <typename TContainer, typename TSpec>
52 struct Spec<Iter<TContainer, TSpec> const>
53 {
54         typedef TSpec Type;
55 };
56
57 //////////////////////////////////////////////////////////////////////////////
58
59 ///.Metafunction.Value.param.T.type:Class.Iter
60
61 template <typename TContainer, typename TSpec>
62 struct Value<Iter<TContainer, TSpec> >:
63         Value<TContainer>
64 {
65 };
66 template <typename TContainer, typename TSpec>
67 struct Value<Iter<TContainer, TSpec> const>:
68         Value<TContainer>
69 {
70 };
71
72 //////////////////////////////////////////////////////////////////////////////
73
74 ///.Metafunction.GetValue.param.T.type:Class.Iter
75
76 template <typename TContainer, typename TSpec>
77 struct GetValue<Iter<TContainer, TSpec> >:
78         GetValue<TContainer>
79 {
80 };
81 template <typename TContainer, typename TSpec>
82 struct GetValue<Iter<TContainer, TSpec> const>:
83         GetValue<TContainer>
84 {
85 };
86
87 //////////////////////////////////////////////////////////////////////////////
88
89 ///.Metafunction.Reference.param.T.type:Class.Iter
90
91 template <typename TContainer, typename TSpec>
92 struct Reference<Iter<TContainer, TSpec> >:
93         Reference<TContainer>
94 {
95 };
96 template <typename TContainer, typename TSpec>
97 struct Reference<Iter<TContainer, TSpec> const>:
98         Reference<TContainer>
99 {
100 };
101
102 //////////////////////////////////////////////////////////////////////////////
103
104 ///.Metafunction.Container.param.T.type:Class.Iter
105
106 template <typename T> struct Container;
107
108 template <typename TContainer, typename TSpec>
109 struct Container<Iter<TContainer, TSpec> >
110 {
111         typedef TContainer Type;
112 };
113 template <typename TContainer, typename TSpec>
114 struct Container<Iter<TContainer, TSpec> const>
115 {
116         typedef TContainer Type;
117 };
118
119 //////////////////////////////////////////////////////////////////////////////
120
121 /*
122 ///.Metafunction.Host.param.T.type:Class.Iter
123
124 template <typename TContainer, typename TSpec>
125 struct Host<Iter<TContainer, TSpec> >:
126         Container<Iter<TContainer, TSpec> >
127 {
128 };
129 template <typename TContainer, typename TSpec>
130 struct Host<Iter<TContainer, TSpec> const>:
131         Container<Iter<TContainer, TSpec> const>
132 {
133 };
134 */
135
136 //////////////////////////////////////////////////////////////////////////////
137 // operator *
138 //////////////////////////////////////////////////////////////////////////////
139
140 template <typename TContainer, typename TSpec>
141 inline typename Reference<Iter<TContainer, TSpec> >::Type 
142 operator * (Iter<TContainer, TSpec> & me)
143 {
144 SEQAN_CHECKPOINT
145         return value(me);
146 }
147 template <typename TContainer, typename TSpec>
148 inline typename Reference<Iter<TContainer, TSpec> const>::Type 
149 operator * (Iter<TContainer, TSpec> const & me)
150 {
151 SEQAN_CHECKPOINT
152         return value(me);
153 }
154
155 //////////////////////////////////////////////////////////////////////////////
156 // operator ++
157 //////////////////////////////////////////////////////////////////////////////
158
159 template <typename TContainer, typename TSpec>
160 inline Iter<TContainer, TSpec> const &
161 operator ++ (Iter<TContainer, TSpec> & me)
162 {
163 SEQAN_CHECKPOINT
164         goNext(me);
165         return me;
166 }
167
168 template <typename TContainer, typename TSpec>
169 inline Iter<TContainer, TSpec> const
170 operator ++ (Iter<TContainer, TSpec> & me, int)
171 {
172 SEQAN_CHECKPOINT
173         Iter<TContainer, TSpec> temp_(me);
174         goNext(me);
175         return temp_;
176 }
177
178 //////////////////////////////////////////////////////////////////////////////
179 // operator --
180 //////////////////////////////////////////////////////////////////////////////
181
182 template <typename TContainer, typename TSpec>
183 inline Iter<TContainer, TSpec> const &
184 operator -- (Iter<TContainer, TSpec> & me)
185 {
186 SEQAN_CHECKPOINT
187         goPrevious(me);
188         return me;
189 }
190
191 template <typename TContainer, typename TSpec>
192 inline Iter<TContainer, TSpec> const
193 operator -- (Iter<TContainer, TSpec> & me, int)
194 {
195 SEQAN_CHECKPOINT
196         Iter<TContainer, TSpec> temp_(me);
197         goPrevious(me);
198         return temp_;
199 }
200
201 //////////////////////////////////////////////////////////////////////////////
202 // position
203 //////////////////////////////////////////////////////////////////////////////
204
205 //most Iter classes are rooted strings
206
207 template <typename TContainer, typename TSpec, typename TContainer2>
208 inline typename Position<Iter<TContainer, TSpec> const>::Type 
209 position(Iter<TContainer, TSpec> const & me,
210                  TContainer2 const &)
211 {
212 SEQAN_CHECKPOINT
213         return position(me);
214 }
215
216
217 //////////////////////////////////////////////////////////////////////////////
218
219 } //namespace SEQAN_NAMESPACE_MAIN
220
221 #endif //#ifndef SEQAN_HEADER_...