Merge remote-tracking branch 'origin/development'

This commit is contained in:
John Wellbelove 2015-12-10 14:11:20 +00:00
commit 0025ab6ef5
43 changed files with 589 additions and 519 deletions

19
array.h
View File

@ -111,37 +111,22 @@ namespace etl
//*************************************************************************
/// Returns a reference to the value at index 'i'.
/// If ETL_THROW_EXCEPTIONS is defined then am array_out_of_range is
/// thown if the index is out of range.
///\param i The index of the element to access.
//*************************************************************************
reference at(size_t i)
{
if (i >= SIZE)
{
#ifdef ETL_THROW_EXCEPTIONS
throw array_out_of_range();
#else
error_handler::error(array_out_of_range());
#endif
}
ETL_ASSERT(i < SIZE, array_out_of_range());
return _buffer[i];
}
//*************************************************************************
/// Returns a const reference to the value at index 'i'.
/// If ETL_THROW_EXCEPTIONS is defined then am array_out_of_range is
/// thown if the index is out of range.
///\param i The index of the element to access.
//*************************************************************************
const_reference at(size_t i) const
{
if (i >= SIZE)
{
ETL_ERROR(array_out_of_range());
}
ETL_ASSERT(i < SIZE, array_out_of_range());
return _buffer[i];
}

173
bitset.h
View File

@ -36,10 +36,14 @@ SOFTWARE.
#include <stddef.h>
#include "integral_limits.h"
#include "algorithm.h"
#include "nullptr.h"
#include "log.h"
#include "ibitset.h"
#define ETL_NO_CHECKS
#include "error_handler.h"
#if defined(COMPILER_KEIL)
#pragma diag_suppress 1300
#endif
@ -70,9 +74,7 @@ namespace etl
static const size_t ALLOCATED_BITS = ARRAY_SIZE * BITS_PER_ELEMENT;
public:
//*************************************************************************
/// Default constructor.
//*************************************************************************
@ -88,7 +90,7 @@ namespace etl
bitset(const bitset<N>& other)
: ibitset(N, ARRAY_SIZE, data)
{
std::copy(other.data, other.data + ARRAY_SIZE, data);
etl::copy_n(other.data, ARRAY_SIZE, data);
}
//*************************************************************************
@ -97,27 +99,7 @@ namespace etl
bitset(unsigned long long value)
: ibitset(N, ARRAY_SIZE, data)
{
reset();
const size_t SHIFT = (integral_limits<unsigned long long>::bits <= BITS_PER_ELEMENT) ? 0 : BITS_PER_ELEMENT;
// Can we do it in one hit?
if (SHIFT == 0)
{
data[0] = element_t(value);
}
else
{
size_t i = 0;
while ((value != 0) && (i < ARRAY_SIZE))
{
data[i++] = value & ALL_SET;
value = value >> SHIFT;
}
}
data[ARRAY_SIZE - 1] &= TOP_MASK;
initialise(value);
}
//*************************************************************************
@ -147,12 +129,19 @@ namespace etl
return *this;
}
//#define NDEBUG
//*************************************************************************
/// Set from a string.
//*************************************************************************
bitset<N>& set(const char* text)
bitset<N>& set(const char* text)
{
ibitset::set(text);
if (ETL_ASSERT(text != 0, etl::bitset_nullptr()))
{
ibitset::set(text);
}
return *this;
}
@ -197,11 +186,7 @@ namespace etl
//*************************************************************************
bitset<N>& operator =(const bitset<N>& other)
{
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
data[i] = other.data[i];
}
etl::copy_n(other.data, ARRAY_SIZE, data);
return *this;
}
@ -210,11 +195,7 @@ namespace etl
//*************************************************************************
bitset<N>& operator &=(const bitset<N>& other)
{
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
data[i] &= other.data[i];
}
ibitset::operator &=(other);
return *this;
}
@ -223,11 +204,7 @@ namespace etl
//*************************************************************************
bitset<N>& operator |=(const bitset<N>& other)
{
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
data[i] |= other.data[i];
}
ibitset::operator |=(other);
return *this;
}
@ -236,11 +213,7 @@ namespace etl
//*************************************************************************
bitset<N>& operator ^=(const bitset<N>& other)
{
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
data[i] ^= other.data[i];
}
ibitset::operator ^=(other);
return *this;
}
@ -249,13 +222,10 @@ namespace etl
//*************************************************************************
bitset<N> operator ~() const
{
bitset<N> temp;
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
temp[i] = ~data[i];
}
bitset<N> temp(*this);
temp.invert();
return temp;
}
@ -264,22 +234,9 @@ namespace etl
//*************************************************************************
bitset<N> operator<<(size_t shift) const
{
bitset<N> temp;
bitset<N> temp(*this);
if (ARRAY_SIZE == 1)
{
temp.data[0] = data[0] << shift;
}
else
{
size_t source = N - shift - 1;
size_t destination = N - 1;
for (size_t i = 0; i < (N - shift); ++i)
{
temp.set(destination--, test(source--));
}
}
temp <<= shift;
return temp;
}
@ -289,26 +246,7 @@ namespace etl
//*************************************************************************
bitset<N>& operator<<=(size_t shift)
{
if (ARRAY_SIZE == 1)
{
data[0] <<= shift;
}
else
{
size_t source = N - shift - 1;
size_t destination = N - 1;
for (size_t i = 0; i < (N - shift); ++i)
{
set(destination--, test(source--));
}
for (size_t i = 0; i < shift; ++i)
{
reset(destination--);
}
}
ibitset::operator <<=(shift);
return *this;
}
@ -317,22 +255,9 @@ namespace etl
//*************************************************************************
bitset<N> operator>>(size_t shift) const
{
bitset<N> temp;
bitset<N> temp(*this);
if (ARRAY_SIZE == 1)
{
temp.data[0] = data[0] >> shift;
}
else
{
size_t source = shift;
size_t destination = 0;
while (source != N)
{
temp.set(destination++, test(source++));
}
}
temp >>= shift;
return temp;
}
@ -342,54 +267,16 @@ namespace etl
//*************************************************************************
bitset<N>& operator>>=(size_t shift)
{
if (ARRAY_SIZE == 1)
{
data[0] >>= shift;
}
else
{
size_t source = shift;
size_t destination = 0;
for (size_t i = 0; i < (N - shift); ++i)
{
set(destination++, test(source++));
}
for (size_t i = 0; i < shift; ++i)
{
reset(destination++);
}
}
ibitset::operator >>=(shift);
return *this;
}
//*************************************************************************
/// swap
//*************************************************************************
void swap(bitset<N>& other)
{
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
std::swap(data, other.data);
}
}
//*************************************************************************
/// operator ==
//*************************************************************************
friend bool operator == (const bitset<N>& lhs, const bitset<N>& rhs)
{
for (size_t i = 0; i < ARRAY_SIZE; ++i)
{
if (lhs.data[i] != rhs.data[i])
{
return false;
}
}
return true;
return ibitset::is_equal(lhs, rhs);
}
private:

