64 class pool_no_allocation :
public pool_exception
68 explicit pool_no_allocation(string_type file_name_, numeric_type line_number_)
69 : pool_exception(ETL_ERROR_TEXT(
"pool:allocation", ETL_POOL_FILE_ID
"A"), file_name_, line_number_)
77 class pool_object_not_in_pool :
public pool_exception
81 pool_object_not_in_pool(string_type file_name_, numeric_type line_number_)
82 : pool_exception(ETL_ERROR_TEXT(
"pool:not in pool", ETL_POOL_FILE_ID
"B"), file_name_, line_number_)
90 class pool_element_size :
public pool_exception
94 pool_element_size(string_type file_name_, numeric_type line_number_)
95 : pool_exception(ETL_ERROR_TEXT(
"pool:element size", ETL_POOL_FILE_ID
"C"), file_name_, line_number_)
106 typedef size_t size_type;
114 const char* buffer_end()
const
116 return p_buffer + Item_Size * items_initialised;
124 bool is_pointing_into_pool_or_end_or_nullptr(
const char *address)
const
126 return address == ETL_NULLPTR || (p_buffer <= address && address <= buffer_end());
132 bool is_in_free_list(
const char* address)
const
134 const char* i = p_next;
135 while (i != ETL_NULLPTR)
141 i = *
reinterpret_cast<const char* const*
>(i);
149 template<
bool is_const>
156 typedef typename etl::conditional<is_const, const char*, char*>::type value_type;
157 typedef typename etl::conditional<is_const, const char*&, char*&>::type reference;
158 typedef typename etl::conditional<is_const, const char**, char**>::type pointer;
159 typedef ptrdiff_t difference_type;
160 typedef ETL_OR_STD::forward_iterator_tag iterator_category;
161 typedef typename etl::conditional<is_const, const void*, void*>::type void_type;
162 typedef typename etl::conditional<is_const, const ipool, ipool>::type pool_type;
163 typedef typename etl::conditional<is_const, const char* const*, char**>::type pointer_type;
166 ipool_iterator(
const ipool_iterator& other)
167 : p_current(other.p_current)
168 , p_pool(other.p_pool)
174 ipool_iterator& operator ++()
176 p_current = p_current + p_pool->Item_Size;
182 ipool_iterator operator ++(
int)
184 ipool_iterator temp(*
this);
185 p_current = p_current + p_pool->Item_Size;
191 ipool_iterator& operator =(
const ipool_iterator& other)
193 p_current = other.p_current;
194 p_pool = other.p_pool;
199 void_type operator *()
const
205 template <
typename T>
208 return *
reinterpret_cast<T*
>(p_current);
212 friend bool operator == (
const ipool_iterator& lhs,
const ipool_iterator& rhs)
214 return lhs.p_current == rhs.p_current;
218 friend bool operator != (
const ipool_iterator& lhs,
const ipool_iterator& rhs)
220 return !(lhs == rhs);
229 void find_allocated()
231 while (p_current < p_pool->buffer_end())
233 value_type value = *
reinterpret_cast<pointer_type
>(p_current);
234 if (!p_pool->is_pointing_into_pool_or_end_or_nullptr(value))
238 if (!p_pool->is_in_free_list(p_current))
242 p_current += p_pool->Item_Size;
249 ipool_iterator(value_type p, pool_type* pool_)
256 value_type p_current;
260 template<
bool is_const>
266 class const_iterator :
public ipool_iterator<true>
269 const_iterator(
const ipool_iterator& other) : ipool_iterator(other) {}
270 const_iterator(
const ipool_iterator<false>& other) : ipool_iterator(other.p_current, other.p_pool) {}
271 const_iterator(value_type p, pool_type* pool_) : ipool_iterator<true>(p, pool_) {}
277 return iterator(p_buffer,
this);
283 return iterator(p_buffer + Item_Size * items_initialised,
this);
287 const_iterator begin()
const
289 return const_iterator(p_buffer,
this);
295 return const_iterator(p_buffer + Item_Size * items_initialised,
this);
307 return const_iterator(p_buffer + Item_Size * items_initialised,
this);
315 template <
typename T>
318 if (
sizeof(T) > Item_Size)
323 return reinterpret_cast<T*
>(allocate_item());
326#if ETL_CPP11_NOT_SUPPORTED || ETL_POOL_CPP03_CODE || ETL_USING_STLPORT
332 template <
typename T>
350 template <
typename T,
typename T1>
363 template <
typename T,
typename T1,
typename T2>
364 T*
create(
const T1& value1,
const T2& value2)
370 ::new (p) T(value1, value2);
376 template <
typename T,
typename T1,
typename T2,
typename T3>
377 T*
create(
const T1& value1,
const T2& value2,
const T3& value3)
383 ::new (p) T(value1, value2, value3);
389 template <
typename T,
typename T1,
typename T2,
typename T3,
typename T4>
390 T*
create(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
396 ::new (p) T(value1, value2, value3, value4);
405 template <
typename T,
typename... Args>
412 ::new (p) T(etl::forward<Args>(args)...);
424 template <
typename T>
427 if (
sizeof(T) > Item_Size)
444 const uintptr_t p = uintptr_t(p_object);
445 release_item((
char*)p);
454 items_initialised = 0;
465 const uintptr_t p = uintptr_t(p_object);
466 return is_item_in_pool((
const char*)p);
498 return Max_Size - items_allocated;
506 return items_allocated;
515 return items_allocated == 0;
524 return items_allocated == Max_Size;
532 ipool(
char* p_buffer_, uint32_t item_size_, uint32_t max_size_)
533 : p_buffer(p_buffer_),
536 items_initialised(0),
537 Item_Size(item_size_),
544 static ETL_CONSTANT uintptr_t invalid_item_ptr = 1;
549 char* allocate_item()
551 char* p_value = ETL_NULLPTR;
554 if (items_allocated < Max_Size)
557 if (items_initialised < Max_Size)
559 char* p = p_buffer + (items_initialised * Item_Size);
560 char* np = p + Item_Size;
561 *
reinterpret_cast<char**
>(p) = np;
569 if (items_allocated < Max_Size)
572 p_next = *
reinterpret_cast<char**
>(p_next);
577 p_next = ETL_NULLPTR;
583 *
reinterpret_cast<uintptr_t*
>(p_value) = invalid_item_ptr;
587 ETL_ASSERT(
false, ETL_ERROR(pool_no_allocation));
596 void release_item(
char* p_value)
599 ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool));
601 if (items_allocated > 0)
604 *(uintptr_t*)p_value =
reinterpret_cast<uintptr_t
>(p_next);
612 ETL_ASSERT_FAIL(ETL_ERROR(pool_no_allocation));
619 bool is_item_in_pool(
const char* p)
const
622 intptr_t distance = p - p_buffer;
623 bool is_within_range = (distance >= 0) && (distance <= intptr_t((Item_Size * Max_Size) - Item_Size));
626#if ETL_IS_DEBUG_BUILD
628 bool is_valid_address = ((distance % Item_Size) == 0);
630 bool is_valid_address =
true;
633 return is_within_range && is_valid_address;
643 uint32_t items_allocated;
644 uint32_t items_initialised;
646 const uint32_t Item_Size;
647 const uint32_t Max_Size;
652#if defined(ETL_POLYMORPHIC_POOL) || defined(ETL_POLYMORPHIC_CONTAINERS)
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:962