mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Added array and updated doxygen comments
Added array and updated doxygen comments
This commit is contained in:
parent
33ea175e7f
commit
be36670b9a
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@
|
|||||||
.metadata
|
.metadata
|
||||||
bin/
|
bin/
|
||||||
tmp/
|
tmp/
|
||||||
|
docs/
|
||||||
*.tmp
|
*.tmp
|
||||||
*.bak
|
*.bak
|
||||||
*.swp
|
*.swp
|
||||||
|
|||||||
12
Doxyfile
12
Doxyfile
@ -2107,7 +2107,7 @@ PERL_PATH = /usr/bin/perl
|
|||||||
# powerful graphs.
|
# powerful graphs.
|
||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
|
|
||||||
CLASS_DIAGRAMS = NO
|
CLASS_DIAGRAMS = YES
|
||||||
|
|
||||||
# You can define message sequence charts within doxygen comments using the \msc
|
# You can define message sequence charts within doxygen comments using the \msc
|
||||||
# command. Doxygen will then run the mscgen tool (see:
|
# command. Doxygen will then run the mscgen tool (see:
|
||||||
@ -2138,7 +2138,7 @@ HIDE_UNDOC_RELATIONS = YES
|
|||||||
# set to NO
|
# set to NO
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
HAVE_DOT = YES
|
HAVE_DOT = NO
|
||||||
|
|
||||||
# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
|
# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
|
||||||
# to run in parallel. When set to 0 doxygen will base this on the number of
|
# to run in parallel. When set to 0 doxygen will base this on the number of
|
||||||
@ -2180,7 +2180,7 @@ DOT_FONTPATH =
|
|||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||||
|
|
||||||
CLASS_GRAPH = YES
|
CLASS_GRAPH = NO
|
||||||
|
|
||||||
# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
|
# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
|
||||||
# graph for each documented class showing the direct and indirect implementation
|
# graph for each documented class showing the direct and indirect implementation
|
||||||
@ -2196,7 +2196,7 @@ COLLABORATION_GRAPH = NO
|
|||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||||
|
|
||||||
GROUP_GRAPHS = YES
|
GROUP_GRAPHS = NO
|
||||||
|
|
||||||
# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
|
# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
|
||||||
# collaboration diagrams in a style similar to the OMG's Unified Modeling
|
# collaboration diagrams in a style similar to the OMG's Unified Modeling
|
||||||
@ -2204,7 +2204,7 @@ GROUP_GRAPHS = YES
|
|||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||||
|
|
||||||
UML_LOOK = NO
|
UML_LOOK = YES
|
||||||
|
|
||||||
# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
|
# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
|
||||||
# class node. If there are many fields or methods and many nodes the graph may
|
# class node. If there are many fields or methods and many nodes the graph may
|
||||||
@ -2272,7 +2272,7 @@ CALLER_GRAPH = NO
|
|||||||
# The default value is: YES.
|
# The default value is: YES.
|
||||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||||
|
|
||||||
GRAPHICAL_HIERARCHY = NO
|
GRAPHICAL_HIERARCHY = YES
|
||||||
|
|
||||||
# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
|
# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
|
||||||
# dependencies a directory has on other directories in a graphical way. The
|
# dependencies a directory has on other directories in a graphical way. The
|
||||||
|
|||||||
451
array.h
Normal file
451
array.h
Normal file
@ -0,0 +1,451 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
|
||||||
|
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_array__
|
||||||
|
#define __etl_array__
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <functional>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
#include "exception.h"
|
||||||
|
|
||||||
|
///\defgroup array array
|
||||||
|
/// A replacement for std::array if you haven't got C++0x11.
|
||||||
|
///\ingroup containers
|
||||||
|
|
||||||
|
namespace etl
|
||||||
|
{
|
||||||
|
#ifdef ETL_USE_EXCEPTIONS
|
||||||
|
//***************************************************************************
|
||||||
|
///\ingroup array
|
||||||
|
/// The base class for array exceptions.
|
||||||
|
//***************************************************************************
|
||||||
|
class array_exception : public exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
array_exception(const char* what)
|
||||||
|
: exception(what)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
///\ingroup array
|
||||||
|
/// The out of range exceptions.
|
||||||
|
//***************************************************************************
|
||||||
|
class array_out_of_range_exception : public array_exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
array_out_of_range_exception()
|
||||||
|
: array_exception("array out of range")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
///\ingroup array
|
||||||
|
/// A replacement for std::array if you haven't got C++0x11.
|
||||||
|
//***************************************************************************
|
||||||
|
template <typename T, const size_t SIZE>
|
||||||
|
class array
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// STL style typedefs.
|
||||||
|
//*************************************************************************
|
||||||
|
typedef T* iterator;
|
||||||
|
typedef const T* const_iterator;
|
||||||
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||||
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||||
|
typedef T* pointer;
|
||||||
|
typedef const T* const_pointer;
|
||||||
|
typedef T& reference;
|
||||||
|
typedef const T& const_reference;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::size_t size_type;
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns an iterator to the beginning of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline iterator begin()
|
||||||
|
{
|
||||||
|
return &_buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const iterator to the beginning of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_iterator begin() const
|
||||||
|
{
|
||||||
|
return &_buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const iterator to the beginning of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_iterator cbegin() const
|
||||||
|
{
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
// Returns an reverse iterator to the reverse beginning of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline reverse_iterator rbegin()
|
||||||
|
{
|
||||||
|
return reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reverse_iterator rbegin() const
|
||||||
|
{
|
||||||
|
return const_reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reverse_iterator crbegin() const
|
||||||
|
{
|
||||||
|
return const_reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns an iterator to the end of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline iterator end()
|
||||||
|
{
|
||||||
|
return &_buffer[SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const iterator to the end of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_iterator end() const
|
||||||
|
{
|
||||||
|
return &_buffer[SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
// Returns a const iterator to the end of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_iterator cend() const
|
||||||
|
{
|
||||||
|
return &_buffer[SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a reverse iterator to the end of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline reverse_iterator rend()
|
||||||
|
{
|
||||||
|
return reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reverse iterator to the end of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reverse_iterator rend() const
|
||||||
|
{
|
||||||
|
return const_reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reverse iterator to the end of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reverse_iterator crend() const
|
||||||
|
{
|
||||||
|
return const_reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a reference to the value at index 'i'.
|
||||||
|
/// If ETL_USE_EXCEPTIONS is defined then am array_out_of_range_exception is
|
||||||
|
/// thown if the index is out of range.
|
||||||
|
///\param i The index of the element to access.
|
||||||
|
//*************************************************************************
|
||||||
|
inline reference at(size_t i)
|
||||||
|
{
|
||||||
|
#if ETL_USE_EXCEPTIONS
|
||||||
|
if (i >= SIZE)
|
||||||
|
{
|
||||||
|
throw array_out_of_range_exception();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return _buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reference to the value at index 'i'.
|
||||||
|
/// If ETL_USE_EXCEPTIONS is defined then am array_out_of_range_exception is
|
||||||
|
/// thown if the index is out of range.
|
||||||
|
///\param i The index of the element to access.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reference at(size_t i) const
|
||||||
|
{
|
||||||
|
#if ETL_USE_EXCEPTIONS
|
||||||
|
if (i >= SIZE)
|
||||||
|
{
|
||||||
|
throw array_out_of_range_exception();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return _buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// [] operator.
|
||||||
|
/// Returns a reference to the value at index 'i'.
|
||||||
|
///\param i The index of the element to access.
|
||||||
|
//*************************************************************************
|
||||||
|
inline reference operator[](size_t i)
|
||||||
|
{
|
||||||
|
return _buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// [] operator.
|
||||||
|
/// Returns a const reference to the value at index 'i'.
|
||||||
|
///\param i The index of the element to access.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reference operator[](size_t i) const
|
||||||
|
{
|
||||||
|
return _buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns <b>true</b> if the array size is zero.
|
||||||
|
/// </summary>
|
||||||
|
//*************************************************************************
|
||||||
|
inline bool empty() const
|
||||||
|
{
|
||||||
|
return (SIZE == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns the size of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline size_t size() const
|
||||||
|
{
|
||||||
|
return SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns the maximum possible size of the array.
|
||||||
|
//*************************************************************************
|
||||||
|
inline size_t max_size() const
|
||||||
|
{
|
||||||
|
return SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Fills the array with the specified value.
|
||||||
|
///\param value The value to fill the array with.
|
||||||
|
//*************************************************************************
|
||||||
|
void fill(const T& value)
|
||||||
|
{
|
||||||
|
std::fill(begin(), end(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Swaps the contents of this array and another.
|
||||||
|
///\param other A reference to the other array.
|
||||||
|
//*************************************************************************
|
||||||
|
void swap(array& other)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < SIZE; ++i)
|
||||||
|
{
|
||||||
|
std::swap(_buffer[i], other._buffer[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a reference to the first element.
|
||||||
|
//*************************************************************************
|
||||||
|
inline reference front()
|
||||||
|
{
|
||||||
|
return _buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reference to the first element.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reference front() const
|
||||||
|
{
|
||||||
|
return _buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a reference to the last element.
|
||||||
|
//*************************************************************************
|
||||||
|
inline reference back()
|
||||||
|
{
|
||||||
|
return _buffer[SIZE - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const reference to the last element.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_reference back() const
|
||||||
|
{
|
||||||
|
return _buffer[SIZE - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a pointer to the first element of the internal buffer.
|
||||||
|
//*************************************************************************
|
||||||
|
inline pointer data()
|
||||||
|
{
|
||||||
|
return &_buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Returns a const pointer to the first element of the internal buffer.
|
||||||
|
//*************************************************************************
|
||||||
|
inline const_pointer data() const
|
||||||
|
{
|
||||||
|
return &_buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
T _buffer[SIZE]; ///< The buffer that stores the array data.
|
||||||
|
};
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// <summary>
|
||||||
|
/// Overloaded std::swap for etl::array<T, SIZE>
|
||||||
|
/// </summary>
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
//*************************************************************************
|
||||||
|
template <typename T, const size_t SIZE>
|
||||||
|
void swap(elt::array<T, SIZE> &lhs, etl::array<T, SIZE> &rhs)
|
||||||
|
{
|
||||||
|
lhs.swap(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// <summary>
|
||||||
|
/// Equal operator.
|
||||||
|
/// </summary>
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
///\return <b>true</b> if the arrays are equal, otherwise <b>false</b>
|
||||||
|
//*************************************************************************
|
||||||
|
template <typename T, std::size_t SIZE>
|
||||||
|
bool operator ==(const elt::array<T, SIZE>& lhs, const elt::array<T, SIZE>& rhs)
|
||||||
|
{
|
||||||
|
return std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Not equal operator.
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b>
|
||||||
|
//*************************************************************************
|
||||||
|
template <typename T, std::size_t SIZE>
|
||||||
|
bool operator !=(const elt::array<T, SIZE>& lhs, const elt::array<T, SIZE>& rhs)
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Less than operator.
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
///\return <b>true</b> if the first array is lexicographically less than the second, otherwise <b>false</b>
|
||||||
|
//*************************************************************************
|
||||||
|
template <typename T, std::size_t SIZE>
|
||||||
|
bool operator <(const elt::array<T, SIZE>& lhs, const elt::array<T, SIZE>& rhs)
|
||||||
|
{
|
||||||
|
return std::lexicographical_compare(lhs.cbegin(),
|
||||||
|
lhs.cend(),
|
||||||
|
rhs.cbegin(),
|
||||||
|
rhs.cend());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Less than or equal operator.
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
///\return <b>true</b> if the first array is lexicographically less than or equal to the second, otherwise <b>false</b>
|
||||||
|
//*************************************************************************
|
||||||
|
template <typename T, std::size_t SIZE>
|
||||||
|
bool operator <=(const elt::array<T, SIZE>& lhs, const elt::array<T, SIZE>& rhs)
|
||||||
|
{
|
||||||
|
return !std::lexicographical_compare(lhs.cbegin(),
|
||||||
|
lhs.cend(),
|
||||||
|
rhs.cbegin(),
|
||||||
|
rhs.cend(),
|
||||||
|
std::greater<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Greater than operator.
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
///\return <b>true</b> if the first array is lexicographically greater than the second, otherwise <b>false</b>
|
||||||
|
template <typename T, std::size_t SIZE>
|
||||||
|
//*************************************************************************
|
||||||
|
bool operator >(const elt::array<T, SIZE>& lhs, const elt::array<T, SIZE>& rhs)
|
||||||
|
{
|
||||||
|
return std::lexicographical_compare(lhs.cbegin(),
|
||||||
|
lhs.cend(),
|
||||||
|
rhs.cbegin(),
|
||||||
|
rhs.cend(),
|
||||||
|
std::greater<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
/// Greater than or equal operator.
|
||||||
|
///\param lhs Reference to the first array.
|
||||||
|
///\param rhs Reference to the second array.
|
||||||
|
///\return <b>true</b> if the first array is lexicographically greater than or equal to the second, otherwise <b>false</b>
|
||||||
|
//*************************************************************************
|
||||||
|
template <typename T, std::size_t SIZE>
|
||||||
|
bool operator >=(const elt::array<T, SIZE>& lhs, const elt::array<T, SIZE>& rhs)
|
||||||
|
{
|
||||||
|
return !std::lexicographical_compare(lhs.cbegin(),
|
||||||
|
lhs.cend(),
|
||||||
|
rhs.cbegin(),
|
||||||
|
rhs.cend());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
17
doxygen.h
17
doxygen.h
@ -24,18 +24,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
///\defgroup ETL Embedded Template Library
|
///\defgroup etl Embedded Template Library
|
||||||
|
|
||||||
///\defgroup Containers Containers
|
///\defgroup containers Containers
|
||||||
///\ingroup ETL
|
///\ingroup etl
|
||||||
|
|
||||||
///\defgroup Utilities Utilities
|
///\defgroup utilities Utilities
|
||||||
///\ingroup ETL
|
/// A set of utility templates.
|
||||||
|
///\ingroup etl
|
||||||
|
|
||||||
///\defgroup Math Math
|
///\defgroup math Math
|
||||||
///\ingroup ETL
|
///\ingroup etl
|
||||||
|
|
||||||
///\ingroup ETL
|
///\ingroup etl
|
||||||
namespace etl {}
|
namespace etl {}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
114
enum_type.h
Normal file
114
enum_type.h
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
|
||||||
|
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_enum_type__
|
||||||
|
#define __etl_enum_type__
|
||||||
|
|
||||||
|
///\defgroup enum_type enum_type
|
||||||
|
/// Smart enumerations.<br>
|
||||||
|
/// A method of declaring enumerations that allow grouping within a structure.
|
||||||
|
/// Avoids the problem of clashing names that can occur with standard enumerations.
|
||||||
|
/// One way to think of the code is as a type with built-in constants and an optional conversion to a string.<br><br>
|
||||||
|
/// <b>Declaring the enumeration.</b>
|
||||||
|
///\code
|
||||||
|
/// struct CompassDirection
|
||||||
|
/// {
|
||||||
|
/// enum enum_type
|
||||||
|
/// {
|
||||||
|
/// North = 0,
|
||||||
|
/// South = 180,
|
||||||
|
/// East = 90,
|
||||||
|
/// West = 270
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// DECLARE_ENUM_TYPE(CompassDirection, int)
|
||||||
|
/// ENUM_TYPE("North", North)
|
||||||
|
/// ENUM_TYPE("South", South)
|
||||||
|
/// ENUM_TYPE("East", East)
|
||||||
|
/// ENUM_TYPE("West", West)
|
||||||
|
/// END_ENUM_TYPE
|
||||||
|
/// };
|
||||||
|
///\endcode
|
||||||
|
/// <b>Using the enumeration.</b>
|
||||||
|
///\code
|
||||||
|
/// CompassDirection direction; // Default construction.
|
||||||
|
///
|
||||||
|
/// direction = CompassDirection::North; // Assignment from an enumeration constant;
|
||||||
|
///
|
||||||
|
/// int value = direction; // Implicit conversion to 'int'.
|
||||||
|
///
|
||||||
|
/// direction = CompassDirection(value); // Explicit conversion from 'int'.
|
||||||
|
///
|
||||||
|
/// direction = CompassDirection(3); // Explicit conversion from an invalid value. This unfortunately cannot be avoided. Caveat emptor!
|
||||||
|
///
|
||||||
|
/// direction = value; // **** Compilation error ****
|
||||||
|
///
|
||||||
|
/// std::cout << "Direction = " << direction.to_string(); // Prints "Direction = North"
|
||||||
|
///\endcode
|
||||||
|
/// If a conversion to a string is not required then the 'ENUM_TYPE' declaration may be omitted.
|
||||||
|
/// In that case the to_string() function will return a "?". This will also be the case for any
|
||||||
|
/// enumeration value that does not have an ENUM_TYPE entry.
|
||||||
|
///\ingroup utilities
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The declaration of the member functions and the first section of the 'to_string' function.
|
||||||
|
//*****************************************************************************
|
||||||
|
#define DECLARE_ENUM_TYPE(TypeName, ValueType) \
|
||||||
|
typedef ValueType value_type; \
|
||||||
|
inline TypeName() {} \
|
||||||
|
inline TypeName(const TypeName &other) : value(other.value) {} \
|
||||||
|
inline TypeName(enum_type value) : value(value) {} \
|
||||||
|
inline TypeName& operator=(const TypeName &other) { value = other.value} \
|
||||||
|
inline explicit TypeName(ValueType value) : value(static_cast<enum_type>(value)) {} \
|
||||||
|
inline operator ValueType() const {return (static_cast<ValueType>(value));} \
|
||||||
|
inline ValueType get_value() const {return (static_cast<ValueType>(value));} \
|
||||||
|
inline enum_type get_enum() const {return value;} \
|
||||||
|
const char* to_string() const \
|
||||||
|
{ \
|
||||||
|
switch (value) \
|
||||||
|
{
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// A case in the 'to_string' function's switch statement.
|
||||||
|
//*****************************************************************************
|
||||||
|
#define ENUM_TYPE(value, name) \
|
||||||
|
case value: \
|
||||||
|
return name; \
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The final section of the 'to_string' function and the value declaration.
|
||||||
|
//*****************************************************************************
|
||||||
|
#define END_ENUM_TYPE \
|
||||||
|
default: \
|
||||||
|
return "?"; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
private: \
|
||||||
|
enum_type value;
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -29,14 +29,14 @@ SOFTWARE.
|
|||||||
#ifndef __etl_exception__
|
#ifndef __etl_exception__
|
||||||
#define __etl_exception__
|
#define __etl_exception__
|
||||||
|
|
||||||
///\defgroup Exception Exceptions
|
///\defgroup exception exception
|
||||||
/// The base class for all ETL exceptions.
|
/// The base class for all ETL exceptions.
|
||||||
///\ingroup Utilities
|
///\ingroup utilities
|
||||||
|
|
||||||
namespace etl
|
namespace etl
|
||||||
{
|
{
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Exception
|
///\ingroup exception
|
||||||
/// A low overhead exception base class.
|
/// A low overhead exception base class.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
class exception
|
class exception
|
||||||
|
|||||||
16
function.h
16
function.h
@ -30,18 +30,18 @@ SOFTWARE.
|
|||||||
#define __etl_function__
|
#define __etl_function__
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
///\defgroup Function Function
|
///\defgroup function function
|
||||||
/// A set of wrapper templates to allow a member or static function to be called
|
/// A set of wrapper templates to allow a member or static function to be called
|
||||||
/// without the caller having to know the specific details of the callee.
|
/// without the caller having to know the specific details of the callee.
|
||||||
/// This template class may be used to link interrupt vectors to specific member
|
/// This template class may be used to link interrupt vectors to specific member
|
||||||
/// functions of a handler class.
|
/// functions of a handler class.
|
||||||
///\ingroup Utilities
|
///\ingroup utilities
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
||||||
namespace etl
|
namespace etl
|
||||||
{
|
{
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Function
|
///\ingroup function
|
||||||
/// The base interface template for function template specialisations.
|
/// The base interface template for function template specialisations.
|
||||||
///\tparam TParameter The parameter type expected by the function.
|
///\tparam TParameter The parameter type expected by the function.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
@ -59,7 +59,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Function
|
///\ingroup function
|
||||||
/// The base interface template for functions taking <b>void</b> parameters.
|
/// The base interface template for functions taking <b>void</b> parameters.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <>
|
template <>
|
||||||
@ -74,7 +74,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Function
|
///\ingroup function
|
||||||
/// A derived function template that takes an object type and parameter type.
|
/// A derived function template that takes an object type and parameter type.
|
||||||
///\tparam TObject The object type that contains the member function.
|
///\tparam TObject The object type that contains the member function.
|
||||||
///\tparam TParameter The parameter type accepted by the member function.
|
///\tparam TParameter The parameter type accepted by the member function.
|
||||||
@ -116,7 +116,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Function
|
///\ingroup function
|
||||||
/// A derived function template that takes a parameter type.
|
/// A derived function template that takes a parameter type.
|
||||||
///\tparam TObject The object type that contains the member function.
|
///\tparam TObject The object type that contains the member function.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
@ -152,7 +152,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Function
|
///\ingroup function
|
||||||
/// Specialisation for static or global functions that take a parameter.
|
/// Specialisation for static or global functions that take a parameter.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <typename TParameter>
|
template <typename TParameter>
|
||||||
@ -185,7 +185,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Function
|
///\ingroup function
|
||||||
/// Specialisation static functions taking void parameter.
|
/// Specialisation static functions taking void parameter.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <>
|
template <>
|
||||||
|
|||||||
7
iqueue.h
7
iqueue.h
@ -33,15 +33,12 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "queue_base.h"
|
#include "queue_base.h"
|
||||||
|
|
||||||
///\defgroup Queue Queue
|
|
||||||
///\ingroup Containers
|
|
||||||
|
|
||||||
namespace etl
|
namespace etl
|
||||||
{
|
{
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Queue
|
///\ingroup queue
|
||||||
///\brief This is the base for all queues that contain a particular type.
|
///\brief This is the base for all queues that contain a particular type.
|
||||||
///\detail Normally a reference to this type will be taken from a derived queue.
|
///\details Normally a reference to this type will be taken from a derived queue.
|
||||||
///\code
|
///\code
|
||||||
/// etl::queue<int, 10> myQueue;
|
/// etl::queue<int, 10> myQueue;
|
||||||
/// etl::iqueue<int>& iQueue = myQueue;
|
/// etl::iqueue<int>& iQueue = myQueue;
|
||||||
|
|||||||
23
math.h
23
math.h
@ -31,10 +31,17 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
///\defgroup log log
|
||||||
|
/// A set of templates to generate compile time constants.<br>
|
||||||
|
/// log<N, BASE> : Calculates logs to any base, rounded down to the nearest integer.<br>
|
||||||
|
/// log2<N> : Calculates logs to base 2, rounded down to the nearest integer.<br>
|
||||||
|
/// log10<N> : Calculates logs to base 10, rounded down to the nearest integer.<br>
|
||||||
|
///\ingroup math
|
||||||
|
|
||||||
namespace etl
|
namespace etl
|
||||||
{
|
{
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Math
|
///\ingroup log
|
||||||
/// The base generic log template.
|
/// The base generic log template.
|
||||||
/// Defines 'value' as the log of the number at the specified base.
|
/// Defines 'value' as the log of the number at the specified base.
|
||||||
/// The result is rounded down to the next integer.
|
/// The result is rounded down to the next integer.
|
||||||
@ -52,8 +59,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Math
|
// Specialisation for N = 1
|
||||||
/// Specialisation for N = 1
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <const size_t BASE>
|
template <const size_t BASE>
|
||||||
struct log<1, BASE>
|
struct log<1, BASE>
|
||||||
@ -65,8 +71,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Math
|
// Specialisation for N = 0
|
||||||
/// Specialisation for N = 0
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <const size_t BASE>
|
template <const size_t BASE>
|
||||||
struct log<0, BASE>
|
struct log<0, BASE>
|
||||||
@ -78,8 +83,8 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Math
|
///\ingroup log
|
||||||
/// The specialisation for base 2 logs.
|
/// Calculates base 2 logs.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <const size_t N>
|
template <const size_t N>
|
||||||
struct Log2
|
struct Log2
|
||||||
@ -91,8 +96,8 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Math
|
///\ingroup log
|
||||||
/// The specialisation for base 10 logs.
|
/// Calculates base 10 logs.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
template <const size_t N>
|
template <const size_t N>
|
||||||
struct Log10
|
struct Log10
|
||||||
|
|||||||
4
queue.h
4
queue.h
@ -34,7 +34,7 @@ SOFTWARE.
|
|||||||
#include "IQueue.h"
|
#include "IQueue.h"
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
///\defgroup Queue Queue
|
///\defgroup queue queue
|
||||||
/// A First-in / first-out queue with the capacity defined at compile time,
|
/// A First-in / first-out queue with the capacity defined at compile time,
|
||||||
/// written in the STL style.
|
/// written in the STL style.
|
||||||
///\ingroup Containers
|
///\ingroup Containers
|
||||||
@ -43,7 +43,7 @@ SOFTWARE.
|
|||||||
namespace etl
|
namespace etl
|
||||||
{
|
{
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Queue
|
///\ingroup queue
|
||||||
/// A fixed capacity queue.
|
/// A fixed capacity queue.
|
||||||
/// This queue does not support concurrent access by different threads.
|
/// This queue does not support concurrent access by different threads.
|
||||||
/// \tparam T The type this queue should support.
|
/// \tparam T The type this queue should support.
|
||||||
|
|||||||
18
queue_base.h
18
queue_base.h
@ -33,16 +33,14 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
///\defgroup Queue Queue
|
///\defgroup queue Queue
|
||||||
///\ingroup Containers
|
///\ingroup containers
|
||||||
|
|
||||||
namespace etl
|
namespace etl
|
||||||
{
|
{
|
||||||
#ifdef ETL_USE_EXCEPTIONS
|
#ifdef ETL_USE_EXCEPTIONS
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Queue
|
///\ingroup queue
|
||||||
///\brief This is the base for all queues.
|
|
||||||
///\detail This is the base for all queues. Instances or references to this type should never need to be created.
|
|
||||||
/// The base class for queue exceptions.
|
/// The base class for queue exceptions.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
class queue_exception : public exception
|
class queue_exception : public exception
|
||||||
@ -56,7 +54,7 @@ namespace etl
|
|||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Queue
|
///\ingroup queue
|
||||||
/// The exception thrown when the queue is full.
|
/// The exception thrown when the queue is full.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
class queue_full_exception : public queue_exception
|
class queue_full_exception : public queue_exception
|
||||||
@ -64,13 +62,13 @@ namespace etl
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
queue_full_exception()
|
queue_full_exception()
|
||||||
: queue_exception("queue full exception")
|
: queue_exception("queue full")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Queue
|
///\ingroup queue
|
||||||
/// The exception thrown when the queue is empty.
|
/// The exception thrown when the queue is empty.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
class queue_empty_exception : public queue_exception
|
class queue_empty_exception : public queue_exception
|
||||||
@ -78,14 +76,14 @@ namespace etl
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
queue_empty_exception()
|
queue_empty_exception()
|
||||||
: queue_exception("queue empty exception")
|
: queue_exception("queue empty")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
///\ingroup Queue
|
///\ingroup queue
|
||||||
/// A fixed capacity queue written in the STL style.
|
/// A fixed capacity queue written in the STL style.
|
||||||
/// \warning This queue cannot be used for concurrent access from multiple threads.
|
/// \warning This queue cannot be used for concurrent access from multiple threads.
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user