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 "generic_pool.h"
36#include "ipool.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
57 typedef etl::generic_pool<sizeof(T), etl::alignment_of<T>::value, VSize> base_t;
58
59 public:
60
61 using base_t::ALIGNMENT;
62 using base_t::SIZE;
63 using base_t::TYPE_SIZE;
64
65 //*************************************************************************
67 //*************************************************************************
68 pool() {}
69
70 //*************************************************************************
75 //*************************************************************************
77 {
78 return base_t::template allocate<T>();
79 }
80
81#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
82 //*************************************************************************
86 //*************************************************************************
87 T* create()
88 {
89 return base_t::template create<T>();
90 }
91
92 //*************************************************************************
97 //*************************************************************************
98 template <typename T1>
99 T* create(const T1& value1)
100 {
101 return base_t::template create<T>(value1);
102 }
103
104 //*************************************************************************
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 //*************************************************************************
121 //*************************************************************************
122 template <typename T1, typename T2, typename T3>
123 T* create(const T1& value1, const T2& value2, const T3& value3)
124 {
125 return base_t::template create<T>(value1, value2, value3);
126 }
127
128 //*************************************************************************
133 //*************************************************************************
134 template <typename T1, typename T2, typename T3, typename T4>
135 T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
136 {
137 return base_t::template create<T>(value1, value2, value3, value4);
138 }
139#else
140 //*************************************************************************
145 //*************************************************************************
146 template <typename... Args>
147 T* create(Args&&... args)
148 {
149 return base_t::template create<T>(etl::forward<Args>(args)...);
150 }
151#endif
152
153 //*************************************************************************
157 //*************************************************************************
158 template <typename U>
159 void release(const U* const p_object)
160 {
161 ETL_STATIC_ASSERT((etl::is_same<U, T>::value || etl::is_base_of<U, T>::value), "Pool does not contain this type");
162 base_t::release(p_object);
163 }
164
165 //*************************************************************************
169 //*************************************************************************
170 template <typename U>
171 void destroy(const U* const p_object)
172 {
173 ETL_STATIC_ASSERT((etl::is_base_of<U, T>::value), "Pool does not contain this type");
174 base_t::destroy(p_object);
175 }
176
177 private:
178
179 // Should not be copied.
180 pool(const pool&) ETL_DELETE;
181 pool& operator=(const pool&) ETL_DELETE;
182 };
183
184 //*************************************************************************
188 //*************************************************************************
189 template <typename T>
190 class pool_ext : public etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value>
191 {
192 private:
193
194 typedef etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value> base_t;
195
196 public:
197
198 using base_t::ALIGNMENT;
199 using base_t::TYPE_SIZE;
200
201 //*************************************************************************
203 //*************************************************************************
204 pool_ext(typename base_t::element* buffer, size_t size)
205 : base_t(buffer, size)
206 {
207 }
208
209 //*************************************************************************
215 //*************************************************************************
217 {
218 return base_t::template allocate<T>();
219 }
220
221#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
222 //*************************************************************************
226 //*************************************************************************
228 {
229 return base_t::template create<T>();
230 }
231
232 //*************************************************************************
237 //*************************************************************************
238 template <typename T1>
239 T* create(const T1& value1)
240 {
241 return base_t::template create<T>(value1);
242 }
243
244 //*************************************************************************
249 //*************************************************************************
250 template <typename T1, typename T2>
251 T* create(const T1& value1, const T2& value2)
252 {
253 return base_t::template create<T>(value1, value2);
254 }
255
256 //*************************************************************************
261 //*************************************************************************
262 template <typename T1, typename T2, typename T3>
263 T* create(const T1& value1, const T2& value2, const T3& value3)
264 {
265 return base_t::template create<T>(value1, value2, value3);
266 }
267
268 //*************************************************************************
273 //*************************************************************************
274 template <typename T1, typename T2, typename T3, typename T4>
275 T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
276 {
277 return base_t::template create<T>(value1, value2, value3, value4);
278 }
279#else
280 //*************************************************************************
285 //*************************************************************************
286 template <typename... Args>
287 T* create(Args&&... args)
288 {
289 return base_t::template create<T>(etl::forward<Args>(args)...);
290 }
291#endif
292
293 //*************************************************************************
297 //*************************************************************************
298 template <typename U>
299 void release(const U* const p_object)
300 {
301 ETL_STATIC_ASSERT((etl::is_same<U, T>::value || etl::is_base_of<U, T>::value), "Pool does not contain this type");
302 base_t::release(p_object);
303 }
304
305 //*************************************************************************
309 //*************************************************************************
310 template <typename U>
311 void destroy(const U* const p_object)
312 {
313 ETL_STATIC_ASSERT((etl::is_base_of<U, T>::value), "Pool does not contain this type");
314 base_t::destroy(p_object);
315 }
316
317 private:
318
319 // Should not be copied.
320 pool_ext(const pool_ext&) ETL_DELETE;
321 pool_ext& operator=(const pool_ext&) ETL_DELETE;
322 };
323} // namespace etl
324
325#endif
size_t size() const
Returns the number of allocated items in the pool.
Definition ipool.h:522
pool_ext(typename base_t::element *buffer, size_t size)
Constructor.
Definition pool.h:204
T * allocate()
Definition pool.h:76
T * allocate()
Definition pool.h:216
T * create(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition pool.h:135
void release(const U *const p_object)
Definition pool.h:299
T * create(const T1 &value1, const T2 &value2)
Definition pool.h:111
T * create(const T1 &value1)
Definition pool.h:239
T * create(const T1 &value1)
Definition pool.h:99
void destroy(const U *const p_object)
Definition pool.h:311
T * create()
Definition pool.h:87
void destroy(const U *const p_object)
Definition pool.h:171
T * create(const T1 &value1, const T2 &value2)
Definition pool.h:251
T * create(const T1 &value1, const T2 &value2, const T3 &value3)
Definition pool.h:123
T * create()
Definition pool.h:227
T * create(const T1 &value1, const T2 &value2, const T3 &value3)
Definition pool.h:263
pool()
Constructor.
Definition pool.h:68
void release(const U *const p_object)
Definition pool.h:159
T * create(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition pool.h:275
Definition generic_pool.h:56
Definition generic_pool.h:216
Definition pool.h:54
Definition pool.h:191
bitset_ext
Definition absolute.h:40