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_type.h,v 1.1 2008/08/25 16:20:01 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_BASIC_TYPE_H
22 #define SEQAN_HEADER_BASIC_TYPE_H
24 namespace SEQAN_NAMESPACE_MAIN
28 //////////////////////////////////////////////////////////////////////////////
32 ..summary:Type of the items in the container.
33 ..signature:Value<T>::Type
34 ..param.T:Type for which the value type is determined.
35 ..returns.param.Type:Value type of $T$.
36 ..remarks.text:The value type of a container $T$ is the type of the elements in $T$.
37 For example, the value type of a sequence of $int$ is $int$.
38 ..example.code:Value<String<char> >::Type c; //c has type char
41 template <typename T, const int i = 0>
53 //____________________________________________________________________________
56 .Metafunction.GetValue:
57 ..summary:Type for reading values.
58 ..signature:GetValue<T>::Type
59 ..param.T:Type of container that holds a value.
60 ..returns.param.Type:GetValue type of $T$.
61 ..remarks.text:Depending on $T$, the $GetValue$-type can either be $Value<T>::Type &$ or $Value<T>::Type$.
62 ..text:$GetValue$ is the return type of @Function.getValue@ that allows a (read-only) access to objects.
63 Do not confuse it with @Function.value@ that returns a @Metafunction.Reference.reference@ to the value.
64 ..see:Metafunction.Value
65 ..see:Function.getValue
70 typedef typename Value<T>::Type const & Type;
73 struct GetValue<T const>:
78 //____________________________________________________________________________
81 .Metafunction.Reference:
82 ..summary:Reference type.
83 ..signature:Reference<T>::Type
85 ..returns.param.Type:Either $T &$ or a proxy object @Class.Proxy@ for $T$.
86 ..see:Metafunction.Value
87 ..see:Metafunction.GetValue
92 typedef typename Value<T>::Type & Type;
95 struct Reference<T const>
97 typedef typename Value<T>::Type const & Type;
100 //____________________________________________________________________________
105 ..summary:Type of an object that is suitable to hold size information.
106 ..signature:Size<T>::Type
107 ..param.T:Type for which the size type is determined.
108 ..returns.param.Type:Size type of $T$.
109 ..remarks.text:In most cases this type is $size_t$.
111 template <typename T>
116 template <typename T>
117 struct Size<T const>:
122 //____________________________________________________________________________
126 .Metafunction.Difference:
127 ..summary:Type of an object that stores the difference between two iterators.
128 ..signature:Difference<T>::Type
129 ..param.T:Type for which the difference type is determined.
131 ..returns.param.Type:Difference type of $T$.
132 ..remarks.text:In most cases this type is $ptrdiff_t$.
133 ..see:Metafunction.Size
135 template <typename T>
138 typedef ptrdiff_t Type;
140 template <typename T>
141 struct Difference<T const>:
146 //____________________________________________________________________________
150 .Metafunction.Position:
151 ..summary:Type of an object that represents a position in a container.
152 ..signature:Position<T>::Type
153 ..param.T:Type for which the position type is determined.
156 ..returns.param.Type:Position type of $T$.
157 ..see:Metafunction.Iterator
159 template <typename T>
162 typedef typename Size<T>::Type Type;
164 template <typename T>
165 struct Position<T const>:
170 //____________________________________________________________________________
174 ..summary:Type of the object a given object depends on.
175 ..signature:Host<T>::Type
176 ..param.T:Type for which the host type is determined.
177 ..returns.param.Type:Host type of $T$.
179 template <typename T>
185 //____________________________________________________________________________
189 ..summary:The spec of a class.
190 ..signature:Spec<T>::Type
191 ..param.T:Type for which the spec is determined.
192 ..returns.param.Type:Spec of $T$.
193 ..remarks:The spec of a SeqAn type is the class that is used in template subclassing
194 to specify the specialization.
195 For example, the spec of $String<char, Alloc<> >$ is $Alloc<>$.
199 template <typename T>
206 template <template <typename> class T, typename TSpec>
207 struct Spec< T<TSpec> > {
211 template <typename T>
212 struct Spec<T const>:
215 //____________________________________________________________________________
218 .Metafunction.DeepestSpec:
219 ..summary:The deepest spec of a class with nested template arguments.
220 ..signature:DeepestSpec<T>::Type
221 ..param.T:Type for which the deepest spec is determined.
222 ..returns.param.Type:Deepest spec of $T$.
223 ..remarks:The spec of a SeqAn type is the innermost class that is used in nested subclassing.
224 For example, the deepest spec of $Iter<..., VSTree<BottomUp<MUMs> > >$ is $MUMs$.
228 template <typename T>
233 // recursion for 1 argument
235 template <typename> class T,
237 struct DeepestSpec< T<T1> > {
240 TYPECMP<T1, void>::VALUE, // is T1 void?
241 T<T1>, // yes, end of recursion
242 typename DeepestSpec< typename Spec< T<T1> >::Type >::Type // no, recurse
246 // recursion for 2 arguments
248 template <typename, typename> class T,
249 typename T1, typename T2 >
250 struct DeepestSpec< T<T1,T2> >:
251 DeepestSpec< typename Spec< T<T1,T2> >::Type > {};
253 // recursion for 3 arguments
255 template <typename, typename, typename> class T,
256 typename T1, typename T2, typename T3 >
257 struct DeepestSpec< T<T1,T2,T3> >:
258 DeepestSpec< typename Spec< T<T1,T2,T3> >::Type > {};
260 // recursion for 4 arguments
262 template <typename, typename, typename, typename> class T,
263 typename T1, typename T2, typename T3, typename T4 >
264 struct DeepestSpec< T<T1,T2,T3,T4> >:
265 DeepestSpec< typename Spec< T<T1,T2,T3,T4> >::Type > {};
267 // recursion for 5 arguments
269 template <typename, typename, typename, typename, typename> class T,
270 typename T1, typename T2, typename T3, typename T4, typename T5 >
271 struct DeepestSpec< T<T1,T2,T3,T4,T5> >:
272 DeepestSpec< typename Spec< T<T1,T2,T3,T4,T5> >::Type > {};
274 template <typename T>
275 struct DeepestSpec<T const>:
276 public DeepestSpec<T> {};
278 //____________________________________________________________________________
282 ..summary:Type of additional data stored in an object.
283 ..signature:Cargo<T>::Type
284 ..param.T:Type for which the cargo tyoe is determined.
285 ..returns.param.Type:Cargo of $T$.
286 ..remarks:The definition of Cargo allows the addition of user specific data to existing data structures.
289 template <typename T>
291 typedef Nothing Type;
293 template <typename T>
294 struct Cargo<T const> {
295 typedef typename Cargo<T>::Type const Type;
298 //____________________________________________________________________________
301 .Metafunction.VertexDescriptor:
302 ..summary:Type of an object that represents a vertex descriptor.
303 ..signature:VertexDescriptor<T>::Type
304 ..param.T:Type T must be a graph. All graphs currently use ids as vertex descriptors.
305 ..returns.param.Type:VertexDescriptor type.
306 ..remarks.text:The vertex descriptor is a unique handle to a vertex in a graph.
307 It is used in various graph functions, e.g., to add edges, to create OutEdge Iterators or to remove a vertex.
308 It is also used to attach properties to vertices.
309 ..example.code:VertexDescriptor<Graph<> >::Type vD; //vD is a vertex descriptor
312 template <typename T>
313 struct VertexDescriptor {
316 template <typename T>
317 struct VertexDescriptor<T const>:
318 public VertexDescriptor<T> {};
321 //____________________________________________________________________________
326 ..summary:Type of an object that represents an id.
327 ..signature:Id<T>::Type
328 ..param.T:Type for which a suitable id type is determined.
329 ..returns.param.Type:Id type.
330 ..remarks.text:The id type of a container is the type that is used to uniquely identify its elements.
331 In most cases this type is unsigned int.
332 ..example.code:Id<Graph<> >::Type id; //id has type unsigned int
336 typedef unsigned int Type;
339 //____________________________________________________________________________
343 typedef unsigned int Type;
346 //____________________________________________________________________________
350 ..summary:Key type of a key to cargo mapping.
351 ..signature:Key<T>::Type
352 ..param.T:Type for which a key type is determined.
353 ..returns.param.Type:Key type.
354 ...default:The type $T$ itself.
356 template< typename T >
362 template <typename T>
366 //____________________________________________________________________________
369 .Metafunction.Object:
370 ..summary:Object type of a key to object mapping.
371 ..signature:Object<T>::Type
372 ..param.T:Type for which a object type is determined.
373 ..returns.param.Type:Object type.
379 template <typename T>
380 struct Object<T const>:
384 //____________________________________________________________________________
390 template < typename TSpec = void >
396 template <typename T>
397 struct Source<T const>:
402 //____________________________________________________________________________
405 .Internal._Parameter:
407 ..summary:Type for function parameters and return values.
408 ..signature:_Parameter<T>::Type
410 ..returns.param.Type:The parameter type for arguments of type $T$.
411 ...text:If $T$ is a pointer or array type, then $_Parameter<T>::Type$ is $T$,
412 otherwise $_Parameter<T>::Type$ is $T &$.
414 template <typename T>
420 template <typename T>
421 struct _Parameter<T *>
425 template <typename T, size_t I>
426 struct _Parameter<T [I]>
433 .Internal._toParameter:
435 ..summary:Transforms pointers to parameter types.
436 ..signature:_toParameter<T>(pointer)
437 ..param.pointer:A pointer.
439 ...text:$object$ is transformed into the parameter type of $T$ that is given by @Internal._Parameter@.
440 ...note:This type must be explicitely specified.
441 ..returns:To $TParameter$ transformed $object$.
442 ..see:Internal._Parameter
444 template <typename T>
445 typename _Parameter<T>::Type
446 _toParameter(T * _object)
451 template <typename T>
452 typename _Parameter<T>::Type
453 _toParameter(T _object)
459 //____________________________________________________________________________
462 .Internal._ConstParameter:
464 ..summary:Type for constant function parameters and return values.
465 ..signature:_ConstParameter<T>::Type
467 ..returns.param.Type:The const parameter type for arguments of type $T$.
468 ...text:If $T$ is a pointer or array type, then $_Parameter<T>::Type$ is a pointer to a const array,
469 otherwise $_Parameter<T>::Type$ is $T const &$.
470 ..see:Internal._Parameter
472 template <typename T>
473 struct _ConstParameter
475 typedef T const & Type;
477 template <typename T>
478 struct _ConstParameter<T const>:
479 public _ConstParameter<T> {};
481 template <typename T>
482 struct _ConstParameter<T *>
484 typedef T const * Type;
486 template <typename T>
487 struct _ConstParameter<T const *>
489 typedef T const * Type;
492 template <typename T, size_t I>
493 struct _ConstParameter<T [I]>
495 typedef T const * Type;
497 template <typename T, size_t I>
498 struct _ConstParameter<T const [I]>
500 typedef T const * Type;
503 //____________________________________________________________________________
508 ..summary:The associated pointer type.
509 ..signature:_Pointer<T>::Type
511 ..returns.param.Type:A pointer type for $T$.
512 ...text:if $T$ is already a pointer type, then $_Pointer<T>::Type$ is $T$,
513 otherwise $_Pointer<T>::Type$ is $T *$.
514 ..see:Internal._Parameter
515 ..see:Internal._toParameter
517 template <typename T>
523 template <typename T>
528 template <typename T>
529 struct _Pointer<T * const>
531 typedef T * const Type;
534 template <typename T, size_t I>
535 struct _Pointer<T [I]>
541 .Internal._toPointer:
543 ..summary:Transforms types into pointers.
544 ..signature:_toPointer(object)
545 ..param.object:An object.
546 ..returns:$object$, transformed to a pointer.
547 ...text:The type of the returned pointer is given by @Internal._Pointer@.
548 ..see:Internal._Pointer
550 template <typename T>
551 typename _Pointer<T>::Type
552 _toPointer(T & _object)
557 template <typename T>
558 typename _Pointer<T const>::Type
559 _toPointer(T const & _object)
565 template <typename T>
566 typename _Pointer<T *>::Type
567 _toPointer(T * _object)
573 //____________________________________________________________________________
577 .Metafunction.LENGTH:
578 ..summary:Number of elements in a fixed-size container.
579 ..signature:LENGTH<T>::Type
580 ..param.T:Type for which the number of elements is determined.
581 ..returns.param.VALUE:Number of elements.
582 ..remarks.text:The default return value is 1 for dynamic-size containers.
584 template <typename T>
589 template <typename T>
590 struct LENGTH<T const>:
596 .Metafunction.WEIGHT:
597 ..summary:Number of relevant positions in a shape.
598 ..signature:WEIGHT<T>::Type
599 ..param.T:Shape type for which the number of relevant positions is determined.
601 ..returns.param.VALUE:Number of relevant positions.
602 ..remarks.text:The default return value is the result of the @Metafunction.LENGTH@ function.
603 For gapped shapes this is the number of '1's.
605 template <typename T>
610 template <typename T>
611 struct WEIGHT<T const>:
616 //////////////////////////////////////////////////////////////////////////////
618 //Iterator: see basic_iterator.h
620 //////////////////////////////////////////////////////////////////////////////
622 }// namespace SEQAN_NAMESPACE_MAIN
624 #endif //#ifndef SEQAN_HEADER_...