Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/etl/version.h
  • Loading branch information
jwellbelove committed Jul 29, 2018
1 parent 85e51ee commit 0b4543f
Show file tree
Hide file tree
Showing 16 changed files with 2,262 additions and 157 deletions.
36 changes: 33 additions & 3 deletions include/etl/memory_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,44 @@ SOFTWARE.
#define ETL_MEMORY_MODEL_INCLUDED

#include "user_type.h"
#include <stdint.h>
#include "type_lookup.h"

namespace etl
{
ETL_DECLARE_USER_TYPE(memory_model, int)
ETL_USER_TYPE(MM_SMALL, 0)
ETL_USER_TYPE(MM_MEDIUM, 1)
ETL_USER_TYPE(MM_LARGE, 2)
ETL_USER_TYPE(MEMORY_MODEL_SMALL, 0)
ETL_USER_TYPE(MEMORY_MODEL_MEDIUM, 1)
ETL_USER_TYPE(MEMORY_MODEL_LARGE, 2)
ETL_USER_TYPE(MEMORY_MODEL_HUGE, 3)
ETL_END_USER_TYPE(memory_model)

template <const size_t MEMORY_MODEL>
struct size_type_lookup;

template <>
struct size_type_lookup<etl::memory_model::MEMORY_MODEL_SMALL>
{
typedef uint_least8_t type;
};

template <>
struct size_type_lookup<etl::memory_model::MEMORY_MODEL_MEDIUM>
{
typedef uint_least16_t type;
};

template <>
struct size_type_lookup<etl::memory_model::MEMORY_MODEL_LARGE>
{
typedef uint_least32_t type;
};

template <>
struct size_type_lookup<etl::memory_model::MEMORY_MODEL_HUGE>
{
typedef uint_least64_t type;
};
}

#endif
Expand Down
6 changes: 4 additions & 2 deletions include/etl/priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ namespace etl
/// Returns the remaining capacity.
///\return The remaining capacity.
//*************************************************************************
size_t available() const
size_type available() const
{
return container.max_size() - container.size();
}
Expand Down Expand Up @@ -372,7 +372,9 @@ namespace etl
{
public:

static const size_t MAX_SIZE = SIZE;
typedef typename TContainer::size_type size_type;

static const size_type MAX_SIZE = size_type(SIZE);

//*************************************************************************
/// Default constructor.
Expand Down
96 changes: 58 additions & 38 deletions include/etl/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ SOFTWARE.
#include "debug_count.h"
#include "type_traits.h"
#include "parameter_type.h"
#include "memory_model.h"
#include "integral_limits.h"

#undef ETL_FILE
#define ETL_FILE "13"
Expand Down Expand Up @@ -102,11 +104,13 @@ namespace etl
/// The base class for all queues.
///\ingroup queue
//***************************************************************************
template <const size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
class queue_base
{
public:

typedef size_t size_type; ///< The type used for determining the size of queue.
/// The type used for determining the size of queue.
typedef typename etl::size_type_lookup<MEMORY_MODEL>::type size_type;

//*************************************************************************
/// Returns the current number of items in the queue.
Expand Down Expand Up @@ -154,7 +158,7 @@ namespace etl
/// Returns the remaining capacity.
///\return The remaining capacity.
//*************************************************************************
size_t available() const
size_type available() const
{
return max_size() - size();
}
Expand Down Expand Up @@ -217,8 +221,8 @@ namespace etl
ETL_RESET_DEBUG_COUNT;
}

size_type in; ///< Where to input new data.
size_type out; ///< Where to get the oldest data.
size_type in; ///< Where to input new data.
size_type out; ///< Where to get the oldest data.
size_type current_size; ///< The number of items in the queue.
const size_type CAPACITY; ///< The maximum number of items in the queue.
ETL_DECLARE_DEBUG_COUNT; ///< For internal debugging purposes.
Expand All @@ -236,25 +240,32 @@ namespace etl
/// \warning This queue cannot be used for concurrent access from multiple threads.
/// \tparam T The type of value that the queue holds.
//***************************************************************************
template <typename T>
class iqueue : public etl::queue_base
template <typename T, const size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
class iqueue : public etl::queue_base<MEMORY_MODEL>
{
public:

typedef T value_type; ///< The type stored in the queue.
typedef T& reference; ///< A reference to the type used in the queue.
typedef const T& const_reference; ///< A const reference to the type used in the queue.
typedef T* pointer; ///< A pointer to the type used in the queue.
typedef const T* const_pointer; ///< A const pointer to the type used in the queue.
typedef queue_base::size_type size_type; ///< The type used for determining the size of the queue.

private:

typedef typename etl::parameter_type<T>::type parameter_t;
typedef typename etl::queue_base base_t;
typedef typename etl::parameter_type<T>::type parameter_t;
typedef typename etl::queue_base<MEMORY_MODEL> base_t;

public:

typedef T value_type; ///< The type stored in the queue.
typedef T& reference; ///< A reference to the type used in the queue.
typedef const T& const_reference; ///< A const reference to the type used in the queue.
typedef T* pointer; ///< A pointer to the type used in the queue.
typedef const T* const_pointer; ///< A const pointer to the type used in the queue.
typedef typename base_t::size_type size_type; ///< The type used for determining the size of the queue.

using base_t::in;
using base_t::out;
using base_t::CAPACITY;
using base_t::current_size;
using base_t::full;
using base_t::empty;
using base_t::add_in;
using base_t::del_out;

//*************************************************************************
/// Gets a reference to the value at the front of the queue.<br>
/// \return A reference to the value at the front of the queue.
Expand Down Expand Up @@ -302,7 +313,7 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
::new (&p_buffer[in]) T(value);
base_t::add_in();
add_in();
}

//*************************************************************************
Expand All @@ -319,7 +330,7 @@ namespace etl
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
base_t::add_in();
add_in();

return p_buffer[next];
}
Expand All @@ -336,7 +347,7 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
::new (&p_buffer[in]) T(value1);
base_t::add_in();
add_in();
}

