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: basic_proxy.h,v 1.1 2008/08/25 16:20:02 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_BASIC_PROXY_H
22 #define SEQAN_HEADER_BASIC_PROXY_H
25 namespace SEQAN_NAMESPACE_MAIN
29 //////////////////////////////////////////////////////////////////////////////
31 //////////////////////////////////////////////////////////////////////////////
35 ..summary:Emulates object of another class.
36 ..signature:Proxy<TSpec>
37 ..param.TSpec:The specializing type.
38 ...metafunction:Metafunction.Spec
39 ..remarks.text:Use @Metafunction.Value@ to get the emulated type.
40 An instance of $Proxy$ behaves like an object of its value type.
41 $Proxy$ can be used as reference type (see @Metafunction.Reference@).
42 ..remarks.text:Note that functions that are both general and specialized for
43 the value type should be specialized for $Proxy<TSpec>$ too,
44 since otherwise the general version will be called.
47 template <typename TSpec>
50 //////////////////////////////////////////////////////////////////////////////
52 ///.Metafunction.Spec.param.T.type:Class.Proxy
54 template <typename TSpec>
55 struct Spec< Proxy<TSpec> >
59 template <typename TSpec>
60 struct Spec< Proxy<TSpec> const>
65 //////////////////////////////////////////////////////////////////////////////
67 //////////////////////////////////////////////////////////////////////////////
72 ..summary:Proxy that is implemented by an iterator.
73 ..signature:Proxy<IteratorProxy<TIterator> >
74 ..param.TIterator:Iterator type.
75 ..remarks.text:The value type of an iterator proxy is the value type of the
79 template <typename TIterator>
82 //____________________________________________________________________________
84 template <typename TIterator>
85 struct Proxy<IteratorProxy<TIterator> >
88 typedef typename Value<Proxy>::Type TValue;
89 typedef typename GetValue<Proxy>::Type TAccessor;
91 typedef typename _RemoveConst<TAccessor>::Type TAccessor_NotConst;
94 TIterator data_iterator;
97 Proxy(TIterator const _it):
102 Proxy(Proxy const & _other):
103 data_iterator(_other.data_iterator)
114 operator = (Proxy const & _other)
117 assignValue(data_iterator, getValue(_other.data_iterator));
122 operator = (TValue const & _value)
125 assignValue(data_iterator, _value);
129 operator TAccessor_NotConst()
132 return getValue(data_iterator);
135 //____________________________________________________________________________
138 friend inline TIterator &
141 return me.data_iterator;
143 friend inline TIterator const &
144 iter(Proxy const & me)
146 return me.data_iterator;
149 //____________________________________________________________________________
152 //////////////////////////////////////////////////////////////////////////////
154 //////////////////////////////////////////////////////////////////////////////
156 ///.Metafunction.Value.param.T.type:Class.Proxy
158 template <typename TIterator>
159 struct Value< Proxy<IteratorProxy<TIterator> > >:
163 template <typename TIterator>
164 struct Value< Proxy<IteratorProxy<TIterator> > const>
166 typedef typename Value<TIterator>::Type const Type;
169 //////////////////////////////////////////////////////////////////////////////
171 ///.Metafunction.GetValue.param.T.type:Class.Proxy
173 template <typename TIterator>
174 struct GetValue< Proxy<IteratorProxy<TIterator> > >:
178 template <typename TIterator>
179 struct GetValue< Proxy<IteratorProxy<TIterator> > const>
181 typedef typename GetValue<TIterator const>::Type Type;
184 //////////////////////////////////////////////////////////////////////////////
186 ///.Metafunction.Reference.param.T.type:Class.Proxy
188 template <typename TIterator>
189 struct Reference< Proxy<IteratorProxy<TIterator> > >
191 typedef Proxy<IteratorProxy<TIterator> > Type;
193 template <typename TIterator>
194 struct Reference< Proxy<IteratorProxy<TIterator> > const >
196 typedef Proxy<IteratorProxy<TIterator> > const Type;
199 //////////////////////////////////////////////////////////////////////////////
201 ///.Metafunction.Size.param.T.type:Class.Proxy
203 template <typename TIterator>
204 struct Size< Proxy<IteratorProxy<TIterator> > >:
208 template <typename TIterator>
209 struct Size< Proxy<IteratorProxy<TIterator> > const>:
214 //////////////////////////////////////////////////////////////////////////////
216 ///.Metafunction.Difference.param.T.type:Class.Proxy
218 template <typename TIterator>
219 struct Difference< Proxy<IteratorProxy<TIterator> > >:
220 Difference<TIterator>
223 template <typename TIterator>
224 struct Difference< Proxy<IteratorProxy<TIterator> > const>:
225 Difference<TIterator>
229 //////////////////////////////////////////////////////////////////////////////
230 //////////////////////////////////////////////////////////////////////////////
232 template <typename TSpec>
233 typename GetValue<Proxy<TSpec> >::Type
234 getValue(Proxy<TSpec> & me)
236 return getValue(iter(me));
238 template <typename TSpec>
239 typename GetValue<Proxy<TSpec> const>::Type
240 getValue(Proxy<TSpec> const & me)
242 return getValue(iter(me));
245 //////////////////////////////////////////////////////////////////////////////
247 //////////////////////////////////////////////////////////////////////////////
249 template <typename TSpec, typename T>
250 struct CompareType <Proxy<TSpec>, T>
252 typedef typename Value<Proxy<TSpec> >::Type TValue;
253 typedef typename _RemoveConst<TValue>::Type TValue_NoConst;
254 typedef typename CompareType<TValue_NoConst, T>::Type Type;
257 //???TODO: Symmetrie von CompareType herstellen
258 //____________________________________________________________________________
260 template <typename TTarget, typename T, typename TSpec>
261 inline typename Convert<TTarget, Proxy<TSpec> >::Type
262 convertImpl(Convert<TTarget, T> const,
263 Proxy<TSpec> & source)
265 return convert<TTarget>(getValue(source));
267 template <typename TTarget, typename T, typename TSpec>
268 inline typename Convert<TTarget, Proxy<TSpec> const>::Type
269 convertImpl(Convert<TTarget, T> const,
270 Proxy<TSpec> const & source)
272 return convert<TTarget>(getValue(source));
274 //////////////////////////////////////////////////////////////////////////////
277 template <typename TSpec, typename TRight>
279 operator == (Proxy<TSpec> const & left_,
280 TRight const & right_)
283 typedef Proxy<TSpec> TLeft;
284 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
285 return convert<TCompareType>(left_) == convert<TCompareType>(right_);
288 template <typename TLeft, typename TSpec>
290 operator == (TLeft const & left_,
291 Proxy<TSpec> const & right_)
294 typedef Proxy<TSpec> TRight;
295 typedef typename CompareType<TRight, TLeft>::Type TCompareType;
296 return convert<TCompareType>(left_) == convert<TCompareType>(right_);
299 template <typename TLeftSpec, typename TRightSpec>
301 operator == (Proxy<TLeftSpec> const & left_,
302 Proxy<TRightSpec> const & right_)
305 typedef Proxy<TLeftSpec> TLeft;
306 typedef Proxy<TRightSpec> TRight;
307 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
308 return convert<TCompareType>(left_) == convert<TCompareType>(right_);
311 template <typename TSpec>
313 operator == (Proxy<TSpec> const & left_,
314 Proxy<TSpec> const & right_)
317 typedef typename GetValue<Proxy<TSpec> >::Type TAccessor;
318 return convert<TAccessor>(left_) == convert<TAccessor>(right_);
321 //____________________________________________________________________________
324 template <typename TSpec, typename TRight>
326 operator != (Proxy<TSpec> const & left_,
327 TRight const & right_)
330 typedef Proxy<TSpec> TLeft;
331 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
332 return convert<TCompareType>(left_) != convert<TCompareType>(right_);
335 template <typename TLeft, typename TSpec>
337 operator != (TLeft const & left_,
338 Proxy<TSpec> const & right_)
341 typedef Proxy<TSpec> TRight;
342 typedef typename CompareType<TRight, TLeft>::Type TCompareType;
343 return convert<TCompareType>(left_) != convert<TCompareType>(right_);
346 template <typename TLeftSpec, typename TRightSpec>
348 operator != (Proxy<TLeftSpec> const & left_,
349 Proxy<TRightSpec> const & right_)
352 typedef Proxy<TLeftSpec> TLeft;
353 typedef Proxy<TRightSpec> TRight;
354 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
355 return convert<TCompareType>(left_) != convert<TCompareType>(right_);
358 template <typename TSpec>
360 operator != (Proxy<TSpec> const & left_,
361 Proxy<TSpec> const & right_)
364 typedef typename GetValue<Proxy<TSpec> >::Type TAccessor;
365 return convert<TAccessor>(left_) != convert<TAccessor>(right_);
369 //____________________________________________________________________________
372 template <typename TSpec, typename TRight>
374 operator < (Proxy<TSpec> const & left_,
375 TRight const & right_)
378 typedef Proxy<TSpec> TLeft;
379 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
380 return convert<TCompareType>(left_) < convert<TCompareType>(right_);
383 template <typename TLeft, typename TSpec>
385 operator < (TLeft const & left_,
386 Proxy<TSpec> const & right_)
389 typedef Proxy<TSpec> TRight;
390 typedef typename CompareType<TRight, TLeft>::Type TCompareType;
391 return convert<TCompareType>(left_) < convert<TCompareType>(right_);
394 template <typename TLeftSpec, typename TRightSpec>
396 operator < (Proxy<TLeftSpec> const & left_,
397 Proxy<TRightSpec> const & right_)
400 typedef Proxy<TLeftSpec> TLeft;
401 typedef Proxy<TRightSpec> TRight;
402 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
403 return convert<TCompareType>(left_) < convert<TCompareType>(right_);
406 template <typename TSpec>
408 operator < (Proxy<TSpec> const & left_,
409 Proxy<TSpec> const & right_)
412 typedef typename GetValue<Proxy<TSpec> >::Type TAccessor;
413 return convert<TAccessor>(left_) < convert<TAccessor>(right_);
416 //____________________________________________________________________________
419 template <typename TSpec, typename TRight>
421 operator <= (Proxy<TSpec> const & left_,
422 TRight const & right_)
425 typedef Proxy<TSpec> TLeft;
426 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
427 return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
430 template <typename TLeft, typename TSpec>
432 operator <= (TLeft const & left_,
433 Proxy<TSpec> const & right_)
436 typedef Proxy<TSpec> TRight;
437 typedef typename CompareType<TRight, TLeft>::Type TCompareType;
438 return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
441 template <typename TLeftSpec, typename TRightSpec>
443 operator <= (Proxy<TLeftSpec> const & left_,
444 Proxy<TRightSpec> const & right_)
447 typedef Proxy<TLeftSpec> TLeft;
448 typedef Proxy<TRightSpec> TRight;
449 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
450 return convert<TCompareType>(left_) <= convert<TCompareType>(right_);
453 template <typename TSpec>
455 operator <= (Proxy<TSpec> const & left_,
456 Proxy<TSpec> const & right_)
459 typedef typename GetValue<Proxy<TSpec> >::Type TAccessor;
460 return convert<TAccessor>(left_) <= convert<TAccessor>(right_);
464 //____________________________________________________________________________
467 template <typename TSpec, typename TRight>
469 operator > (Proxy<TSpec> const & left_,
470 TRight const & right_)
473 typedef Proxy<TSpec> TLeft;
474 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
475 return convert<TCompareType>(left_) > convert<TCompareType>(right_);
478 template <typename TLeft, typename TSpec>
480 operator > (TLeft const & left_,
481 Proxy<TSpec> const & right_)
484 typedef Proxy<TSpec> TRight;
485 typedef typename CompareType<TRight, TLeft>::Type TCompareType;
486 return convert<TCompareType>(left_) > convert<TCompareType>(right_);
489 template <typename TLeftSpec, typename TRightSpec>
491 operator > (Proxy<TLeftSpec> const & left_,
492 Proxy<TRightSpec> const & right_)
495 typedef Proxy<TLeftSpec> TLeft;
496 typedef Proxy<TRightSpec> TRight;
497 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
498 return convert<TCompareType>(left_) > convert<TCompareType>(right_);
501 template <typename TSpec>
503 operator > (Proxy<TSpec> const & left_,
504 Proxy<TSpec> const & right_)
507 typedef typename GetValue<Proxy<TSpec> >::Type TAccessor;
508 return convert<TAccessor>(left_) > convert<TAccessor>(right_);
512 //____________________________________________________________________________
515 template <typename TSpec, typename TRight>
517 operator >= (Proxy<TSpec> const & left_,
518 TRight const & right_)
521 typedef Proxy<TSpec> TLeft;
522 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
523 return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
526 template <typename TLeft, typename TSpec>
528 operator >= (TLeft const & left_,
529 Proxy<TSpec> const & right_)
532 typedef Proxy<TSpec> TRight;
533 typedef typename CompareType<TRight, TLeft>::Type TCompareType;
534 return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
537 template <typename TLeftSpec, typename TRightSpec>
539 operator >= (Proxy<TLeftSpec> const & left_,
540 Proxy<TRightSpec> const & right_)
543 typedef Proxy<TLeftSpec> TLeft;
544 typedef Proxy<TRightSpec> TRight;
545 typedef typename CompareType<TLeft, TRight>::Type TCompareType;
546 return convert<TCompareType>(left_) >= convert<TCompareType>(right_);
549 template <typename TSpec>
551 operator >= (Proxy<TSpec> const & left_,
552 Proxy<TSpec> const & right_)
555 typedef typename GetValue<Proxy<TSpec> >::Type TAccessor;
556 return convert<TAccessor>(left_) >= convert<TAccessor>(right_);
559 //////////////////////////////////////////////////////////////////////////////
561 template <typename TStream, typename TSpec>
563 operator >> (TStream & strm,
564 Proxy<TSpec> & proxy)
566 typedef Proxy<TSpec> TProxy;
567 typedef typename Value<TProxy>::Type TValue;
570 assignValue(iter(proxy), temp);
573 template <typename TStream, typename TSpec>
575 operator >> (TStream & strm,
576 Proxy<TSpec> const& proxy)
578 typedef Proxy<TSpec> TProxy;
579 typedef typename Value<TProxy>::Type TValue;
582 assignValue(iter(proxy), temp);
587 template <typename TStream, typename TSpec>
589 operator << (TStream & strm,
590 Proxy<TSpec> & proxy)
592 return strm << getValue(proxy);
594 template <typename TStream, typename TSpec>
596 operator << (TStream & strm,
597 Proxy<TSpec> const & proxy)
599 return strm << getValue(proxy);
603 //////////////////////////////////////////////////////////////////////////////
604 } //namespace SEQAN_NAMESPACE_MAIN
606 #endif //#ifndef SEQAN_HEADER_...