mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-28 13:28:43 +08:00
Merge remote-tracking branch 'origin/development'
This commit is contained in:
commit
c7abb82309
@ -45,9 +45,38 @@ SOFTWARE.
|
||||
#include "nullptr.h"
|
||||
#include "type_traits.h"
|
||||
#include "basic_intrusive_forward_list_node.h"
|
||||
#include "error_handler.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// Exception for the intrusive_forward_list.
|
||||
///\ingroup intrusive_forward_list
|
||||
//***************************************************************************
|
||||
class basic_intrusive_forward_list_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
basic_intrusive_forward_list_exception(string_type what, string_type file_name, numeric_type line_number)
|
||||
: exception(what, file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Empty exception for the intrusive_forward_list.
|
||||
///\ingroup intrusive_forward_list
|
||||
//***************************************************************************
|
||||
class basic_intrusive_forward_list_empty : public basic_intrusive_forward_list_exception
|
||||
{
|
||||
public:
|
||||
|
||||
basic_intrusive_forward_list_empty(string_type file_name, numeric_type line_number)
|
||||
: basic_intrusive_forward_list_exception(ETL_ERROR_TEXT("basic_intrusive_forward_list:empty", ETL_FILE"A"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// An intrusive forward list.
|
||||
///\ingroup basic_intrusive_forward_list
|
||||
@ -400,10 +429,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_front()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
remove_node_after(start_node);
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(basic_intrusive_forward_list_empty));
|
||||
remove_node_after(start_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
6
bitset.h
6
bitset.h
@ -138,10 +138,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
bitset<N>& set(const char* text)
|
||||
{
|
||||
if (ETL_ASSERT(text != 0, ETL_ERROR(bitset_nullptr)))
|
||||
{
|
||||
ibitset::set(text);
|
||||
}
|
||||
ETL_ASSERT(text != 0, ETL_ERROR(bitset_nullptr));
|
||||
ibitset::set(text);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -94,16 +94,22 @@ namespace etl
|
||||
///\ingroup error_handler
|
||||
//***************************************************************************
|
||||
#if defined(ETL_NO_CHECKS)
|
||||
#define ETL_ASSERT(b, e) (true) // Does nothing. Evaluates to 'true'.
|
||||
#define ETL_ASSERT(b, e) // Does nothing.
|
||||
#elif defined(ETL_THROW_EXCEPTIONS)
|
||||
#define ETL_ASSERT(b, e) (((b) ? true : throw((e))), true) // Throws an exception if the condition fails. Evaluates to 'true'.
|
||||
#elif defined(ETL_LOG_ERRORS)
|
||||
#define ETL_ASSERT(b, e) (((b) ? true : etl::error_handler::error((e))), (b)) // Logs the error if the condition fails. Evaluates to the result of the condition.
|
||||
#if defined(ETL_LOG_ERRORS)
|
||||
#define ETL_ASSERT(b, e) {if (b) {etl::error_handler::error((e)); throw((e);)}} // If the condition fails, calls the error handler then throws an exception.
|
||||
#else
|
||||
#define ETL_ASSERT(b, e) {if (b) {throw((e));}} // If the condition fails, throws an exception.
|
||||
#endif
|
||||
#else
|
||||
#if defined(NDEBUG)
|
||||
#define ETL_ASSERT(b, e) (true) // Does nothing. Evaluates to 'true'.
|
||||
#define ETL_ASSERT(b, e) // Does nothing.
|
||||
#else
|
||||
#define ETL_ASSERT(b, e) ((assert((b))), true) // Asserts if the condition fails. Evaluates to 'true'.
|
||||
#if defined(ETL_LOG_ERRORS)
|
||||
#define ETL_ASSERT(b, e) {etl::error_handler::error((e)); assert((b));} // If the condition fails, calls the error handler then asserts.
|
||||
#else
|
||||
#define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts.
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
569
ideque.h
569
ideque.h
@ -492,18 +492,17 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void assign(size_type n, const value_type& value)
|
||||
{
|
||||
if (ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(deque_full)))
|
||||
ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(deque_full));
|
||||
|
||||
initialise();
|
||||
|
||||
_begin.index = 0;
|
||||
_end.index = 0;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
initialise();
|
||||
|
||||
_begin.index = 0;
|
||||
_end.index = 0;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
create_element_back(value);
|
||||
--n;
|
||||
}
|
||||
create_element_back(value);
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
@ -711,43 +710,42 @@ namespace etl
|
||||
{
|
||||
iterator position(insert_position.index, *this, p_buffer);
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(deque_full)))
|
||||
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
|
||||
|
||||
if (insert_position == begin())
|
||||
{
|
||||
if (insert_position == begin())
|
||||
create_element_front(value);
|
||||
position = _begin;
|
||||
}
|
||||
else if (insert_position == end())
|
||||
{
|
||||
create_element_back(value);
|
||||
position = _end - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Are we closer to the front?
|
||||
if (std::distance(_begin, position) < std::distance(position, _end - 1))
|
||||
{
|
||||
create_element_front(value);
|
||||
position = _begin;
|
||||
}
|
||||
else if (insert_position == end())
|
||||
{
|
||||
create_element_back(value);
|
||||
position = _end - 1;
|
||||
// Construct the _begin.
|
||||
create_element_front(*_begin);
|
||||
|
||||
// Move the values.
|
||||
std::copy(_begin + 1, position, _begin);
|
||||
|
||||
// Write the new value.
|
||||
*--position = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Are we closer to the front?
|
||||
if (std::distance(_begin, position) < std::distance(position, _end - 1))
|
||||
{
|
||||
// Construct the _begin.
|
||||
create_element_front(*_begin);
|
||||
|
||||
// Move the values.
|
||||
std::copy(_begin + 1, position, _begin);
|
||||
|
||||
// Write the new value.
|
||||
*--position = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct the _end.
|
||||
create_element_back(*(_end - 1));
|
||||
// Construct the _end.
|
||||
create_element_back(*(_end - 1));
|
||||
|
||||
// Move the values.
|
||||
std::copy_backward(position, _end - 2, _end - 1);
|
||||
// Move the values.
|
||||
std::copy_backward(position, _end - 2, _end - 1);
|
||||
|
||||
// Write the new value.
|
||||
*position = value;
|
||||
}
|
||||
// Write the new value.
|
||||
*position = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -765,99 +763,98 @@ namespace etl
|
||||
{
|
||||
iterator position;
|
||||
|
||||
if (ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(deque_full)))
|
||||
ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(deque_full));
|
||||
|
||||
if (insert_position == begin())
|
||||
{
|
||||
if (insert_position == begin())
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
create_element_front(value);
|
||||
}
|
||||
|
||||
position = _begin;
|
||||
}
|
||||
else if (insert_position == end())
|
||||
{
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
create_element_back(value);
|
||||
}
|
||||
|
||||
position = _end - n;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-const insert iterator.
|
||||
position = iterator(insert_position.index, *this, p_buffer);
|
||||
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, insert_position) <= difference_type(current_size / 2))
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(begin(), position);
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Remember the original start.
|
||||
iterator from = _begin + n_create_copy - 1;
|
||||
iterator to;
|
||||
|
||||
// Create new.
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_front(value);
|
||||
}
|
||||
|
||||
position = _begin;
|
||||
|
||||
// Create copy.
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
create_element_front(*from--);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
from = position - n_copy_old;
|
||||
to = _begin + n_create_copy;
|
||||
etl::copy_n(from, n_copy_old, to);
|
||||
|
||||
// Copy new.
|
||||
to = position - n_create_copy;
|
||||
std::fill_n(to, n_copy_new, value);
|
||||
|
||||
position = _begin + n_move;
|
||||
}
|
||||
else if (insert_position == end())
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Create new.
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_back(value);
|
||||
}
|
||||
|
||||
position = _end - n;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-const insert iterator.
|
||||
position = iterator(insert_position.index, *this, p_buffer);
|
||||
// Create copy.
|
||||
const_iterator from = position + n_copy_old;
|
||||
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, insert_position) <= difference_type(current_size / 2))
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(begin(), position);
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Remember the original start.
|
||||
iterator from = _begin + n_create_copy - 1;
|
||||
iterator to;
|
||||
|
||||
// Create new.
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_front(value);
|
||||
}
|
||||
|
||||
// Create copy.
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
create_element_front(*from--);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
from = position - n_copy_old;
|
||||
to = _begin + n_create_copy;
|
||||
etl::copy_n(from, n_copy_old, to);
|
||||
|
||||
// Copy new.
|
||||
to = position - n_create_copy;
|
||||
std::fill_n(to, n_copy_new, value);
|
||||
|
||||
position = _begin + n_move;
|
||||
create_element_back(*from++);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Create new.
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_back(value);
|
||||
}
|
||||
// Copy old.
|
||||
std::copy_backward(position, position + n_copy_old, position + n_insert + n_copy_old);
|
||||
|
||||
// Create copy.
|
||||
const_iterator from = position + n_copy_old;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
create_element_back(*from++);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
std::copy_backward(position, position + n_copy_old, position + n_insert + n_copy_old);
|
||||
|
||||
// Copy new.
|
||||
std::fill_n(position, n_copy_new, value);
|
||||
}
|
||||
// Copy new.
|
||||
std::fill_n(position, n_copy_new, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -879,93 +876,92 @@ namespace etl
|
||||
|
||||
difference_type n = std::distance(range_begin, range_end);
|
||||
|
||||
if (ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(deque_full)))
|
||||
ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(deque_full));
|
||||
|
||||
if (insert_position == begin())
|
||||
{
|
||||
if (insert_position == begin())
|
||||
{
|
||||
create_element_front(n, range_begin);
|
||||
create_element_front(n, range_begin);
|
||||
|
||||
position = _begin;
|
||||
position = _begin;
|
||||
}
|
||||
else if (insert_position == end())
|
||||
{
|
||||
for (difference_type i = 0; i < n; ++i)
|
||||
{
|
||||
create_element_back(*range_begin++);
|
||||
}
|
||||
else if (insert_position == end())
|
||||
{
|
||||
for (difference_type i = 0; i < n; ++i)
|
||||
{
|
||||
create_element_back(*range_begin++);
|
||||
}
|
||||
|
||||
position = _end - n;
|
||||
position = _end - n;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-const insert iterator.
|
||||
position = iterator(insert_position.index, *this, p_buffer);
|
||||
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, insert_position) < difference_type(current_size / 2))
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(begin(), position);
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Remember the original start.
|
||||
iterator from;
|
||||
iterator to;
|
||||
|
||||
// Create new.
|
||||
create_element_front(n_create_new, range_begin);
|
||||
|
||||
// Create copy.
|
||||
create_element_front(n_create_copy, _begin + n_create_new);
|
||||
|
||||
// Copy old.
|
||||
from = position - n_copy_old;
|
||||
to = _begin + n_create_copy;
|
||||
etl::copy_n(from, n_copy_old, to);
|
||||
|
||||
// Copy new.
|
||||
to = position - n_create_copy;
|
||||
range_begin += n_create_new;
|
||||
etl::copy_n(range_begin, n_copy_new, to);
|
||||
|
||||
position = _begin + n_move;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-const insert iterator.
|
||||
position = iterator(insert_position.index, *this, p_buffer);
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, insert_position) < difference_type(current_size / 2))
|
||||
// Create new.
|
||||
TIterator item = range_begin + (n - n_create_new);
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(begin(), position);
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Remember the original start.
|
||||
iterator from;
|
||||
iterator to;
|
||||
|
||||
// Create new.
|
||||
create_element_front(n_create_new, range_begin);
|
||||
|
||||
// Create copy.
|
||||
create_element_front(n_create_copy, _begin + n_create_new);
|
||||
|
||||
// Copy old.
|
||||
from = position - n_copy_old;
|
||||
to = _begin + n_create_copy;
|
||||
etl::copy_n(from, n_copy_old, to);
|
||||
|
||||
// Copy new.
|
||||
to = position - n_create_copy;
|
||||
range_begin += n_create_new;
|
||||
etl::copy_n(range_begin, n_copy_new, to);
|
||||
|
||||
position = _begin + n_move;
|
||||
create_element_back(*item++);
|
||||
}
|
||||
else
|
||||
|
||||
// Create copy.
|
||||
const_iterator from = position + n_copy_old;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = n_move - n_create_copy;
|
||||
|
||||
// Create new.
|
||||
TIterator item = range_begin + (n - n_create_new);
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_back(*item++);
|
||||
}
|
||||
|
||||
// Create copy.
|
||||
const_iterator from = position + n_copy_old;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
create_element_back(*from++);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
std::copy_backward(position, position + n_copy_old, position + n_insert + n_copy_old);
|
||||
|
||||
// Copy new.
|
||||
item = range_begin;
|
||||
etl::copy_n(item, n_copy_new, position);
|
||||
create_element_back(*from++);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
std::copy_backward(position, position + n_copy_old, position + n_insert + n_copy_old);
|
||||
|
||||
// Copy new.
|
||||
item = range_begin;
|
||||
etl::copy_n(item, n_copy_new, position);
|
||||
}
|
||||
}
|
||||
|
||||
@ -981,32 +977,31 @@ namespace etl
|
||||
{
|
||||
iterator position(erase_position.index, *this, p_buffer);
|
||||
|
||||
if (ETL_ASSERT(distance(position) <= difference_type(current_size), ETL_ERROR(deque_out_of_bounds)))
|
||||
ETL_ASSERT(distance(position) <= difference_type(current_size), ETL_ERROR(deque_out_of_bounds));
|
||||
|
||||
if (position == _begin)
|
||||
{
|
||||
if (position == _begin)
|
||||
destroy_element_front();
|
||||
position = begin();
|
||||
}
|
||||
else if (position == _end - 1)
|
||||
{
|
||||
destroy_element_back();
|
||||
position = end();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, position) < difference_type(current_size / 2))
|
||||
{
|
||||
std::copy_backward(_begin, position, position + 1);
|
||||
destroy_element_front();
|
||||
position = begin();
|
||||
}
|
||||
else if (position == _end - 1)
|
||||
{
|
||||
destroy_element_back();
|
||||
position = end();
|
||||
++position;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, position) < difference_type(current_size / 2))
|
||||
{
|
||||
std::copy_backward(_begin, position, position + 1);
|
||||
destroy_element_front();
|
||||
++position;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(position + 1, _end, position);
|
||||
destroy_element_back();
|
||||
}
|
||||
std::copy(position + 1, _end, position);
|
||||
destroy_element_back();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1023,58 +1018,57 @@ namespace etl
|
||||
{
|
||||
iterator position(range_begin.index, *this, p_buffer);
|
||||
|
||||
if (ETL_ASSERT((distance(range_begin) <= difference_type(current_size)) && (distance(range_end) <= difference_type(current_size)), ETL_ERROR(deque_out_of_bounds)))
|
||||
{
|
||||
// How many to erase?
|
||||
size_t length = std::distance(range_begin, range_end);
|
||||
ETL_ASSERT((distance(range_begin) <= difference_type(current_size)) && (distance(range_end) <= difference_type(current_size)), ETL_ERROR(deque_out_of_bounds));
|
||||
|
||||
// At the beginning?
|
||||
if (position == _begin)
|
||||
// How many to erase?
|
||||
size_t length = std::distance(range_begin, range_end);
|
||||
|
||||
// At the beginning?
|
||||
if (position == _begin)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
destroy_element_front();
|
||||
}
|
||||
|
||||
position = begin();
|
||||
}
|
||||
// At the end?
|
||||
else if (position == _end - length)
|
||||
{
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
destroy_element_back();
|
||||
}
|
||||
|
||||
position = end();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy the smallest number of items.
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, position) < difference_type(current_size / 2))
|
||||
{
|
||||
// Move the items.
|
||||
std::copy_backward(_begin, position, position + length);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
destroy_element_front();
|
||||
}
|
||||
|
||||
position = begin();
|
||||
position += length;
|
||||
}
|
||||
// At the end?
|
||||
else if (position == _end - length)
|
||||
else
|
||||
// Must be closer to the back.
|
||||
{
|
||||
// Move the items.
|
||||
std::copy(position + length, _end, position);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
destroy_element_back();
|
||||
}
|
||||
|
||||
position = end();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy the smallest number of items.
|
||||
// Are we closer to the front?
|
||||
if (distance(_begin, position) < difference_type(current_size / 2))
|
||||
{
|
||||
// Move the items.
|
||||
std::copy_backward(_begin, position, position + length);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
destroy_element_front();
|
||||
}
|
||||
|
||||
position += length;
|
||||
}
|
||||
else
|
||||
// Must be closer to the back.
|
||||
{
|
||||
// Move the items.
|
||||
std::copy(position + length, _end, position);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
{
|
||||
destroy_element_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1088,10 +1082,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_back(parameter_t item)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(deque_full)))
|
||||
{
|
||||
create_element_back(item);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
|
||||
create_element_back(item);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1103,10 +1095,8 @@ namespace etl
|
||||
{
|
||||
reference r = *_end;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(deque_full)))
|
||||
{
|
||||
create_element_back();
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
|
||||
create_element_back();
|
||||
|
||||
return r;
|
||||
}
|
||||
@ -1116,10 +1106,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_back()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
destroy_element_back();
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(deque_empty));
|
||||
destroy_element_back();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1129,10 +1117,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_front(parameter_t item)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(deque_full)))
|
||||
{
|
||||
create_element_front(item);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
|
||||
create_element_front(item);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1142,10 +1128,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
reference push_front()
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(deque_full)))
|
||||
{
|
||||
create_element_front();
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
|
||||
create_element_front();
|
||||
|
||||
return *_begin;
|
||||
}
|
||||
@ -1155,10 +1139,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_front()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
destroy_element_front();
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(deque_empty));
|
||||
destroy_element_front();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1169,25 +1151,24 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void resize(size_t new_size, const value_type& value = value_type())
|
||||
{
|
||||
if (ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(deque_out_of_bounds)))
|
||||
{
|
||||
// Make it smaller?
|
||||
if (new_size < current_size)
|
||||
{
|
||||
while (current_size > new_size)
|
||||
{
|
||||
destroy_element_back();
|
||||
}
|
||||
}
|
||||
// Make it larger?
|
||||
else if (new_size > current_size)
|
||||
{
|
||||
size_t count = new_size - current_size;
|
||||
ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(deque_out_of_bounds));
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
create_element_back(value);
|
||||
}
|
||||
// Make it smaller?
|
||||
if (new_size < current_size)
|
||||
{
|
||||
while (current_size > new_size)
|
||||
{
|
||||
destroy_element_back();
|
||||
}
|
||||
}
|
||||
// Make it larger?
|
||||
else if (new_size > current_size)
|
||||
{
|
||||
size_t count = new_size - current_size;
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
create_element_back(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
iflat_map.h
20
iflat_map.h
@ -300,12 +300,10 @@ namespace etl
|
||||
if (i_element == end())
|
||||
{
|
||||
// At the end.
|
||||
if (ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_map_full)))
|
||||
{
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_map_full));
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -321,12 +319,10 @@ namespace etl
|
||||
else
|
||||
{
|
||||
// A new one.
|
||||
if (ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_map_full)))
|
||||
{
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_map_full));
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -246,22 +246,21 @@ namespace etl
|
||||
|
||||
iterator i_element = lower_bound(value.first);
|
||||
|
||||
if (ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_multimap_full)))
|
||||
ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_multimap_full));
|
||||
|
||||
if (i_element == end())
|
||||
{
|
||||
if (i_element == end())
|
||||
{
|
||||
// At the end.
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not at the end.
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
// At the end.
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not at the end.
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -221,26 +221,25 @@ namespace etl
|
||||
{
|
||||
std::pair<iterator, bool> result(end(), false);
|
||||
|
||||
if (ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_multiset_full)))
|
||||
ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_multiset_full));
|
||||
|
||||
iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare());
|
||||
|
||||
if (i_element == end())
|
||||
{
|
||||
iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare());
|
||||
|
||||
if (i_element == end())
|
||||
{
|
||||
// At the end.
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not at the end.
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
// At the end.
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Not at the end.
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
39
iflat_set.h
39
iflat_set.h
@ -220,32 +220,31 @@ namespace etl
|
||||
{
|
||||
std::pair<iterator, bool> result(end(), false);
|
||||
|
||||
if (ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_set_full)))
|
||||
{
|
||||
iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare());
|
||||
ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_set_full));
|
||||
|
||||
if (i_element == end())
|
||||
iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare());
|
||||
|
||||
if (i_element == end())
|
||||
{
|
||||
// At the end. Doesn't exist.
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not at the end.
|
||||
// Does not exist already?
|
||||
if (*i_element != value)
|
||||
{
|
||||
// At the end. Doesn't exist.
|
||||
buffer.push_back(value);
|
||||
result.first = end() - 1;
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not at the end.
|
||||
// Does not exist already?
|
||||
if (*i_element != value)
|
||||
{
|
||||
buffer.insert(i_element, value);
|
||||
result.first = i_element;
|
||||
result.second = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.first = i_element;
|
||||
result.second = false;
|
||||
}
|
||||
result.first = i_element;
|
||||
result.second = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
135
iforward_list.h
135
iforward_list.h
@ -374,14 +374,13 @@ namespace etl
|
||||
// Add all of the elements.
|
||||
while (first != last)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(forward_list_iterator)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(*first++);
|
||||
join(p_last_node, &data_node);
|
||||
data_node.next = nullptr;
|
||||
p_last_node = &data_node;
|
||||
++current_size;
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(forward_list_iterator));
|
||||
|
||||
Data_Node& data_node = allocate_data_node(*first++);
|
||||
join(p_last_node, &data_node);
|
||||
data_node.next = nullptr;
|
||||
p_last_node = &data_node;
|
||||
++current_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,21 +389,20 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void assign(size_t n, parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full)))
|
||||
ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full));
|
||||
|
||||
initialise();
|
||||
|
||||
Node* p_last_node = &start_node;
|
||||
|
||||
// Add all of the elements.
|
||||
while (current_size < n)
|
||||
{
|
||||
initialise();
|
||||
|
||||
Node* p_last_node = &start_node;
|
||||
|
||||
// Add all of the elements.
|
||||
while (current_size < n)
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
join(p_last_node, &data_node);
|
||||
data_node.next = nullptr;
|
||||
p_last_node = &data_node;
|
||||
++current_size;
|
||||
}
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
join(p_last_node, &data_node);
|
||||
data_node.next = nullptr;
|
||||
p_last_node = &data_node;
|
||||
++current_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,11 +411,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_front()
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(T());
|
||||
insert_node_after(start_node, data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
|
||||
|
||||
Data_Node& data_node = allocate_data_node(T());
|
||||
insert_node_after(start_node, data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -425,11 +422,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_front(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node_after(start_node, data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
|
||||
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node_after(start_node, data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -437,10 +433,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_front()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
remove_node_after(start_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(forward_list_empty));
|
||||
remove_node_after(start_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -458,33 +452,32 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void resize(size_t n, T value)
|
||||
{
|
||||
if (ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full)))
|
||||
ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full));
|
||||
|
||||
size_t i = 0;
|
||||
iterator i_node = begin();
|
||||
iterator i_last_node;
|
||||
|
||||
// Find where we're currently at.
|
||||
while ((i < n) && (i_node != end()))
|
||||
{
|
||||
size_t i = 0;
|
||||
iterator i_node = begin();
|
||||
iterator i_last_node;
|
||||
++i;
|
||||
i_last_node = i_node;
|
||||
++i_node;
|
||||
}
|
||||
|
||||
// Find where we're currently at.
|
||||
while ((i < n) && (i_node != end()))
|
||||
if (i_node != end())
|
||||
{
|
||||
// Reduce.
|
||||
erase_after(i_node, end());
|
||||
}
|
||||
else if (i_node == end())
|
||||
{
|
||||
// Increase.
|
||||
while (i < n)
|
||||
{
|
||||
i_last_node = insert_after(i_last_node, value);
|
||||
++i;
|
||||
i_last_node = i_node;
|
||||
++i_node;
|
||||
}
|
||||
|
||||
if (i_node != end())
|
||||
{
|
||||
// Reduce.
|
||||
erase_after(i_node, end());
|
||||
}
|
||||
else if (i_node == end())
|
||||
{
|
||||
// Increase.
|
||||
while (i < n)
|
||||
{
|
||||
i_last_node = insert_after(i_last_node, value);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -494,13 +487,12 @@ namespace etl
|
||||
//*************************************************************************
|
||||
iterator insert_after(iterator position, parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node_after(*position.p_node, data_node);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
|
||||
|
||||
return iterator(data_node);
|
||||
}
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node_after(*position.p_node, data_node);
|
||||
|
||||
return iterator(data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -508,14 +500,13 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void insert_after(iterator position, size_t n, parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)))
|
||||
ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
|
||||
|
||||
for (size_t i = 0; !full() && (i < n); ++i)
|
||||
{
|
||||
for (size_t i = 0; !full() && (i < n); ++i)
|
||||
{
|
||||
// Set up the next free node.
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(*position.p_node, data_node);
|
||||
}
|
||||
// Set up the next free node.
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(*position.p_node, data_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
112
ilist.h
112
ilist.h
@ -495,11 +495,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_front()
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(T());
|
||||
insert_node(get_head(), data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
Data_Node& data_node = allocate_data_node(T());
|
||||
insert_node(get_head(), data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -507,11 +506,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_front(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
Node& data_node = allocate_data_node(value);
|
||||
insert_node(get_head(), data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
Node& data_node = allocate_data_node(value);
|
||||
insert_node(get_head(), data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -519,11 +517,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_front()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
Node& node = get_head();
|
||||
remove_node(node);
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(list_empty));
|
||||
|
||||
Node& node = get_head();
|
||||
remove_node(node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -531,11 +528,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_back()
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(T());
|
||||
insert_node(terminal_node, data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
Data_Node& data_node = allocate_data_node(T());
|
||||
insert_node(terminal_node, data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -543,11 +539,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_back(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(terminal_node, data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(terminal_node, data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -555,11 +550,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_back()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
Node& node = get_tail();
|
||||
remove_node(node);
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(list_empty));
|
||||
|
||||
Node& node = get_tail();
|
||||
remove_node(node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -567,13 +561,12 @@ namespace etl
|
||||
//*************************************************************************
|
||||
iterator insert(iterator position, const value_type& value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(*position.p_node, data_node);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
return iterator(data_node);
|
||||
}
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(*position.p_node, data_node);
|
||||
|
||||
return iterator(data_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -583,12 +576,11 @@ namespace etl
|
||||
{
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
// Set up the next free node and insert.
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(*position.p_node, data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
// Set up the next free node and insert.
|
||||
Data_Node& data_node = allocate_data_node(value);
|
||||
insert_node(*position.p_node, data_node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -600,12 +592,11 @@ namespace etl
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(list_full)))
|
||||
{
|
||||
// Set up the next free node and insert.
|
||||
Data_Node& data_node = allocate_data_node(*first++);
|
||||
insert_node(*position.p_node, data_node);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(list_full));
|
||||
|
||||
// Set up the next free node and insert.
|
||||
Data_Node& data_node = allocate_data_node(*first++);
|
||||
insert_node(*position.p_node, data_node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,20 +652,19 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void resize(size_t n, parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(list_full)))
|
||||
ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(list_full));
|
||||
|
||||
// Smaller?
|
||||
if (n < size())
|
||||
{
|
||||
// Smaller?
|
||||
if (n < size())
|
||||
{
|
||||
iterator i_start = end();
|
||||
std::advance(i_start, -difference_type(size() - n));
|
||||
erase(i_start, end());
|
||||
}
|
||||
// Larger?
|
||||
else if (n > size())
|
||||
{
|
||||
insert(end(), n - size(), value);
|
||||
}
|
||||
iterator i_start = end();
|
||||
std::advance(i_start, -difference_type(size() - n));
|
||||
erase(i_start, end());
|
||||
}
|
||||
// Larger?
|
||||
else if (n > size())
|
||||
{
|
||||
insert(end(), n - size(), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
imap.h
41
imap.h
@ -691,15 +691,14 @@ namespace etl
|
||||
Node* inserted_node = nullptr;
|
||||
bool inserted = false;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(map_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(map_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
inserted = inserted_node == &node;
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
inserted = inserted_node == &node;
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return std::make_pair(iterator(*this, inserted_node), inserted);
|
||||
@ -716,14 +715,13 @@ namespace etl
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(map_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(map_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return iterator(*this, inserted_node);
|
||||
@ -740,14 +738,13 @@ namespace etl
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(map_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(map_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return iterator(*this, inserted_node);
|
||||
|
||||
13
imultimap.h
13
imultimap.h
@ -656,14 +656,13 @@ namespace etl
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(multimap_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(multimap_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return iterator(*this, inserted_node);
|
||||
|
||||
13
imultiset.h
13
imultiset.h
@ -637,15 +637,14 @@ namespace etl
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(multiset_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(multiset_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return iterator(*this, inserted_node);
|
||||
}
|
||||
|
||||
@ -60,6 +60,20 @@ namespace etl
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Empty exception for the intrusive_forward_list.
|
||||
///\ingroup intrusive_forward_list
|
||||
//***************************************************************************
|
||||
class intrusive_forward_list_empty : public intrusive_forward_list_exception
|
||||
{
|
||||
public:
|
||||
|
||||
intrusive_forward_list_empty(string_type file_name, numeric_type line_number)
|
||||
: intrusive_forward_list_exception(ETL_ERROR_TEXT("intrusive_forward_list:empty", ETL_FILE"A"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Iterator exception for the intrusive_forward_list.
|
||||
///\ingroup intrusive_forward_list
|
||||
@ -69,7 +83,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
intrusive_forward_list_iterator_exception(string_type file_name, numeric_type line_number)
|
||||
: intrusive_forward_list_exception("intrusive_forward_list: iterator", file_name, line_number)
|
||||
: intrusive_forward_list_exception(ETL_ERROR_TEXT("intrusive_forward_list:iterator", ETL_FILE"B"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -83,7 +97,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
intrusive_forward_list_index_exception(string_type file_name, numeric_type line_number)
|
||||
: intrusive_forward_list_exception("intrusive_forward_list:bounds", file_name, line_number)
|
||||
: intrusive_forward_list_exception(ETL_ERROR_TEXT("intrusive_forward_list:bounds", ETL_FILE"C"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -440,10 +454,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_front()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
remove_node_after(start_node);
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(intrusive_forward_list_empty));
|
||||
remove_node_after(start_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
69
ipool.h
69
ipool.h
@ -324,21 +324,16 @@ namespace etl
|
||||
T* allocate()
|
||||
{
|
||||
#if defined(_DEBUG) || defined(DEBUG)
|
||||
if (ETL_ASSERT(items_allocated < MAX_SIZE && !in_use_flags.test(next_free), ETL_ERROR(pool_no_allocation)))
|
||||
ETL_ASSERT(items_allocated < MAX_SIZE && !in_use_flags.test(next_free), ETL_ERROR(pool_no_allocation));
|
||||
#else
|
||||
if (ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation)))
|
||||
ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation));
|
||||
#endif
|
||||
{
|
||||
T* result = new(&p_buffer[next_free]) T();
|
||||
in_use_flags.set(next_free);
|
||||
next_free = in_use_flags.find_first(false);
|
||||
++items_allocated;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
T* result = new(&p_buffer[next_free]) T();
|
||||
in_use_flags.set(next_free);
|
||||
next_free = in_use_flags.find_first(false);
|
||||
++items_allocated;
|
||||
return result;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -350,21 +345,16 @@ namespace etl
|
||||
T* allocate(const T& initial)
|
||||
{
|
||||
#if defined(_DEBUG) || defined(DEBUG)
|
||||
if (ETL_ASSERT(items_allocated < MAX_SIZE && !in_use_flags.test(next_free), ETL_ERROR(pool_no_allocation)))
|
||||
ETL_ASSERT(items_allocated < MAX_SIZE && !in_use_flags.test(next_free), ETL_ERROR(pool_no_allocation));
|
||||
#else
|
||||
if (ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation)))
|
||||
ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation));
|
||||
#endif
|
||||
{
|
||||
T* result = new(&p_buffer[next_free]) T(initial);
|
||||
in_use_flags.set(next_free);
|
||||
next_free = in_use_flags.find_first(false);
|
||||
++items_allocated;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
T* result = new(&p_buffer[next_free]) T(initial);
|
||||
in_use_flags.set(next_free);
|
||||
next_free = in_use_flags.find_first(false);
|
||||
++items_allocated;
|
||||
return result;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -387,21 +377,20 @@ namespace etl
|
||||
void release(const T* const p_object)
|
||||
{
|
||||
// Does it belong to me?
|
||||
if (ETL_ASSERT(is_in_pool(p_object), ETL_ERROR(pool_object_not_in_pool)))
|
||||
{
|
||||
// Where is it in the buffer?
|
||||
typename std::iterator_traits<T*>::difference_type distance = p_object - p_buffer;
|
||||
size_t index = static_cast<size_t>(distance);
|
||||
ETL_ASSERT(is_in_pool(p_object), ETL_ERROR(pool_object_not_in_pool));
|
||||
|
||||
// Check that it hasn't already been released.
|
||||
if (in_use_flags.test(index))
|
||||
{
|
||||
// Destroy the object and mark as available.
|
||||
p_object->~T();
|
||||
in_use_flags.reset(index);
|
||||
--items_allocated;
|
||||
next_free = index;
|
||||
}
|
||||
// Where is it in the buffer?
|
||||
typename std::iterator_traits<T*>::difference_type distance = p_object - p_buffer;
|
||||
size_t index = static_cast<size_t>(distance);
|
||||
|
||||
// Check that it hasn't already been released.
|
||||
if (in_use_flags.test(index))
|
||||
{
|
||||
// Destroy the object and mark as available.
|
||||
p_object->~T();
|
||||
in_use_flags.reset(index);
|
||||
--items_allocated;
|
||||
next_free = index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -102,15 +102,14 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(priority_queue_full)))
|
||||
{
|
||||
// Put element at end
|
||||
container.push_back(value);
|
||||
// Pre-increment size
|
||||
++current_size;
|
||||
// Make elements in container into heap
|
||||
std::push_heap(container.begin(), container.end(), TCompare());
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(priority_queue_full));
|
||||
|
||||
// Put element at end
|
||||
container.push_back(value);
|
||||
// Pre-increment size
|
||||
++current_size;
|
||||
// Make elements in container into heap
|
||||
std::push_heap(container.begin(), container.end(), TCompare());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -122,7 +121,7 @@ namespace etl
|
||||
current_size = 0;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
//*************************************************************************
|
||||
/// Assigns values to the priority queue.
|
||||
/// If ETL_THROW_EXCEPTIONS is defined, emits priority_queue_full if
|
||||
/// priority queue does not have enough free space.
|
||||
@ -130,7 +129,7 @@ namespace etl
|
||||
/// iterators are reversed.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*********************************************************************
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
void assign(TIterator first, TIterator last)
|
||||
{
|
||||
|
||||
33
iqueue.h
33
iqueue.h
@ -114,12 +114,11 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(queue_full)))
|
||||
{
|
||||
new(&p_buffer[in]) T(value);
|
||||
in = (in == (MAX_SIZE - 1)) ? 0 : in + 1;
|
||||
++current_size;
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
|
||||
|
||||
new(&p_buffer[in]) T(value);
|
||||
in = (in == (MAX_SIZE - 1)) ? 0 : in + 1;
|
||||
++current_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -134,12 +133,11 @@ namespace etl
|
||||
{
|
||||
const size_type next = in;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(queue_full)))
|
||||
{
|
||||
new(&p_buffer[in]) T();
|
||||
in = (in == (MAX_SIZE - 1)) ? 0 : in + 1;
|
||||
++current_size;
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
|
||||
|
||||
new(&p_buffer[in]) T();
|
||||
in = (in == (MAX_SIZE - 1)) ? 0 : in + 1;
|
||||
++current_size;
|
||||
|
||||
return p_buffer[next];
|
||||
}
|
||||
@ -166,12 +164,11 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop()
|
||||
{
|
||||
if ETL_ASSERT(!empty(), ETL_ERROR(queue_empty))
|
||||
{
|
||||
p_buffer[out].~T();
|
||||
out = (out == (MAX_SIZE - 1)) ? 0 : out + 1;
|
||||
--current_size;
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(queue_empty));
|
||||
|
||||
p_buffer[out].~T();
|
||||
out = (out == (MAX_SIZE - 1)) ? 0 : out + 1;
|
||||
--current_size;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
41
iset.h
41
iset.h
@ -633,15 +633,14 @@ namespace etl
|
||||
Node* inserted_node = nullptr;
|
||||
bool inserted = false;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(set_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(set_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
inserted = inserted_node == &node;
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
inserted = inserted_node == &node;
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return std::make_pair(iterator(*this, inserted_node), inserted);
|
||||
@ -658,14 +657,13 @@ namespace etl
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(set_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(set_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return iterator(*this, inserted_node);
|
||||
@ -682,14 +680,13 @@ namespace etl
|
||||
// Default to no inserted node
|
||||
Node* inserted_node = nullptr;
|
||||
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(set_full)))
|
||||
{
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
ETL_ASSERT(!full(), ETL_ERROR(set_full));
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
}
|
||||
// Get next available free node
|
||||
Data_Node& node = allocate_data_node(value);
|
||||
|
||||
// Obtain the inserted node (might be nullptr if node was a duplicate)
|
||||
inserted_node = insert_node(root_node, node);
|
||||
|
||||
// Insert node into tree and return iterator to new node location in tree
|
||||
return iterator(*this, inserted_node);
|
||||
|
||||
29
istack.h
29
istack.h
@ -86,11 +86,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(stack_full)))
|
||||
{
|
||||
top_index = current_size++;
|
||||
new(&p_buffer[top_index]) T(value);
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
|
||||
top_index = current_size++;
|
||||
new(&p_buffer[top_index]) T(value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -102,11 +101,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
reference push()
|
||||
{
|
||||
if (ETL_ASSERT(!full(), ETL_ERROR(stack_full)))
|
||||
{
|
||||
top_index = current_size++;
|
||||
new(&p_buffer[top_index]) T();
|
||||
}
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
|
||||
top_index = current_size++;
|
||||
new(&p_buffer[top_index]) T();
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
@ -139,12 +137,11 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop()
|
||||
{
|
||||
if (!empty())
|
||||
{
|
||||
p_buffer[top_index].~T();
|
||||
--top_index;
|
||||
--current_size;
|
||||
}
|
||||
ETL_ASSERT(!empty(), ETL_ERROR(stack_empty));
|
||||
|
||||
p_buffer[top_index].~T();
|
||||
--top_index;
|
||||
--current_size;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
266
ivector.h
266
ivector.h
@ -193,25 +193,24 @@ namespace etl
|
||||
//*********************************************************************
|
||||
void resize(size_t new_size)
|
||||
{
|
||||
if (ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full));
|
||||
|
||||
// Size up or size down?
|
||||
if (new_size > current_size)
|
||||
{
|
||||
// Size up or size down?
|
||||
if (new_size > current_size)
|
||||
for (size_t i = current_size; i < new_size; ++i)
|
||||
{
|
||||
for (size_t i = current_size; i < new_size; ++i)
|
||||
while (current_size < new_size)
|
||||
{
|
||||
while (current_size < new_size)
|
||||
{
|
||||
create_element();
|
||||
}
|
||||
create_element();
|
||||
}
|
||||
}
|
||||
else if (new_size < current_size)
|
||||
}
|
||||
else if (new_size < current_size)
|
||||
{
|
||||
while (current_size > new_size)
|
||||
{
|
||||
while (current_size > new_size)
|
||||
{
|
||||
destroy_element();
|
||||
}
|
||||
destroy_element();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -225,23 +224,22 @@ namespace etl
|
||||
//*********************************************************************
|
||||
void resize(size_t new_size, T value)
|
||||
{
|
||||
if (ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full));
|
||||
|
||||
// Size up?
|
||||
if (new_size > current_size)
|
||||
{
|
||||
// Size up?
|
||||
if (new_size > current_size)
|
||||
while (current_size < new_size)
|
||||
{
|
||||
while (current_size < new_size)
|
||||
{
|
||||
create_element(value);
|
||||
}
|
||||
create_element(value);
|
||||
}
|
||||
// Size down?
|
||||
else if (new_size < current_size)
|
||||
}
|
||||
// Size down?
|
||||
else if (new_size < current_size)
|
||||
{
|
||||
while (current_size > new_size)
|
||||
{
|
||||
while (current_size > new_size)
|
||||
{
|
||||
destroy_element();
|
||||
}
|
||||
destroy_element();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -380,13 +378,12 @@ namespace etl
|
||||
{
|
||||
initialise();
|
||||
|
||||
if (ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(vector_full));
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
create_element(value);
|
||||
--n;
|
||||
}
|
||||
create_element(value);
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,10 +401,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void push_back()
|
||||
{
|
||||
if (ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
{
|
||||
create_element();
|
||||
}
|
||||
ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full));
|
||||
create_element();
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
@ -417,10 +412,8 @@ namespace etl
|
||||
//*********************************************************************
|
||||
void push_back(parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
{
|
||||
create_element(value);
|
||||
}
|
||||
ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full));
|
||||
create_element(value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -429,10 +422,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void pop_back()
|
||||
{
|
||||
if (current_size > 0)
|
||||
{
|
||||
destroy_element();
|
||||
}
|
||||
ETL_ASSERT(current_size > 0, ETL_ERROR(vector_empty));
|
||||
destroy_element();
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
@ -443,15 +434,14 @@ namespace etl
|
||||
//*********************************************************************
|
||||
iterator insert(iterator position, parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT((current_size) + 1 <= MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
{
|
||||
create_element(value);
|
||||
ETL_ASSERT((current_size)+1 <= MAX_SIZE, ETL_ERROR(vector_full));
|
||||
|
||||
if (position != end())
|
||||
{
|
||||
std::copy_backward(position, end() - 1, end());
|
||||
*position = value;
|
||||
}
|
||||
create_element(value);
|
||||
|
||||
if (position != end())
|
||||
{
|
||||
std::copy_backward(position, end() - 1, end());
|
||||
*position = value;
|
||||
}
|
||||
|
||||
return position;
|
||||
@ -466,54 +456,53 @@ namespace etl
|
||||
//*********************************************************************
|
||||
void insert(iterator position, size_t n, parameter_t value)
|
||||
{
|
||||
if (ETL_ASSERT((current_size) + 1 <= MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
ETL_ASSERT((current_size)+1 <= MAX_SIZE, ETL_ERROR(vector_full));
|
||||
|
||||
if (position == end())
|
||||
{
|
||||
if (position == end())
|
||||
while (n > 0)
|
||||
{
|
||||
while (n > 0)
|
||||
{
|
||||
create_element(value);
|
||||
--n;
|
||||
}
|
||||
create_element(value);
|
||||
--n;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0;
|
||||
|
||||
// Create copy (backwards).
|
||||
size_t from = size() - 1;
|
||||
size_t to = from + n_insert;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = n;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0;
|
||||
|
||||
// Create copy (backwards).
|
||||
size_t from = size() - 1;
|
||||
size_t to = from + n_insert;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
create_element_at(to--, p_buffer[from--]);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
from = insert_index;
|
||||
to = from + n_insert;
|
||||
etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]);
|
||||
|
||||
// Copy new.
|
||||
to = insert_index;
|
||||
std::fill_n(&p_buffer[to], n_copy_new, value);
|
||||
|
||||
// Create new.
|
||||
to = size();
|
||||
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_at(to++, value);
|
||||
}
|
||||
|
||||
current_size += n_insert;
|
||||
create_element_at(to--, p_buffer[from--]);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
from = insert_index;
|
||||
to = from + n_insert;
|
||||
etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]);
|
||||
|
||||
// Copy new.
|
||||
to = insert_index;
|
||||
std::fill_n(&p_buffer[to], n_copy_new, value);
|
||||
|
||||
// Create new.
|
||||
to = size();
|
||||
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_at(to++, value);
|
||||
}
|
||||
|
||||
current_size += n_insert;
|
||||
}
|
||||
}
|
||||
|
||||
@ -529,55 +518,54 @@ namespace etl
|
||||
{
|
||||
size_t count = std::distance(first, last);
|
||||
|
||||
if (ETL_ASSERT((current_size) + count <= MAX_SIZE, ETL_ERROR(vector_full)))
|
||||
ETL_ASSERT((current_size)+count <= MAX_SIZE, ETL_ERROR(vector_full));
|
||||
|
||||
if (position == end())
|
||||
{
|
||||
if (position == end())
|
||||
while (first != last)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
create_element(*first);
|
||||
++first;
|
||||
}
|
||||
create_element(*first);
|
||||
++first;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = count;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0;
|
||||
|
||||
// Create copy (backwards).
|
||||
size_t from = size() - 1;
|
||||
size_t to = from + n_insert;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
size_t insert_index = std::distance(begin(), position);
|
||||
size_t n_insert = count;
|
||||
size_t n_move = std::distance(position, end());
|
||||
size_t n_create_copy = std::min(n_insert, n_move);
|
||||
size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0;
|
||||
size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0;
|
||||
size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0;
|
||||
|
||||
// Create copy (backwards).
|
||||
size_t from = size() - 1;
|
||||
size_t to = from + n_insert;
|
||||
|
||||
for (size_t i = 0; i < n_create_copy; ++i)
|
||||
{
|
||||
create_element_at(to--, p_buffer[from--]);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
from = insert_index;
|
||||
to = from + n_insert;
|
||||
etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]);
|
||||
|
||||
// Copy new.
|
||||
to = insert_index;
|
||||
etl::copy_n(first, n_copy_new, &p_buffer[to]);
|
||||
first += n_copy_new;
|
||||
|
||||
// Create new.
|
||||
to = size();
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_at(to++, *first);
|
||||
++first;
|
||||
}
|
||||
|
||||
current_size += n_insert;
|
||||
create_element_at(to--, p_buffer[from--]);
|
||||
}
|
||||
|
||||
// Copy old.
|
||||
from = insert_index;
|
||||
to = from + n_insert;
|
||||
etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]);
|
||||
|
||||
// Copy new.
|
||||
to = insert_index;
|
||||
etl::copy_n(first, n_copy_new, &p_buffer[to]);
|
||||
first += n_copy_new;
|
||||
|
||||
// Create new.
|
||||
to = size();
|
||||
for (size_t i = 0; i < n_create_new; ++i)
|
||||
{
|
||||
create_element_at(to++, *first);
|
||||
++first;
|
||||
}
|
||||
|
||||
current_size += n_insert;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
jenkins.h
23
jenkins.h
@ -107,15 +107,13 @@ namespace etl
|
||||
void add(TIterator begin, const TIterator end)
|
||||
{
|
||||
STATIC_ASSERT(sizeof(typename std::iterator_traits<TIterator>::value_type) == 1, "Incompatible type");
|
||||
ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised));
|
||||
|
||||
if (ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)))
|
||||
while (begin != end)
|
||||
{
|
||||
while (begin != end)
|
||||
{
|
||||
hash += *begin++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
hash += *begin++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,12 +122,11 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void add(uint8_t value)
|
||||
{
|
||||
if (ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)))
|
||||
{
|
||||
hash += value;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised));
|
||||
|
||||
hash += value;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
43
murmur3.h
43
murmur3.h
@ -120,22 +120,20 @@ namespace etl
|
||||
void add(TIterator begin, const TIterator end)
|
||||
{
|
||||
STATIC_ASSERT(sizeof(typename std::iterator_traits<TIterator>::value_type) == 1, "Incompatible type");
|
||||
ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised));
|
||||
|
||||
if (ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)))
|
||||
while (begin != end)
|
||||
{
|
||||
while (begin != end)
|
||||
block |= (*begin++) << (block_fill_count * 8);
|
||||
|
||||
if (++block_fill_count == FULL_BLOCK)
|
||||
{
|
||||
block |= (*begin++) << (block_fill_count * 8);
|
||||
|
||||
if (++block_fill_count == FULL_BLOCK)
|
||||
{
|
||||
add_block();
|
||||
block_fill_count = 0;
|
||||
block = 0;
|
||||
}
|
||||
|
||||
++char_count;
|
||||
add_block();
|
||||
block_fill_count = 0;
|
||||
block = 0;
|
||||
}
|
||||
|
||||
++char_count;
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,19 +145,18 @@ namespace etl
|
||||
void add(uint8_t value)
|
||||
{
|
||||
// We can't add to a finalised hash!
|
||||
if (ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)))
|
||||
ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised));
|
||||
|
||||
block |= value << (block_fill_count * 8);
|
||||
|
||||
if (++block_fill_count == FULL_BLOCK)
|
||||
{
|
||||
block |= value << (block_fill_count * 8);
|
||||
|
||||
if (++block_fill_count == FULL_BLOCK)
|
||||
{
|
||||
add_block();
|
||||
block_fill_count = 0;
|
||||
block = 0;
|
||||
}
|
||||
|
||||
++char_count;
|
||||
add_block();
|
||||
block_fill_count = 0;
|
||||
block = 0;
|
||||
}
|
||||
|
||||
++char_count;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -121,11 +121,10 @@ namespace etl
|
||||
if (i_observer == observer_list.end())
|
||||
{
|
||||
// Is there enough room?
|
||||
if (ETL_ASSERT(!observer_list.full(), ETL_ERROR(etl::observer_list_full)))
|
||||
{
|
||||
// Add it.
|
||||
observer_list.push_back(&observer);
|
||||
}
|
||||
ETL_ASSERT(!observer_list.full(), ETL_ERROR(etl::observer_list_full));
|
||||
|
||||
// Add it.
|
||||
observer_list.push_back(&observer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -72,6 +72,20 @@ namespace etl
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Empty exception for the forward_list.
|
||||
///\ingroup forward_list
|
||||
//***************************************************************************
|
||||
class forward_list_empty : public forward_list_exception
|
||||
{
|
||||
public:
|
||||
|
||||
forward_list_empty(string_type file_name, numeric_type line_number)
|
||||
: forward_list_exception(ETL_ERROR_TEXT("forward_list:empty", ETL_FILE"B"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Iterator exception for the forward_list.
|
||||
///\ingroup forward_list
|
||||
@ -81,7 +95,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
forward_list_iterator(string_type file_name, numeric_type line_number)
|
||||
: forward_list_exception(ETL_ERROR_TEXT("forward_list:iterator", ETL_FILE"B"), file_name, line_number)
|
||||
: forward_list_exception(ETL_ERROR_TEXT("forward_list:iterator", ETL_FILE"C"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,6 +72,20 @@ namespace etl
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Empty exception for the list.
|
||||
///\ingroup list
|
||||
//***************************************************************************
|
||||
class list_empty : public list_exception
|
||||
{
|
||||
public:
|
||||
|
||||
list_empty(string_type file_name, numeric_type line_number)
|
||||
: list_exception(ETL_ERROR_TEXT("list:empty", ETL_FILE"B"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Iterator exception for the list.
|
||||
///\ingroup list
|
||||
@ -81,7 +95,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
list_iterator(string_type file_name, numeric_type line_number)
|
||||
: list_exception(ETL_ERROR_TEXT("list:iterator", ETL_FILE"B"), file_name, line_number)
|
||||
: list_exception(ETL_ERROR_TEXT("list:iterator", ETL_FILE"C"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@ -67,7 +67,21 @@ namespace etl
|
||||
public:
|
||||
|
||||
stack_full(string_type file_name, numeric_type line_number)
|
||||
: stack_exception(ETL_ERROR_TEXT("stack: full", ETL_FILE"A"), file_name, line_number)
|
||||
: stack_exception(ETL_ERROR_TEXT("stack:full", ETL_FILE"A"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup stack
|
||||
/// The exception thrown when the stack is empty.
|
||||
//***************************************************************************
|
||||
class stack_empty : public stack_exception
|
||||
{
|
||||
public:
|
||||
|
||||
stack_empty(string_type file_name, numeric_type line_number)
|
||||
: stack_exception(ETL_ERROR_TEXT("stack:empty", ETL_FILE"B"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@ -67,7 +67,21 @@ namespace etl
|
||||
public:
|
||||
|
||||
vector_full(string_type file_name, numeric_type line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:full", ETL_FILE"0"), file_name, line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:full", ETL_FILE"A"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup vector
|
||||
/// Vector empty exception.
|
||||
//***************************************************************************
|
||||
class vector_empty : public vector_exception
|
||||
{
|
||||
public:
|
||||
|
||||
vector_empty(string_type file_name, numeric_type line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:empty", ETL_FILE"B"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -81,7 +95,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
vector_out_of_bounds(string_type file_name, numeric_type line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:bounds", ETL_FILE"1"), file_name, line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:bounds", ETL_FILE"C"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -95,7 +109,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
vector_iterator(string_type file_name, numeric_type line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:iterator", ETL_FILE"2"), file_name, line_number)
|
||||
: vector_exception(ETL_ERROR_TEXT("vector:iterator", ETL_FILE"D"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user