remove \r
[extl.git] / extl / win / memory / process_heap_allocator.h
blob588aab15f2ef5f09b3b28cf2b17204e45be5662c
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: process_heap_allocator.h
4 * Created: 08.02.20
5 * Updated: 08.05.05
7 * Brief: process_heap_allocator class
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_PLATFORM_WIN_MEMORY_PROCESS_HEAP_ALLOCATOR_H
13 #define EXTL_PLATFORM_WIN_MEMORY_PROCESS_HEAP_ALLOCATOR_H
15 /*!\file process_heap_allocator.h
16 * \brief process_heap_allocator class
18 #ifndef __cplusplus
19 # error process_heap_allocator.h need be supported by c++.
20 #endif
22 /* ///////////////////////////////////////////////////////////////////////
23 * Includes
25 #include "extl/memory/allocator_base.h"
26 #include "process_heap.h"
27 /* ///////////////////////////////////////////////////////////////////////
28 * ::extl::platform::win namespace
30 EXTL_WIN_BEGIN_WHOLE_NAMESPACE
32 /*!\brief process_heap_allocator class
33 * \param T The value type
34 * \ingroup extl_group_memory
36 template < typename_param_k T >
37 class process_heap_allocator : public allocator_base< T, process_heap_allocator<T> >
39 /// \name Types
40 /// @{
41 public:
42 typedef process_heap_allocator< T > class_type;
43 typedef allocator_base< T, class_type > base_type;
44 typedef typename_type_k base_type::value_type value_type;
45 typedef typename_type_k base_type::pointer pointer;
46 typedef typename_type_k base_type::const_pointer const_pointer;
47 typedef typename_type_k base_type::reference reference;
48 typedef typename_type_k base_type::const_reference const_reference;
49 typedef typename_type_k base_type::size_type size_type;
50 typedef typename_type_k process_heap::handle_type handle_type;
51 /// @}
53 public:
54 /// Rebinds allocator
55 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
56 template <typename_param_k U>
57 struct rebind
59 typedef process_heap_allocator< U > other_type;
61 #endif
63 public:
64 /// The deleter
65 struct deleter : process_heap
67 public:
68 typedef process_heap base_type;
69 typedef deleter class_type;
70 typedef typename_type_k process_heap::handle_type handle_type;
72 public:
73 void operator()(pointer p)
75 if(NULL != p)
77 base_type::deallocate(p);
82 /// The deleter Type
83 typedef deleter deleter_type;
85 /// \name Types
86 /// @{
87 public:
88 process_heap_allocator() EXTL_THROW_0()
89 : m_process_heap(){};
91 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
92 template <typename_param_k U>
93 process_heap_allocator(process_heap_allocator< U > const&)
94 : m_process_heap(){};
95 #else
96 process_heap_allocator(class_type const&)
97 : m_process_heap(){};
98 #endif
99 /// @}
101 private:
102 friend class allocator_base< T, class_type >;
104 private:
105 /// Allocates memory
106 void* do_allocate(size_type n, void const* hint)
108 EXTL_SUPPRESS_UNUSED(hint);
109 return m_process_heap.allocate(n * sizeof(value_type));
111 /// Reallocates memory
112 void* do_reallocate(void* p, size_type n, void const* hint)
114 EXTL_SUPPRESS_UNUSED(hint);
115 return m_process_heap.reallocate(p, n * sizeof(value_type));
117 /// Deallocates memory
118 void do_deallocate(void* p, size_type n)
120 EXTL_SUPPRESS_UNUSED(n);
121 m_process_heap.deallocate(p);
123 /// Deallocates memory
124 void do_deallocate(void* p)
126 m_process_heap.deallocate(p);
129 private:
130 process_heap m_process_heap; //!< The process heap
134 /* ///////////////////////////////////////////////////////////////////////
135 * void specialization
137 EXTL_TEMPLATE_SPECIALISATION
138 class process_heap_allocator< void >
140 public:
141 typedef process_heap_allocator< void > class_type;
142 typedef void value_type;
143 typedef void* pointer;
144 typedef void const* const_pointer;
145 typedef e_size_t size_type;
147 public:
148 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
149 template <typename_param_k U>
150 struct rebind
152 typedef process_heap_allocator< U > other_type;
154 #endif
156 public:
157 struct deleter : process_heap
159 public:
160 typedef process_heap base_type;
161 typedef deleter class_type;
162 typedef process_heap::handle_type handle_type;
164 public:
165 void operator()(pointer p)
167 if(NULL != p)
169 base_type::deallocate(p);
174 typedef deleter deleter_type;
176 public:
177 void* do_allocate(size_type n, void const* hint);
178 void* do_reallocate(void* p, size_type n, void const* hint);
179 void do_deallocate(void* p, size_type n);
180 void do_deallocate(void* p);
183 /* //////////////////////////////////////////////////////////////////// */
184 template < typename_param_k T >
185 inline e_bool_t operator ==(process_heap_allocator<T> const&, process_heap_allocator<T> const &)
187 return e_true_v;
190 template < typename_param_k T >
191 inline e_bool_t operator !=(process_heap_allocator<T> const &, process_heap_allocator<T> const &)
193 return e_false_v;
195 /* ///////////////////////////////////////////////////////////////////////
196 * Unit-testing
198 #ifdef EXTL_MEMORY_ALLOCATOR_TEST_ENABLE
199 # include "unit_test/process_heap_allocator_test.h"
200 #endif
202 /* ///////////////////////////////////////////////////////////////////////
203 * ::extl::platform::win namespace
205 EXTL_WIN_END_WHOLE_NAMESPACE
207 /* //////////////////////////////////////////////////////////////////// */
208 #endif /* EXTL_PLATFORM_WIN_MEMORY_PROCESS_HEAP_ALLOCATOR_H */
209 /* //////////////////////////////////////////////////////////////////// */