Imported Upstream version 0.12.7
[bowtie.git] / SeqAn-1.1 / seqan / sequence / string_array.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: string_array.h,v 1.1 2008/08/25 16:20:04 langmead Exp $
19  ==========================================================================*/
20
21 #ifndef SEQAN_HEADER_SEQUENCE_STRING_ARRAY_H
22 #define SEQAN_HEADER_SEQUENCE_STRING_ARRAY_H
23
24
25 namespace SEQAN_NAMESPACE_MAIN
26 {
27
28 /**
29 .Spec.Array String:
30 ..cat:Strings
31 ..general:Class.String
32 ..summary:Fast but non-expandable string.
33 ..signature:String<TValue, Array<size> >
34 ..param.TValue:The value type, that is the type of the items/characters stored in the string.
35 ...remarks:Use @Metafunction.Value@ to get the value type for a given class.
36 ..param.size:A positive integer that specifies the capacity of the string.
37 ...remarks:Note that the capacity of a stack string cannot be changed later.
38 */
39 //////////////////////////////////////////////////////////////////////////////
40
41 template <unsigned int ISize>
42 struct Array;
43
44 //////////////////////////////////////////////////////////////////////////////
45
46 template <typename TValue, unsigned int ISize>
47 class String<TValue, Array<ISize> >
48 {
49 protected:
50         mutable TValue data_begin[ISize];
51         TValue * data_end;
52
53 //____________________________________________________________________________
54
55 public:
56         String()
57         {
58 SEQAN_CHECKPOINT
59                 data_end = data_begin;
60         }
61
62         template <typename TSource>
63         String(TSource & source)
64         {
65 SEQAN_CHECKPOINT
66                 data_end = data_begin;
67                 assign(*this, source);
68         }
69         template <typename TSource>
70         String(TSource const & source)
71         {
72 SEQAN_CHECKPOINT
73                 data_end = data_begin;
74                 assign(*this, source);
75         }
76         String(String const & source)
77         {
78 SEQAN_CHECKPOINT
79                 data_end = data_begin;
80                 assign(*this, source);
81         }
82
83         template <typename TSource>
84         String & operator =(TSource const & source)
85         {
86 SEQAN_CHECKPOINT
87                 assign(*this, source);
88                 return *this;
89         }
90         String & operator =(String const & source)
91         {
92 SEQAN_CHECKPOINT
93                 assign(*this, source);
94                 return *this;
95         }
96
97         ~String()
98         {
99         }
100
101 //____________________________________________________________________________
102
103         template <typename TPos>
104         inline typename Reference<String>::Type
105         operator [] (TPos pos)
106         {
107 SEQAN_CHECKPOINT
108                 return value(*this, pos);
109         }
110
111         template <typename TPos>
112         inline typename Reference<String const>::Type 
113         operator [] (TPos pos) const
114         {
115 SEQAN_CHECKPOINT
116                 return value(*this, pos);
117         }
118
119 //____________________________________________________________________________
120
121         friend inline typename Iterator<String, Standard>::Type
122         begin(String & me,
123                 Standard)
124         {
125 SEQAN_CHECKPOINT
126                 return me.data_begin;
127         }
128         friend inline typename Iterator<String const, Standard>::Type
129         begin(String const & me,
130                 Standard)
131         {
132 SEQAN_CHECKPOINT
133                 return me.data_begin;
134         }
135
136 //____________________________________________________________________________
137
138         friend inline typename Iterator<String, Standard>::Type
139         end(String & me,
140                 Standard)
141         {
142 SEQAN_CHECKPOINT
143                 return me.data_end;
144         }
145         friend inline typename Iterator<String const, Standard>::Type
146         end(String const & me,
147                 Standard)
148         {
149 SEQAN_CHECKPOINT
150                 return me.data_end;
151         }
152
153 //____________________________________________________________________________
154
155         friend inline size_t
156         capacity(String &)
157         {
158 SEQAN_CHECKPOINT
159                 return ISize;
160         }
161
162         friend inline size_t
163         capacity(String const &)
164         {
165 SEQAN_CHECKPOINT
166                 return ISize;
167         }
168 //____________________________________________________________________________
169
170 /**
171 .Internal._setLength.param.object.type:Spec.Array String
172 */
173         friend inline void 
174         _setLength(
175                 String & me, 
176                 size_t new_length)
177         {
178 SEQAN_CHECKPOINT
179                 me.data_end = me.data_begin + new_length;
180         }
181
182 //____________________________________________________________________________
183
184 };
185
186
187 //////////////////////////////////////////////////////////////////////////////
188
189 template <typename TValue, unsigned int ISize>
190 struct DefaultOverflowImplicit<String<TValue, Array<ISize> > >
191 {
192         typedef Limit Type;
193 };
194
195 template <typename TValue, unsigned int ISize>
196 struct DefaultOverflowImplicit<String<TValue, Array<ISize> > const >
197 {
198         typedef Limit Type;
199 };
200
201 //////////////////////////////////////////////////////////////////////////////
202
203 template <typename TValue, unsigned int ISize>
204 struct DefaultOverflowExplicit<String<TValue, Array<ISize> > >
205 {
206         typedef Limit Type;
207 };
208
209 template <typename TValue, unsigned int ISize>
210 struct DefaultOverflowExplicit<String<TValue, Array<ISize> > const >
211 {
212         typedef Limit Type;
213 };
214
215 //////////////////////////////////////////////////////////////////////////////
216
217 template <typename TValue, unsigned int ISize>
218 struct IsContiguous< String<TValue, Array<ISize> > >
219 {
220     typedef True Type;
221         enum { VALUE = true };
222 };
223
224 //////////////////////////////////////////////////////////////////////////////
225
226 ///.Metafunction.LENGTH.param.T.type:Spec.Array String
227 template <typename TValue, unsigned int ISize>
228 struct LENGTH< String<TValue, Array<ISize> > >
229 {
230         enum { VALUE = ISize };
231 };
232
233 //////////////////////////////////////////////////////////////////////////////
234
235 } //namespace SEQAN_NAMESPACE_MAIN
236
237 #endif //#ifndef SEQAN_HEADER_...