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_)
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;
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;
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;
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;
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;
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;
367 STATIC_ASSERT((!etl::is_same<void, type>::value),
"Invalid index");
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));
400 if (pool.is_in_pool(vp))
425 return pool.available();
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,
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
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:304
factory()
Default constructor.
Definition factory.h:138
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:293
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
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:326
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
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:315
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:356
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
Definition exception.h:47
bool full() const
Definition ipool.h:522
Definition generic_pool.h:56
is_base_of
Definition type_traits_generator.h:1315
is_same
Definition type_traits_generator.h:1104
bitset_ext
Definition absolute.h:39
Definition type_lookup.h:238
The type/id pair type to use for type/id lookup template parameters.
Definition type_lookup_generator.h:67