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_definition.h,v 1.1 2008/08/25 16:20:01 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_BASIC_DEFINITION_H
22 #define SEQAN_HEADER_BASIC_DEFINITION_H
24 namespace SEQAN_NAMESPACE_MAIN
27 //////////////////////////////////////////////////////////////////////////////
34 //////////////////////////////////////////////////////////////////////////////
37 ..summary:Tag that specifies default behavior.
38 ..tag.Default:Use default behavior.
41 typedef Tag<Default_> const Default;
43 //////////////////////////////////////////////////////////////////////////////
46 ..summary:Switch to force move.
47 ..tag.Move:Move instead of assign.
48 ..remarks.text:The difference between move constructor and copy constructor
49 is that the source object is not copied but moved into the target object.
50 The source object can lose its content and will be empty after
51 this operation in this case.
52 A move constructor can sigificantly faster than a copy constructor.
53 ..example.code:String source("hello");
54 String target(source, Move()); // source is moved to target
55 std::cout << source; //nothing printed since source lost content
56 std::cout << target; //"hello"
61 typedef Tag<Move_> const Move;
63 //////////////////////////////////////////////////////////////////////////////
65 //Pass to c'tor of iterator to move it to the end
67 typedef Tag<GoEnd_> const GoEnd;
70 //////////////////////////////////////////////////////////////////////////////
72 //construct without initializing
74 typedef Tag<MinimalCtor_> const MinimalCtor;
76 //construct with initializing
77 struct NonMinimalCtor_;
78 typedef Tag<NonMinimalCtor_> const NonMinimalCtor;
80 //////////////////////////////////////////////////////////////////////////////
83 ..summary:Tag that represents true and false.
84 ..tag.True:The logical value "true".
85 ..tag.False:The logical value "false".
87 struct True { enum { VALUE = true }; };
88 struct False { enum { VALUE = false }; };
91 //////////////////////////////////////////////////////////////////////////////
95 ..summary:Tag that represents an absent parameter or an absent type.
96 ..tag.Nothing:Omit parameter.
103 //////////////////////////////////////////////////////////////////////////////
104 // returns TTo const, if TFrom is const, TTo otherwise
106 template <typename TFrom, typename TTo>
111 template <typename TFrom, typename TTo>
112 struct _CopyConst<TFrom const, TTo>
114 typedef TTo const Type;
117 //////////////////////////////////////////////////////////////////////////////
120 .Internal._RemoveConst:
121 ..signature:_RemoveConst<T>
122 ..returns:$t$ if $T$ is $t const$, otherwise $T$.
124 template <typename T>
129 template <typename T>
130 struct _RemoveConst<T const>:
131 public _RemoveConst<T> {};
133 template <typename T>
134 struct _RemoveConst<T &>
136 typedef typename _RemoveConst<T>::Type & Type;
138 template <typename T>
139 struct _RemoveConst<T *>
141 typedef typename _RemoveConst<T>::Type * Type;
143 template <typename T, size_t I>
144 struct _RemoveConst<T const [I]>
149 //////////////////////////////////////////////////////////////////////////////
151 .Internal._MakeUnsigned:
152 ..signature:_MakeUnsigned<T>
153 ..returns:$unsigned t$ if $T$ is not $unsigned t$, otherwise $T$.
155 template <typename T>
161 template <typename T>
162 struct _MakeUnsigned<T const> {
163 typedef typename _MakeUnsigned<T>::Type const Type;
167 struct _MakeUnsigned<char>
169 typedef unsigned char Type;
173 struct _MakeUnsigned<signed char>
175 typedef unsigned char Type;
179 struct _MakeUnsigned<int>
181 typedef unsigned int Type;
185 struct _MakeUnsigned<short>
187 typedef unsigned short Type;
191 struct _MakeUnsigned<long>
193 typedef unsigned long Type;
198 struct _MakeUnsigned<long long>
200 typedef unsigned long long Type;
204 //////////////////////////////////////////////////////////////////////////////
206 .Internal._MakeSigned:
207 ..signature:_MakeSigned<T>
208 ..returns:$signed t$ if $T$ is not $signed t$, otherwise $T$.
210 template <typename T>
216 template <typename T>
217 struct _MakeSigned<T const> {
218 typedef typename _MakeSigned<T>::Type const Type;
222 struct _MakeSigned<char>
224 typedef signed char Type;
228 struct _MakeSigned<unsigned char>
230 typedef signed char Type;
234 struct _MakeSigned<unsigned int>
236 typedef signed int Type;
240 struct _MakeSigned<unsigned short>
242 typedef signed short Type;
246 struct _MakeSigned<unsigned long>
248 typedef signed long Type;
253 struct _MakeSigned<unsigned long long>
255 typedef signed long long Type;
259 //////////////////////////////////////////////////////////////////////////////
261 .Internal._ClassIdentifier:
262 ..signature:void * _ClassIdentifier<T>::getID()
263 ..returns:A void * that identifies $T$.
264 ...text:The returned values of two calls of $getID$ are equal if and only if
265 the used type $T$ was the same.
267 template <typename T>
268 struct _ClassIdentifier
274 static bool _id_dummy;
279 //////////////////////////////////////////////////////////////////////////////
283 ..summary:Computes logarithm of base 2 for integer types
284 ..signature:unsigned int log2(i)
285 ..param.i:An integer type.
286 ..returns:The largest integer smaller or equal than
287 the logarithm of $i$.
291 template <int BITS_MAX>
294 template <typename T>
295 static inline unsigned int
296 log2(T val, unsigned int offset)
298 unsigned int val2 = val >> (BITS_MAX / 2);
302 offset += BITS_MAX / 2;
304 return _Log2_Impl<BITS_MAX / 2>::log2(val, offset);
311 template <typename T>
312 static inline unsigned int
313 log2(T /*val*/, unsigned int offset)
320 template <typename T>
326 // BITS_PER_VALUE = BitsPerValue<T>::VALUE //TODO???
327 BITS_PER_VALUE = sizeof(T) * 8
330 return _Log2_Impl<BITS_PER_VALUE>::log2(val, 0);
334 template <typename TValue, typename TExponent>
335 inline TValue _intPow(TValue a, TExponent b)
348 //////////////////////////////////////////////////////////////////////////////
349 // to avoid conflicts with non-standard macros and namespaces
350 // we define our own Min/Max functions
352 template<typename _Tx> inline
353 const _Tx& _min(const _Tx& _Left, const _Tx& _Right)
354 { // return smaller of _Left and _Right
361 template<typename _Tx, typename _Ty> inline
362 _Tx _min(const _Tx& _Left, const _Ty& _Right)
363 { // return smaller of _Left and _Right
364 return (_Right < _Left ? _Right : _Left);
367 template<typename _Ty> inline
368 const _Ty& _max(const _Ty& _Left, const _Ty& _Right)
369 { // return larger of _Left and _Right
376 //////////////////////////////////////////////////////////////////////////////
378 template <typename T1, typename T2>
381 enum {VALUE = false};
385 template <typename T>
386 struct _IsSameType<T, T>
392 template <typename T1, typename T2>
396 return _IsSameType<T1, T2>::VALUE;
399 //////////////////////////////////////////////////////////////////////////////
401 } //namespace SEQAN_NAMESPACE_MAIN
403 #endif //#ifndef SEQAN_HEADER_...