diff --git a/src/container.h b/src/container.h index 5e622566..5fffc7b7 100644 --- a/src/container.h +++ b/src/container.h @@ -295,11 +295,11 @@ namespace etl char(&array_size(T(&array)[ARRAY_SIZE]))[ARRAY_SIZE]; } -//#if ETL_CPP11_SUPPORTED -// #define ETL_ARRAY_SIZE(a) (etl::size(a)) -//#else +#if ETL_CPP11_SUPPORTED + #define ETL_ARRAY_SIZE(a) (etl::size(a)) +#else #define ETL_ARRAY_SIZE(a) sizeof(etl::array_size(a)) -//#endif +#endif #endif diff --git a/src/generate_variant_pool.bat b/src/generate_variant_pool.bat new file mode 100644 index 00000000..87d1fba7 --- /dev/null +++ b/src/generate_variant_pool.bat @@ -0,0 +1 @@ +python -m cogapp -d -e -ovariant_pool.h -DNTypes=16 variant_pool_generator.h diff --git a/src/variant_pool.h b/src/variant_pool.h index f671776a..55e1a45a 100644 --- a/src/variant_pool.h +++ b/src/variant_pool.h @@ -26,6 +26,28 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ +#if 0 +#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. +#endif + +//*************************************************************************** +// This file has been auto generated. Do not edit this file. +//*************************************************************************** + +//*************************************************************************** +// To generate to header file, run this at the command line. +// Note: You will need Python and COG installed. +// +// python -m cogapp -d -e -ovariant_pool.h -DNTypes= variant_pool_generator.h +// Where is the number of types to support. +// +// e.g. +// To generate handlers for up to 16 types... +// python -m cogapp -d -e -ovariant_pool.h -DNTypes=16 variant_pool_generator.h +// +// See generate.bat +//*************************************************************************** + #ifndef __ETL_VARIANT_POOL__ #define __ETL_VARIANT_POOL__ @@ -82,21 +104,21 @@ namespace etl //*************************************************************************** template class variant_pool { @@ -282,15 +304,15 @@ namespace etl bool destroy(const T* const p) { STATIC_ASSERT((etl::is_one_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || - etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || + etl::is_base_of::value || etl::is_base_of::value || etl::is_base_of::value || etl::is_base_of::value || diff --git a/src/variant_pool_generator.h b/src/variant_pool_generator.h new file mode 100644 index 00000000..6ca24891 --- /dev/null +++ b/src/variant_pool_generator.h @@ -0,0 +1,479 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +/*[[[cog +import cog +cog.outl("#if 0") +]]]*/ +/*[[[end]]]*/ +#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. +/*[[[cog +import cog +cog.outl("#endif") +]]]*/ +/*[[[end]]]*/ + +/*[[[cog +import cog +cog.outl("//***************************************************************************") +cog.outl("// This file has been auto generated. Do not edit this file.") +cog.outl("//***************************************************************************") +]]]*/ +/*[[[end]]]*/ + +//*************************************************************************** +// To generate to header file, run this at the command line. +// Note: You will need Python and COG installed. +// +// python -m cogapp -d -e -ovariant_pool.h -DNTypes= variant_pool_generator.h +// Where is the number of types to support. +// +// e.g. +// To generate handlers for up to 16 types... +// python -m cogapp -d -e -ovariant_pool.h -DNTypes=16 variant_pool_generator.h +// +// See generate.bat +//*************************************************************************** + +#ifndef __ETL_VARIANT_POOL__ +#define __ETL_VARIANT_POOL__ + +#include +#include + +#include "platform.h" +#include "error_handler.h" +#include "exception.h" +#include "largest.h" +#include "type_traits.h" +#include "alignment.h" +#include "static_assert.h" +#include "type_lookup.h" +#include + +#undef ETL_FILE +#define ETL_FILE "40" + +namespace etl +{ + //*************************************************************************** + class variant_pool_exception : public etl::exception + { + public: + + variant_pool_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + class variant_pool_cannot_create : public etl::variant_pool_exception + { + public: + + variant_pool_cannot_create(string_type file_name_, numeric_type line_number_) + : variant_pool_exception(ETL_ERROR_TEXT("variant_pool:cannot create", ETL_FILE"A"), file_name_, line_number_) + { + } + }; + + //*************************************************************************** + class variant_pool_did_not_create : public etl::variant_pool_exception + { + public: + + variant_pool_did_not_create(string_type file_name_, numeric_type line_number_) + : variant_pool_exception(ETL_ERROR_TEXT("variant_pool:did not create", ETL_FILE"B"), file_name_, line_number_) + { + } + }; + + //*************************************************************************** + /*[[[cog + import cog + cog.outl("template " % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + class variant_pool + { + public: + + static const size_t MAX_SIZE = MAX_SIZE_; + + //************************************************************************* + /// Default constructor. + //************************************************************************* + variant_pool() + { + } + +#if !ETL_CPP11_SUPPORTED + //************************************************************************* + /// Creates the object. Default constructor. + //************************************************************************* + template + T* create() + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value), \"Unsupported type\");" % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::variant_pool_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(); + } + } + + return p; + } + + //************************************************************************* + /// Creates the object. One parameter constructor. + //************************************************************************* + template + T* create(const TP1& p1) + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value), \"Unsupported type\");" % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::variant_pool_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(p1); + } + } + + return p; + } + + //************************************************************************* + /// Creates the object. Two parameter constructor. + //************************************************************************* + template + T* create(const TP1& p1, const TP2& p2) + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value), \"Unsupported type\");" % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::variant_pool_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(p1, p2); + } + } + + return p; + } + + //************************************************************************* + /// Creates the object. Three parameter constructor. + //************************************************************************* + template + T* create(const TP1& p1, const TP2& p2, const TP3& p3) + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value), \"Unsupported type\");" % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::variant_pool_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(p1, p2, p3); + } + } + + return p; + } + + //************************************************************************* + /// Creates the object. Four parameter constructor. + //************************************************************************* + template + T* create(const TP1& p1, const TP2& p2, const TP3& p3, const TP4& p4) + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value), \"Unsupported type\");" % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::variant_pool_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(p1, p2, p3, p4); + } + } + + return p; + } +#else + //************************************************************************* + /// Creates the object from a type. Variadic parameter constructor. + //************************************************************************* + template + T* create(Args&&... args) + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value), \"Unsupported type\");" % int(NTypes)) + ]]]*/ + /*[[[end]]]*/ + + T* p = nullptr; + + if (pool.full()) + { + ETL_ASSERT(false, ETL_ERROR(etl::variant_pool_cannot_create)); + } + else + { + p = pool.template allocate(); + + if (p != nullptr) + { + new (p) T(std::forward(args)...); + } + } + + return p; + } +#endif + + //************************************************************************* + /// Destroys the object. + //************************************************************************* + template + bool destroy(const T* const p) + { + /*[[[cog + import cog + cog.out("STATIC_ASSERT((etl::is_one_of::value ||" % int(NTypes)) + + for n in range(1, int(NTypes)): + cog.outl(" etl::is_base_of::value ||" % n) + cog.outl(" etl::is_base_of::value), \"Invalid type\");" % int(NTypes)) + + ]]]*/ + /*[[[end]]]*/ + + p->~T(); + + void* vp = reinterpret_cast(const_cast(p)); + + if (pool.is_in_pool(vp)) + { + pool.release(vp); + return true; + } + else + { + ETL_ASSERT(false, ETL_ERROR(variant_pool_did_not_create)); + return false; + } + } + + //************************************************************************* + /// Returns the maximum number of items in the variant_pool. + //************************************************************************* + size_t max_size() const + { + return MAX_SIZE; + } + + //************************************************************************* + /// Returns the number of free items in the variant_pool. + //************************************************************************* + size_t available() const + { + return pool.available(); + } + + //************************************************************************* + /// Returns the number of allocated items in the variant_pool. + //************************************************************************* + size_t size() const + { + return pool.size(); + } + + //************************************************************************* + /// Checks to see if there are no allocated items in the variant_pool. + /// \return true if there are none allocated. + //************************************************************************* + bool empty() const + { + return pool.empty(); + } + + //************************************************************************* + /// Checks to see if there are no free items in the variant_pool. + /// \return true if there are none free. + //************************************************************************* + bool full() const + { + return pool.full(); + } + + private: + + variant_pool(const variant_pool&); + variant_pool& operator =(const variant_pool&); + + // The pool. + /*[[[cog + import cog + cog.out("etl::generic_pool::size," % int(NTypes)) + + cog.out(" etl::largest<") + for n in range(1, int(NTypes)): + cog.out("T%s, " % n) + if n % 16 == 0: + cog.outl("") + cog.out(" ") + cog.outl("T%s>::alignment," % int(NTypes)) + cog.outl(" MAX_SIZE> pool;") + ]]]*/ + /*[[[end]]]*/ + }; +} + +#undef ETL_FILE + +#endif diff --git a/test/codeblocks/.gitignore b/test/codeblocks/.gitignore index 1c0f0f11..bb6d6ef9 100644 --- a/test/codeblocks/.gitignore +++ b/test/codeblocks/.gitignore @@ -2,3 +2,4 @@ random_*.csv /ETL.depend /ETL.layout *.depend +*.layout diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index 9c71eeb5..5b77f6af 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -2,439 +2,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + @@ -442,9 +52,154 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -457,124 +212,19 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -582,4 +232,354 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index 49eab9a4..46b66b98 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -171,6 +171,7 @@ + @@ -478,6 +479,7 @@ + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index dea71e14..77db216e 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -58,6 +58,9 @@ {4ac80fd1-3eca-4775-8695-eb1ea39c93f1} + + {e4a699ae-e7f3-418e-bf9f-211c21f7f4b2} + @@ -570,6 +573,9 @@ ETL\Containers + + ETL\Containers\Generators + @@ -985,6 +991,9 @@ Resource Files + + Resource Files +