mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Merge branch 'master' into feature/github-actions-for-windows-compilers
# Conflicts: # .github/workflows/main.yml # include/etl/version.h # library.json # library.properties # support/Release notes.txt # test/vs2019/etl.vcxproj.filters
This commit is contained in:
commit
5550500e7b
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
@ -63,3 +63,4 @@ jobs:
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ version: 1.0.{build}
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
image: Visual Studio 2017
|
||||
image: Visual Studio 2019
|
||||
configuration:
|
||||
- Debug
|
||||
- DebugNoSTL
|
||||
@ -12,7 +12,7 @@ install:
|
||||
before_build:
|
||||
- cmd: git clone https://github.com/unittest-cpp/unittest-cpp.git c:\projects\unittest-cpp
|
||||
build:
|
||||
project: test/vs2017/etl.vcxproj
|
||||
project: test/vs2019/etl.vcxproj
|
||||
verbosity: minimal
|
||||
notifications:
|
||||
- provider: Webhook
|
||||
@ -20,4 +20,5 @@ notifications:
|
||||
method: POST
|
||||
on_build_success: true
|
||||
on_build_failure: true
|
||||
on_build_status_changed: true
|
||||
on_build_status_changed: true
|
||||
|
||||
@ -127,7 +127,7 @@ namespace etl
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
|
||||
@ -142,7 +142,7 @@ namespace etl
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
!etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
{
|
||||
while (sb != se)
|
||||
@ -192,7 +192,7 @@ namespace etl
|
||||
template <typename TIterator1, typename TSize, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_n(TIterator1 sb, TSize count, TIterator2 db)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
|
||||
@ -204,7 +204,7 @@ namespace etl
|
||||
template <typename TIterator1, typename TSize, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
!etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_n(TIterator1 sb, TSize count, TIterator2 db)
|
||||
{
|
||||
while (count != 0)
|
||||
@ -236,8 +236,8 @@ namespace etl
|
||||
// Pointer
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
|
||||
@ -250,8 +250,8 @@ namespace etl
|
||||
// Other iterator
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
{
|
||||
while (se != sb)
|
||||
@ -275,8 +275,12 @@ namespace etl
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// move
|
||||
// non-pointer or not trivially copyable
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
move(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
{
|
||||
while (sb != se)
|
||||
{
|
||||
@ -285,6 +289,21 @@ namespace etl
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
// pointer and trivially copyable
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
move(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
|
||||
typedef typename etl::iterator_traits<TIterator1>::difference_type difference_t;
|
||||
|
||||
difference_t count = (se - sb);
|
||||
|
||||
return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count;
|
||||
}
|
||||
#else
|
||||
//***************************************************************************
|
||||
// move
|
||||
@ -310,8 +329,12 @@ namespace etl
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// move_backward
|
||||
// non-pointer, non-pod
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value ||
|
||||
!etl::is_pointer<TIterator2>::value ||
|
||||
!etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
{
|
||||
while (sb != se)
|
||||
{
|
||||
@ -320,6 +343,22 @@ namespace etl
|
||||
|
||||
return de;
|
||||
}
|
||||
|
||||
// pointer and pod
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value &&
|
||||
etl::is_pointer<TIterator2>::value &&
|
||||
etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, TIterator2>::type
|
||||
move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
|
||||
typedef typename etl::iterator_traits<TIterator1>::difference_type difference_t;
|
||||
|
||||
difference_t count = (se - sb);
|
||||
TIterator2 db = de - count;
|
||||
|
||||
return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count;
|
||||
}
|
||||
#else
|
||||
//***************************************************************************
|
||||
// move_backward
|
||||
@ -690,7 +729,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// count_if
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
@ -722,12 +761,12 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// equal
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
ETL_NODISCARD
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value || !etl::is_pointer<TIterator2>::value || !etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
typename etl::enable_if<!etl::is_pointer<TIterator1>::value || !etl::is_pointer<TIterator2>::value || !etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
|
||||
{
|
||||
while (first1 != last1)
|
||||
@ -743,7 +782,7 @@ namespace etl
|
||||
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
ETL_NODISCARD
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value && etl::is_pointer<TIterator2>::value && etl::is_pod<typename etl::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
typename etl::enable_if<etl::is_pointer<TIterator1>::value && etl::is_pointer<TIterator2>::value && etl::is_trivially_copyable<typename etl::iterator_traits<TIterator1>::value_type>::value, bool>::type
|
||||
equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator1>::value_type value_t;
|
||||
@ -761,7 +800,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// lexicographical_compare
|
||||
template <typename TIterator1, typename TIterator2, typename TCompare>
|
||||
@ -823,7 +862,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// min
|
||||
template <typename T, typename TCompare>
|
||||
@ -859,7 +898,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// max
|
||||
template <typename T, typename TCompare>
|
||||
@ -895,7 +934,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// transform
|
||||
template <typename TIteratorIn, typename TIteratorOut, typename TUnaryOperation>
|
||||
@ -935,7 +974,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// replace
|
||||
template <typename TIterator, typename T>
|
||||
@ -1056,7 +1095,7 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
// Pop Heap
|
||||
template <typename TIterator, typename TCompare>
|
||||
void pop_heap(TIterator first, TIterator last, TCompare compare)
|
||||
@ -1258,7 +1297,7 @@ namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// Search
|
||||
template<typename TIterator1, typename TIterator2, typename TCompare>
|
||||
@ -1323,33 +1362,91 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// Rotate
|
||||
namespace private_algorithm
|
||||
{
|
||||
//*********************************
|
||||
template <typename TIterator>
|
||||
TIterator rotate_general(TIterator first, TIterator middle, TIterator last)
|
||||
{
|
||||
TIterator next = middle;
|
||||
|
||||
while (first != next)
|
||||
{
|
||||
using ETL_OR_STD::swap; // Allow ADL
|
||||
|
||||
swap(*first++, *next++);
|
||||
|
||||
if (next == last)
|
||||
{
|
||||
next = middle;
|
||||
}
|
||||
else if (first == middle)
|
||||
{
|
||||
middle = next;
|
||||
}
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
template <typename TIterator>
|
||||
TIterator rotate_left_by_one(TIterator first, TIterator last)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator>::value_type value_type;
|
||||
|
||||
// Save the first item.
|
||||
value_type temp(etl::move(*first));
|
||||
|
||||
// Move the rest.
|
||||
TIterator result = etl::move(etl::next(first), last, first);
|
||||
|
||||
// Restore the first item in its rotated position.
|
||||
*result = etl::move(temp);
|
||||
|
||||
// The new position of the first item.
|
||||
return result;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
template <typename TIterator>
|
||||
TIterator rotate_right_by_one(TIterator first, TIterator last)
|
||||
{
|
||||
typedef typename etl::iterator_traits<TIterator>::value_type value_type;
|
||||
|
||||
// Save the last item.
|
||||
TIterator previous = etl::prev(last);
|
||||
value_type temp(etl::move(*previous));
|
||||
|
||||
// Move the rest.
|
||||
TIterator result = etl::move_backward(first, previous, last);
|
||||
|
||||
// Restore the last item in its rotated position.
|
||||
*first = etl::move(temp);
|
||||
|
||||
// The new position of the first item.
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//*********************************
|
||||
template<typename TIterator>
|
||||
TIterator rotate(TIterator first, TIterator middle, TIterator last)
|
||||
{
|
||||
using ETL_OR_STD::swap; // Allow ADL
|
||||
|
||||
TIterator next = middle;
|
||||
|
||||
while (first != next)
|
||||
if (etl::next(first) == middle)
|
||||
{
|
||||
using ETL_OR_STD::swap;
|
||||
|
||||
swap(*first++, *next++);
|
||||
|
||||
if (next == last)
|
||||
{
|
||||
next = middle;
|
||||
}
|
||||
else if (first == middle)
|
||||
{
|
||||
middle = next;
|
||||
}
|
||||
return private_algorithm::rotate_left_by_one(first, last);
|
||||
}
|
||||
|
||||
return first;
|
||||
if (etl::next(middle) == last)
|
||||
{
|
||||
return private_algorithm::rotate_right_by_one(first, last);
|
||||
}
|
||||
|
||||
return private_algorithm::rotate_general(first, middle, last);
|
||||
}
|
||||
#else
|
||||
//***************************************************************************
|
||||
@ -1361,7 +1458,7 @@ namespace etl
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (ETL_NO_STL)
|
||||
#if ETL_NOT_USING_STL
|
||||
//***************************************************************************
|
||||
// find_end
|
||||
// Predicate
|
||||
|
||||
@ -184,7 +184,7 @@ namespace etl
|
||||
return reinterpret_cast<const T*>(data);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5)
|
||||
alignas(ALIGNMENT) char data[LENGTH];
|
||||
#else
|
||||
union
|
||||
|
||||
@ -552,6 +552,15 @@ namespace etl
|
||||
T _buffer[SIZE];
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename T, typename... Ts>
|
||||
array(T, Ts...)
|
||||
-> array<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Overloaded swap for etl::array<T, SIZE>
|
||||
///\param lhs The first array.
|
||||
@ -670,4 +679,3 @@ namespace etl
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ SOFTWARE.
|
||||
#include "hash.h"
|
||||
#include "algorithm.h"
|
||||
#include "memory.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
///\defgroup array array
|
||||
/// A wrapper for arrays
|
||||
@ -132,7 +133,7 @@ namespace etl
|
||||
/// data() and size() member functions.
|
||||
//*************************************************************************
|
||||
template <typename TArray>
|
||||
ETL_CONSTEXPR explicit array_view(TArray& a)
|
||||
ETL_CONSTEXPR array_view(TArray& a)
|
||||
: mbegin(a.data()),
|
||||
mend(a.data() + a.size())
|
||||
{
|
||||
@ -162,8 +163,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from C array
|
||||
//*************************************************************************
|
||||
template<const size_t ARRAY_SIZE>
|
||||
ETL_CONSTEXPR explicit array_view(T(&begin_)[ARRAY_SIZE])
|
||||
template<size_t ARRAY_SIZE>
|
||||
ETL_CONSTEXPR array_view(T(&begin_)[ARRAY_SIZE])
|
||||
: mbegin(begin_),
|
||||
mend(begin_ + ARRAY_SIZE)
|
||||
{
|
||||
@ -505,6 +506,24 @@ namespace etl
|
||||
T* mend;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename TArray>
|
||||
array_view(TArray& a)
|
||||
-> array_view<typename TArray::value_type>;
|
||||
|
||||
template <typename TIterator>
|
||||
array_view(const TIterator begin_, const TIterator end_)
|
||||
-> array_view<etl::remove_pointer_t<TIterator>>;
|
||||
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
array_view(const TIterator begin_, const TSize size_)
|
||||
-> array_view<etl::remove_pointer_t<TIterator>>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
@ -533,4 +552,3 @@ void swap(etl::array_view<T>& lhs, etl::array_view<T>& rhs)
|
||||
#undef ETL_FILE
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -874,7 +874,7 @@ namespace etl
|
||||
/// The class emulates an array of bool elements, but optimized for space allocation.
|
||||
/// Will accommodate any number of bits.
|
||||
/// Does not use std::string.
|
||||
///\tparam N The number of bits.
|
||||
///\tparam MAXN The number of bits.
|
||||
///\ingroup bitset
|
||||
//*************************************************************************
|
||||
template <const size_t MAXN>
|
||||
|
||||
361
include/etl/bresenham_line.h
Normal file
361
include/etl/bresenham_line.h
Normal file
@ -0,0 +1,361 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 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_BRESENHAM_LINE_INCLUDED
|
||||
#define ETL_BRESENHAM_LINE_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "iterator.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// A pseudo-container that generates points on a line, using Bresenham's
|
||||
/// line algorithm.
|
||||
/// T is the type for the etl::coordinate_2d value type.
|
||||
/// TWork is the internal working variable type. Default is int16_t.
|
||||
//***************************************************************************
|
||||
template <typename T, typename TWork = int16_t>
|
||||
class bresenham_line
|
||||
{
|
||||
public:
|
||||
|
||||
//***************************************************
|
||||
/// Standard container types.
|
||||
//***************************************************
|
||||
typedef etl::coordinate_2d<T> value_type;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
|
||||
//***************************************************
|
||||
/// Const Iterator
|
||||
//***************************************************
|
||||
class const_iterator : public etl::iterator<ETL_OR_STD::forward_iterator_tag, const value_type>
|
||||
{
|
||||
public:
|
||||
|
||||
friend class bresenham_line;
|
||||
|
||||
//***************************************************
|
||||
/// Default constructor
|
||||
//***************************************************
|
||||
const_iterator()
|
||||
: p_bresenham_line(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Copy constuctor
|
||||
//***************************************************
|
||||
const_iterator(const const_iterator& other)
|
||||
: p_bresenham_line(other.p_bresenham_line)
|
||||
{
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Assignment operator
|
||||
//***************************************************
|
||||
const_iterator& operator =(const const_iterator& rhs)
|
||||
{
|
||||
p_bresenham_line = rhs.p_bresenham_line;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Pre-increment operator
|
||||
//***************************************************
|
||||
const_iterator& operator ++()
|
||||
{
|
||||
// Has the end of the series has been reached?
|
||||
if (p_bresenham_line->get_coordinate() == p_bresenham_line->back())
|
||||
{
|
||||
// Mark it as an end iterator.
|
||||
p_bresenham_line = ETL_NULLPTR;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_bresenham_line->next();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// De-reference operator
|
||||
//***************************************************
|
||||
value_type operator *() const
|
||||
{
|
||||
return p_bresenham_line->get_coordinate();
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Equality operator
|
||||
//***************************************************
|
||||
friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs)
|
||||
{
|
||||
return lhs.p_bresenham_line == rhs.p_bresenham_line;
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Inequality operator
|
||||
//***************************************************
|
||||
friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//***************************************************
|
||||
/// Constructor for use by bresenham_line
|
||||
//***************************************************
|
||||
const_iterator(bresenham_line<T>* pb)
|
||||
: p_bresenham_line(pb)
|
||||
{
|
||||
}
|
||||
|
||||
bresenham_line<T>* p_bresenham_line;
|
||||
};
|
||||
|
||||
//***************************************************
|
||||
/// Constructor.
|
||||
//***************************************************
|
||||
bresenham_line()
|
||||
{
|
||||
initialise(T(0), T(0), T(0), T(0));
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Constructor.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
bresenham_line(etl::coordinate_2d<T> first_, etl::coordinate_2d<T> last_)
|
||||
{
|
||||
initialise(first_.x, first_.y, last_.x, last_.y);
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Constructor.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
bresenham_line(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
initialise(first_x, first_y, last_x, last_y);
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Resets the line.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
void reset(etl::coordinate_2d<T> first_, etl::coordinate_2d<T> last_)
|
||||
{
|
||||
initialise(first_.x, first_.y, last_.x, last_.y);
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Resets the line.
|
||||
/// Supplied first and last coordinates
|
||||
//***************************************************
|
||||
void reset(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
initialise(first_x, first_y, last_x, last_y);
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Get a const_iterator to the first coordinate.
|
||||
/// Resets the Bresenham line.
|
||||
//***************************************************
|
||||
const_iterator begin()
|
||||
{
|
||||
coordinate = first;
|
||||
|
||||
return const_iterator(this);
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Get a const_iterator to one past the last coordinate.
|
||||
//***************************************************
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator();
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Get the first coordinate.
|
||||
//***************************************************
|
||||
const_reference front() const
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Get the last coordinate.
|
||||
//***************************************************
|
||||
const_reference back() const
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Get the size of the series.
|
||||
//***************************************************
|
||||
size_t size() const
|
||||
{
|
||||
if (y_is_major_axis())
|
||||
{
|
||||
return (dy / 2) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (dx / 2) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Equality operator
|
||||
//***************************************************
|
||||
friend bool operator ==(const bresenham_line& lhs, const bresenham_line& rhs)
|
||||
{
|
||||
return (lhs.front() == rhs.front()) && (lhs.back() == rhs.back());
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Inequality operator
|
||||
//***************************************************
|
||||
friend bool operator !=(const bresenham_line& lhs, const bresenham_line& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//***************************************************
|
||||
/// Get the current number of generated points.
|
||||
//***************************************************
|
||||
void initialise(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
first = value_type(first_x, first_y);
|
||||
last = value_type(last_x, last_y);
|
||||
coordinate = first;
|
||||
x_increment = (last_x < first_x) ? -1 : 1;
|
||||
y_increment = (last_y < first_y) ? -1 : 1;
|
||||
dx = (last_x < first_x) ? first_x - last_x : last_x - first_x;
|
||||
dy = (last_y < first_y) ? first_y - last_y : last_y - first_y;
|
||||
do_minor_increment = false;
|
||||
|
||||
if (y_is_major_axis())
|
||||
{
|
||||
dx *= 2;
|
||||
balance = dx - dy;
|
||||
dy *= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
dy *= 2;
|
||||
balance = dy - dx;
|
||||
dx *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Returns true if Y is the major axis.
|
||||
//***************************************************
|
||||
bool y_is_major_axis() const
|
||||
{
|
||||
return dx < dy;
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Calculate the next point.
|
||||
//***************************************************
|
||||
void next()
|
||||
{
|
||||
if (y_is_major_axis())
|
||||
{
|
||||
// Y is major axis.
|
||||
if (do_minor_increment)
|
||||
{
|
||||
coordinate.x = T(coordinate.x + x_increment);
|
||||
balance -= dy;
|
||||
}
|
||||
|
||||
coordinate.y = T(coordinate.y + y_increment);
|
||||
balance += dx;
|
||||
}
|
||||
else
|
||||
{
|
||||
// X is major axis.
|
||||
if (do_minor_increment)
|
||||
{
|
||||
coordinate.y = T(coordinate.y + y_increment);
|
||||
balance -= dx;
|
||||
}
|
||||
|
||||
coordinate.x = T(coordinate.x + x_increment);
|
||||
balance += dy;
|
||||
}
|
||||
|
||||
do_minor_increment = (balance >= 0);
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Get the current coordinate.
|
||||
//***************************************************
|
||||
value_type get_coordinate() const
|
||||
{
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
typedef TWork work_t;
|
||||
|
||||
value_type first;
|
||||
value_type last;
|
||||
value_type coordinate;
|
||||
work_t x_increment;
|
||||
work_t y_increment;
|
||||
work_t dx;
|
||||
work_t dy;
|
||||
work_t balance;
|
||||
bool do_minor_increment;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -102,19 +102,19 @@ namespace etl
|
||||
typedef typename char_traits_types<T>::state_type state_type;
|
||||
|
||||
//*************************************************************************
|
||||
static bool eq(char_type a, char_type b)
|
||||
ETL_CONSTEXPR static bool eq(char_type a, char_type b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static bool lt(char_type a, char_type b)
|
||||
ETL_CONSTEXPR static bool lt(char_type a, char_type b)
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
static size_t length(const char_type* str)
|
||||
ETL_CONSTEXPR14 static size_t length(const char_type* str)
|
||||
{
|
||||
size_t count = 0;
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2016 jwellbelove
|
||||
Copyright(c) 2020 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
|
||||
@ -28,460 +28,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_STRING_INCLUDED
|
||||
#define ETL_STRING_INCLUDED
|
||||
//*****************************************************************************
|
||||
// This header is deprecated. Use "string.h"
|
||||
//*****************************************************************************
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_string.h"
|
||||
#include "string_view.h"
|
||||
#include "hash.h"
|
||||
#pragma message ("This header is deprecated. Use 'etl/string.h'")
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#include "private/minmax_push.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
typedef etl::ibasic_string<char> istring;
|
||||
|
||||
//***************************************************************************
|
||||
/// A string implementation that uses a fixed size buffer.
|
||||
///\tparam MAX_SIZE_ The maximum number of elements that can be stored.
|
||||
///\ingroup string
|
||||
//***************************************************************************
|
||||
template <const size_t MAX_SIZE_>
|
||||
class string : public istring
|
||||
{
|
||||
public:
|
||||
|
||||
typedef istring base_type;
|
||||
typedef istring interface_type;
|
||||
|
||||
typedef istring::value_type value_type;
|
||||
|
||||
static const size_t MAX_SIZE = MAX_SIZE_;
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
string()
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
///\param other The other string.
|
||||
//*************************************************************************
|
||||
string(const etl::string<MAX_SIZE_>& other)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other istring.
|
||||
///\param other The other istring.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other string, position, length.
|
||||
///\param other The other string.
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other, size_t position, size_t length_ = npos)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
this->assign(other.begin() + position, other.begin() + position + length_);
|
||||
|
||||
if (other.truncated())
|
||||
{
|
||||
this->is_truncated = true;
|
||||
|
||||
#if defined(ETL_STRING_TRUNCATION_IS_ERROR)
|
||||
ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the string.
|
||||
//*************************************************************************
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(text, text + etl::char_traits<value_type>::length(text));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text and count.
|
||||
///\param text The initial text of the string.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
string(const value_type* text, size_t count)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from initial size and value.
|
||||
///\param initialSize The initial size of the string.
|
||||
///\param value The value to fill the string with.
|
||||
//*************************************************************************
|
||||
string(size_t count, value_type c)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
string(TIterator first, TIterator last)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
string(std::initializer_list<value_type> init)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// From string_view.
|
||||
///\param view The string_view.
|
||||
//*************************************************************************
|
||||
explicit string(const etl::string_view& view)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a sub-string.
|
||||
///\param position The position of the first character. Default = 0.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
etl::string<MAX_SIZE_> substr(size_t position = 0, size_t length_ = npos) const
|
||||
{
|
||||
etl::string<MAX_SIZE_> new_string;
|
||||
|
||||
if (position != this->size())
|
||||
{
|
||||
ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
length_ = etl::min(length_, this->size() - position);
|
||||
|
||||
new_string.assign(buffer + position, buffer + position + length_);
|
||||
}
|
||||
|
||||
return new_string;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const string& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const istring& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const value_type* text)
|
||||
{
|
||||
this->assign(text);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair()
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
ETL_OVERRIDE
|
||||
#endif
|
||||
{
|
||||
etl::istring::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
value_type buffer[MAX_SIZE + 1];
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// A string implementation that uses a fixed size buffer.
|
||||
/// A specilisation that requires an external buffer to be specified.
|
||||
///\ingroup string
|
||||
//***************************************************************************
|
||||
template <>
|
||||
class string<0U> : public istring
|
||||
{
|
||||
public:
|
||||
|
||||
typedef istring base_type;
|
||||
typedef istring interface_type;
|
||||
|
||||
typedef istring::value_type value_type;
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
string(value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
///\param other The other string.
|
||||
//*************************************************************************
|
||||
string(const etl::string<0U>& other, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other istring.
|
||||
///\param other The other istring.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other string, position, length.
|
||||
///\param other The other string.
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
this->assign(other.begin() + position, other.begin() + position + length_);
|
||||
|
||||
if (other.truncated())
|
||||
{
|
||||
this->is_truncated = true;
|
||||
|
||||
#if defined(ETL_STRING_TRUNCATION_IS_ERROR)
|
||||
ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the string.
|
||||
//*************************************************************************
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(text, text + etl::char_traits<value_type>::length(text));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text and count.
|
||||
///\param text The initial text of the string.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
string(const value_type* text, size_t count, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from initial size and value.
|
||||
///\param initialSize The initial size of the string.
|
||||
///\param value The value to fill the string with.
|
||||
//*************************************************************************
|
||||
string(size_t count, value_type c, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
string(TIterator first, TIterator last, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
string(std::initializer_list<value_type> init, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// From string_view.
|
||||
///\param view The string_view.
|
||||
//*************************************************************************
|
||||
explicit string(const etl::string_view& view, value_type* buffer, size_t max_size)
|
||||
: istring(buffer, max_size - 1)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const string& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const istring& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const value_type* text)
|
||||
{
|
||||
this->assign(text);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair()
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
ETL_OVERRIDE
|
||||
#endif
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
#if ETL_8BIT_SUPPORT
|
||||
template <>
|
||||
struct hash<etl::istring>
|
||||
{
|
||||
size_t operator()(const etl::istring& text) const
|
||||
{
|
||||
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
|
||||
reinterpret_cast<const uint8_t*>(&text[text.size()]));
|
||||
}
|
||||
};
|
||||
|
||||
template <const size_t SIZE>
|
||||
struct hash<etl::string<SIZE> >
|
||||
{
|
||||
size_t operator()(const etl::string<SIZE>& text) const
|
||||
{
|
||||
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
|
||||
reinterpret_cast<const uint8_t*>(&text[text.size()]));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string from string literal or char array
|
||||
//***************************************************************************
|
||||
template<const size_t MAX_SIZE>
|
||||
etl::string<MAX_SIZE - 1> make_string(const char (&text) [MAX_SIZE])
|
||||
{
|
||||
return etl::string<MAX_SIZE - 1>(text, MAX_SIZE - 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string with max capacity from string literal or char array
|
||||
//***************************************************************************
|
||||
template<const size_t MAX_SIZE, const size_t SIZE>
|
||||
etl::string<MAX_SIZE> make_string_with_capacity(const char(&text)[SIZE])
|
||||
{
|
||||
return etl::string<MAX_SIZE>(text, SIZE - 1);
|
||||
}
|
||||
}
|
||||
|
||||
#include "private/minmax_pop.h"
|
||||
|
||||
#endif
|
||||
#include "string.h"
|
||||
|
||||
@ -186,6 +186,15 @@ namespace etl
|
||||
return CAPACITY;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the maximum possible size of the deque.
|
||||
///\return The maximum size of the deque.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return CAPACITY;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the remaining capacity.
|
||||
///\return The remaining capacity.
|
||||
@ -2457,6 +2466,15 @@ namespace etl
|
||||
typename etl::aligned_storage<sizeof(T), etl::alignment_of<T>::value>::type buffer[BUFFER_SIZE];
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
deque(T, Ts...)
|
||||
->deque<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Equal operator.
|
||||
///\param lhs Reference to the _begin deque.
|
||||
|
||||
@ -43,40 +43,9 @@ SOFTWARE.
|
||||
#include "function.h"
|
||||
#include "nullptr.h"
|
||||
|
||||
#if defined(ETL_LOG_ERRORS) || defined(ETL_IN_UNIT_TEST)
|
||||
namespace etl
|
||||
{
|
||||
namespace private_error_handler
|
||||
{
|
||||
// A wrapper template to allow static definition in header.
|
||||
template <typename TDummy>
|
||||
struct wrapper
|
||||
{
|
||||
typedef void(*stub_type)(void* object, const etl::exception&);
|
||||
|
||||
//*************************************************************************
|
||||
/// The internal invocation object.
|
||||
//*************************************************************************
|
||||
struct invocation_element
|
||||
{
|
||||
//***********************************************************************
|
||||
invocation_element()
|
||||
: object(ETL_NULLPTR)
|
||||
, stub(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
void* object;
|
||||
stub_type stub;
|
||||
};
|
||||
|
||||
static invocation_element invocation;
|
||||
};
|
||||
|
||||
template <typename TDummy>
|
||||
typename wrapper<TDummy>::invocation_element wrapper<TDummy>::invocation;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Error handler for when throwing exceptions is not required.
|
||||
///\ingroup error_handler
|
||||
@ -86,7 +55,7 @@ namespace etl
|
||||
public:
|
||||
|
||||
//*************************************************************************
|
||||
/// Callback class for free handler functions.
|
||||
/// Callback class for free handler functions. Deprecated.
|
||||
//*************************************************************************
|
||||
struct free_function : public etl::function<void, const etl::exception&>
|
||||
{
|
||||
@ -97,7 +66,7 @@ namespace etl
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Callback class for member handler functions.
|
||||
/// Callback class for member handler functions. Deprecated.
|
||||
//*************************************************************************
|
||||
template <typename TObject>
|
||||
struct member_function : public etl::function<TObject, const etl::exception&>
|
||||
@ -109,7 +78,7 @@ namespace etl
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
/// Sets the error callback function.
|
||||
/// Sets the error callback function. Deprecated.
|
||||
///\param f A reference to an etl::function object that will handler errors.
|
||||
//*****************************************************************************
|
||||
static void set_callback(ifunction<const etl::exception&>& f)
|
||||
@ -168,9 +137,11 @@ namespace etl
|
||||
//*****************************************************************************
|
||||
static void error(const etl::exception& e)
|
||||
{
|
||||
if (private_error_handler::wrapper<void>::invocation.stub != ETL_NULLPTR)
|
||||
invocation_element& invocation = get_invocation_element();
|
||||
|
||||
if (invocation.stub != ETL_NULLPTR)
|
||||
{
|
||||
(*private_error_handler::wrapper<void>::invocation.stub)(private_error_handler::wrapper<void>::invocation.object, e);
|
||||
(*invocation.stub)(invocation.object, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,24 +154,37 @@ namespace etl
|
||||
//*************************************************************************
|
||||
struct invocation_element
|
||||
{
|
||||
//***********************************************************************
|
||||
invocation_element()
|
||||
: object(ETL_NULLPTR)
|
||||
, stub(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//***********************************************************************
|
||||
void* object;
|
||||
stub_type stub;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the static invocation element.
|
||||
//*************************************************************************
|
||||
static invocation_element& get_invocation_element()
|
||||
{
|
||||
static invocation_element invocation;
|
||||
|
||||
return invocation;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructs a callback from an object and stub.
|
||||
//*************************************************************************
|
||||
static void create(void* object, stub_type stub)
|
||||
{
|
||||
private_error_handler::wrapper<void>::invocation.object = object;
|
||||
private_error_handler::wrapper<void>::invocation.stub = stub;
|
||||
invocation_element& invocation = get_invocation_element();
|
||||
|
||||
invocation.object = object;
|
||||
invocation.stub = stub;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -208,8 +192,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
static void create(stub_type stub)
|
||||
{
|
||||
private_error_handler::wrapper<void>::invocation.object = ETL_NULLPTR;
|
||||
private_error_handler::wrapper<void>::invocation.stub = stub;
|
||||
invocation_element& invocation = get_invocation_element();
|
||||
|
||||
invocation.object = ETL_NULLPTR;
|
||||
invocation.stub = stub;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -269,6 +255,7 @@ namespace etl
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Asserts a condition.
|
||||
|
||||
@ -1004,6 +1004,17 @@ namespace etl
|
||||
/// The vector that stores pointers to the nodes.
|
||||
etl::vector<node_t*, MAX_SIZE> lookup;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
flat_map(T, Ts...)
|
||||
->flat_map<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::first_type>,
|
||||
etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::second_type>,
|
||||
1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -907,6 +907,17 @@ namespace etl
|
||||
// The vector that stores pointers to the nodes.
|
||||
etl::vector<node_t*, MAX_SIZE> lookup;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
flat_multimap(T, Ts...)
|
||||
->flat_multimap<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::first_type>,
|
||||
etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::second_type>,
|
||||
1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -857,6 +857,15 @@ namespace etl
|
||||
// The vector that stores pointers to the nodes.
|
||||
etl::vector<node_t*, MAX_SIZE> lookup;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
flat_multiset(T, Ts...)
|
||||
->flat_multiset<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -944,6 +944,15 @@ namespace etl
|
||||
// The vector that stores pointers to the nodes.
|
||||
etl::vector<node_t*, MAX_SIZE> lookup;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
flat_set(T, Ts...)
|
||||
->flat_set<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -35,7 +35,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_format_spec.h"
|
||||
#include "cstring.h"
|
||||
#include "string.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
|
||||
@ -172,6 +172,22 @@ namespace etl
|
||||
return pool_is_shared;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the forward_list.
|
||||
//*************************************************************************
|
||||
size_type max_size() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the forward_list.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the size of the forward_list.
|
||||
//*************************************************************************
|
||||
@ -194,33 +210,16 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool));
|
||||
return p_node_pool->size();
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the forward_list.
|
||||
//*************************************************************************
|
||||
size_type max_size() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the forward_list is empty.
|
||||
//*************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
if (has_shared_pool())
|
||||
{
|
||||
return (size() == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool));
|
||||
return p_node_pool->empty();
|
||||
}
|
||||
return (start_node.next == ETL_NULLPTR);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1735,6 +1734,15 @@ namespace etl
|
||||
etl::pool<typename etl::iforward_list<T>::data_node_t, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
forward_list(T, Ts...)
|
||||
->forward_list<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// A templated forward_list implementation that uses a fixed size pool.
|
||||
///\note 'merge' and 'splice_after' and are not supported.
|
||||
|
||||
@ -386,7 +386,7 @@ namespace etl
|
||||
//********************************************
|
||||
bool is_consumer() const ETL_OVERRIDE
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -52,23 +52,23 @@ namespace etl
|
||||
|
||||
typedef T type;
|
||||
|
||||
explicit reference_wrapper(T& t_)
|
||||
ETL_CONSTEXPR20 explicit reference_wrapper(T& t_) ETL_NOEXCEPT
|
||||
: t(&t_)
|
||||
{
|
||||
}
|
||||
|
||||
operator T& () const
|
||||
ETL_CONSTEXPR20 reference_wrapper<T>& operator = (const reference_wrapper& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
t = rhs.t;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR20 T& get() const ETL_NOEXCEPT
|
||||
{
|
||||
return *t;
|
||||
}
|
||||
|
||||
reference_wrapper<T>& operator = (T value)
|
||||
{
|
||||
*t = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T& get() const
|
||||
ETL_CONSTEXPR20 operator T&() const ETL_NOEXCEPT
|
||||
{
|
||||
return *t;
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ namespace etl
|
||||
//********************************************
|
||||
bool is_consumer() const ETL_OVERRIDE
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -1404,6 +1404,15 @@ namespace etl
|
||||
etl::pool<T, MAX_SIZE> storage_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
indirect_vector(T, Ts...)
|
||||
->indirect_vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// A indirect_vector implementation that uses a fixed size buffer.
|
||||
/// The buffer is supplied on construction.
|
||||
|
||||
@ -32,6 +32,7 @@ SOFTWARE.
|
||||
#define ETL_INTEGRAL_LIMITS_INCLUDED
|
||||
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
@ -233,6 +233,14 @@ namespace etl
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the list.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the size of the list.
|
||||
//*************************************************************************
|
||||
@ -241,7 +249,7 @@ namespace etl
|
||||
if (has_shared_pool())
|
||||
{
|
||||
// We have to count what we actually own.
|
||||
size_type count = 0;
|
||||
size_type count = 0U;
|
||||
|
||||
node_t* p_node = terminal_node.next;
|
||||
|
||||
@ -255,7 +263,6 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
|
||||
return p_node_pool->size();
|
||||
}
|
||||
}
|
||||
@ -265,15 +272,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
bool empty() const
|
||||
{
|
||||
if (has_shared_pool())
|
||||
{
|
||||
return (size() == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
|
||||
return p_node_pool->empty();
|
||||
}
|
||||
return (terminal_node.next == &terminal_node);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -282,17 +281,17 @@ namespace etl
|
||||
bool full() const
|
||||
{
|
||||
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
|
||||
return p_node_pool->size() == MAX_SIZE;
|
||||
return p_node_pool->full();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the remaining capacity.
|
||||
///\return The remaining capacity.
|
||||
//*************************************************************************
|
||||
size_t available() const
|
||||
size_type available() const
|
||||
{
|
||||
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
|
||||
return max_size() - p_node_pool->size();
|
||||
return p_node_pool->available();
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -756,6 +755,14 @@ namespace etl
|
||||
return reverse_iterator(get_head());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the reverse end of the list.
|
||||
//*************************************************************************
|
||||
const_reverse_iterator rend() const
|
||||
{
|
||||
return const_reverse_iterator(get_head());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the reverse beginning of the list.
|
||||
//*************************************************************************
|
||||
@ -2159,6 +2166,15 @@ namespace etl
|
||||
etl::pool<typename etl::ilist<T>::data_node_t, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
list(T, Ts...)
|
||||
->list<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// A templated list implementation that uses a fixed size buffer.
|
||||
//*************************************************************************
|
||||
|
||||
@ -2298,6 +2298,17 @@ namespace etl
|
||||
etl::pool<typename etl::imap<TKey, TValue, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
map(T, Ts...)
|
||||
->map<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::first_type>,
|
||||
typename T::second_type,
|
||||
1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Equal operator.
|
||||
///\param lhs Reference to the first lookup.
|
||||
|
||||
@ -2033,7 +2033,6 @@ namespace etl
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
@ -2158,6 +2157,17 @@ namespace etl
|
||||
etl::pool<typename etl::imultimap<TKey, TValue, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
multimap(T, Ts...)
|
||||
->multimap<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::first_type>,
|
||||
typename T::second_type,
|
||||
1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Equal operator.
|
||||
///\param lhs Reference to the first lookup.
|
||||
|
||||
@ -2140,6 +2140,15 @@ namespace etl
|
||||
etl::pool<typename etl::imultiset<TKey, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
multiset(T, Ts...)
|
||||
->multiset<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Equal operator.
|
||||
///\param lhs Reference to the first lookup.
|
||||
|
||||
@ -507,6 +507,14 @@ namespace etl
|
||||
bool valid;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template<class T>
|
||||
optional(T) -> optional<T>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Equality operator. cppreference 1
|
||||
//***************************************************************************
|
||||
|
||||
@ -159,9 +159,11 @@ SOFTWARE.
|
||||
#if ETL_CPP20_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP)
|
||||
#define ETL_LIKELY [[likely]]
|
||||
#define ETL_UNLIKELY [[unlikely]]
|
||||
#define ETL_CONSTEXPR20 constexpr
|
||||
#else
|
||||
#define ETL_LIKELY
|
||||
#define ETL_UNLIKELY
|
||||
#define ETL_CONSTEXPR20
|
||||
#endif
|
||||
|
||||
// Sort out namespaces for STL/No STL options.
|
||||
|
||||
@ -256,7 +256,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void release(const void* const p_object)
|
||||
{
|
||||
release_item((char*)p_object);
|
||||
const uintptr_t p = uintptr_t(p_object);
|
||||
release_item((char*)p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -264,7 +265,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void release_all()
|
||||
{
|
||||
items_allocated = 0;
|
||||
items_allocated = 0;
|
||||
items_initialised = 0;
|
||||
p_next = p_buffer;
|
||||
}
|
||||
@ -274,10 +275,10 @@ namespace etl
|
||||
/// \param p_object A pointer to the object to be checked.
|
||||
/// \return <b>true<\b> if it does, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
//template <typename T>
|
||||
bool is_in_pool(const void* p_object) const
|
||||
{
|
||||
return is_item_in_pool((const char*)p_object);
|
||||
const uintptr_t p = uintptr_t(p_object);
|
||||
return is_item_in_pool((const char*)p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -2221,6 +2221,15 @@ namespace etl
|
||||
etl::pool<typename etl::iset<TKey, TCompare>::Data_Node, MAX_SIZE> node_pool;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
set(T, Ts...)
|
||||
->set<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Equal operator.
|
||||
///\param lhs Reference to the first lookup.
|
||||
|
||||
@ -234,7 +234,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Assign from a span.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR span& operator =(const span& other) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT
|
||||
{
|
||||
mbegin = other.mbegin;
|
||||
mend = other.mend;
|
||||
@ -309,6 +309,24 @@ namespace etl
|
||||
element_type* mend;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename TArray>
|
||||
span(TArray& a)
|
||||
->span<typename TArray::value_type>;
|
||||
|
||||
template <typename TIterator>
|
||||
span(const TIterator begin_, const TIterator end_)
|
||||
->span<etl::remove_pointer_t<TIterator>>;
|
||||
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
span(const TIterator begin_, const TSize size_)
|
||||
->span<etl::remove_pointer_t<TIterator>>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
|
||||
@ -447,8 +447,7 @@ namespace etl
|
||||
istack& operator = (istack&& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
clear();
|
||||
{
|
||||
clone(etl::move(rhs));
|
||||
}
|
||||
|
||||
@ -463,6 +462,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void clone(const istack& other)
|
||||
{
|
||||
clear();
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
for (size_t i = 0; i < other.size(); ++i)
|
||||
@ -477,6 +478,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void clone(istack&& other)
|
||||
{
|
||||
clear();
|
||||
|
||||
size_t index = 0;
|
||||
|
||||
for (size_t i = 0; i < other.size(); ++i)
|
||||
|
||||
495
include/etl/string.h
Normal file
495
include/etl/string.h
Normal file
@ -0,0 +1,495 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2016 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_STRING_INCLUDED
|
||||
#define ETL_STRING_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "basic_string.h"
|
||||
#include "string_view.h"
|
||||
#include "hash.h"
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#include "private/minmax_push.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
typedef etl::ibasic_string<char> istring;
|
||||
|
||||
//***************************************************************************
|
||||
/// A string implementation that uses a fixed size buffer.
|
||||
///\tparam MAX_SIZE_ The maximum number of elements that can be stored.
|
||||
///\ingroup string
|
||||
//***************************************************************************
|
||||
template <const size_t MAX_SIZE_>
|
||||
class string : public istring
|
||||
{
|
||||
public:
|
||||
|
||||
typedef istring base_type;
|
||||
typedef istring interface_type;
|
||||
|
||||
typedef istring::value_type value_type;
|
||||
|
||||
static const size_t MAX_SIZE = MAX_SIZE_;
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
string()
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
///\param other The other string.
|
||||
//*************************************************************************
|
||||
string(const etl::string<MAX_SIZE_>& other)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other istring.
|
||||
///\param other The other istring.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other string, position, length.
|
||||
///\param other The other string.
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other, size_t position, size_t length_ = npos)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
this->assign(other.begin() + position, other.begin() + position + length_);
|
||||
|
||||
if (other.truncated())
|
||||
{
|
||||
this->is_truncated = true;
|
||||
|
||||
#if defined(ETL_STRING_TRUNCATION_IS_ERROR)
|
||||
ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the string.
|
||||
//*************************************************************************
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(text, text + etl::char_traits<value_type>::length(text));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text and count.
|
||||
///\param text The initial text of the string.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
string(const value_type* text, size_t count)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from initial size and value.
|
||||
///\param initialSize The initial size of the string.
|
||||
///\param value The value to fill the string with.
|
||||
//*************************************************************************
|
||||
string(size_t count, value_type c)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
string(TIterator first, TIterator last)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
string(std::initializer_list<value_type> init)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// From string_view.
|
||||
///\param view The string_view.
|
||||
//*************************************************************************
|
||||
explicit string(const etl::string_view& view)
|
||||
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a sub-string.
|
||||
///\param position The position of the first character. Default = 0.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
etl::string<MAX_SIZE_> substr(size_t position = 0, size_t length_ = npos) const
|
||||
{
|
||||
etl::string<MAX_SIZE_> new_string;
|
||||
|
||||
if (position != this->size())
|
||||
{
|
||||
ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
length_ = etl::min(length_, this->size() - position);
|
||||
|
||||
new_string.assign(buffer + position, buffer + position + length_);
|
||||
}
|
||||
|
||||
return new_string;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const string& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const istring& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const value_type* text)
|
||||
{
|
||||
this->assign(text);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair()
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
ETL_OVERRIDE
|
||||
#endif
|
||||
{
|
||||
etl::istring::repair_buffer(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
value_type buffer[MAX_SIZE + 1];
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// A string implementation that uses a fixed size buffer.
|
||||
/// A specilisation that requires an external buffer to be specified.
|
||||
///\ingroup string
|
||||
//***************************************************************************
|
||||
template <>
|
||||
class string<0U> : public istring
|
||||
{
|
||||
public:
|
||||
|
||||
typedef istring base_type;
|
||||
typedef istring interface_type;
|
||||
|
||||
typedef istring::value_type value_type;
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
string(value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor.
|
||||
///\param other The other string.
|
||||
//*************************************************************************
|
||||
string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other istring.
|
||||
///\param other The other istring.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// From other string, position, length.
|
||||
///\param other The other string.
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
this->assign(other.begin() + position, other.begin() + position + length_);
|
||||
|
||||
if (other.truncated())
|
||||
{
|
||||
this->is_truncated = true;
|
||||
|
||||
#if defined(ETL_STRING_TRUNCATION_IS_ERROR)
|
||||
ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the string.
|
||||
//*************************************************************************
|
||||
string(const value_type* text, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
// Is the initial text at the same address as the buffer?
|
||||
if (text == buffer)
|
||||
{
|
||||
this->current_size = etl::strlen(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->assign(text, text + etl::strlen(text));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from null terminated text and count.
|
||||
///\param text The initial text of the string.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from initial size and value.
|
||||
///\param initialSize The initial size of the string.
|
||||
///\param value The value to fill the string with.
|
||||
//*************************************************************************
|
||||
string(size_t count, value_type c, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor, from an iterator range.
|
||||
///\tparam TIterator The iterator type.
|
||||
///\param first The iterator to the first element.
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
string(std::initializer_list<value_type> init, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// From string_view.
|
||||
///\param view The string_view.
|
||||
//*************************************************************************
|
||||
explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size)
|
||||
: istring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const string& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const istring& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->assign(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
string& operator = (const value_type* text)
|
||||
{
|
||||
this->assign(text);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fix the internal pointers after a low level memory copy.
|
||||
//*************************************************************************
|
||||
void repair()
|
||||
#ifdef ETL_ISTRING_REPAIR_ENABLE
|
||||
ETL_OVERRIDE
|
||||
#endif
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
#if ETL_8BIT_SUPPORT
|
||||
template <>
|
||||
struct hash<etl::istring>
|
||||
{
|
||||
size_t operator()(const etl::istring& text) const
|
||||
{
|
||||
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
|
||||
reinterpret_cast<const uint8_t*>(&text[text.size()]));
|
||||
}
|
||||
};
|
||||
|
||||
template <const size_t SIZE>
|
||||
struct hash<etl::string<SIZE> >
|
||||
{
|
||||
size_t operator()(const etl::string<SIZE>& text) const
|
||||
{
|
||||
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
|
||||
reinterpret_cast<const uint8_t*>(&text[text.size()]));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string from string literal or char array
|
||||
//***************************************************************************
|
||||
template<const size_t MAX_SIZE>
|
||||
etl::string<MAX_SIZE - 1> make_string(const char(&text)[MAX_SIZE])
|
||||
{
|
||||
return etl::string<MAX_SIZE - 1>(text, MAX_SIZE - 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Make string with max capacity from string literal or char array
|
||||
//***************************************************************************
|
||||
template<const size_t MAX_SIZE, const size_t SIZE>
|
||||
etl::string<MAX_SIZE> make_string_with_capacity(const char(&text)[SIZE])
|
||||
{
|
||||
return etl::string<MAX_SIZE>(text, SIZE - 1);
|
||||
}
|
||||
}
|
||||
|
||||
#include "private/minmax_pop.h"
|
||||
|
||||
#endif
|
||||
@ -34,7 +34,7 @@ SOFTWARE.
|
||||
///\ingroup string
|
||||
|
||||
#include "platform.h"
|
||||
#include "cstring.h"
|
||||
#include "string.h"
|
||||
#include "format_spec.h"
|
||||
#include "to_string.h"
|
||||
#include "string_view.h"
|
||||
|
||||
@ -697,16 +697,22 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// get_token
|
||||
//***************************************************************************
|
||||
template <typename TIString, typename TStringView>
|
||||
etl::optional<TStringView> get_token(const TIString& s, typename TIString::const_pointer delimiters, const etl::optional<TStringView>& last_view, bool ignore_empty_tokens)
|
||||
template <typename TInput, typename TStringView>
|
||||
etl::optional<TStringView> get_token(const TInput& input, typename TInput::const_pointer delimiters, const etl::optional<TStringView>& last_view, bool ignore_empty_tokens)
|
||||
{
|
||||
typedef typename TIString::const_pointer const_pointer;
|
||||
typedef typename TInput::const_pointer const_pointer;
|
||||
|
||||
bool token_found = false;
|
||||
size_t position = 0U;
|
||||
TStringView view = last_view.value_or(TStringView());
|
||||
const_pointer begin_ptr = s.data();
|
||||
const_pointer end_ptr = begin_ptr + s.size();
|
||||
const_pointer begin_ptr = input.data();
|
||||
|
||||
if (begin_ptr == ETL_NULLPTR)
|
||||
{
|
||||
return etl::optional<TStringView>();
|
||||
}
|
||||
|
||||
const_pointer end_ptr = begin_ptr + input.size();
|
||||
|
||||
while (!token_found)
|
||||
{
|
||||
@ -716,7 +722,7 @@ namespace etl
|
||||
position = etl::distance(begin_ptr, view.data() + view.size() + 1U);
|
||||
|
||||
// Have we reached the end of the string?
|
||||
if (position > s.size())
|
||||
if (position > input.size())
|
||||
{
|
||||
return etl::optional<TStringView>();
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "cstring.h"
|
||||
#include "string.h"
|
||||
#include "format_spec.h"
|
||||
#include "private/to_string_helper.h"
|
||||
|
||||
|
||||
@ -751,7 +751,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Alignment templates.
|
||||
/// These require compiler specific intrinsics.
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5)
|
||||
template <typename T> struct alignment_of : integral_constant<size_t, alignof(T)> { };
|
||||
#elif ETL_COMPILER_MICROSOFT
|
||||
template <typename T> struct alignment_of : integral_constant<size_t, size_t(__alignof(T))> {};
|
||||
|
||||
@ -260,8 +260,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
u16string(value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
@ -270,8 +270,8 @@ namespace etl
|
||||
/// Copy constructor.
|
||||
///\param other The other u16string.
|
||||
//*************************************************************************
|
||||
u16string(const etl::u16string<0U>& other, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(const etl::u16string<0U>& other, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
@ -280,8 +280,8 @@ namespace etl
|
||||
/// From other iu16string.
|
||||
///\param other The other iu16string.
|
||||
//*************************************************************************
|
||||
u16string(const etl::iu16string& other, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
@ -292,8 +292,8 @@ namespace etl
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
u16string(const etl::iu16string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
@ -313,10 +313,18 @@ namespace etl
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the u16string.
|
||||
//*************************************************************************
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(const value_type* text, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + etl::char_traits<value_type>::length(text));
|
||||
// Is the initial text at the same address as the buffer?
|
||||
if (text == buffer)
|
||||
{
|
||||
this->current_size = etl::strlen(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->assign(text, text + etl::strlen(text));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -324,8 +332,8 @@ namespace etl
|
||||
///\param text The initial text of the u16string.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
u16string(const value_type* text, size_t count, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
@ -335,8 +343,8 @@ namespace etl
|
||||
///\param initialSize The initial size of the u16string.
|
||||
///\param value The value to fill the u16string with.
|
||||
//*************************************************************************
|
||||
u16string(size_t count, value_type c, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(size_t count, value_type c, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
@ -349,8 +357,8 @@ namespace etl
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
u16string(TIterator first, TIterator last, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
@ -359,8 +367,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
u16string(std::initializer_list<value_type> init, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
u16string(std::initializer_list<value_type> init, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
@ -370,8 +378,8 @@ namespace etl
|
||||
/// From u16string_view.
|
||||
///\param view The u16string_view.
|
||||
//*************************************************************************
|
||||
explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t max_size)
|
||||
: iu16string(buffer, max_size - 1)
|
||||
explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t buffer_size)
|
||||
: iu16string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
@ -260,8 +260,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
u32string(value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
@ -270,8 +270,8 @@ namespace etl
|
||||
/// Copy constructor.
|
||||
///\param other The other u32string.
|
||||
//*************************************************************************
|
||||
u32string(const etl::u32string<0U>& other, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(const etl::u32string<0U>& other, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
@ -280,8 +280,8 @@ namespace etl
|
||||
/// From other iu32string.
|
||||
///\param other The other iu32string.
|
||||
//*************************************************************************
|
||||
u32string(const etl::iu32string& other, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
@ -292,8 +292,8 @@ namespace etl
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
u32string(const etl::iu32string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
@ -313,10 +313,18 @@ namespace etl
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the u32string.
|
||||
//*************************************************************************
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + etl::char_traits<value_type>::length(text));
|
||||
// Is the initial text at the same address as the buffer?
|
||||
if (text == buffer)
|
||||
{
|
||||
this->current_size = etl::strlen(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->assign(text, text + etl::strlen(text));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -324,8 +332,8 @@ namespace etl
|
||||
///\param text The initial text of the u32string.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
u32string(const value_type* text, size_t count, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
@ -335,8 +343,8 @@ namespace etl
|
||||
///\param initialSize The initial size of the u32string.
|
||||
///\param value The value to fill the u32string with.
|
||||
//*************************************************************************
|
||||
u32string(size_t count, value_type c, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(size_t count, value_type c, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
@ -349,8 +357,8 @@ namespace etl
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
u32string(TIterator first, TIterator last, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
@ -359,8 +367,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
u32string(std::initializer_list<value_type> init, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
u32string(std::initializer_list<value_type> init, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
@ -370,8 +378,8 @@ namespace etl
|
||||
/// From u32string_view.
|
||||
///\param view The u32string_view.
|
||||
//*************************************************************************
|
||||
explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t max_size)
|
||||
: iu32string(buffer, max_size - 1)
|
||||
explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t buffer_size)
|
||||
: iu32string(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
@ -54,6 +54,10 @@ SOFTWARE.
|
||||
#include "debug_count.h"
|
||||
#include "iterator.h"
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#undef ETL_FILE
|
||||
#define ETL_FILE "16"
|
||||
|
||||
@ -1229,6 +1233,14 @@ namespace etl
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the unordered_map.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the unordered_map is empty.
|
||||
//*************************************************************************
|
||||
@ -1579,6 +1591,17 @@ namespace etl
|
||||
base::assign(first_, last_);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
unordered_map(std::initializer_list<ETL_OR_STD::pair<TKey, TValue>> init)
|
||||
: base(node_pool, buckets, MAX_BUCKETS_)
|
||||
{
|
||||
base::assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Destructor.
|
||||
//*************************************************************************
|
||||
@ -1626,6 +1649,17 @@ namespace etl
|
||||
/// The buckets of node lists.
|
||||
etl::intrusive_forward_list<typename base::node_t> buckets[MAX_BUCKETS_];
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
unordered_map(T, Ts...)
|
||||
->unordered_map<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::first_type>,
|
||||
typename T::second_type,
|
||||
1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -54,6 +54,10 @@ SOFTWARE.
|
||||
#include "debug_count.h"
|
||||
#include "iterator.h"
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#undef ETL_FILE
|
||||
#define ETL_FILE "25"
|
||||
|
||||
@ -1135,6 +1139,14 @@ namespace etl
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the unordered_multimap.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the unordered_multimap is empty.
|
||||
//*************************************************************************
|
||||
@ -1491,6 +1503,17 @@ namespace etl
|
||||
base::assign(first_, last_);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
unordered_multimap(std::initializer_list<ETL_OR_STD::pair<TKey, TValue>> init)
|
||||
: base(node_pool, buckets, MAX_BUCKETS_)
|
||||
{
|
||||
base::assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Destructor.
|
||||
//*************************************************************************
|
||||
@ -1538,6 +1561,17 @@ namespace etl
|
||||
/// The buckets of node lists.
|
||||
etl::intrusive_forward_list<typename base::node_t> buckets[MAX_BUCKETS_];
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
unordered_multimap(T, Ts...)
|
||||
->unordered_multimap<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), typename T::first_type>,
|
||||
typename T::second_type,
|
||||
1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -55,6 +55,10 @@ SOFTWARE.
|
||||
#include "debug_count.h"
|
||||
#include "iterator.h"
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#undef ETL_FILE
|
||||
#define ETL_FILE "26"
|
||||
|
||||
@ -1120,6 +1124,14 @@ namespace etl
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the unordered_multiset.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the unordered_multiset is empty.
|
||||
//*************************************************************************
|
||||
@ -1479,6 +1491,17 @@ namespace etl
|
||||
base::assign(first_, last_);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
unordered_multiset(std::initializer_list<TKey> init)
|
||||
: base(node_pool, buckets, MAX_BUCKETS)
|
||||
{
|
||||
base::assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Destructor.
|
||||
//*************************************************************************
|
||||
@ -1526,6 +1549,15 @@ namespace etl
|
||||
/// The buckets of node lists.
|
||||
etl::intrusive_forward_list<typename base::node_t> buckets[MAX_BUCKETS_];
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
unordered_multiset(T, Ts...)
|
||||
->unordered_multiset<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -54,6 +54,10 @@ SOFTWARE.
|
||||
#include "debug_count.h"
|
||||
#include "iterator.h"
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
|
||||
#undef ETL_FILE
|
||||
#define ETL_FILE "23"
|
||||
|
||||
@ -1112,6 +1116,14 @@ namespace etl
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the maximum possible size of the unordered_set.
|
||||
//*************************************************************************
|
||||
size_type capacity() const
|
||||
{
|
||||
return pnodepool->max_size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Checks to see if the unordered_set is empty.
|
||||
//*************************************************************************
|
||||
@ -1475,6 +1487,17 @@ namespace etl
|
||||
base::assign(first_, last_);
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
unordered_set(std::initializer_list<TKey> init)
|
||||
: base(node_pool, buckets, MAX_BUCKETS)
|
||||
{
|
||||
base::assign(init.begin(), init.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Destructor.
|
||||
//*************************************************************************
|
||||
@ -1522,6 +1545,15 @@ namespace etl
|
||||
/// The buckets of node lists.
|
||||
etl::intrusive_forward_list<typename base::node_t> buckets[MAX_BUCKETS_];
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
unordered_set(T, Ts...)
|
||||
->unordered_set<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_FILE
|
||||
|
||||
@ -230,6 +230,14 @@ namespace etl
|
||||
#endif
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED
|
||||
template <typename T1, typename T2>
|
||||
pair(T1, T2) ->pair<T1, T2>;
|
||||
#endif
|
||||
|
||||
//******************************************************************************
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
template <typename T1, typename T2>
|
||||
@ -328,6 +336,37 @@ namespace etl
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/// 2D coordinate type.
|
||||
template <typename T>
|
||||
struct coordinate_2d
|
||||
{
|
||||
coordinate_2d()
|
||||
: x(T(0))
|
||||
, y(T(0))
|
||||
{
|
||||
}
|
||||
|
||||
coordinate_2d(T x_, T y_)
|
||||
: x(x_)
|
||||
, y(y_)
|
||||
{
|
||||
}
|
||||
|
||||
friend bool operator ==(const coordinate_2d& lhs, const coordinate_2d& rhs)
|
||||
{
|
||||
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
|
||||
}
|
||||
|
||||
friend bool operator !=(const coordinate_2d& lhs, const coordinate_2d& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
T x;
|
||||
T y;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1286,6 +1286,15 @@ namespace etl
|
||||
typename etl::aligned_storage<sizeof(T) * MAX_SIZE, etl::alignment_of<T>::value>::type buffer;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
vector(T, Ts...)
|
||||
->vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// A vector implementation that uses a fixed size buffer.
|
||||
/// The buffer is supplied on construction.
|
||||
@ -1569,6 +1578,15 @@ namespace etl
|
||||
typename etl::aligned_storage<sizeof(T*) * MAX_SIZE, etl::alignment_of<T*>::value>::type buffer;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL
|
||||
template <typename T, typename... Ts>
|
||||
vector(T*, Ts*...)
|
||||
->vector<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T*>, 1U + sizeof...(Ts)>;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// A vector implementation that uses a fixed size buffer.
|
||||
/// The buffer is supplied on construction.
|
||||
|
||||
@ -38,8 +38,8 @@ SOFTWARE.
|
||||
///\ingroup utilities
|
||||
|
||||
#define ETL_VERSION_MAJOR 18
|
||||
#define ETL_VERSION_MINOR 12
|
||||
#define ETL_VERSION_PATCH 5
|
||||
#define ETL_VERSION_MINOR 16
|
||||
#define ETL_VERSION_PATCH 1
|
||||
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
#define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
#define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
|
||||
@ -261,8 +261,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
wstring(value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
}
|
||||
@ -271,8 +271,8 @@ namespace etl
|
||||
/// Copy constructor.
|
||||
///\param other The other wstring.
|
||||
//*************************************************************************
|
||||
wstring(const etl::wstring<0U>& other, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(const etl::wstring<0U>& other, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
@ -281,8 +281,8 @@ namespace etl
|
||||
/// From other iwstring.
|
||||
///\param other The other iwstring.
|
||||
//*************************************************************************
|
||||
wstring(const etl::iwstring& other, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(other);
|
||||
}
|
||||
@ -293,8 +293,8 @@ namespace etl
|
||||
///\param position The position of the first character.
|
||||
///\param length The number of characters. Default = npos.
|
||||
//*************************************************************************
|
||||
wstring(const etl::iwstring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
|
||||
|
||||
@ -314,10 +314,18 @@ namespace etl
|
||||
/// Constructor, from null terminated text.
|
||||
///\param text The initial text of the wstring.
|
||||
//*************************************************************************
|
||||
ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(const value_type* text, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + etl::char_traits<value_type>::length(text));
|
||||
// Is the initial text at the same address as the buffer?
|
||||
if (text == buffer)
|
||||
{
|
||||
this->current_size = etl::strlen(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->assign(text, text + etl::strlen(text));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -325,8 +333,8 @@ namespace etl
|
||||
///\param text The initial text of the wstring.
|
||||
///\param count The number of characters to copy.
|
||||
//*************************************************************************
|
||||
wstring(const value_type* text, size_t count, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(const value_type* text, size_t count, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(text, text + count);
|
||||
}
|
||||
@ -336,8 +344,8 @@ namespace etl
|
||||
///\param initialSize The initial size of the wstring.
|
||||
///\param value The value to fill the wstring with.
|
||||
//*************************************************************************
|
||||
wstring(size_t count, value_type c, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(size_t count, value_type c, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->initialise();
|
||||
this->resize(count, c);
|
||||
@ -350,8 +358,8 @@ namespace etl
|
||||
///\param last The iterator to the last element + 1.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
wstring(TIterator first, TIterator last, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(TIterator first, TIterator last, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(first, last);
|
||||
}
|
||||
@ -360,8 +368,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from initializer_list.
|
||||
//*************************************************************************
|
||||
wstring(std::initializer_list<value_type> init, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
wstring(std::initializer_list<value_type> init, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(init.begin(), init.end());
|
||||
}
|
||||
@ -371,8 +379,8 @@ namespace etl
|
||||
/// From wstring_view.
|
||||
///\param view The wstring_view.
|
||||
//*************************************************************************
|
||||
explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t max_size)
|
||||
: iwstring(buffer, max_size - 1)
|
||||
explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t buffer_size)
|
||||
: iwstring(buffer, buffer_size - 1U)
|
||||
{
|
||||
this->assign(view.begin(), view.end());
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ SOFTWARE.
|
||||
///\ingroup string
|
||||
|
||||
#include "platform.h"
|
||||
#include "cstring.h"
|
||||
#include "string.h"
|
||||
#include "wformat_spec.h"
|
||||
#include "to_wstring.h"
|
||||
#include "string_view.h"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library",
|
||||
"version": "18.12.5",
|
||||
"version": "18.16.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=18.12.5
|
||||
version=18.16.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,3 +1,60 @@
|
||||
===============================================================================
|
||||
18.16.1
|
||||
Updates to CI configuration files.
|
||||
|
||||
===============================================================================
|
||||
18.16.0
|
||||
Added template deduction guides for most containers.
|
||||
|
||||
===============================================================================
|
||||
18.15.5
|
||||
Refactored empty(), full(), available() member functions for etl::list and etl::forward_list
|
||||
|
||||
===============================================================================
|
||||
18.15.4
|
||||
Performance optimisations for etl::rotate, etl::move & etl::move_backward
|
||||
when not using the STL, iterators are pointers and the objects are trivially
|
||||
copyable (currently POD types).
|
||||
|
||||
===============================================================================
|
||||
18.15.3
|
||||
etl::array_view constructor from C array is no longer explicit.
|
||||
|
||||
===============================================================================
|
||||
18.15.2
|
||||
Workaround for Segger ARM Link-Time-Optimisation (LTO) bug.
|
||||
etl::array_view constructor from etl or std array is no longer explicit.
|
||||
|
||||
===============================================================================
|
||||
18.15.1
|
||||
Refactoring of 18.15.0.
|
||||
Modified constructor syntax.
|
||||
|
||||
===============================================================================
|
||||
18.15.0
|
||||
Allow strings with external buffers to use a pre-initialised buffer.
|
||||
|
||||
===============================================================================
|
||||
18.14.1
|
||||
Fixed conditional compilation macro use for template deduction guides.
|
||||
|
||||
===============================================================================
|
||||
18.14.0
|
||||
Added template deduction guides for array and array_view
|
||||
|
||||
===============================================================================
|
||||
18.13.0
|
||||
Added a line coordinate generator using the Bresenham algorithm.
|
||||
The API is similar to a container.
|
||||
|
||||
===============================================================================
|
||||
18.12.7
|
||||
Made etl::reference_wrapper API closer to the STL version. Does not support invocation of a callable object.
|
||||
|
||||
===============================================================================
|
||||
18.12.6
|
||||
Fixed etl::stack top level assignment operator not clearing before copy.
|
||||
|
||||
===============================================================================
|
||||
18.12.5
|
||||
Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when
|
||||
|
||||
@ -33,6 +33,7 @@ set(TEST_SOURCE_FILES
|
||||
test_bitset.cpp
|
||||
test_bit_stream.cpp
|
||||
test_bloom_filter.cpp
|
||||
test_bresenham_line.cpp
|
||||
test_bsd_checksum.cpp
|
||||
test_callback_service.cpp
|
||||
test_callback_timer.cpp
|
||||
|
||||
@ -234,6 +234,7 @@
|
||||
<Unit filename="../../include/etl/bit_stream.h" />
|
||||
<Unit filename="../../include/etl/bitset.h" />
|
||||
<Unit filename="../../include/etl/bloom_filter.h" />
|
||||
<Unit filename="../../include/etl/bresenham_line.h" />
|
||||
<Unit filename="../../include/etl/callback.h" />
|
||||
<Unit filename="../../include/etl/callback_service.h" />
|
||||
<Unit filename="../../include/etl/callback_timer.h" />
|
||||
@ -492,6 +493,7 @@
|
||||
<Unit filename="../test_bit_stream.cpp" />
|
||||
<Unit filename="../test_bitset.cpp" />
|
||||
<Unit filename="../test_bloom_filter.cpp" />
|
||||
<Unit filename="../test_bresenham_line.cpp" />
|
||||
<Unit filename="../test_bsd_checksum.cpp" />
|
||||
<Unit filename="../test_callback_service.cpp" />
|
||||
<Unit filename="../test_callback_timer.cpp" />
|
||||
@ -544,6 +546,7 @@
|
||||
<Unit filename="../test_maths.cpp" />
|
||||
<Unit filename="../test_memory.cpp" />
|
||||
<Unit filename="../test_message_bus.cpp" />
|
||||
<Unit filename="../test_message_packet.cpp" />
|
||||
<Unit filename="../test_message_router.cpp" />
|
||||
<Unit filename="../test_message_timer.cpp" />
|
||||
<Unit filename="../test_multi_array.cpp" />
|
||||
@ -578,15 +581,19 @@
|
||||
<Unit filename="../test_scaled_rounding.cpp" />
|
||||
<Unit filename="../test_set.cpp" />
|
||||
<Unit filename="../test_smallest.cpp" />
|
||||
<Unit filename="../test_span.cpp" />
|
||||
<Unit filename="../test_stack.cpp" />
|
||||
<Unit filename="../test_state_chart.cpp" />
|
||||
<Unit filename="../test_string_char.cpp" />
|
||||
<Unit filename="../test_string_char_external_buffer.cpp" />
|
||||
<Unit filename="../test_string_stream.cpp" />
|
||||
<Unit filename="../test_string_stream_u16.cpp" />
|
||||
<Unit filename="../test_string_stream_u32.cpp" />
|
||||
<Unit filename="../test_string_stream_wchar_t.cpp" />
|
||||
<Unit filename="../test_string_u16.cpp" />
|
||||
<Unit filename="../test_string_u16_external_buffer.cpp" />
|
||||
<Unit filename="../test_string_u32.cpp" />
|
||||
<Unit filename="../test_string_u32_external_buffer.cpp" />
|
||||
<Unit filename="../test_string_utilities.cpp" />
|
||||
<Unit filename="../test_string_utilities_std.cpp" />
|
||||
<Unit filename="../test_string_utilities_std_u16.cpp" />
|
||||
@ -597,6 +604,7 @@
|
||||
<Unit filename="../test_string_utilities_wchar_t.cpp" />
|
||||
<Unit filename="../test_string_view.cpp" />
|
||||
<Unit filename="../test_string_wchar_t.cpp" />
|
||||
<Unit filename="../test_string_wchar_t_external_buffer.cpp" />
|
||||
<Unit filename="../test_task_scheduler.cpp" />
|
||||
<Unit filename="../test_to_string.cpp" />
|
||||
<Unit filename="../test_to_u16string.cpp" />
|
||||
|
||||
@ -105,6 +105,10 @@ SOFTWARE.
|
||||
|
||||
#include "../include/etl/profiles/determine_development_os.h"
|
||||
|
||||
#if defined(ETL_COMPILER_GCC) && (ETL_COMPILER_VERSION < 8)
|
||||
#define ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED
|
||||
#endif
|
||||
|
||||
#if defined(ETL_DEVELOPMENT_OS_WINDOWS)
|
||||
#define ETL_TARGET_OS_WINDOWS
|
||||
#elif defined(ETL_DEVELOPMENT_OS_LINUX)
|
||||
|
||||
@ -1099,7 +1099,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(rotate)
|
||||
TEST(rotate_pod)
|
||||
{
|
||||
std::vector<int> initial_data = { 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
@ -1116,6 +1116,25 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
TEST(rotate_non_pod)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1), NDC(2), NDC(3), NDC(4), NDC(5), NDC(6), NDC(7) };
|
||||
|
||||
for (size_t i = 0; i < initial_data.size(); ++i)
|
||||
{
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::rotate(data1.data(), data1.data() + i, data1.data() + data1.size());
|
||||
etl::rotate(data2.data(), data2.data() + i, data2.data() + data2.size());
|
||||
|
||||
bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2));
|
||||
CHECK(isEqual);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(any_of)
|
||||
{
|
||||
|
||||
@ -57,6 +57,18 @@ namespace
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
}
|
||||
|
||||
#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
Data compare = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
bool isEqual = std::equal(data.begin(), data.end(), compare.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assignment)
|
||||
{
|
||||
|
||||
@ -91,6 +91,18 @@ namespace
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_implicit_constructor_etl_array_1)
|
||||
{
|
||||
View view = etldata;
|
||||
|
||||
CHECK_EQUAL(etldata.size(), view.size());
|
||||
CHECK_EQUAL(etldata.max_size(), view.max_size());
|
||||
|
||||
bool isEqual = std::equal(view.begin(), view.end(), etldata.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_etl_array_1_const)
|
||||
{
|
||||
@ -139,6 +151,18 @@ namespace
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_implicit_constructor_stl_array_1)
|
||||
{
|
||||
View view = stldata;
|
||||
|
||||
CHECK_EQUAL(stldata.size(), view.size());
|
||||
CHECK_EQUAL(stldata.max_size(), view.max_size());
|
||||
|
||||
bool isEqual = std::equal(view.begin(), view.end(), stldata.begin());
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_stl_array_1_const)
|
||||
{
|
||||
@ -235,6 +259,18 @@ namespace
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_implicit_constructor_c_array)
|
||||
{
|
||||
View view = cdata;
|
||||
|
||||
CHECK_EQUAL(SIZE, view.size());
|
||||
CHECK_EQUAL(SIZE, view.max_size());
|
||||
|
||||
bool isEqual = std::equal(view.begin(), view.end(), cdata);
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_c_array_2_const)
|
||||
{
|
||||
@ -247,6 +283,39 @@ namespace
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
etl::array_view view1{ data };
|
||||
etl::array_view view2{ data.begin(), data.end() };
|
||||
etl::array_view view3{ data.begin(), data.size() };
|
||||
etl::array_view view4{ view1 };
|
||||
|
||||
int c_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
etl::array_view view5{ c_array };
|
||||
|
||||
bool isEqual = false;
|
||||
|
||||
isEqual = std::equal(view1.begin(), view1.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(view2.begin(), view2.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(view3.begin(), view3.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(view4.begin(), view4.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(view5.begin(), view5.end(), c_array);
|
||||
CHECK(isEqual);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_range)
|
||||
{
|
||||
|
||||
436
test/test_bresenham_line.cpp
Normal file
436
test/test_bresenham_line.cpp
Normal file
@ -0,0 +1,436 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 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.
|
||||
******************************************************************************/
|
||||
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
|
||||
#include "etl/bresenham_line.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
template <typename T>
|
||||
std::ostream& operator << (std::ostream& os, const etl::coordinate_2d<T>& point)
|
||||
{
|
||||
os << "(" << int(point.x) << "," << int(point.y) << ")";
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
using Value = char;
|
||||
|
||||
using Point = etl::coordinate_2d<Value>;
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const Point& point)
|
||||
{
|
||||
os << "(" << int(point.x) << "," << int(point.y) << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
using BresenhamLine = etl::bresenham_line<Value>;
|
||||
|
||||
SUITE(test_bresenham_line)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(horizontal_line_left_right)
|
||||
{
|
||||
Point first = { -5, 5 };
|
||||
Point last = { 5, 5 };
|
||||
|
||||
BresenhamLine bl(first.x, first.y, last.x, last.y);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 },
|
||||
Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(horizontal_line_right_left)
|
||||
{
|
||||
Point first = { 5, 5 };
|
||||
Point last = { -5, 5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 },
|
||||
Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(vertical_line_bottom_top)
|
||||
{
|
||||
Point first = { 5, -5 };
|
||||
Point last = { 5, 5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 },
|
||||
Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(vertical_line_top_bottom)
|
||||
{
|
||||
Point first = { 5, 5 };
|
||||
Point last = { 5, -5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 },
|
||||
Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(low_slope_diagonal_line_bottom_left_top_right)
|
||||
{
|
||||
Point first = { -5, -3 };
|
||||
Point last = { 5, 3};
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 },
|
||||
Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(low_slope_diagonal_line_top_right_bottom_left)
|
||||
{
|
||||
Point first = { 5, 3 };
|
||||
Point last = { -5, -3 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 },
|
||||
Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(low_slope_diagonal_line_bottom_right_top_left)
|
||||
{
|
||||
Point first = { 5, -3 };
|
||||
Point last = { -5, 3 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 },
|
||||
Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(low_slope_diagonal_line_top_left_bottom_right)
|
||||
{
|
||||
Point first = { -5, 3 };
|
||||
Point last = { 5, -3 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 },
|
||||
Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(high_slope_diagonal_line_bottom_left_top_right)
|
||||
{
|
||||
Point first = { -3, -5 };
|
||||
Point last = { 3, 5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 },
|
||||
Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(high_slope_diagonal_line_top_right_bottom_left)
|
||||
{
|
||||
Point first = { 3, 5 };
|
||||
Point last = { -3, -5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 },
|
||||
Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(high_slope_diagonal_line_bottom_right_top_left)
|
||||
{
|
||||
Point first = { 3, -5 };
|
||||
Point last = { -3, 5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 },
|
||||
Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(high_slope_diagonal_line_top_left_bottom_right)
|
||||
{
|
||||
Point first = { -3, 5 };
|
||||
Point last = { 3, -5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
std::vector<Point> expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 },
|
||||
Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(reset_the_line_from_coordinate_2d)
|
||||
{
|
||||
Point first = { 3, -5 };
|
||||
Point last = { -3, 5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
CHECK_EQUAL(first, bl.front());
|
||||
CHECK_EQUAL(last, bl.back());
|
||||
|
||||
Point new_first = { -3, 5 };
|
||||
Point new_last = { 3, -5 };
|
||||
|
||||
bl.reset(new_first, new_last);
|
||||
|
||||
std::vector<Point> expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 },
|
||||
Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(reset_the_line_from_individual_coordinates)
|
||||
{
|
||||
Point first = { 3, -5 };
|
||||
Point last = { -3, 5 };
|
||||
|
||||
BresenhamLine bl(first, last);
|
||||
|
||||
Point new_first = { -3, 5 };
|
||||
Point new_last = { 3, -5 };
|
||||
|
||||
bl.reset(new_first.x, new_first.y, new_last.x, new_last.y);
|
||||
|
||||
std::vector<Point> expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 },
|
||||
Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } };
|
||||
std::vector<Point> actual;
|
||||
|
||||
for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr)
|
||||
{
|
||||
actual.push_back(*itr);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected.size(), bl.size());
|
||||
CHECK_EQUAL(expected.size(), actual.size());
|
||||
CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size())));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_equality)
|
||||
{
|
||||
BresenhamLine bl1(0, 1, 2, 3);
|
||||
BresenhamLine bl2(0, 1, 2, 3);
|
||||
BresenhamLine bl3(0, 1, 2, 4);
|
||||
BresenhamLine bl4(0, 2, 2, 3);
|
||||
|
||||
CHECK(bl1 == bl2);
|
||||
CHECK(!(bl1 != bl2));
|
||||
|
||||
CHECK(bl1 != bl3);
|
||||
CHECK(!(bl1 == bl3));
|
||||
|
||||
CHECK(bl1 != bl4);
|
||||
CHECK(!(bl1 == bl4));
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -101,6 +101,24 @@ namespace
|
||||
CHECK_EQUAL(SIZE, data.max_size());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::deque data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 };
|
||||
etl::deque<NDC, 14> check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(14U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(14U, data.capacity());
|
||||
CHECK_EQUAL(14U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_fill)
|
||||
{
|
||||
|
||||
@ -316,6 +316,26 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::flat_map data{ ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4),
|
||||
ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) };
|
||||
etl::flat_map<int, NDC, 10U> check = { ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4),
|
||||
ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_destruct_via_iflat_map)
|
||||
{
|
||||
|
||||
@ -293,6 +293,26 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::flat_multimap data{ ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4),
|
||||
ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) };
|
||||
etl::flat_multimap<int, NDC, 10U> check = { ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4),
|
||||
ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_destruct_via_iflat_multimap)
|
||||
{
|
||||
|
||||
@ -262,6 +262,24 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::flat_multiset data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 };
|
||||
etl::flat_multiset<NDC, 10U> check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_destruct_via_iflat_multiset)
|
||||
{
|
||||
|
||||
@ -274,6 +274,24 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::flat_set data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 };
|
||||
etl::flat_set<NDC, 10U> check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_destruct_via_iflat_set)
|
||||
{
|
||||
|
||||
@ -95,6 +95,24 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::forward_list data{ ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) };
|
||||
etl::forward_list< ItemNDC, 10> check = { ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_size)
|
||||
{
|
||||
|
||||
@ -97,7 +97,10 @@ namespace
|
||||
PoolDC pool;
|
||||
DataDC data(pool);
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
CHECK(data.empty());
|
||||
CHECK(!data.full());
|
||||
CHECK_EQUAL(data.available(), SIZE);
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
CHECK(data.begin() == data.end());
|
||||
CHECK(data.has_shared_pool());
|
||||
@ -109,6 +112,8 @@ namespace
|
||||
DataNDC data;
|
||||
|
||||
CHECK_THROW(data.push_front(ItemNDC("1")), etl::forward_list_no_pool);
|
||||
CHECK_THROW(data.full(), etl::forward_list_no_pool);
|
||||
CHECK_THROW(data.available(), etl::forward_list_no_pool);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -123,6 +128,10 @@ namespace
|
||||
CHECK(!data2.empty());
|
||||
CHECK_EQUAL(INITIAL_SIZE, data1.size());
|
||||
CHECK_EQUAL(INITIAL_SIZE, data2.size());
|
||||
|
||||
CHECK_EQUAL(SIZE - (INITIAL_SIZE * 2), data1.available());
|
||||
CHECK_EQUAL(SIZE - (INITIAL_SIZE * 2), data2.available());
|
||||
|
||||
CHECK_EQUAL((2 * INITIAL_SIZE), pool.size());
|
||||
}
|
||||
|
||||
@ -533,9 +542,14 @@ namespace
|
||||
data1.assign(compare_data.begin(), compare_data.end());
|
||||
data1.assign(compare_data.begin(), compare_data.end());
|
||||
|
||||
CHECK_EQUAL(pool.available(), data1.available());
|
||||
CHECK_EQUAL(pool.available(), data2.available());
|
||||
|
||||
data2.assign(compare_data.begin(), compare_data.end());
|
||||
data2.assign(compare_data.begin(), compare_data.end());
|
||||
|
||||
CHECK_EQUAL(pool.available(), data1.available());
|
||||
CHECK_EQUAL(pool.available(), data2.available());
|
||||
|
||||
CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size());
|
||||
CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size());
|
||||
|
||||
@ -338,6 +338,9 @@ namespace
|
||||
{
|
||||
etl::null_message_router nmr;
|
||||
|
||||
CHECK(motorControl.is_producer());
|
||||
CHECK(motorControl.is_consumer());
|
||||
|
||||
motorControl.Initialise(stateList, etl::size(stateList));
|
||||
motorControl.reset();
|
||||
motorControl.ClearStatistics();
|
||||
|
||||
@ -104,7 +104,7 @@ namespace
|
||||
int a = 0;
|
||||
etl::reference_wrapper<int> ra(a);
|
||||
|
||||
ra = 1;
|
||||
ra.get() = 1;
|
||||
CHECK_EQUAL(1, a);
|
||||
CHECK_EQUAL(1, ra);
|
||||
|
||||
@ -113,42 +113,15 @@ namespace
|
||||
CHECK_EQUAL(2, ra);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_reference_wrapper_vector)
|
||||
{
|
||||
std::vector<etl::reference_wrapper<int>> ref_int;
|
||||
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
|
||||
ref_int.push_back(etl::ref(a));
|
||||
ref_int.push_back(etl::ref(b));
|
||||
|
||||
CHECK_EQUAL(a, ref_int[0]);
|
||||
CHECK_EQUAL(b, ref_int[1]);
|
||||
|
||||
ref_int[0] = 3;
|
||||
ref_int[1] = 4;
|
||||
|
||||
CHECK_EQUAL(3, a);
|
||||
CHECK_EQUAL(4, b);
|
||||
|
||||
CHECK_EQUAL(3, ref_int[0]);
|
||||
CHECK_EQUAL(4, ref_int[1]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_reference_wrapper_container)
|
||||
{
|
||||
std::list<int> test = { 0, 1, 2, 3, 4 };
|
||||
std::list<int> compare = { 5, 6, 7, 8, 9 };
|
||||
std::list<int> test = { 0, 1, 2, 3, 4 };
|
||||
std::list<int> compare = { 0, 1, 2, 3, 4 };
|
||||
std::vector<etl::reference_wrapper<int>> test_ref(test.begin(), test.end());
|
||||
|
||||
std::iota(test_ref.begin(), test_ref.end(), 5);
|
||||
|
||||
std::list<int>::const_iterator itest = test.begin();
|
||||
std::list<int>::const_iterator itest = test.begin();
|
||||
std::list<int>::const_iterator icompare = compare.begin();
|
||||
//std::vector<etl::reference_wrapper<int>>::const_iterator ivector = test_ref.begin();
|
||||
|
||||
while (icompare != compare.end())
|
||||
{
|
||||
@ -164,7 +137,7 @@ namespace
|
||||
int a = 0;
|
||||
etl::reference_wrapper<int> ra = etl::ref(a);
|
||||
|
||||
ra = 1;
|
||||
ra.get() = 1;
|
||||
CHECK_EQUAL(1, a);
|
||||
CHECK_EQUAL(1, ra);
|
||||
}
|
||||
|
||||
@ -136,6 +136,24 @@ namespace
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::indirect_vector data{ NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") };
|
||||
etl::indirect_vector<NDC, 10U> check = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_destruct_via_ivector)
|
||||
{
|
||||
|
||||
@ -106,6 +106,24 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::list data{ ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) };
|
||||
etl::list< ItemNDC, 10> check = { ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_destruct_via_ilist)
|
||||
{
|
||||
|
||||
@ -106,6 +106,8 @@ namespace
|
||||
DataNDC data;
|
||||
|
||||
CHECK_EQUAL(data.max_size(), 0U);
|
||||
CHECK_EQUAL(data.size(), 0U);
|
||||
CHECK(data.empty());
|
||||
CHECK(data.has_shared_pool());
|
||||
}
|
||||
|
||||
@ -115,6 +117,8 @@ namespace
|
||||
DataNDC data;
|
||||
|
||||
CHECK_THROW(data.push_back(ItemNDC("1")), etl::list_no_pool);
|
||||
CHECK_THROW(data.full(), etl::list_no_pool);
|
||||
CHECK_THROW(data.available(), etl::list_no_pool);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -125,6 +129,8 @@ namespace
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
CHECK(data.empty());
|
||||
CHECK(!data.full());
|
||||
CHECK_EQUAL(data.available(), SIZE);
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
CHECK(data.begin() == data.end());
|
||||
|
||||
@ -524,12 +530,19 @@ namespace
|
||||
DataNDC data1(pool);
|
||||
DataNDC data2(pool);
|
||||
|
||||
CHECK_EQUAL(pool.available(), data1.available());
|
||||
CHECK_EQUAL(pool.available(), data2.available());
|
||||
|
||||
data1.assign(compare_data.begin(), compare_data.end());
|
||||
CHECK(!data1.empty());
|
||||
CHECK(data2.empty());
|
||||
CHECK_EQUAL(pool.available(), data1.available());
|
||||
CHECK_EQUAL(pool.available(), data2.available());
|
||||
data2.assign(compare_data.begin(), compare_data.end());
|
||||
CHECK(!data1.empty());
|
||||
CHECK(!data2.empty());
|
||||
CHECK_EQUAL(pool.available(), data1.available());
|
||||
CHECK_EQUAL(pool.available(), data2.available());
|
||||
|
||||
CHECK_EQUAL(compare_data.size(), data1.size());
|
||||
CHECK_EQUAL(compare_data.size(), data2.size());
|
||||
|
||||
@ -30,7 +30,7 @@ SOFTWARE.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/wstring.h"
|
||||
#include "etl/u16string.h"
|
||||
#include "etl/u32string.h"
|
||||
|
||||
@ -225,6 +225,26 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::map data{ std::pair<std::string, int>("0", 0), std::pair<std::string, int>("1", 1), std::pair<std::string, int>("2", 2), std::pair<std::string, int>("3", 3), std::pair<std::string, int>("4", 4),
|
||||
std::pair<std::string, int>("5", 5), std::pair<std::string, int>("6", 6), std::pair<std::string, int>("7", 7), std::pair<std::string, int>("8", 8), std::pair<std::string, int>("9", 9) };
|
||||
etl::map<std::string, int, 10U> check = { std::pair<std::string, int>("0", 0), std::pair<std::string, int>("1", 1), std::pair<std::string, int>("2", 2), std::pair<std::string, int>("3", 3), std::pair<std::string, int>("4", 4),
|
||||
std::pair<std::string, int>("5", 5), std::pair<std::string, int>("6", 6), std::pair<std::string, int>("7", 7), std::pair<std::string, int>("8", 8), std::pair<std::string, int>("9", 9) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
||||
{
|
||||
|
||||
@ -887,7 +887,6 @@ namespace
|
||||
{
|
||||
etl::unique_ptr<int> up(new int);
|
||||
|
||||
int* p = new int(1);
|
||||
up = nullptr;
|
||||
|
||||
CHECK(up.get() == nullptr);
|
||||
@ -1018,7 +1017,6 @@ namespace
|
||||
{
|
||||
etl::unique_ptr<int> up(new int[4]);
|
||||
|
||||
int* p = new int[4];
|
||||
up = nullptr;
|
||||
|
||||
CHECK(up.get() == nullptr);
|
||||
|
||||
@ -227,6 +227,26 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::multimap data{ std::pair<std::string, int>("0", 0), std::pair<std::string, int>("1", 1), std::pair<std::string, int>("2", 2), std::pair<std::string, int>("3", 3), std::pair<std::string, int>("4", 4),
|
||||
std::pair<std::string, int>("5", 5), std::pair<std::string, int>("6", 6), std::pair<std::string, int>("7", 7), std::pair<std::string, int>("8", 8), std::pair<std::string, int>("9", 9) };
|
||||
etl::multimap<std::string, int, 10U> check = { std::pair<std::string, int>("0", 0), std::pair<std::string, int>("1", 1), std::pair<std::string, int>("2", 2), std::pair<std::string, int>("3", 3), std::pair<std::string, int>("4", 4),
|
||||
std::pair<std::string, int>("5", 5), std::pair<std::string, int>("6", 6), std::pair<std::string, int>("7", 7), std::pair<std::string, int>("8", 8), std::pair<std::string, int>("9", 9) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
||||
{
|
||||
|
||||
@ -234,6 +234,24 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::multiset data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
etl::multiset<int, 10U> check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
||||
{
|
||||
|
||||
@ -68,7 +68,6 @@ namespace
|
||||
CHECK(!data1.has_value());
|
||||
CHECK(!data2.has_value());
|
||||
|
||||
|
||||
data1 = Data("Hello");
|
||||
CHECK(bool(data1));
|
||||
CHECK(data1.has_value());
|
||||
@ -97,9 +96,22 @@ namespace
|
||||
data4 = etl::nullopt;
|
||||
CHECK(!bool(data4));
|
||||
CHECK(!data4.has_value());
|
||||
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_deduced_initialisation)
|
||||
{
|
||||
Data data("Hello");
|
||||
|
||||
etl::optional opt{ data };
|
||||
|
||||
CHECK(opt.has_value());
|
||||
CHECK(bool(opt));
|
||||
CHECK_EQUAL(data, opt);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_emplace)
|
||||
{
|
||||
|
||||
@ -485,6 +485,10 @@ namespace
|
||||
|
||||
etl::queue<int, 4> queue2;
|
||||
|
||||
// These should be overwritten.
|
||||
queue2.push(5);
|
||||
queue2.push(6);
|
||||
|
||||
queue2 = queue;
|
||||
|
||||
CHECK(queue.size() == queue2.size());
|
||||
|
||||
@ -244,11 +244,30 @@ namespace
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
CHECK(data.empty());
|
||||
CHECK_EQUAL(data.capacity(), MAX_SIZE);
|
||||
CHECK_EQUAL(data.max_size(), MAX_SIZE);
|
||||
CHECK_EQUAL(MAX_SIZE, data.available());
|
||||
CHECK_EQUAL(MAX_SIZE, data.capacity());
|
||||
CHECK_EQUAL(MAX_SIZE, data.max_size());
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::set data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
etl::set<int, 10U> check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
||||
{
|
||||
|
||||
@ -247,6 +247,39 @@ namespace
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
etl::span span1{ data };
|
||||
etl::span span2{ data.begin(), data.end() };
|
||||
etl::span span3{ data.begin(), data.size() };
|
||||
etl::span span4{ span1 };
|
||||
|
||||
int c_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
etl::span span5{ c_array };
|
||||
|
||||
bool isEqual = false;
|
||||
|
||||
isEqual = std::equal(span1.begin(), span1.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(span2.begin(), span2.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(span3.begin(), span3.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(span4.begin(), span4.end(), data.begin());
|
||||
CHECK(isEqual);
|
||||
|
||||
isEqual = std::equal(span5.begin(), span5.end(), c_array);
|
||||
CHECK(isEqual);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_range)
|
||||
{
|
||||
|
||||
@ -437,6 +437,10 @@ namespace
|
||||
|
||||
etl::stack<int, 4> stack2;
|
||||
|
||||
// These should be overwritten.
|
||||
stack2.push(5);
|
||||
stack2.push(6);
|
||||
|
||||
stack2 = stack;
|
||||
|
||||
CHECK(stack.size() == stack2.size());
|
||||
|
||||
@ -32,7 +32,7 @@ SOFTWARE.
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/fnv_1.h"
|
||||
|
||||
#undef STR
|
||||
|
||||
@ -32,7 +32,7 @@ SOFTWARE.
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/fnv_1.h"
|
||||
|
||||
#undef STR
|
||||
@ -73,6 +73,9 @@ namespace
|
||||
Compare_Text short_text;
|
||||
|
||||
const value_t* pinitial_text = STR("Hello World");
|
||||
|
||||
value_t array_text[12];
|
||||
value_t* p_text = array_text;
|
||||
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
@ -94,6 +97,8 @@ namespace
|
||||
different_text = STR("Byee Planet");
|
||||
longer_text = STR("Hello World There");
|
||||
short_text = STR("Hello");
|
||||
|
||||
std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text);
|
||||
}
|
||||
};
|
||||
|
||||
@ -111,6 +116,59 @@ namespace
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size)
|
||||
{
|
||||
size_t length = etl::strlen(p_text);
|
||||
Text text(p_text, length + 1);
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(length, text.capacity());
|
||||
CHECK_EQUAL(length, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size)
|
||||
{
|
||||
Text text(p_text, p_text, etl::strlen(p_text) + 1);
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(p_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.capacity());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer)
|
||||
{
|
||||
Text text(array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text)
|
||||
{
|
||||
Text text(array_text, array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(array_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_iterator_comparison_empty)
|
||||
{
|
||||
@ -186,16 +244,16 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size)
|
||||
{
|
||||
Compare_Text compare_text(SIZE, STR('A'));
|
||||
Compare_Text compare_text(SIZE, STR('A'));
|
||||
|
||||
TextBuffer buffer;
|
||||
Text text(SIZE, STR('A'), buffer.data(), buffer.size());
|
||||
TextBuffer buffer;
|
||||
Text text(SIZE, STR('A'), buffer.data(), buffer.size());
|
||||
|
||||
CHECK(!text.empty());
|
||||
CHECK(!text.empty());
|
||||
|
||||
bool is_equal = Equal(compare_text, text);
|
||||
CHECK(is_equal);
|
||||
CHECK(!text.truncated());
|
||||
bool is_equal = Equal(compare_text, text);
|
||||
CHECK(is_equal);
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -216,16 +274,16 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_size_char)
|
||||
{
|
||||
Compare_Text compare_text(initial_text.c_str(), initial_text.size() / 2);
|
||||
Compare_Text compare_text(initial_text.c_str(), initial_text.size() / 2);
|
||||
|
||||
TextBuffer buffer;
|
||||
Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size());
|
||||
TextBuffer buffer;
|
||||
Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size());
|
||||
|
||||
CHECK(!text.empty());
|
||||
CHECK(!text.empty());
|
||||
|
||||
bool is_equal = Equal(compare_text, text);
|
||||
CHECK(is_equal);
|
||||
CHECK(!text.truncated());
|
||||
bool is_equal = Equal(compare_text, text);
|
||||
CHECK(is_equal);
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -33,7 +33,7 @@ SOFTWARE.
|
||||
#include <iomanip>
|
||||
|
||||
#include "etl/string_stream.h"
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/format_spec.h"
|
||||
|
||||
#undef STR
|
||||
|
||||
@ -74,6 +74,9 @@ namespace
|
||||
|
||||
const value_t* pinitial_text = STR("Hello World");
|
||||
|
||||
value_t array_text[12];
|
||||
value_t* p_text = array_text;
|
||||
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
bool Equal(const T1& compare_text, const T2& text)
|
||||
@ -94,6 +97,8 @@ namespace
|
||||
different_text = STR("Byee Planet");
|
||||
longer_text = STR("Hello World There");
|
||||
short_text = STR("Hello");
|
||||
|
||||
std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text);
|
||||
}
|
||||
};
|
||||
|
||||
@ -111,6 +116,59 @@ namespace
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size)
|
||||
{
|
||||
size_t length = etl::strlen(p_text);
|
||||
Text text(p_text, length + 1);
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(length, text.capacity());
|
||||
CHECK_EQUAL(length, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size)
|
||||
{
|
||||
Text text(p_text, p_text, etl::strlen(p_text) + 1);
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(p_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.capacity());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer)
|
||||
{
|
||||
Text text(array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text)
|
||||
{
|
||||
Text text(array_text, array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(array_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_iterator_comparison_empty)
|
||||
{
|
||||
|
||||
@ -74,6 +74,9 @@ namespace
|
||||
|
||||
const value_t* pinitial_text = STR("Hello World");
|
||||
|
||||
value_t array_text[12];
|
||||
value_t* p_text = array_text;
|
||||
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
bool Equal(const T1& compare_text, const T2& text)
|
||||
@ -94,6 +97,8 @@ namespace
|
||||
different_text = STR("Byee Planet");
|
||||
longer_text = STR("Hello World There");
|
||||
short_text = STR("Hello");
|
||||
|
||||
std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text);
|
||||
}
|
||||
};
|
||||
|
||||
@ -111,6 +116,59 @@ namespace
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size)
|
||||
{
|
||||
size_t length = etl::strlen(p_text);
|
||||
Text text(p_text, length + 1);
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(length, text.capacity());
|
||||
CHECK_EQUAL(length, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size)
|
||||
{
|
||||
Text text(p_text, p_text, etl::strlen(p_text) + 1);
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(p_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.capacity());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer)
|
||||
{
|
||||
Text text(array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text)
|
||||
{
|
||||
Text text(array_text, array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(array_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_iterator_comparison_empty)
|
||||
{
|
||||
|
||||
@ -28,7 +28,7 @@ SOFTWARE.
|
||||
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/string_view.h"
|
||||
#include "etl/string_utilities.h"
|
||||
#include "etl/vector.h"
|
||||
@ -1059,6 +1059,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1061,6 +1061,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1061,6 +1061,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1061,6 +1061,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1061,6 +1061,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1059,6 +1059,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1059,6 +1059,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -1059,6 +1059,22 @@ namespace
|
||||
CHECK_EQUAL(1U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_get_token_delimiters_empty_string_view)
|
||||
{
|
||||
Vector tokens;
|
||||
|
||||
StringView textview;
|
||||
etl::optional<StringView> token;
|
||||
|
||||
while ((token = etl::get_token(textview, Whitespace, token, true)))
|
||||
{
|
||||
tokens.emplace_back(token.value());
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0U, tokens.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pad_left)
|
||||
{
|
||||
|
||||
@ -29,7 +29,7 @@ SOFTWARE.
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
|
||||
#include "etl/string_view.h"
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/wstring.h"
|
||||
#include "etl/u16string.h"
|
||||
#include "etl/u32string.h"
|
||||
|
||||
@ -74,6 +74,9 @@ namespace
|
||||
|
||||
const value_t* pinitial_text = STR("Hello World");
|
||||
|
||||
value_t array_text[12];
|
||||
value_t* p_text = array_text;
|
||||
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
bool Equal(const T1& compare_text, const T2& text)
|
||||
@ -94,6 +97,8 @@ namespace
|
||||
different_text = STR("Byee Planet");
|
||||
longer_text = STR("Hello World There");
|
||||
short_text = STR("Hello");
|
||||
|
||||
std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text);
|
||||
}
|
||||
};
|
||||
|
||||
@ -111,6 +116,59 @@ namespace
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size)
|
||||
{
|
||||
size_t length = etl::strlen(p_text);
|
||||
Text text(p_text, length + 1);
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(length, text.capacity());
|
||||
CHECK_EQUAL(length, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size)
|
||||
{
|
||||
Text text(p_text, p_text, etl::strlen(p_text) + 1);
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(p_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.capacity());
|
||||
CHECK_EQUAL(etl::strlen(p_text), text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer)
|
||||
{
|
||||
Text text(array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(0U, text.size());
|
||||
CHECK(text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() == text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text)
|
||||
{
|
||||
Text text(array_text, array_text, etl::size(array_text));
|
||||
|
||||
CHECK_EQUAL(text.size(), etl::strlen(array_text));
|
||||
CHECK(!text.empty());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.capacity());
|
||||
CHECK_EQUAL(etl::size(array_text) - 1, text.max_size());
|
||||
CHECK(text.begin() != text.end());
|
||||
CHECK(!text.truncated());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_iterator_comparison_empty)
|
||||
{
|
||||
|
||||
@ -33,7 +33,7 @@ SOFTWARE.
|
||||
#include <iomanip>
|
||||
|
||||
#include "etl/to_string.h"
|
||||
#include "etl/cstring.h"
|
||||
#include "etl/string.h"
|
||||
#include "etl/format_spec.h"
|
||||
|
||||
#undef STR
|
||||
|
||||
@ -43,6 +43,7 @@ SOFTWARE.
|
||||
#include "data.h"
|
||||
|
||||
#include "etl/unordered_map.h"
|
||||
#include "etl/hash.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -73,19 +74,35 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef TestDataDC<std::string> DC;
|
||||
typedef TestDataNDC<std::string> NDC;
|
||||
|
||||
typedef ETL_OR_STD::pair<std::string, DC> ElementDC;
|
||||
typedef ETL_OR_STD::pair<std::string, NDC> ElementNDC;
|
||||
}
|
||||
|
||||
namespace etl
|
||||
{
|
||||
template <>
|
||||
struct hash<std::string>
|
||||
{
|
||||
size_t operator ()(const std::string& e) const
|
||||
{
|
||||
size_t sum = 0U;
|
||||
return std::accumulate(e.begin(), e.end(), sum);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_unordered_map)
|
||||
{
|
||||
static const size_t SIZE = 10;
|
||||
|
||||
typedef TestDataDC<std::string> DC;
|
||||
typedef TestDataNDC<std::string> NDC;
|
||||
|
||||
using ItemM = TestDataM<int>;
|
||||
using DataM = etl::unordered_map<std::string, ItemM, SIZE, SIZE, std::hash<std::string>>;
|
||||
|
||||
typedef ETL_OR_STD::pair<std::string, DC> ElementDC;
|
||||
typedef ETL_OR_STD::pair<std::string, NDC> ElementNDC;
|
||||
|
||||
typedef etl::unordered_map<std::string, DC, SIZE, SIZE / 2, simple_hash> DataDC;
|
||||
typedef etl::unordered_map<std::string, NDC, SIZE, SIZE / 2, simple_hash> DataNDC;
|
||||
typedef etl::iunordered_map<std::string, NDC, simple_hash> IDataNDC;
|
||||
@ -227,6 +244,26 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::unordered_map data{ ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4),
|
||||
ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) };
|
||||
etl::unordered_map<std::string, NDC, 10U, 10U> check = { ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4),
|
||||
ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
||||
{
|
||||
|
||||
@ -42,6 +42,19 @@ SOFTWARE.
|
||||
|
||||
#include "etl/unordered_multimap.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
template <>
|
||||
struct hash<std::string>
|
||||
{
|
||||
size_t operator ()(const std::string& e) const
|
||||
{
|
||||
size_t sum = 0U;
|
||||
return std::accumulate(e.begin(), e.end(), sum);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
//*************************************************************************
|
||||
@ -71,6 +84,12 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef TestDataDC<std::string> DC;
|
||||
typedef TestDataNDC<std::string> NDC;
|
||||
|
||||
typedef ETL_OR_STD::pair<std::string, DC> ElementDC;
|
||||
typedef ETL_OR_STD::pair<std::string, NDC> ElementNDC;
|
||||
|
||||
SUITE(test_unordered_multimap)
|
||||
{
|
||||
static const size_t SIZE = 10;
|
||||
@ -202,6 +221,26 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::unordered_multimap data{ ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4),
|
||||
ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) };
|
||||
etl::unordered_multimap<std::string, NDC, 10U, 10U> check = { ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4),
|
||||
ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
||||
{
|
||||
|
||||
@ -42,15 +42,31 @@ SOFTWARE.
|
||||
#include "etl/unordered_multiset.h"
|
||||
#include "etl/checksum.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef TestDataDC<std::string> DC;
|
||||
typedef TestDataNDC<std::string> NDC;
|
||||
}
|
||||
|
||||
namespace etl
|
||||
{
|
||||
template <>
|
||||
struct hash<NDC>
|
||||
{
|
||||
size_t operator ()(const NDC& e) const
|
||||
{
|
||||
size_t sum = 0U;
|
||||
return std::accumulate(e.value.begin(), e.value.end(), sum);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_unordered_multiset)
|
||||
{
|
||||
static const size_t SIZE = 10;
|
||||
|
||||
typedef TestDataDC<std::string> DC;
|
||||
typedef TestDataNDC<std::string> NDC;
|
||||
|
||||
using ItemM = TestDataM<int>;
|
||||
|
||||
struct simple_hash
|
||||
@ -146,6 +162,24 @@ namespace
|
||||
CHECK(data.begin() == data.end());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
||||
//*************************************************************************
|
||||
TEST(test_cpp17_deduced_constructor)
|
||||
{
|
||||
etl::unordered_multiset data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 };
|
||||
etl::unordered_multiset<NDC, 10U> check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 };
|
||||
|
||||
CHECK(!data.empty());
|
||||
CHECK(data.full());
|
||||
CHECK(data.begin() != data.end());
|
||||
CHECK_EQUAL(10U, data.size());
|
||||
CHECK_EQUAL(0U, data.available());
|
||||
CHECK_EQUAL(10U, data.capacity());
|
||||
CHECK_EQUAL(10U, data.max_size());
|
||||
CHECK(data == check);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user