//*************************************************************************
Expand All @@ -351,7 +362,7 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
::new (&p_buffer[in]) T(value1, value2);
base_t::add_in();
add_in();
}

//*************************************************************************
Expand All @@ -366,7 +377,7 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
::new (&p_buffer[in]) T(value1, value2, value3);
base_t::add_in();
add_in();
}

//*************************************************************************
Expand All @@ -381,7 +392,7 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
::new (&p_buffer[in]) T(value1, value2, value3, value4);
base_t::add_in();
add_in();
}

//*************************************************************************
Expand All @@ -398,7 +409,7 @@ namespace etl
while (current_size > 0)
{
p_buffer[out].~T();
base_t::del_out();
del_out();
}

in = 0;
Expand All @@ -417,7 +428,7 @@ namespace etl
ETL_ASSERT(!empty(), ETL_ERROR(queue_empty));
#endif
p_buffer[out].~T();
base_t::del_out();
del_out();
}

//*************************************************************************
Expand Down Expand Up @@ -466,9 +477,9 @@ namespace etl
{
clear();

size_t index = other.out;
size_type index = other.out;

for (size_t i = 0; i < other.size(); ++i)
for (size_type i = 0; i < other.size(); ++i)
{
push(other.p_buffer[index]);
index = (index == (CAPACITY - 1)) ? 0 : index + 1;
Expand All @@ -479,7 +490,7 @@ namespace etl
/// The constructor that is called from derived classes.
//*************************************************************************
iqueue(T* p_buffer_, size_type max_size_)
: queue_base(max_size_),
: base_t(max_size_),
p_buffer(p_buffer_)
{
}
Expand Down Expand Up @@ -511,39 +522,48 @@ namespace etl
///\ingroup queue
/// A fixed capacity queue.
/// This queue does not support concurrent access by different threads.
/// \tparam T The type this queue should support.
/// \tparam SIZE The maximum capacity of the queue.
/// \tparam T The type this queue should support.
/// \tparam SIZE The maximum capacity of the queue.
/// \tparam MEMORY_MODEL The memory model for the queue. Determines the type of the internal counter variables.
//***************************************************************************
template <typename T, const size_t SIZE>
class queue : public etl::iqueue<T>
template <typename T, const size_t SIZE, const size_t MEMORY_MODEL = etl::memory_model::MEMORY_MODEL_LARGE>
class queue : public etl::iqueue<T, MEMORY_MODEL>
{
private:

typedef etl::iqueue<T, MEMORY_MODEL> base_t;

public:

static const size_t MAX_SIZE = SIZE;
typedef typename base_t::size_type size_type;

ETL_STATIC_ASSERT((SIZE <= etl::integral_limits<size_type>::max), "Size too large for memory model");

static const size_type MAX_SIZE = size_type(SIZE);

//*************************************************************************
/// Default constructor.
//*************************************************************************
queue()
: etl::iqueue<T>(reinterpret_cast<T*>(&buffer[0]), SIZE)
: base_t(reinterpret_cast<T*>(&buffer[0]), SIZE)
{
}

//*************************************************************************
/// Copy constructor
//*************************************************************************
queue(const queue& rhs)
: etl::iqueue<T>(reinterpret_cast<T*>(&buffer[0]), SIZE)
: base_t(reinterpret_cast<T*>(&buffer[0]), SIZE)
{
etl::iqueue<T>::clone(rhs);
base_t::clone(rhs);
}

//*************************************************************************
/// Destructor.
//*************************************************************************
~queue()
{
etl::iqueue<T>::clear();
base_t::clear();
}

//*************************************************************************
Expand All @@ -553,7 +573,7 @@ namespace etl
{
if (&rhs != this)
{
etl::iqueue<T>::clone(rhs);
base_t::clone(rhs);
}

return *this;
Expand Down
Loading

0 comments on commit 0b4543f

Please sign in to comment.