Loading...
Searching...
No Matches
pool.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2014 John Wellbelove
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.
******************************************************************************/
#ifndef ETL_POOL_INCLUDED
#define ETL_POOL_INCLUDED
#include "platform.h"
#include "generic_pool.h"
#include "ipool.h"
#define ETL_POOL_CPP03_CODE 0
//*****************************************************************************
//*****************************************************************************
namespace etl
{
//*************************************************************************
//*************************************************************************
template <typename T, const size_t VSize>
class pool : public etl::generic_pool<sizeof(T), etl::alignment_of<T>::value, VSize>
{
private:
typedef etl::generic_pool<sizeof(T), etl::alignment_of<T>::value, VSize> base_t;
public:
using base_t::ALIGNMENT;
using base_t::SIZE;
using base_t::TYPE_SIZE;
//*************************************************************************
//*************************************************************************
pool() {}
//*************************************************************************
//*************************************************************************
T* allocate()
{
return base_t::template allocate<T>();
}
#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
//*************************************************************************
//*************************************************************************
T* create()
{
return base_t::template create<T>();
}
//*************************************************************************
//*************************************************************************
template <typename T1>
T* create(const T1& value1)
{
return base_t::template create<T>(value1);
}
//*************************************************************************
//*************************************************************************
template <typename T1, typename T2>
T* create(const T1& value1, const T2& value2)
{
return base_t::template create<T>(value1, value2);
}
//*************************************************************************
//*************************************************************************
template <typename T1, typename T2, typename T3>
T* create(const T1& value1, const T2& value2, const T3& value3)
{
return base_t::template create<T>(value1, value2, value3);
}
//*************************************************************************
//*************************************************************************
template <typename T1, typename T2, typename T3, typename T4>
T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
{
return base_t::template create<T>(value1, value2, value3, value4);
}
#else
//*************************************************************************
//*************************************************************************
template <typename... Args>
T* create(Args&&... args)
{
return base_t::template create<T>(etl::forward<Args>(args)...);
}
#endif
//*************************************************************************
//*************************************************************************
template <typename U>
void release(const U* const p_object)
{
ETL_STATIC_ASSERT((etl::is_same<U, T>::value || etl::is_base_of<U, T>::value), "Pool does not contain this type");
base_t::release(p_object);
}
//*************************************************************************
//*************************************************************************
template <typename U>
void destroy(const U* const p_object)
{
ETL_STATIC_ASSERT((etl::is_base_of<U, T>::value), "Pool does not contain this type");
base_t::destroy(p_object);
}
private:
// Should not be copied.
pool(const pool&) ETL_DELETE;
pool& operator=(const pool&) ETL_DELETE;
};
//*************************************************************************
//*************************************************************************
template <typename T>
class pool_ext : public etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value>
{
private:
typedef etl::generic_pool_ext<sizeof(T), etl::alignment_of<T>::value> base_t;
public:
using base_t::ALIGNMENT;
using base_t::TYPE_SIZE;
//*************************************************************************
//*************************************************************************
pool_ext(typename base_t::element* buffer, size_t size)
: base_t(buffer, size)
{
}
//*************************************************************************
//*************************************************************************
T* allocate()
{
return base_t::template allocate<T>();
}
#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
//*************************************************************************
//*************************************************************************
T* create()
{
return base_t::template create<T>();
}
//*************************************************************************
//*************************************************************************
template <typename T1>
T* create(const T1& value1)
{
return base_t::template create<T>(value1);
}
//*************************************************************************
//*************************************************************************
template <typename T1, typename T2>
T* create(const T1& value1, const T2& value2)
{
return base_t::template create<T>(value1, value2);
}
//*************************************************************************
//*************************************************************************
template <typename T1, typename T2, typename T3>
T* create(const T1& value1, const T2& value2, const T3& value3)
{
return base_t::template create<T>(value1, value2, value3);
}
//*************************************************************************
//*************************************************************************
template <typename T1, typename T2, typename T3, typename T4>
T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
{
return base_t::template create<T>(value1, value2, value3, value4);
}
#else
//*************************************************************************
//*************************************************************************
template <typename... Args>
T* create(Args&&... args)
{
return base_t::template create<T>(etl::forward<Args>(args)...);
}
#endif
//*************************************************************************
//*************************************************************************
template <typename U>
void release(const U* const p_object)
{
ETL_STATIC_ASSERT((etl::is_same<U, T>::value || etl::is_base_of<U, T>::value), "Pool does not contain this type");
base_t::release(p_object);
}
//*************************************************************************
//*************************************************************************
template <typename U>
void destroy(const U* const p_object)
{
ETL_STATIC_ASSERT((etl::is_base_of<U, T>::value), "Pool does not contain this type");
base_t::destroy(p_object);
}
private:
// Should not be copied.
pool_ext(const pool_ext&) ETL_DELETE;
pool_ext& operator=(const pool_ext&) ETL_DELETE;
};
} // namespace etl
#endif
generic_pool.h
etl::ipool::size
size_t size() const
Returns the number of allocated items in the pool.
Definition ipool.h:523
etl::pool_ext::pool_ext
pool_ext(typename base_t::element *buffer, size_t size)
Constructor.
Definition pool.h:204
etl::pool::allocate
T * allocate()
Definition pool.h:76
etl::pool_ext::allocate
T * allocate()
Definition pool.h:216
etl::pool::create
T * create(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition pool.h:135
etl::pool_ext::release
void release(const U *const p_object)
Definition pool.h:299
etl::pool::create
T * create(const T1 &value1, const T2 &value2)
Definition pool.h:111
etl::pool_ext::create
T * create(const T1 &value1)
Definition pool.h:239
etl::pool::create
T * create(const T1 &value1)
Definition pool.h:99
etl::pool_ext::destroy
void destroy(const U *const p_object)
Definition pool.h:311
etl::pool::create
T * create()
Definition pool.h:87
etl::pool::destroy
void destroy(const U *const p_object)
Definition pool.h:171
etl::pool_ext::create
T * create(const T1 &value1, const T2 &value2)
Definition pool.h:251
etl::pool::create
T * create(const T1 &value1, const T2 &value2, const T3 &value3)
Definition pool.h:123
etl::pool_ext::create
T * create()
Definition pool.h:227
etl::pool_ext::create
T * create(const T1 &value1, const T2 &value2, const T3 &value3)
Definition pool.h:263
etl::pool::pool
pool()
Constructor.
Definition pool.h:68
etl::pool::release
void release(const U *const p_object)
Definition pool.h:159
etl::pool_ext::create
T * create(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition pool.h:275
etl::generic_pool
Definition generic_pool.h:56
etl::generic_pool_ext
Definition generic_pool.h:216
etl::pool
Definition pool.h:54
etl::pool_ext
Definition pool.h:191
ipool.h
etl
Definition absolute.h:40
platform.h