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_)
72 factory_cannot_create(string_type file_name_, numeric_type line_number_)
73 : factory_exception(ETL_ERROR_TEXT(
"factory:cannot create", ETL_FILE
"A"), file_name_, line_number_)
83 factory_did_not_create(string_type file_name_, numeric_type line_number_)
84 : factory_exception(ETL_ERROR_TEXT(
"factory:did not create", ETL_FILE
"B"), file_name_, line_number_)
102 typedef typename T1::type TT1;
103 typedef typename T2::type TT2;
104 typedef typename T3::type TT3;
105 typedef typename T4::type TT4;
106 typedef typename T5::type TT5;
107 typedef typename T6::type TT6;
108 typedef typename T7::type TT7;
109 typedef typename T8::type TT8;
110 typedef typename T9::type TT9;
111 typedef typename T10::type TT10;
112 typedef typename T11::type TT11;
113 typedef typename T12::type TT12;
114 typedef typename T13::type TT13;
115 typedef typename T14::type TT14;
116 typedef typename T15::type TT15;
117 typedef typename T16::type TT16;
119 typedef etl::type_id_lookup<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> lookup_t;
123 static const size_t MAX_SIZE = MAX_SIZE_;
130#if !ETL_CPP11_SUPPORTED
134 template <
typename T>
137 STATIC_ASSERT((etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
148 p = pool.template allocate<T>();
162 template <
typename T,
typename TP1>
165 STATIC_ASSERT((etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
176 p = pool.template allocate<T>();
190 template <
typename T,
typename TP1,
typename TP2>
193 STATIC_ASSERT((etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
204 p = pool.template allocate<T>();
218 template <
typename T,
typename TP1,
typename TP2,
typename TP3>
221 STATIC_ASSERT((etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
232 p = pool.template allocate<T>();
236 new (p) T(p1, p2, p3);
246 template <
typename T,
typename TP1,
typename TP2,
typename TP3,
typename TP4>
249 STATIC_ASSERT((etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
260 p = pool.template allocate<T>();
264 new (p) T(p1, p2, p3, p4);
277 typedef typename lookup_t::template type_from_id<ID>::type
type;
278 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
285 template <
size_t ID,
typename TP1>
286 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1)
288 typedef typename lookup_t::template type_from_id<ID>::type
type;
289 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
296 template <
size_t ID,
typename TP1,
typename TP2>
297 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1,
const TP2& p2)
299 typedef typename lookup_t::template type_from_id<ID>::type
type;
300 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
307 template <
size_t ID,
typename TP1,
typename TP2,
typename TP3>
308 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1,
const TP2& p2,
const TP3& p3)
310 typedef typename lookup_t::template type_from_id<ID>::type
type;
311 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
318 template <
size_t ID,
typename TP1,
typename TP2,
typename TP3,
typename TP4>
319 typename lookup_t::template type_from_id<ID>::type*
create_from_id(
const TP1& p1,
const TP2& p2,
const TP3& p3,
const TP4& p4)
321 typedef typename lookup_t::template type_from_id<ID>::type
type;
322 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
329 template <
typename T,
typename... Args>
332 STATIC_ASSERT((etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value),
343 p = pool.template allocate<T>();
347 new (p) T(std::forward<Args>(args)...);
357 template <
size_t ID,
typename... Args>
358 typename lookup_t::template type_from_id<ID>::type*
create_from_id(Args&&... args)
360 typedef typename lookup_t::template type_from_id<ID>::type type;
361 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
369 template <
typename T>
373 (etl::is_one_of<T, TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::value
374 || etl::is_base_of<T, TT1>::value || etl::is_base_of<T, TT2>::value || etl::is_base_of<T, TT3>::value || etl::is_base_of<T, TT4>::value
375 || etl::is_base_of<T, TT5>::value || etl::is_base_of<T, TT6>::value || etl::is_base_of<T, TT7>::value || etl::is_base_of<T, TT8>::value
376 || etl::is_base_of<T, TT9>::value || etl::is_base_of<T, TT10>::value || etl::is_base_of<T, TT11>::value || etl::is_base_of<T, TT12>::value
377 || etl::is_base_of<T, TT13>::value || etl::is_base_of<T, TT14>::value || etl::is_base_of<T, TT15>::value || etl::is_base_of<T, TT16>::value),
382 void* vp =
reinterpret_cast<char*
>(
const_cast<T*
>(p));
384 if (pool.is_in_pool(vp))
409 return pool.available();
444 etl::generic_pool< etl::largest<TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::size,
445 etl::largest<TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8, TT9, TT10, TT11, TT12, TT13, TT14, TT15, TT16>::alignment, MAX_SIZE>
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:247
lookup_t::template type_from_id< ID >::type * create_from_id(const TP1 &p1, const TP2 &p2)
Creates the object from an index. Two parameter constructor.
Definition factory.h:297
factory()
Default constructor.
Definition factory.h:128
lookup_t::template type_from_id< ID >::type * create_from_id(const TP1 &p1)
Creates the object from an index. One parameter constructor.
Definition factory.h:286
bool empty() const
Definition factory.h:424
bool full() const
Definition factory.h:433
T * create_from_type(const TP1 &p1)
Creates the object. One parameter constructor.
Definition factory.h:163
T * create_from_type(const TP1 &p1, const TP2 &p2)
Creates the object. Two parameter constructor.
Definition factory.h:191
lookup_t::template type_from_id< ID >::type * create_from_id(const TP1 &p1, const TP2 &p2, const TP3 &p3, const TP4 &p4)
Creates the object from an index. Three parameter constructor.
Definition factory.h:319
size_t available() const
Returns the number of free items in the factory.
Definition factory.h:407
lookup_t::template type_from_id< ID >::type * create_from_id()
Creates the object from an index. Default constructor.
Definition factory.h:275
bool destroy(const T *const p)
Destroys the object.
Definition factory.h:370
T * create_from_type()
Creates the object. Default constructor.
Definition factory.h:135
size_t size() const
Returns the number of allocated items in the factory.
Definition factory.h:415
lookup_t::template type_from_id< ID >::type * create_from_id(const TP1 &p1, const TP2 &p2, const TP3 &p3)
Creates the object from an index. Three parameter constructor.
Definition factory.h:308
T * create_from_type(const TP1 &p1, const TP2 &p2, const TP3 &p3)
Creates the object. Three parameter constructor.
Definition factory.h:219
size_t max_size() const
Returns the maximum number of items in the factory.
Definition factory.h:399
Definition null_type.h:40
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
Definition exception.h:59
bool full() const
Definition ipool.h:540
Definition generic_pool.h:56
bitset_ext
Definition absolute.h:40
Definition type_lookup.h:54
The type/id pair type to use for type/id lookup template parameters.
Definition type_lookup.h:46