View File

@ -35,6 +35,8 @@ SOFTWARE.
/// Error handler for when throwing exceptions is not required.
///\ingroup utilities
#include <assert.h>
#include "exception.h"
#include "function.h"
@ -80,15 +82,27 @@ namespace etl
};
//***************************************************************************
/// Raise an error.
/// If ETL_THROW_EXCEPTIONS is defined then the error is thrown, otherwise
/// the error handler is called.
/// Asserts a coondition.
/// Versions of the macro that return a constant value of 'true' will allow the compiler to optimise away
/// any 'if' statements that it is contained within.
/// If ETL_NO_CHECKS is defined then no runtime checks are executed at all.
/// If ETL_THROW_EXCEPTIONS is defined then the error is thrown if the assert fails. The return value is always 'true'.
/// If ETL_LOG_ERRORS is defined then the error is logged if the assert fails. The return value is the value of the boolean test.
/// Otherwise 'assert' is called. The return value is always 'true'.
///\ingroup error_handler
//***************************************************************************
#ifdef ETL_THROW_EXCEPTIONS
#define ETL_ERROR(e) throw e
#if defined(ETL_NO_CHECKS)
#define ETL_ASSERT(b, e) (true) // Does nothing. Evaluates to 'true'.
#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.
#else
#define ETL_ERROR(e) etl::error_handler::error(e);
#if defined(NDEBUG)
#define ETL_ASSERT(b, e) (true) // Does nothing. Evaluates to 'true'.
#elif
#define ETL_ASSERT(b, e) ((assert((b))), true) // Asserts if the condition fails. Evaluates to 'true'.
#endif
#endif
}

181
ibitset.h
View File

