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_allocator_to_std.h,v 1.1 2008/08/25 16:20:01 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_BASIC_ALLOCATOR_TO_STD_H
22 #define SEQAN_HEADER_BASIC_ALLOCATOR_TO_STD_H
25 namespace SEQAN_NAMESPACE_MAIN
28 //////////////////////////////////////////////////////////////////////////////
29 //helper caller for calling functions that have same name as member functions
31 template <typename TMe, typename TValue, typename TSize>
32 inline void call_allocate(TMe & me, TValue * & data, TSize const count)
34 allocate(me, data, count);
36 template <typename TMe, typename TValue, typename TSize>
37 inline void call_deallocate(TMe & me, TValue * data, TSize const count)
39 deallocate(me, data, count);
42 //////////////////////////////////////////////////////////////////////////////
43 //Filter that adapts seqan allocator zu std allocator
45 .Class.ToStdAllocator:
46 ..summary:Emulates standard conform allocator.
47 ..signature:ToStdAllocator<THost, TValue>
48 ..param.THost:Type of the host allocator object.
49 ...text:This object is used to call @Function.allocate@ and @Function.deallocate@.
50 ..param.TValue:Type of allocated items.
51 ..remarks:The member functions $allocate$ and $deallocate$ of $ToStdAllocator$ call
52 the (globale) functions @Function.allocate@ and @Function.deallocate@, respectively. The globale functions
53 get an allocator object as their first arguments. This allocator object is not the $ToStdAllocator$ object itself,
54 but the host object that was given to the constructor.
56 ..see:Function.allocate
57 ..see:Function.deallocate
59 template <typename THost, typename TValue>
62 typedef TValue value_type;
63 typedef value_type * pointer;
64 typedef value_type & reference;
65 typedef value_type const * const_pointer;
66 typedef value_type const & const_reference;
68 // typedef typename THost::Size size_type;
69 // typedef typename THost::Difference difference_type;
70 typedef size_t size_type;
71 typedef ptrdiff_t difference_type;
74 .Memfunc.ToStdAllocator:
76 ..signature:ToStdAllocator(host)
77 ..class:Class.ToStdAllocator
78 ..param.host:The host object that is used as allocator for @Function.allocate@ and @Function.deallocate@.
80 ToStdAllocator(THost & host): m_host(& host)
83 ToStdAllocator(ToStdAllocator const & alloc): m_host(alloc.m_host)
86 ToStdAllocator & operator= (ToStdAllocator const & alloc)
88 m_host = alloc.m_host;
96 ..summary:The object a given object depends on.
97 ..cat:Dependent Objects
98 ..signature:host(object)
99 ..param.object:An object.
100 ...type:Class.ToStdAllocator
101 ..returns:The host object.
103 friend THost & host(ToStdAllocator & me)
108 pointer allocate(size_type count)
111 call_allocate(*m_host, ptr, count);
114 pointer allocate(size_type count, const void *)
117 call_allocate(*m_host, ptr, count);
121 void deallocate(pointer data, size_type count)
123 call_deallocate(*m_host, data, count);
126 void construct(pointer ptr, const_reference data)
128 new(ptr) TValue(data);
131 void destroy(pointer ptr)
136 pointer address(reference value) const
140 const_pointer address(const_reference value) const
145 size_type max_size() const
147 return ~0UL / sizeof(value_type);
150 template<class TValue2>
153 typedef ToStdAllocator<THost, TValue2> other;
159 //////////////////////////////////////////////////////////////////////////////
163 //returns std-allocator type (for allocators)
164 template <typename T, typename TData>
167 typedef ToStdAllocator<T, TData> Type;
171 //////////////////////////////////////////////////////////////////////////////
173 } //namespace SEQAN_NAMESPACE_MAIN
176 //////////////////////////////////////////////////////////////////////////////
178 #endif //#ifndef SEQAN_HEADER_...