From ec6d1db186e1ab2826c4cfa605855215187c4e07 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 15 Dec 2017 20:40:12 +0000 Subject: [PATCH] Modified factory to use pool instead of custom internal allocator. --- src/factory.h | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/factory.h b/src/factory.h index 30886ec9..bf287777 100644 --- a/src/factory.h +++ b/src/factory.h @@ -30,6 +30,7 @@ SOFTWARE. #define __ETL_FACTORY__ #include +#include #include "platform.h" #include "error_handler.h" @@ -132,6 +133,7 @@ namespace etl { } +#if !ETL_CPP11_SUPPORTED //************************************************************************* /// Creates the object. Default constructor. //************************************************************************* @@ -321,6 +323,45 @@ namespace etl STATIC_ASSERT((!etl::is_same::value), "Invalid index"); return create_from_type(p1, p2, p3, p4); } +#else + //************************************************************************* + /// Creates the object from a type. Variadic parameter constructor. + //************************************************************************* + template + T* create_from_type(Args&&... args) + { + STATIC_ASSERT((etl::is_one_of::value), "Unsupported type"); + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::factory_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(std::forward(args)...); + } + } + + return p; + } + + //************************************************************************* + /// Creates the object from an index. Variadic parameter constructor. + //************************************************************************* + template + typename lookup_t::template type_from_id::type* create_from_id(Args&&... args) + { + typedef typename lookup_t::template type_from_id::type type; + STATIC_ASSERT((!etl::is_same::value), "Invalid index"); + return create_from_type(std::forward(args)...); + } +#endif //************************************************************************* /// Destroys the object. @@ -352,7 +393,7 @@ namespace etl if (pool.is_in_pool(vp)) { - pool.release(reinterpret_cast(const_cast(p))); + pool.release(vp); return true; } else