@ -33,6 +33,7 @@ SOFTWARE.
#include <algorithm>
#include <stdint.h>
#include "exception.h"
#include "integral_limits.h"
#include "binary.h"
@ -42,6 +43,34 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// Exception base for bitset
///\ingroup bitset
//***************************************************************************
class bitset_exception : public etl::exception
{
public:
bitset_exception(const char* what)
: exception(what)
{
}
};
//***************************************************************************
/// Bitset nullptr exception.
///\ingroup bitset
//***************************************************************************
class bitset_nullptr : public bitset_exception
{
public:
bitset_nullptr()
: bitset_exception("bitset: nullptr")
{
}
};
//*************************************************************************
/// The base class for etl::bitset
///\ingroup bitset
@ -466,8 +495,152 @@ namespace etl
return bit_reference(*this, position);
}
//*************************************************************************
/// operator &=
//*************************************************************************
ibitset& operator &=(const ibitset& other)
{
for (size_t i = 0; i < SIZE; ++i)
{
pdata[i] &= other.pdata[i];
}
return *this;
}
//*************************************************************************
/// operator |=
//*************************************************************************
ibitset& operator |=(const ibitset& other)
{
for (size_t i = 0; i < SIZE; ++i)
{
pdata[i] |= other.pdata[i];
}
return *this;
}
//*************************************************************************
/// operator ^=
//*************************************************************************
ibitset& operator ^=(const ibitset& other)
{
for (size_t i = 0; i < SIZE; ++i)
{
pdata[i] ^= other.pdata[i];
}
return *this;
}
//*************************************************************************
/// operator <<=
//*************************************************************************
ibitset& operator<<=(size_t shift)
{
if (SIZE == 1)
{
pdata[0] <<= shift;
}
else
{
size_t source = NBITS - shift - 1;
size_t destination = NBITS - 1;
for (size_t i = 0; i < (NBITS - shift); ++i)
{
set(destination--, test(source--));
}
for (size_t i = 0; i < shift; ++i)
{
reset(destination--);
}
}
return *this;
}
//*************************************************************************
/// operator >>=
//*************************************************************************
ibitset& operator>>=(size_t shift)
{
if (SIZE == 1)
{
pdata[0] >>= shift;
}
else
{
size_t source = shift;
size_t destination = 0;
for (size_t i = 0; i < (NBITS - shift); ++i)
{
set(destination++, test(source++));
}
for (size_t i = 0; i < shift; ++i)
{
reset(destination++);
}
}
return *this;
}
//*************************************************************************
/// swap
//*************************************************************************
void swap(ibitset& other)
{
std::swap_ranges(pdata, pdata + SIZE, other.pdata);
}
protected:
//*************************************************************************
/// Initialise from an unsigned long long.
//*************************************************************************
ibitset& initialise(unsigned long long value)
{
reset();
const size_t SHIFT = (integral_limits<unsigned long long>::bits <= BITS_PER_ELEMENT) ? 0 : BITS_PER_ELEMENT;
// Can we do it in one hit?
if (SHIFT == 0)
{
pdata[0] = element_t(value);
}
else
{
size_t i = 0;
while ((value != 0) && (i < SIZE))
{
pdata[i++] = value & ALL_SET;
value = value >> SHIFT;
}
}
pdata[SIZE - 1] &= TOP_MASK;
return *this;
}
//*************************************************************************
/// Invert
//*************************************************************************
void invert()
{
for (size_t i = 0; i < SIZE; ++i)
{
pdata[i] = ~pdata[i];
}
}
//*************************************************************************
/// Gets a reference to the specified bit.
//*************************************************************************
@ -489,6 +662,14 @@ namespace etl
TOP_MASK = element_t(top_mask_shift == 0 ? ALL_SET : ~(ALL_SET << top_mask_shift));
}
//*************************************************************************
/// Compare bitsets.
//*************************************************************************
static bool is_equal(const ibitset& lhs, const ibitset&rhs)
{
return std::equal(lhs.pdata, lhs.pdata + lhs.SIZE, rhs.pdata);
}
element_t TOP_MASK;
private:

View File

