1 /*==========================================================================
2 SeqAn - The Library for Sequence Analysis
4 ============================================================================
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.
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.
17 ============================================================================
18 $Id: string_value_expand.h,v 1.1 2008/08/25 16:20:04 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_SEQUENCE_STRING_VALUEEXPAND_H
22 #define SEQAN_HEADER_SEQUENCE_STRING_VALUEEXPAND_H
25 namespace SEQAN_NAMESPACE_MAIN
27 //////////////////////////////////////////////////////////////////////////////
30 template <typename THost, typename TMap, typename TSpec = Default>
33 struct ValueExpandIter;
35 //////////////////////////////////////////////////////////////////////////////
37 template <typename TValue, typename THost, typename TMap, typename TSpec>
38 class String<TValue, ValueExpand<THost, TMap, TSpec> >
40 //____________________________________________________________________________
43 typedef typename Value<String>::Type TLargeValue;
44 typedef typename Value<THost>::Type TSmallValue;
46 Holder<THost> data_host;
47 Holder<TMap> data_map;
49 //____________________________________________________________________________
55 String(String const & other_):
56 data_host(other_.data_host),
57 data_map(other_.data_map)
64 operator = (String const & other_)
66 data_host = other_.data_host;
67 data_map = other_.data_map;
69 //____________________________________________________________________________
71 template <typename TPos>
72 inline typename Reference<String>::Type
75 return value(*this, pos);
78 //____________________________________________________________________________
80 friend inline Holder<THost> &
81 _dataHost(String & me)
85 //____________________________________________________________________________
87 friend inline Holder<TMap> &
92 //____________________________________________________________________________
95 //////////////////////////////////////////////////////////////////////////////
98 template <typename TValue, typename THost, typename TMap, typename TSpec>
99 struct Value<String< TValue, ValueExpand<THost, TMap, TSpec> > >
103 template <typename TValue, typename THost, typename TMap, typename TSpec>
104 struct Value<String< TValue, ValueExpand<THost, TMap, TSpec> > const>
106 typedef TValue const Type;
109 //____________________________________________________________________________
111 template <typename TValue, typename THost, typename TMap, typename TSpec>
112 struct GetValue<String< TValue, ValueExpand<THost, TMap, TSpec> > >:
113 Value<String< TValue, ValueExpand<THost, TMap, TSpec> > >
116 template <typename TValue, typename THost, typename TMap, typename TSpec>
117 struct GetValue<String< TValue, ValueExpand<THost, TMap, TSpec> > const>:
118 Value<String< TValue, ValueExpand<THost, TMap, TSpec> > const>
122 //____________________________________________________________________________
124 template <typename TValue, typename THost, typename TMap, typename TSpec>
125 struct Reference<String< TValue, ValueExpand<THost, TMap, TSpec> > >
127 typedef String< TValue, ValueExpand<THost, TMap, TSpec> > TMe;
128 typedef typename Iterator<TMe, Standard>::Type TIterator;
129 typedef Proxy<IteratorProxy<TIterator> > Type;
131 template <typename TValue, typename THost, typename TMap, typename TSpec>
132 struct Reference<String< TValue, ValueExpand<THost, TMap, TSpec> > const>
134 typedef String< TValue, ValueExpand<THost, TMap, TSpec> > const TMe;
135 typedef typename Iterator<TMe, Standard>::Type TIterator;
136 typedef Proxy<IteratorProxy<TIterator> > Type;
139 //____________________________________________________________________________
141 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TIteratorSpec>
142 struct Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> >, TIteratorSpec>
144 typedef ValueExpand<THost, TMap, TSpec> TValueExpand;
145 typedef String< TValue, TValueExpand> TMe;
146 typedef typename Iterator<THost, Standard>::Type THostIterator;
148 typedef Iter<TMe, AdaptorIterator<THostIterator, ValueExpandIter> > Type;
150 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TIteratorSpec>
151 struct Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> > const, TIteratorSpec>
153 typedef ValueExpand<THost, TMap, TSpec> TValueExpand;
154 typedef String< TValue, TValueExpand> const TMe;
155 typedef typename Iterator<THost, Standard>::Type THostIterator;
157 typedef Iter<TMe, AdaptorIterator<THostIterator, ValueExpandIter> > Type;
160 //____________________________________________________________________________
162 template <typename TValue, typename THost, typename TMap, typename TSpec>
163 struct DefaultOverflowImplicit<String< TValue, ValueExpand<THost, TMap, TSpec> > >:
164 DefaultOverflowImplicit< typename Host<String< TValue, ValueExpand<THost, TMap, TSpec> > >::Type >
167 template <typename TValue, typename THost, typename TMap, typename TSpec>
168 struct DefaultOverflowImplicit<String< TValue, ValueExpand<THost, TMap, TSpec> > const>:
169 DefaultOverflowImplicit< typename Host<String< TValue, ValueExpand<THost, TMap, TSpec> > const>::Type >
173 //____________________________________________________________________________
175 template <typename TValue, typename THost, typename TMap, typename TSpec>
176 struct DefaultOverflowExplicit<String< TValue, ValueExpand<THost, TMap, TSpec> > >:
177 DefaultOverflowExplicit< typename Host<String< TValue, ValueExpand<THost, TMap, TSpec> > >::Type >
180 template <typename TValue, typename THost, typename TMap, typename TSpec>
181 struct DefaultOverflowExplicit<String< TValue, ValueExpand<THost, TMap, TSpec> > const>:
182 DefaultOverflowExplicit< typename Host<String< TValue, ValueExpand<THost, TMap, TSpec> > const>::Type >
186 //____________________________________________________________________________
188 template <typename TValue, typename THost, typename TMap, typename TSpec>
189 struct IsContiguous<String< TValue, ValueExpand<THost, TMap, TSpec> > >
192 enum { VALUE = false };
195 //____________________________________________________________________________
197 template <typename TValue, typename THost, typename TMap, typename TSpec>
198 struct Host<String< TValue, ValueExpand<THost, TMap, TSpec> > >
202 template <typename TValue, typename THost, typename TMap, typename TSpec>
203 struct Host<String< TValue, ValueExpand<THost, TMap, TSpec> > const>
205 typedef THost const Type;
208 //____________________________________________________________________________
210 template <typename T>
213 template <typename TValue, typename THost, typename TMap, typename TSpec>
214 struct MapType<String< TValue, ValueExpand<THost, TMap, TSpec> > >
218 template <typename TValue, typename THost, typename TMap, typename TSpec>
219 struct MapType<String< TValue, ValueExpand<THost, TMap, TSpec> > const>
221 typedef TMap const Type;
224 //////////////////////////////////////////////////////////////////////////////
227 template <typename TValue, typename THost, typename TMap, typename TSpec>
229 _getMap(String< TValue, ValueExpand<THost, TMap, TSpec> > & me)
231 return value(_dataMap(me));
233 template <typename TValue, typename THost, typename TMap, typename TSpec>
235 _getMap(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me)
237 return value(_dataMap(me));
240 //____________________________________________________________________________
242 template <typename TValue, typename THost, typename TMap, typename TSpec>
243 inline typename Value<THost>::Type
244 _getValueExpandFlagValue(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me)
246 typedef typename Value<THost>::Type TSmallValue;
247 return supremumValue<TSmallValue>();
250 //////////////////////////////////////////////////////////////////////////////
254 template <typename TValue, typename THost, typename TMap, typename TSpec>
256 id(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me)
262 //____________________________________________________________________________
264 template <typename TValue, typename THost, typename TMap, typename TPos, typename TSpec, typename TTag>
265 inline typename Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> >, Tag<TTag> const>::Type
266 iter(String< TValue, ValueExpand<THost, TMap, TSpec> > & me,
268 Tag<TTag> const tag_)
271 typedef String< TValue, ValueExpand<THost, TMap, TSpec> > TMe;
272 typedef typename Iterator<TMe, Tag<TTag> const>::Type TIterator;
273 return TIterator(me, begin(host(me), Standard()) + pos_);
275 template <typename TValue, typename THost, typename TMap, typename TPos, typename TSpec, typename TTag>
276 inline typename Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> > const, Tag<TTag> const>::Type
277 iter(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me,
279 Tag<TTag> const tag_ )
282 typedef String< TValue, ValueExpand<THost, TMap, TSpec> > const TMe;
283 typedef typename Iterator<TMe, Tag<TTag> const>::Type TIterator;
284 return TIterator(me, begin(host(me), Standard()) + pos_);
287 //____________________________________________________________________________
289 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TTag>
290 inline typename Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> >, Tag<TTag> const>::Type
291 begin(String< TValue, ValueExpand<THost, TMap, TSpec> > & me,
292 Tag<TTag> const tag_)
295 return iter(me, 0, tag_);
297 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TTag>
298 inline typename Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> > const, Tag<TTag> const>::Type
299 begin(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me,
300 Tag<TTag> const tag_)
303 return iter(me, 0, tag_);
306 //____________________________________________________________________________
308 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TTag>
309 inline typename Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> >, Tag<TTag> const>::Type
310 end(String< TValue, ValueExpand<THost, TMap, TSpec> > & me,
311 Tag<TTag> const tag_)
314 return iter(me, length(me), tag_);
316 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TTag>
317 inline typename Iterator<String< TValue, ValueExpand<THost, TMap, TSpec> > const, Tag<TTag> const>::Type
318 end(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me,
319 Tag<TTag> const tag_)
322 return iter(me, length(me), tag_);
325 //____________________________________________________________________________
327 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TPos>
328 inline typename Reference<String< TValue, ValueExpand<THost, TMap, TSpec> > >::Type
329 value(String< TValue, ValueExpand<THost, TMap, TSpec> > & me,
334 return *iter(me, pos, Standard());
336 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TPos>
337 inline typename Reference<String< TValue, ValueExpand<THost, TMap, TSpec> > const>::Type
338 value(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me,
343 return *iter(me, pos, Standard());
346 //____________________________________________________________________________
348 template <typename TValue, typename THost, typename TMap, typename TSpec>
349 inline typename Size<String< TValue, ValueExpand<THost, TMap, TSpec> > const>::Type
350 length(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me)
353 return length(host(me));
356 //____________________________________________________________________________
358 template <typename TValue, typename THost, typename TMap, typename TSpec>
359 inline typename Size<String< TValue, ValueExpand<THost, TMap, TSpec> > const>::Type
360 capacity(String< TValue, ValueExpand<THost, TMap, TSpec> > const & me)
363 return capacity(host(me));
366 //____________________________________________________________________________
368 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TSize>
370 resize(String< TValue, ValueExpand<THost, TMap, TSpec> > & me,
374 return resize(host(me), new_length);
377 //____________________________________________________________________________
379 template <typename TValue, typename THost, typename TMap, typename TSpec, typename TSize, typename TExpand>
381 reserve(String< TValue, ValueExpand<THost, TMap, TSpec> > & me,
383 Tag<TExpand> const tag)
386 return reserve(host(me), new_length, tag);
389 //////////////////////////////////////////////////////////////////////////////
390 // Iterator for ValueExpandIterator string: Subclass of AdaptorIterator
391 //////////////////////////////////////////////////////////////////////////////
393 template <typename TContainer, typename TIterator>
394 inline typename Value<TContainer>::Type
395 getValue(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > & me)
398 typedef typename Host<TContainer>::Type THost;
399 typedef typename Value<THost>::Type TSmallValue;
400 TSmallValue c = value(hostIterator(me));
401 if (c == _getValueExpandFlagValue(container(me)))
403 return _getMap(container(me))[position(me)];
410 template <typename TContainer, typename TIterator>
412 getValue(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > const & me)
415 typedef typename Host<TContainer>::Type THost;
416 typedef typename Value<THost>::Type TSmallValue;
417 TSmallValue c = value(hostIterator(me));
418 if (c == _getValueExpandFlagValue(container(me)))
420 return _getMap(container(me))[position(me)];
428 //____________________________________________________________________________
430 template <typename TContainer, typename TIterator>
431 inline typename Reference<Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > >::Type
432 value(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > & me)
435 typedef Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > TMe;
436 return typename Reference<TMe>::Type(me);
438 template <typename TContainer, typename TIterator>
439 inline typename Reference<Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > >::Type
440 value(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > const & me)
443 typedef Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > const TMe;
444 return typename Reference<TMe>::Type(me);
447 //____________________________________________________________________________
449 template <typename TContainer, typename TIterator, typename TValue>
451 assignValue(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > & me,
452 TValue const & _value)
455 typedef typename Host<TContainer>::Type THost;
456 typedef typename Value<THost>::Type TSmallValue;
458 TSmallValue flagValue = _getValueExpandFlagValue(container(me));
459 if (_value >= flagValue)
460 {//use map to store LargeValue
461 assignValue(hostIterator(me), flagValue);
462 _getMap(container(me))[position(me)] = _value;
466 assignValue(hostIterator(me), _value);
469 template <typename TContainer, typename TIterator, typename TValue>
471 assignValue(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > const & me,
472 TValue const & _value)
475 typedef typename Host<TContainer>::Type THost;
476 typedef typename Value<THost>::Type TSmallValue;
478 TSmallValue flagValue = _getValueExpandFlagValue(container(me));
479 if (_value >= flagValue)
480 {//use map to store LargeValue
481 assignValue(hostIterator(me), flagValue);
482 _getMap(container(me))[position(me)] = _value;
486 assignValue(hostIterator(me), _value);
490 //____________________________________________________________________________
492 template <typename TContainer, typename TIterator, typename TValue>
494 moveValue(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > & me,
495 TValue const & _value)
498 assignValue(me, _value);
500 template <typename TContainer, typename TIterator, typename TValue>
502 moveValue(Iter<TContainer, AdaptorIterator<TIterator, ValueExpandIter> > const & me,
503 TValue const & _value)
506 assignValue(me, _value);
510 //////////////////////////////////////////////////////////////////////////////
512 } //namespace SEQAN_NAMESPACE_MAIN
514 #endif //#ifndef SEQAN_HEADER_...