65 class pool_no_allocation :
public pool_exception
69 explicit pool_no_allocation(string_type file_name_, numeric_type line_number_)
70 : pool_exception(ETL_ERROR_TEXT(
"pool:allocation", ETL_POOL_FILE_ID
"A"), file_name_, line_number_)
80 class pool_object_not_in_pool :
public pool_exception
84 pool_object_not_in_pool(string_type file_name_, numeric_type line_number_)
85 : pool_exception(ETL_ERROR_TEXT(
"pool:not in pool", ETL_POOL_FILE_ID
"B"), file_name_, line_number_)
95 class pool_element_size :
public pool_exception
99 pool_element_size(string_type file_name_, numeric_type line_number_)
100 : pool_exception(ETL_ERROR_TEXT(
"pool:element size", ETL_POOL_FILE_ID
"C"), file_name_, line_number_)
112 typedef size_t size_type;
120 const char* buffer_end()
const
122 return p_buffer + Item_Size * items_initialised;
131 bool is_pointing_into_pool_or_end_or_nullptr(
const char* address)
const
133 return address == ETL_NULLPTR || (p_buffer <= address && address <= buffer_end());
139 bool is_in_free_list(
const char* address)
const
141 const char* i = p_next;
142 while (i != ETL_NULLPTR)
148 i = *
reinterpret_cast<const char* const*
>(i);
156 template <
bool is_const>
163 typedef typename etl::conditional<is_const, const char*, char*>::type value_type;
164 typedef typename etl::conditional<is_const, const char*&, char*&>::type reference;
165 typedef typename etl::conditional<is_const, const char**, char**>::type pointer;
166 typedef ptrdiff_t difference_type;
167 typedef ETL_OR_STD::forward_iterator_tag iterator_category;
168 typedef typename etl::conditional<is_const, const void*, void*>::type void_type;
169 typedef typename etl::conditional<is_const, const ipool, ipool>::type pool_type;
170 typedef typename etl::conditional<is_const, const char* const*, char**>::type pointer_type;
173 ipool_iterator(
const ipool_iterator& other)
174 : p_current(other.p_current)
175 , p_pool(other.p_pool)
181 ipool_iterator& operator++()
183 p_current = p_current + p_pool->Item_Size;
189 ipool_iterator operator++(
int)
191 ipool_iterator temp(*
this);
192 p_current = p_current + p_pool->Item_Size;
198 ipool_iterator& operator=(
const ipool_iterator& other)
200 p_current = other.p_current;
201 p_pool = other.p_pool;
206 void_type operator*()
const
212 template <
typename T>
215 return *
reinterpret_cast<T*
>(p_current);
219 friend bool operator==(
const ipool_iterator& lhs,
const ipool_iterator& rhs)
221 return lhs.p_current == rhs.p_current;
225 friend bool operator!=(
const ipool_iterator& lhs,
const ipool_iterator& rhs)
227 return !(lhs == rhs);
236 void find_allocated()
238 while (p_current < p_pool->buffer_end())
240 value_type value = *
reinterpret_cast<pointer_type
>(p_current);
241 if (!p_pool->is_pointing_into_pool_or_end_or_nullptr(value))
245 if (!p_pool->is_in_free_list(p_current))
249 p_current += p_pool->Item_Size;
256 ipool_iterator(value_type p, pool_type* pool_)
263 value_type p_current;
267 template <
bool is_const>
273 class const_iterator :
public ipool_iterator<true>
277 const_iterator(
const ipool_iterator& other)
278 : ipool_iterator(other)
281 const_iterator(
const ipool_iterator<false>& other)
282 : ipool_iterator(other.p_current, other.p_pool)
285 const_iterator(value_type p, pool_type* pool_)
286 : ipool_iterator<true>(p, pool_)
294 return iterator(p_buffer,
this);
300 return iterator(p_buffer + Item_Size * items_initialised,
this);
304 const_iterator begin()
const
306 return const_iterator(p_buffer,
this);
312 return const_iterator(p_buffer + Item_Size * items_initialised,
this);
324 return const_iterator(p_buffer + Item_Size * items_initialised,
this);
332 template <
typename T>
335 if (
sizeof(T) > Item_Size)
340 return reinterpret_cast<T*
>(allocate_item());
343#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
349 template <
typename T>
368 template <
typename T,
typename T1>
381 template <
typename T,
typename T1,
typename T2>
382 T*
create(
const T1& value1,
const T2& value2)
388 ::new (p) T(value1, value2);
394 template <
typename T,
typename T1,
typename T2,
typename T3>
395 T*
create(
const T1& value1,
const T2& value2,
const T3& value3)
401 ::new (p) T(value1, value2, value3);
407 template <
typename T,
typename T1,
typename T2,
typename T3,
typename T4>
408 T*
create(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
414 ::new (p) T(value1, value2, value3, value4);
423 template <
typename T,
typename... Args>
430 ::new (p) T(etl::forward<Args>(args)...);
442 template <
typename T>
445 if (
sizeof(T) > Item_Size)
462 const uintptr_t p = uintptr_t(p_object);
463 release_item((
char*)p);
472 items_initialised = 0;
483 const uintptr_t p = uintptr_t(p_object);
484 return is_item_in_pool((
const char*)p);
516 return Max_Size - items_allocated;
524 return items_allocated;
533 return items_allocated == 0;
542 return items_allocated == Max_Size;
550 ipool(
char* p_buffer_, uint32_t item_size_, uint32_t max_size_)
551 : p_buffer(p_buffer_)
554 , items_initialised(0)
555 , Item_Size(item_size_)
556 , Max_Size(max_size_)
562 static ETL_CONSTANT uintptr_t invalid_item_ptr = 1;
567 char* allocate_item()
569 char* p_value = ETL_NULLPTR;
572 if (items_allocated < Max_Size)
575 if (items_initialised < Max_Size)
577 char* p = p_buffer + (items_initialised * Item_Size);
578 char* np = p + Item_Size;
579 *
reinterpret_cast<char**
>(p) = np;
587 if (items_allocated < Max_Size)
590 p_next = *
reinterpret_cast<char**
>(p_next);
595 p_next = ETL_NULLPTR;
601 *
reinterpret_cast<uintptr_t*
>(p_value) = invalid_item_ptr;
605 ETL_ASSERT(
false, ETL_ERROR(pool_no_allocation));
614 void release_item(
char* p_value)
617 ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool));
619 if (items_allocated > 0)
622 *(uintptr_t*)p_value =
reinterpret_cast<uintptr_t
>(p_next);
630 ETL_ASSERT_FAIL(ETL_ERROR(pool_no_allocation));
637 bool is_item_in_pool(
const char* p)
const
640 intptr_t distance = p - p_buffer;
641 bool is_within_range = (distance >= 0) && (distance <= intptr_t((Item_Size * Max_Size) - Item_Size));
645#if ETL_IS_DEBUG_BUILD
647 bool is_valid_address = ((distance % Item_Size) == 0);
649 bool is_valid_address =
true;
652 return is_within_range && is_valid_address;
662 uint32_t items_allocated;
663 uint32_t items_initialised;
665 const uint32_t Item_Size;
666 const uint32_t Max_Size;
671#if defined(ETL_POLYMORPHIC_POOL) || defined(ETL_POLYMORPHIC_CONTAINERS)
ETL_CONSTEXPR14 bool operator!=(const etl::bitset< Active_Bits, TElement > &lhs, const etl::bitset< Active_Bits, TElement > &rhs) ETL_NOEXCEPT
Definition bitset_new.h:2529