@ -36,7 +36,7 @@ SOFTWARE.
#include "algorithm.h"
#include "type_traits.h"
#include "deque_base.h"
#include "private/deque_base.h"
#include "parameter_type.h"
#include "error_handler.h"
@ -491,20 +491,18 @@ namespace etl
//*************************************************************************
void assign(size_type n, const value_type& value)
{
if (n > MAX_SIZE)
if (ETL_ASSERT(n <= MAX_SIZE, deque_full()))
{
ETL_ERROR(deque_full());
}
initialise();
initialise();
_begin.index = 0;
_end.index = 0;
_begin.index = 0;
_end.index = 0;
while (n > 0)
{
create_element_back(value);
--n;
while (n > 0)
{
create_element_back(value);
--n;
}
}
}
@ -515,14 +513,11 @@ namespace etl
//*************************************************************************
reference at(size_t index)
{
if (index >= current_size)
{
ETL_ERROR(deque_out_of_bounds());
}
ETL_ASSERT(index < current_size, deque_out_of_bounds());
iterator result(_begin);
result += index;
return *result;
}
@ -533,10 +528,7 @@ namespace etl
//*************************************************************************
const_reference at(size_t index) const
{
if (index >= current_size)
{
ETL_ERROR(deque_out_of_bounds());
}
ETL_ASSERT(index < current_size, deque_out_of_bounds());
iterator result(_begin);
result += index;
@ -718,7 +710,7 @@ namespace etl
{
iterator position(insert_position.index, *this, p_buffer);
if (!full())
if (ETL_ASSERT(!full(), deque_full()))
{
if (insert_position == begin())
{
@ -757,10 +749,6 @@ namespace etl
}
}
}
else
{
ETL_ERROR(deque_full());
}
return position;
}
@ -776,7 +764,7 @@ namespace etl
{
iterator position;
if ((current_size + n) <= MAX_SIZE)
if (ETL_ASSERT((current_size + n) <= MAX_SIZE, deque_full()))
{
if (insert_position == begin())
{
@ -871,10 +859,6 @@ namespace etl
}
}
}
else
{
ETL_ERROR(deque_full());
}
return position;
}
@ -894,7 +878,7 @@ namespace etl
difference_type n = std::distance(range_begin, range_end);
if ((current_size + n) <= MAX_SIZE)
if (ETL_ASSERT((current_size + n) <= MAX_SIZE, deque_full()))
{
if (insert_position == begin())
{
@ -983,10 +967,6 @@ namespace etl
}
}
}
else
{
ETL_ERROR(deque_full());
}
return position;
}
@ -1000,7 +980,7 @@ namespace etl
{
iterator position(erase_position.index, *this, p_buffer);
if (distance(position) <= difference_type(current_size))
if (ETL_ASSERT(distance(position) <= difference_type(current_size), deque_out_of_bounds()))
{
if (position == _begin)
{
@ -1028,10 +1008,6 @@ namespace etl
}
}
}
else
{
ETL_ERROR(deque_out_of_bounds());
}
return position;
}
@ -1046,8 +1022,7 @@ namespace etl
{
iterator position(range_begin.index, *this, p_buffer);
if ((distance(range_begin) <= difference_type(current_size)) &&
(distance(range_end) <= difference_type(current_size)))
if (ETL_ASSERT((distance(range_begin) <= difference_type(current_size)) && (distance(range_end) <= difference_type(current_size)), deque_out_of_bounds()))
{
// How many to erase?
size_t length = std::distance(range_begin, range_end);
@ -1101,10 +1076,6 @@ namespace etl
}
}
}
else
{
ETL_ERROR(deque_out_of_bounds());
}
return position;
}
@ -1116,14 +1087,10 @@ namespace etl
//*************************************************************************
void push_back(parameter_t item)
{
if (!full())
if (ETL_ASSERT(!full(), deque_full()))
{
create_element_back(item);
}
else
{
ETL_ERROR(deque_full());
}
}
//*************************************************************************
@ -1135,14 +1102,10 @@ namespace etl
{
reference r = *_end;
if (!full())
if (ETL_ASSERT(!full(), deque_full()))
{
create_element_back();
}
else
{
ETL_ERROR(deque_full());
}
return r;
}
@ -1165,14 +1128,10 @@ namespace etl
//*************************************************************************
void push_front(parameter_t item)
{
if (!full())
if (ETL_ASSERT(!full(), deque_full()))
{
create_element_front(item);
}
else
{
ETL_ERROR(deque_full());
}
}
//*************************************************************************
@ -1182,14 +1141,10 @@ namespace etl
//*************************************************************************
reference push_front()
{
if (!full())
if (ETL_ASSERT(!full(), deque_full()))
{
create_element_front();
}
else
{
ETL_ERROR(deque_full());
}
return *_begin;
}
@ -1213,7 +1168,7 @@ namespace etl
//*************************************************************************
void resize(size_t new_size, const value_type& value = value_type())
{
if (new_size <= MAX_SIZE)
if (ETL_ASSERT(new_size <= MAX_SIZE, deque_out_of_bounds()))
{
// Make it smaller?
if (new_size < current_size)
@ -1234,10 +1189,6 @@ namespace etl
}
}
}
else
{
ETL_ERROR(deque_out_of_bounds());
}
}
//*************************************************************************

View File

