29#ifndef __ETL_FACTORY__
30#define __ETL_FACTORY__
41#include "static_assert.h"
42#include "type_lookup.h"
45#if defined(ETL_COMPILER_GCC)
46 #warning THIS CLASS IS DEPRECATED!USE VARIANT_POOL INSTEAD.
47#elif defined(ETL_COMPILER_MICROSOFT)
48 #pragma message ("THIS CLASS IS DEPRECATED! USE VARIANT_POOL INSTEAD.")
61 factory_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
62 :
exception(reason_, file_name_, line_number_)
73 :
factory_exception(ETL_ERROR_TEXT(
"factory:cannot create", ETL_FILE
"A"), file_name_, line_number_)
84 :
factory_exception(ETL_ERROR_TEXT(
"factory:did not create", ETL_FILE
"B"), file_name_, line_number_)
90 template <
const size_t MAX_SIZE_,
111 typedef typename T1::type TT1;
112 typedef typename T2::type TT2;
113 typedef typename T3::type TT3;
114 typedef typename T4::type TT4;
115 typedef typename T5::type TT5;
116 typedef typename T6::type TT6;
117 typedef typename T7::type TT7;
118 typedef typename T8::type TT8;
119 typedef typename T9::type TT9;
120 typedef typename T10::type TT10;
121 typedef typename T11::type TT11;
122 typedef typename T12::type TT12;
123 typedef typename T13::type TT13;
124 typedef typename T14::type TT14;
125 typedef typename T15::type TT15;
126 typedef typename T16::type TT16;
129 T9, T10, T11, T12, T13, T14, T15, T16>
lookup_t;
133 static const size_t MAX_SIZE = MAX_SIZE_;
142#if !ETL_CPP11_SUPPORTED
146 template <
typename T>
149 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
"Unsupported type");
159 p =
pool.template allocate<T>();
173 template <
typename T,
typename TP1>
176 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
"Unsupported type");
186 p =
pool.template allocate<T>();
200 template <
typename T,
typename TP1,
typename TP2>
203 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
"Unsupported type");
213 p =
pool.template allocate<T>();
227 template <
typename T,
typename TP1,
typename TP2,
typename TP3>
230 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
"Unsupported type");
240 p =
pool.template allocate<T>();
244 new (p) T(p1, p2, p3);
254 template <
typename T,
typename TP1,
typename TP2,
typename TP3,
typename TP4>
257 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
"Unsupported type");
267 p =
pool.template allocate<T>();
271 new (p) T(p1, p2, p3, p4);
284 typedef typename lookup_t::template type_from_id<ID>::type type;
286 return create_from_type<type>();
292 template <
size_t ID,
typename TP1>
293 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1)
295 typedef typename lookup_t::template type_from_id<ID>::type type;
297 return create_from_type<type>(p1);
303 template <
size_t ID,
typename TP1,
typename TP2>
304 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1,
const TP2& p2)
306 typedef typename lookup_t::template type_from_id<ID>::type type;
308 return create_from_type<type>(p1, p2);
314 template <
size_t ID,
typename TP1,
typename TP2,
typename TP3>
315 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1,
const TP2& p2,
const TP3& p3)
317 typedef typename lookup_t::template type_from_id<ID>::type type;
319 return create_from_type<type>(p1, p2, p3);
325 template <
size_t ID,
typename TP1,
typename TP2,
typename TP3,
typename TP4>
326 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1,
const TP2& p2,
const TP3& p3,
const TP4& p4)
328 typedef typename lookup_t::template type_from_id<ID>::type type;
330 return create_from_type<type>(p1, p2, p3, p4);
336 template <
typename T,
typename... Args>
339 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
"Unsupported type");
349 p = pool.template allocate<T>();
353 new (p) T(std::forward<Args>(args)...);
363 template <
size_t ID,
typename... Args>
364 typename lookup_t::template type_from_id<ID>::type*
create_from_id(Args&&... args)
366 typedef typename lookup_t::template type_from_id<ID>::type type;
368 return create_from_type<type>(std::forward<Args>(args)...);
375 template <
typename T>
378 STATIC_ASSERT((
etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value ||
398 void* vp =
reinterpret_cast<char*
>(
const_cast<T*
>(p));
460 etl::generic_pool<etl::largest<TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::size,
461 etl::largest<TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::alignment,
Definition: factory.h:108
T * create_from_type(const TP1 &p1, const TP2 &p2, const TP3 &p3, const TP4 &p4)
Creates the object. Four parameter constructor.
Definition: factory.h:255
factory()
Default constructor.
Definition: factory.h:138
bool empty() const
Definition: factory.h:440
bool full() const
Definition: factory.h:449
T * create_from_type(const TP1 &p1)
Creates the object. One parameter constructor.
Definition: factory.h:174
T * create_from_type(const TP1 &p1, const TP2 &p2)
Creates the object. Two parameter constructor.
Definition: factory.h:201
size_t available() const
Returns the number of free items in the factory.
Definition: factory.h:423
lookup_t::template type_from_id< ID >::type * create_from_id()
Creates the object from an index. Default constructor.
Definition: factory.h:282
bool destroy(const T *const p)
Destroys the object.
Definition: factory.h:376
T * create_from_type()
Creates the object. Default constructor.
Definition: factory.h:147
size_t size() const
Returns the number of allocated items in the factory.
Definition: factory.h:431
T * create_from_type(const TP1 &p1, const TP2 &p2, const TP3 &p3)
Creates the object. Three parameter constructor.
Definition: factory.h:228
size_t max_size() const
Returns the maximum number of items in the factory.
Definition: factory.h:415
Definition: null_type.h:40
#define ETL_ASSERT(b, e)
Definition: error_handler.h:316
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition: exception.h:69
Definition: exception.h:47
Definition: largest.h:367
size_t size() const
Returns the number of allocated items in the pool.
Definition: ipool.h:293
bool empty() const
Definition: ipool.h:302
bool full() const
Definition: ipool.h:311
bool is_in_pool(const void *const p_object) const
Definition: ipool.h:260
size_t available() const
Returns the number of free items in the pool.
Definition: ipool.h:285
void release(const U *const p_object)
Definition: pool.h:157
Definition: generic_pool.h:56
is_base_of
Definition: type_traits_generator.h:1252
is_same
Definition: type_traits_generator.h:1041
bitset_ext
Definition: absolute.h:38
Definition: type_traits.h:1376
Definition: type_lookup.h:238
The type/id pair type to use for type/id lookup template parameters.
Definition: type_lookup_generator.h:67