Embedded Template Library 1.0
Loading...
Searching...
No Matches
variant_pool.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2017 John Wellbelove
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files(the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions :
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27******************************************************************************/
28
29#if 0
30#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
31#endif
32
33//***************************************************************************
34// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.
35//***************************************************************************
36
37//***************************************************************************
38// To generate to header file, run this at the command line.
39// Note: You will need Python and COG installed.
40//
41// cog -d -e -ovariant_pool.h -DNTypes=<n> variant_pool_generator.h
42// Where <n> is the number of types to support.
43//
44// e.g.
45// To generate handlers for up to 16 types...
46// cog -d -e -ovariant_pool.h -DNTypes=16 variant_pool_generator.h
47//
48// See generate.bat
49//***************************************************************************
50
51#ifndef ETL_VARIANT_POOL_INCLUDED
52#define ETL_VARIANT_POOL_INCLUDED
53
54#include "platform.h"
55#include "pool.h"
56#include "type_traits.h"
57#include "static_assert.h"
58#include "largest.h"
59
60#include <stdint.h>
61
62namespace etl
63{
64#if ETL_USING_CPP11 && !defined(ETL_VARIANT_POOL_FORCE_CPP03_IMPLEMENTATION)
65 //***************************************************************************
66 template <size_t MAX_SIZE_, typename ... Ts>
67 class variant_pool
68 : public etl::generic_pool<etl::largest<Ts...>::size,
69 etl::largest<Ts...>::alignment,
70 MAX_SIZE_>
71 {
72 public:
73
74 typedef etl::generic_pool<etl::largest<Ts...>::size,
75 etl::largest<Ts...>::alignment,
76 MAX_SIZE_> base_t;
77
78 static const size_t MAX_SIZE = MAX_SIZE_;
79
80 //*************************************************************************
82 //*************************************************************************
84 {
85 }
86
87 //*************************************************************************
89 //*************************************************************************
90 template <typename T, typename... Args>
91 T* create(Args&&... args)
92 {
93 ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value), "Unsupported type");
94
95 return base_t::template create<T>(etl::forward<Args>(args)...);
96 }
97
98 //*************************************************************************
100 //*************************************************************************
101 template <typename T>
102 void destroy(const T* const p)
103 {
104 ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value || etl::is_base_of_any<T, Ts...>::value), "Invalid type");
105
106 base_t::destroy(p);
107 }
108
109 //*************************************************************************
111 //*************************************************************************
112 size_t max_size() const
113 {
114 return MAX_SIZE;
115 }
116
117 private:
118
119 variant_pool(const variant_pool&) ETL_DELETE;
120 variant_pool& operator =(const variant_pool&) ETL_DELETE;
121 };
122
123 //***************************************************************************
124 template <typename ... Ts>
125 class variant_pool_ext
126 : public etl::generic_pool_ext<etl::largest<Ts...>::size,
127 etl::largest<Ts...>::alignment>
128 {
129 public:
130
131 typedef etl::generic_pool_ext<etl::largest<Ts...>::size,
132 etl::largest<Ts...>::alignment> base_t;
133
134 //*************************************************************************
136 //*************************************************************************
137 variant_pool_ext(typename base_t::element* buffer, size_t size)
138 : base_t(buffer, size)
139 {
140 }
141
142 //*************************************************************************
144 //*************************************************************************
145 template <typename T, typename... Args>
146 T* create(Args&&... args)
147 {
148 ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value), "Unsupported type");
149
150 return base_t::template create<T>(etl::forward<Args>(args)...);
151 }
152
153 //*************************************************************************
155 //*************************************************************************
156 template <typename T>
157 void destroy(const T* const p)
158 {
159 ETL_STATIC_ASSERT((etl::is_one_of<T, Ts...>::value || etl::is_base_of_any<T, Ts...>::value), "Invalid type");
160
161 base_t::destroy(p);
162 }
163
164 //*************************************************************************
166 //*************************************************************************
167 size_t max_size() const
168 {
169 return base_t::max_size();
170 }
171
172 private:
173
174 variant_pool_ext(const variant_pool_ext&) ETL_DELETE;
175 variant_pool_ext& operator =(const variant_pool_ext&) ETL_DELETE;
176 };
177#else
178 //***************************************************************************
179 template <size_t MAX_SIZE_,
180 typename T1,
181 typename T2 = void,
182 typename T3 = void,
183 typename T4 = void,
184 typename T5 = void,
185 typename T6 = void,
186 typename T7 = void,
187 typename T8 = void,
188 typename T9 = void,
189 typename T10 = void,
190 typename T11 = void,
191 typename T12 = void,
192 typename T13 = void,
193 typename T14 = void,
194 typename T15 = void,
195 typename T16 = void>
197 : public etl::generic_pool<etl::largest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::size,
198 etl::largest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::alignment,
199 MAX_SIZE_>
200 {
201 public:
202
204 etl::largest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::alignment,
205 MAX_SIZE_> base_t;
206
207 static const size_t MAX_SIZE = MAX_SIZE_;
208
209 //*************************************************************************
211 //*************************************************************************
213 {
214 }
215
216#if ETL_CPP11_NOT_SUPPORTED || ETL_USING_STLPORT
217 //*************************************************************************
219 //*************************************************************************
220 template <typename T>
222 {
223 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
224
225 return base_t::template create<T>();
226 }
227
228 //*************************************************************************
230 //*************************************************************************
231 template <typename T, typename TP1>
232 T* create(const TP1& p1)
233 {
234 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
235
236 return base_t::template create<T>(p1);
237 }
238
239 //*************************************************************************
241 //*************************************************************************
242 template <typename T, typename TP1, typename TP2>
243 T* create(const TP1& p1, const TP2& p2)
244 {
245 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
246
247 return base_t::template create<T>(p1, p2);
248 }
249
250 //*************************************************************************
252 //*************************************************************************
253 template <typename T, typename TP1, typename TP2, typename TP3>
254 T* create(const TP1& p1, const TP2& p2, const TP3& p3)
255 {
256 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
257
258 return base_t::template create<T>(p1, p2, p3);
259 }
260
261 //*************************************************************************
263 //*************************************************************************
264 template <typename T, typename TP1, typename TP2, typename TP3, typename TP4>
265 T* create(const TP1& p1, const TP2& p2, const TP3& p3, const TP4& p4)
266 {
267 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
268
269 return base_t::template create<T>(p1, p2, p3, p4);
270 }
271#else
272 //*************************************************************************
274 //*************************************************************************
275 template <typename T, typename... Args>
276 T* create(Args&&... args)
277 {
278 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
279
280 return base_t::template create<T>(etl::forward<Args>(args)...);
281 }
282#endif
283
284 //*************************************************************************
286 //*************************************************************************
287 template <typename T>
288 void destroy(const T* const p)
289 {
290 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value ||
306 etl::is_base_of<T, T16>::value), "Invalid type");
307
308 base_t::destroy(p);
309 }
310
311 //*************************************************************************
313 //*************************************************************************
314 size_t max_size() const
315 {
316 return MAX_SIZE;
317 }
318
319 private:
320
321 variant_pool(const variant_pool&) ETL_DELETE;
322 variant_pool& operator =(const variant_pool&) ETL_DELETE;
323 };
324
325 //***************************************************************************
326 template <typename T1,
327 typename T2 = void,
328 typename T3 = void,
329 typename T4 = void,
330 typename T5 = void,
331 typename T6 = void,
332 typename T7 = void,
333 typename T8 = void,
334 typename T9 = void,
335 typename T10 = void,
336 typename T11 = void,
337 typename T12 = void,
338 typename T13 = void,
339 typename T14 = void,
340 typename T15 = void,
341 typename T16 = void>
343 : public etl::generic_pool_ext<etl::largest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::size,
344 etl::largest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::alignment>
345 {
346 public:
347
349 etl::largest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::alignment> base_t;
350
351 //*************************************************************************
353 //*************************************************************************
354 variant_pool_ext(typename base_t::element* buffer, size_t size)
355 : base_t(buffer, size)
356 {
357 }
358
359#if ETL_CPP11_NOT_SUPPORTED || ETL_USING_STLPORT
360 //*************************************************************************
362 //*************************************************************************
363 template <typename T>
365 {
366 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
367
368 return base_t::template create<T>();
369 }
370
371 //*************************************************************************
373 //*************************************************************************
374 template <typename T, typename TP1>
375 T* create(const TP1& p1)
376 {
377 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
378
379 return base_t::template create<T>(p1);
380 }
381
382 //*************************************************************************
384 //*************************************************************************
385 template <typename T, typename TP1, typename TP2>
386 T* create(const TP1& p1, const TP2& p2)
387 {
388 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
389
390 return base_t::template create<T>(p1, p2);
391 }
392
393 //*************************************************************************
395 //*************************************************************************
396 template <typename T, typename TP1, typename TP2, typename TP3>
397 T* create(const TP1& p1, const TP2& p2, const TP3& p3)
398 {
399 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
400
401 return base_t::template create<T>(p1, p2, p3);
402 }
403
404 //*************************************************************************
406 //*************************************************************************
407 template <typename T, typename TP1, typename TP2, typename TP3, typename TP4>
408 T* create(const TP1& p1, const TP2& p2, const TP3& p3, const TP4& p4)
409 {
410 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
411
412 return base_t::template create<T>(p1, p2, p3, p4);
413 }
414#else
415 //*************************************************************************
417 //*************************************************************************
418 template <typename T, typename... Args>
419 T* create(Args&&... args)
420 {
421 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value), "Unsupported type");
422
423 return base_t::template create<T>(etl::forward<Args>(args)...);
424 }
425#endif
426
427 //*************************************************************************
429 //*************************************************************************
430 template <typename T>
431 void destroy(const T* const p)
432 {
433 ETL_STATIC_ASSERT((etl::is_one_of<T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value ||
449 etl::is_base_of<T, T16>::value), "Invalid type");
450
451 base_t::destroy(p);
452 }
453
454 //*************************************************************************
456 //*************************************************************************
457 size_t max_size() const
458 {
459 return base_t::max_size();
460 }
461
462 private:
463
464 variant_pool_ext(const variant_pool_ext&) ETL_DELETE;
465 variant_pool_ext& operator =(const variant_pool_ext&) ETL_DELETE;
466 };
467#endif
468}
469
470#endif
Definition variant_pool.h:345
T * create(const TP1 &p1, const TP2 &p2)
Creates the object. Two parameter constructor.
Definition variant_pool.h:386
T * create(const TP1 &p1, const TP2 &p2, const TP3 &p3, const TP4 &p4)
Creates the object. Four parameter constructor.
Definition variant_pool.h:408
T * create()
Creates the object. Default constructor.
Definition variant_pool.h:364
void destroy(const T *const p)
Destroys the object.
Definition variant_pool.h:431
T * create(const TP1 &p1)
Creates the object. One parameter constructor.
Definition variant_pool.h:375
T * create(const TP1 &p1, const TP2 &p2, const TP3 &p3)
Creates the object. Three parameter constructor.
Definition variant_pool.h:397
variant_pool_ext(typename base_t::element *buffer, size_t size)
Default constructor.
Definition variant_pool.h:354
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition variant_pool.h:457
Definition variant_pool.h:200
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition variant_pool.h:314
void destroy(const T *const p)
Destroys the object.
Definition variant_pool.h:288
T * create(const TP1 &p1)
Creates the object. One parameter constructor.
Definition variant_pool.h:232
T * create()
Creates the object. Default constructor.
Definition variant_pool.h:221
variant_pool()
Default constructor.
Definition variant_pool.h:212
T * create(const TP1 &p1, const TP2 &p2, const TP3 &p3, const TP4 &p4)
Creates the object. Four parameter constructor.
Definition variant_pool.h:265
T * create(const TP1 &p1, const TP2 &p2)
Creates the object. Two parameter constructor.
Definition variant_pool.h:243
T * create(const TP1 &p1, const TP2 &p2, const TP3 &p3)
Creates the object. Three parameter constructor.
Definition variant_pool.h:254
size_t size() const
Returns the number of allocated items in the pool.
Definition ipool.h:504
Definition generic_pool.h:56
Definition generic_pool.h:212
is_base_of
Definition type_traits_generator.h:1315
bitset_ext
Definition absolute.h:39