@ -37,14 +37,11 @@ SOFTWARE.
#include <utility>
#include <stddef.h>
#include "flat_map_base.h"
#include "private/flat_map_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "ivector.h"
#ifndef ETL_THROW_EXCEPTIONS
#include "error_handler.h"
#endif
namespace etl
{
@ -243,11 +240,7 @@ namespace etl
{
iterator i_element = lower_bound(key);
if (i_element == end())
{
// Doesn't exist.
ETL_ERROR(flat_map_out_of_bounds());
}
ETL_ASSERT(i_element != end(), flat_map_out_of_bounds());
return i_element->second;
}
@ -262,11 +255,7 @@ namespace etl
{
typename buffer_t::const_iterator i_element = lower_bound(key);
if (i_element == end())
{
// Doesn't exist.
ETL_ERROR(flat_map_out_of_bounds());
}
ETL_ASSERT(i_element != end(), flat_map_out_of_bounds());
return i_element->second;
}
@ -284,15 +273,8 @@ namespace etl
#ifdef _DEBUG
difference_type count = std::distance(first, last);
if (count < 0)
{
ETL_ERROR(flat_map_iterator());
}
if (count > difference_type(capacity()))
{
ETL_ERROR(flat_map_full());
}
ETL_ASSERT(count >= 0, flat_map_iterator());
ETL_ASSERT(count <= difference_type(capacity()), flat_map_full());
#endif
clear();
@ -317,11 +299,7 @@ namespace etl
if (i_element == end())
{
// At the end.
if (buffer.full())
{
ETL_ERROR(flat_map_full());
}
else
if (ETL_ASSERT(!buffer.full(), flat_map_full()))
{
buffer.push_back(value);
result.first = end() - 1;
@ -342,11 +320,7 @@ namespace etl
else
{
// A new one.
if (buffer.full())
{
ETL_ERROR(flat_map_full());
}
else
if (ETL_ASSERT(!buffer.full(), flat_map_full()))
{
buffer.insert(i_element, value);
result.first = i_element;

View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <utility>
#include <stddef.h>
#include "flat_multimap_base.h"
#include "private/flat_multimap_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "ivector.h"
@ -223,12 +223,7 @@ namespace etl
{
#ifdef _DEBUG
difference_type count = std::distance(first, last);
if (count < 0)
{
ETL_ERROR(flat_multimap_iterator());
return;
}
ETL_ASSERT(count >= 0, flat_multimap_iterator());
#endif
clear();
@ -250,25 +245,22 @@ namespace etl
iterator i_element = lower_bound(value.first);
if (buffer.full())
{
ETL_ERROR(flat_multimap_full());
return result;
}
if (i_element == end())
if (ETL_ASSERT(!buffer.full(), flat_multimap_full()))
{
// 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;
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;
}
}
return result;

View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <utility>
#include <stddef.h>
#include "flat_multiset_base.h"
#include "private/flat_multiset_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "ivector.h"
@ -200,10 +200,7 @@ namespace etl
#ifdef _DEBUG
difference_type count = std::distance(first, last);
if (count < 0)
{
ETL_ERROR(flat_multiset_iterator());
}
ETL_ASSERT(count >= 0, flat_multiset_iterator());
#endif
clear();
@ -223,27 +220,24 @@ namespace etl
{
std::pair<iterator, bool> result(end(), false);
if (buffer.full())
if (ETL_ASSERT(!buffer.full(), flat_multiset_full()))
{
ETL_ERROR(flat_multiset_full());
return result;
}
iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare());
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;
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;
}
}
return result;

View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <utility>
#include <stddef.h>
#include "flat_set_base.h"
#include "private/flat_set_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "ivector.h"
@ -199,11 +199,7 @@ namespace etl
{
#ifdef _DEBUG
difference_type count = std::distance(first, last);
if (count < 0)
{
ETL_ERROR(flat_set_iterator());
}
ETL_ASSERT(count >= 0, flat_set_iterator());
#endif
clear();
@ -223,27 +219,24 @@ namespace etl
{
std::pair<iterator, bool> result(end(), false);
if (buffer.full())
{
ETL_ERROR(flat_set_full());
return result;
}
iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare());
if (ETL_ASSERT(!buffer.full(), flat_set_full()))
{
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;
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;
}
}
return result;

View File

@ -42,7 +42,7 @@ SOFTWARE.
#include "pool.h"
#include "nullptr.h"
#include "forward_list_base.h"
#include "private/forward_list_base.h"
#include "type_traits.h"
#include "parameter_type.h"

View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <stddef.h>
#include "nullptr.h"
#include "list_base.h"
#include "private/list_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "pool.h"

2
imap.h
View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <stddef.h>
#include "nullptr.h"
#include "map_base.h"
#include "private/map_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "pool.h"

View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <stddef.h>
#include "nullptr.h"
#include "multimap_base.h"
#include "private/multimap_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "pool.h"

View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <stddef.h>
#include "nullptr.h"
#include "multiset_base.h"
#include "private/multiset_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "pool.h"

View File

@ -408,11 +408,7 @@ namespace etl
{
#ifdef _DEBUG
difference_type count = std::distance(first, last);
if (count < 0)
{
ETL_ERROR(intrusive_forward_list_iterator_exception());
}
ETL_ASSERT(count >= 0, intrusive_forward_list_iterator_exception());
#endif
initialise();

View File

@ -71,10 +71,7 @@ namespace etl
__private_intrusive_forward_list__::intrusive_forward_list_node_base* get_next(size_t index) const
{
#ifdef _DEBUG
if (index >= SIZE)
{
ETL_ERROR(intrusive_forward_list_index_exception());
}
ETL_ASSERT(index < SIZE, intrusive_forward_list_index_exception());
#endif
return next[index];
}
@ -82,10 +79,7 @@ namespace etl
void set_next(size_t index, __private_intrusive_forward_list__::intrusive_forward_list_node_base* pnext)
{
#ifdef _DEBUG
if (index >= SIZE)
{
ETL_ERROR(intrusive_forward_list_index_exception());
}
ETL_ASSERT(index < SIZE, intrusive_forward_list_index_exception());
#endif
next[index] = pnext;
}

View File

@ -33,7 +33,7 @@ SOFTWARE.
#include <iterator>
#include "pool_base.h"
#include "private/pool_base.h"
#include "nullptr.h"
#include "ibitset.h"

View File

@ -34,7 +34,7 @@ SOFTWARE.
#include <stddef.h>
#include <algorithm>
#include "priority_queue_base.h"
#include "private/priority_queue_base.h"
#include "type_traits.h"
#include "parameter_type.h"

View File

@ -33,7 +33,7 @@ SOFTWARE.
#include <stddef.h>
#include "queue_base.h"
#include "private/queue_base.h"
#include "type_traits.h"
#include "parameter_type.h"

2
iset.h
View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <stddef.h>
#include "nullptr.h"
#include "set_base.h"
#include "private/set_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "pool.h"

View File

@ -33,7 +33,7 @@ SOFTWARE.
#include <stddef.h>
#include "stack_base.h"
#include "private/stack_base.h"
#include "type_traits.h"
#include "parameter_type.h"

118
ivector.h
View File

@ -37,7 +37,7 @@ SOFTWARE.
#include <stddef.h>
#include "algorithm.h"
#include "vector_base.h"
#include "private/vector_base.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "error_handler.h"
@ -188,27 +188,25 @@ namespace etl
//*********************************************************************
void resize(size_t new_size)
{
if (new_size > MAX_SIZE)
if (ETL_ASSERT(new_size <= MAX_SIZE, vector_full()))
{
ETL_ERROR(vector_full());
}
// Size up or size down?
if (new_size > current_size)
{
for (size_t i = current_size; i < new_size; ++i)
// Size up or size down?
if (new_size > current_size)
{
while (current_size < new_size)
for (size_t i = current_size; i < new_size; ++i)
{
create_element();
while (current_size < new_size)
{
create_element();
}
}
}
}
else if (new_size < current_size)
{
while (current_size > new_size)
else if (new_size < current_size)
{
destroy_element();
while (current_size > new_size)
{
destroy_element();
}
}
}
}
@ -222,25 +220,23 @@ namespace etl
//*********************************************************************
void resize(size_t new_size, T value)
{
if (new_size > MAX_SIZE)
if (ETL_ASSERT(new_size <= MAX_SIZE, vector_full()))
{
ETL_ERROR(vector_full());
}
// Size up?
if (new_size > current_size)
{
while (current_size < new_size)
// Size up?
if (new_size > current_size)
{
create_element(value);
while (current_size < new_size)
{
create_element(value);
}
}
}
// Size down?
else if (new_size < current_size)
{
while (current_size > new_size)
// Size down?
else if (new_size < current_size)
{
destroy_element();
while (current_size > new_size)
{
destroy_element();
}
}
}
}
@ -273,11 +269,7 @@ namespace etl
//*********************************************************************
reference at(size_t i)
{
if (i >= current_size)
{
ETL_ERROR(vector_out_of_bounds());
}
ETL_ASSERT(i < current_size, vector_out_of_bounds());
return p_buffer[i];
}
@ -289,11 +281,7 @@ namespace etl
//*********************************************************************
const_reference at(size_t i) const
{
if (i >= current_size)
{
ETL_ERROR(vector_out_of_bounds());
}
ETL_ASSERT(i < current_size, vector_out_of_bounds());
return p_buffer[i];
}
@ -363,16 +351,8 @@ namespace etl
{
#ifdef _DEBUG
difference_type count = std::distance(first, last);
if (count < 0)
{
ETL_ERROR(vector_iterator());
}
if (static_cast<size_t>(count) > MAX_SIZE)
{
ETL_ERROR( vector_full());
}
ETL_ASSERT(count >= 0, vector_iterator());
ETL_ASSERT(static_cast<size_t>(count) <= MAX_SIZE, vector_full());
#endif
initialise();
@ -395,11 +375,7 @@ namespace etl
{
initialise();
if (n > MAX_SIZE)
{
ETL_ERROR(vector_full());
}
else
if (ETL_ASSERT(n <= MAX_SIZE, vector_full()))
{
while (n > 0)
{
@ -423,12 +399,10 @@ namespace etl
//*************************************************************************
void push_back()
{
if (current_size == MAX_SIZE)
if (ETL_ASSERT(current_size != MAX_SIZE, vector_full()))
{
ETL_ERROR(vector_full());
create_element();
}
create_element();
}
//*********************************************************************
@ -438,11 +412,7 @@ namespace etl
//*********************************************************************
void push_back(parameter_t value)
{
if (current_size == MAX_SIZE)
{
ETL_ERROR(vector_full());
}
else
if (ETL_ASSERT(current_size != MAX_SIZE, vector_full()))
{
create_element(value);
}
@ -468,11 +438,7 @@ namespace etl
//*********************************************************************
iterator insert(iterator position, parameter_t value)
{
if ((current_size + 1) > MAX_SIZE)
{
ETL_ERROR(vector_full());
}
else
if (ETL_ASSERT((current_size) + 1 <= MAX_SIZE, vector_full()))
{
create_element(value);
@ -495,11 +461,7 @@ namespace etl
//*********************************************************************
void insert(iterator position, size_t n, parameter_t value)
{
if ((current_size + n) > MAX_SIZE)
{
ETL_ERROR(vector_full());
}
else
if (ETL_ASSERT((current_size) + 1 <= MAX_SIZE, vector_full()))
{
if (position == end())
{
@ -562,11 +524,7 @@ namespace etl
{
size_t count = std::distance(first, last);
if ((current_size + count) > MAX_SIZE)
{
ETL_ERROR(vector_full());
}
else
if (ETL_ASSERT((current_size) + count <= MAX_SIZE, vector_full()))
{
if (position == end())
{

View File

@ -107,11 +107,7 @@ namespace etl
{
STATIC_ASSERT(sizeof(typename std::iterator_traits<TIterator>::value_type) == 1, "Incompatible type");
if (is_finalised)
{
ETL_ERROR(hash_finalised());
}
else
if (ETL_ASSERT(!is_finalised, hash_finalised()))
{
while (begin != end)
{
@ -127,11 +123,7 @@ namespace etl
//*************************************************************************
void add(uint8_t value)
{
if (is_finalised)
{
ETL_ERROR(hash_finalised());
}
else
if (ETL_ASSERT(!is_finalised, hash_finalised()))
{
hash += value;
hash += (hash << 10);

View File

@ -120,11 +120,7 @@ namespace etl
{
STATIC_ASSERT(sizeof(typename std::iterator_traits<TIterator>::value_type) == 1, "Incompatible type");
if (is_finalised)
{
ETL_ERROR(hash_finalised());
}
else
if (ETL_ASSERT(!is_finalised, hash_finalised()))
{
while (begin != end)
{
@ -150,11 +146,7 @@ namespace etl
void add(uint8_t value)
{
// We can't add to a finalised hash!
if (is_finalised)
{
ETL_ERROR(hash_finalised());
}
else
if (ETL_ASSERT(!is_finalised, hash_finalised()))
{
block |= value << (block_fill_count * 8);

View File

@ -0,0 +1,164 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
Copyright(c) 2014 jwellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef __ETL_IN_IUNORDERED_MAP_H__
#error This header is a private element of etl::unordered_map & etl::iunordered_map
#endif
#ifndef __ETL_UNORDERED_MAP_BASE__
#define __ETL_UNORDERED_MAP_BASE__
#include <stddef.h>
#include "exception.h"
namespace etl
{
//***************************************************************************
/// Exception for the unordered_map.
///\ingroup unordered_map
//***************************************************************************
class unordered_map_exception : public exception
{
public:
unordered_map_exception(const char* what)
: exception(what)
{
}
};
//***************************************************************************
/// Full exception for the unordered_map.
///\ingroup unordered_map
//***************************************************************************
class unordered_map_full : public unordered_map_exception
{
public:
unordered_map_full()
: unordered_map_exception("unordered_map: full")
{
}
};
//***************************************************************************
/// Out of range exception for the unordered_map.
///\ingroup unordered_map
//***************************************************************************
class unordered_map_out_of_range : public unordered_map_exception
{
public:
unordered_map_out_of_range()
: unordered_map_exception("unordered_map: out of range")
{}
};
//***************************************************************************
/// Iterator exception for the unordered_map.
///\ingroup unordered_map
//***************************************************************************
class unordered_map_iterator : public unordered_map_exception
{
public:
unordered_map_iterator()
: unordered_map_exception("unordered_map: iterator problem")
{
}
};
//***************************************************************************
/// The base class for all unordered_maps.
///\ingroup unordered_map
//***************************************************************************
class unordered_map_base
{
public:
typedef size_t size_type; ///< The type used for determining the size of unordered_map.
//*************************************************************************
/// Gets the size of the unordered_map.
//*************************************************************************
size_type size() const
{
return current_size;
}
//*************************************************************************
/// Gets the maximum possible size of the unordered_map.
//*************************************************************************
size_type max_size() const
{
return MAX_SIZE;
}
//*************************************************************************
/// Checks to see if the unordered_map is empty.
//*************************************************************************
bool empty() const
{
return current_size == 0;
}
//*************************************************************************
/// Checks to see if the unordered_map is full.
//*************************************************************************
bool full() const
{
return current_size == MAX_SIZE;
}
//*************************************************************************
/// Returns the remaining capacity.
///\return The remaining capacity.
//*************************************************************************
size_t available() const
{
return max_size() - size();
}
protected:
//*************************************************************************
/// The constructor that is called from derived classes.
//*************************************************************************
unordered_map_base(size_type max_size)
: current_size(0),
MAX_SIZE(max_size)
{
}
size_type current_size; ///< The number of the used nodes.
const size_type MAX_SIZE; ///< The maximum size of the unordered_map.
};
}
#endif

View File

@ -575,7 +575,7 @@ namespace
etl::bitset<60> data2(0x23456789);
etl::bitset<60> data3(0x12345678 & 0x23456789);
data2 &= data1;
etl::bitset<60>& rdata = data2 &= data1;
CHECK(data2 == data3);
}
@ -598,7 +598,7 @@ namespace
etl::bitset<60> data2(0x23456789);
etl::bitset<60> data3(0x12345678 | 0x23456789);
data2 |= data1;
etl::bitset<60>& rdata = data2 |= data1;
CHECK(data2 == data3);
}
@ -621,7 +621,7 @@ namespace
etl::bitset<60> data2(0x23456789);
etl::bitset<60> data3(0x12345678 ^ 0x23456789);
data2 ^= data1;
etl::bitset<60>& rdata = data2 ^= data1;
CHECK(data2 == data3);
}

View File

@ -34,6 +34,9 @@
<Filter Include="ETL\Maths">
<UniqueIdentifier>{1c55dd7d-c04b-428c-810b-dd3a08fc4c65}</UniqueIdentifier>
</Filter>
<Filter Include="ETL\Containers\Private">
<UniqueIdentifier>{7028012c-30c4-4993-b2d9-3b1521a610ae}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\unittest-cpp\UnitTest++\AssertException.h">
@ -153,21 +156,12 @@
<ClInclude Include="..\..\queue.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\queue_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\stack.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\stack_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\vector.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\vector_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\largest.h">
<Filter>ETL\Utilities</Filter>
</ClInclude>
@ -201,18 +195,12 @@
<ClInclude Include="..\..\ilist.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\list_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\map.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\imap.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\map_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\crc16.h">
<Filter>ETL\Maths</Filter>
</ClInclude>
@ -234,9 +222,6 @@
<ClInclude Include="..\..\deque.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\deque_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\ideque.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
@ -246,9 +231,6 @@
<ClInclude Include="..\..\forward_list.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\forward_list_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\iforward_list.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
@ -309,9 +291,6 @@
<ClInclude Include="..\..\ipool.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\pool_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\radix.h">
<Filter>ETL\Maths</Filter>
</ClInclude>
@ -336,18 +315,12 @@
<ClInclude Include="..\..\iflat_map.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_map_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\ihash.h">
<Filter>ETL\Maths</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_set.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_set_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\iflat_set.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
@ -357,9 +330,6 @@
<ClInclude Include="..\..\iunordered_map.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\unordered_map_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\io_port.h">
<Filter>ETL\Utilities</Filter>
</ClInclude>
@ -372,9 +342,6 @@
<ClInclude Include="..\..\set.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\set_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\imultimap.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
@ -393,9 +360,6 @@
<ClInclude Include="..\..\priority_queue.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\priority_queue_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\ilru_cache.h">
<Filter>ETL\Maths</Filter>
</ClInclude>
@ -432,15 +396,9 @@
<ClInclude Include="..\..\flat_multimap.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_multimap_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_multiset.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_multiset_base.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\iflat_multiset.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
@ -459,11 +417,56 @@
<ClInclude Include="..\..\basic_intrusive_forward_list_node.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\deque_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_map_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_multimap_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_multiset_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\forward_list_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\flat_set_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\multimap_base.h">
<Filter>ETL\Containers</Filter>
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\priority_queue_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\multiset_base.h">
<Filter>ETL\Containers</Filter>
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\map_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\list_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\stack_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\set_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\queue_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\unordered_map_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\vector_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
<ClInclude Include="..\..\pool_base.h">
<Filter>ETL\Containers\Private</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>