Embedded Template Library 1.0
Loading...
Searching...
No Matches
pool.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2014 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_POOL_INCLUDED
32#define ETL_POOL_INCLUDED
33
34#include "platform.h"
35#include "ipool.h"
36#include "generic_pool.h"
37
38#define ETL_POOL_CPP03_CODE 0
39
40//*****************************************************************************
44//*****************************************************************************
45
46namespace etl
47{
48 //*************************************************************************
51 //*************************************************************************
52 template <typename T, const size_t VSize>
53 class pool : public etl::generic_pool<sizeof(T), etl::alignment_of<T>::value, VSize>
54 {
55 private:
56
58
59 public:
60
61 using base_t::SIZE;
62 using base_t::ALIGNMENT;
63 using base_t::TYPE_SIZE;
64
65 //*************************************************************************
67 //*************************************************************************
69 {
70 }
71
72 //*************************************************************************
77 //*************************************************************************
79 {
80 return base_t::template allocate<T>();
81 }
82
83#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
84 //*************************************************************************
88 //*************************************************************************
90 {
91 return base_t::template create<T>();
92 }
93
94 //*************************************************************************
98 //*************************************************************************
99 template <typename T1>
100 T* create(const T1& value1)
101 {
102 return base_t::template create<T>(value1);
103 }
104
105 //*************************************************************************
109 //*************************************************************************
110 template <typename T1, typename T2>
111 T* create(const T1& value1, const T2& value2)
112 {
113 return base_t::template create<T>(value1, value2);
114 }
115
116 //*************************************************************************
120 //*************************************************************************
121 template <typename T1, typename T2, typename T3>
122 T* create(const T1& value1, const T2& value2, const T3& value3)
123 {
124 return base_t::template create<T>(value1, value2, value3);
125 }
126
127 //*************************************************************************
131 //*************************************************************************
132 template <typename T1, typename T2, typename T3, typename T4>
133 T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
134 {
135 return base_t::template create<T>(value1, value2, value3, value4);
136 }
137#else
138 //*************************************************************************
142 //*************************************************************************
143 template <typename... Args>
144 T* create(Args&&... args)
145 {
146 return base_t::template create<T>(etl::forward<Args>(args)...);
147 }
148#endif
149
150 //*************************************************************************
154 //*************************************************************************
155 template <typename U>
156 void release(const U* const p_object)
157 {
158 ETL_STATIC_ASSERT((etl::is_same<U, T>::value || etl::is_base_of<U, T>::value), "Pool does not contain this type");
159 base_t::release(p_object);
160 }
161
162 //*************************************************************************
166 //*************************************************************************
167 template <typename U>
168 void destroy(const U* const p_object)
169 {
170 ETL_STATIC_ASSERT((etl::is_base_of<U, T>::value), "Pool does not contain this type");
171 base_t::destroy(p_object);
172 }
173
174 private:
175
176 // Should not be copied.
177 pool(const pool&) ETL_DELETE;
178 pool& operator =(const pool&) ETL_DELETE;
179 };
180
181 //*************************************************************************
185 //*************************************************************************
186 template <typename T>
187 class pool_ext : public etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value>
188 {
189 private:
191
192 public:
193 using base_t::ALIGNMENT;
194 using base_t::TYPE_SIZE;
195
196 //*************************************************************************
198 //*************************************************************************
199 pool_ext(typename base_t::element* buffer, size_t size)
200 : base_t(buffer, size)
201 {
202 }
203
204 //*************************************************************************
210 //*************************************************************************
212 {
213 return base_t::template allocate<T>();
214 }
215
216#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
217 //*************************************************************************
221 //*************************************************************************
223 {
224 return base_t::template create<T>();
225 }
226
227 //*************************************************************************
231 //*************************************************************************
232 template <typename T1>
233 T* create(const T1& value1)
234 {
235 return base_t::template create<T>(value1);
236 }
237
238 //*************************************************************************
242 //*************************************************************************
243 template <typename T1, typename T2>
244 T* create(const T1& value1, const T2& value2)
245 {
246 return base_t::template create<T>(value1, value2);
247 }
248
249 //*************************************************************************
253 //*************************************************************************
254 template <typename T1, typename T2, typename T3>
255 T* create(const T1& value1, const T2& value2, const T3& value3)
256 {
257 return base_t::template create<T>(value1, value2, value3);
258 }
259
260 //*************************************************************************
264 //*************************************************************************
265 template <typename T1, typename T2, typename T3, typename T4>
266 T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
267 {
268 return base_t::template create<T>(value1, value2, value3, value4);
269 }
270#else
271 //*************************************************************************
275 //*************************************************************************
276 template <typename... Args>
277 T* create(Args&&... args)
278 {
279 return base_t::template create<T>(etl::forward<Args>(args)...);
280 }
281#endif
282
283 //*************************************************************************
287 //*************************************************************************
288 template <typename U>
289 void release(const U* const p_object)
290 {
291 ETL_STATIC_ASSERT((etl::is_same<U, T>::value || etl::is_base_of<U, T>::value), "Pool does not contain this type");
292 base_t::release(p_object);
293 }
294
295 //*************************************************************************
299 //*************************************************************************
300 template <typename U>
301 void destroy(const U* const p_object)
302 {
303 ETL_STATIC_ASSERT((etl::is_base_of<U, T>::value), "Pool does not contain this type");
304 base_t::destroy(p_object);
305 }
306
307 private:
308 // Should not be copied.
309 pool_ext(const pool_ext&) ETL_DELETE;
310 pool_ext& operator=(const pool_ext&) ETL_DELETE;
311 };
312}
313
314#endif
315
size_t size() const
Returns the number of allocated items in the pool.
Definition ipool.h:293
pool_ext(typename base_t::element *buffer, size_t size)
Constructor.
Definition pool.h:199
T * allocate()
Definition pool.h:78
T * allocate()
Definition pool.h:211
T * create(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition pool.h:133
void release(const U *const p_object)
Definition pool.h:289
T * create(const T1 &value1, const T2 &value2)
Definition pool.h:111
void release(const void *const p_object)
Definition ipool.h:239
T * create(const T1 &value1)
Definition pool.h:233
T * create(const T1 &value1)
Definition pool.h:100
void destroy(const U *const p_object)
Definition pool.h:301
T * create()
Definition pool.h:89
void destroy(const U *const p_object)
Definition pool.h:168
void destroy(const U *const p_object)
Definition generic_pool.h:169
T * create(const T1 &value1, const T2 &value2)
Definition pool.h:244
T * create(const T1 &value1, const T2 &value2, const T3 &value3)
Definition pool.h:122
T * create()
Definition pool.h:222
T * create(const T1 &value1, const T2 &value2, const T3 &value3)
Definition pool.h:255
pool()
Constructor.
Definition pool.h:68
void release(const U *const p_object)
Definition pool.h:156
T * create(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition pool.h:266
void destroy(const U *const p_object)
Definition generic_pool.h:337
Definition generic_pool.h:56
Definition generic_pool.h:213
Definition pool.h:54
Definition pool.h:188
add_rvalue_reference
Definition type_traits_generator.h:1327
is_base_of
Definition type_traits_generator.h:1252
is_same
Definition type_traits_generator.h:1041
bitset_ext
Definition absolute.h:38
Definition alignment.h:233
pair holds two objects of arbitrary type
Definition utility.h:164