Work in progress

This commit is contained in:
John Wellbelove 2021-10-01 14:10:14 +01:00
parent b47e58a8fe
commit 817ae15c7a
6 changed files with 358 additions and 3 deletions

9
.gitignore vendored
View File

@ -325,3 +325,12 @@ test/vs2019/Test2
test/vs2019/Debug MSVC - Force C++03
test/vs2019/Debug LLVM - No STL
test/vs2019/Debug - No STL
test/meson-info
test/etl_unit_tests.p
test/meson-logs
test/meson-private
test/.ninja_deps
test/.ninja_log
test/build.ninja
test/compile_commands.json
test/etl_unit_tests

View File

@ -58,7 +58,7 @@ namespace etl
///\ingroup memory
//*****************************************************************************
template <typename T>
T* addressof(T& t)
ETL_CONSTEXPR T* addressof(T& t)
{
#if ETL_CPP11_SUPPORTED && ETL_USING_STL
return std::addressof(t);

336
include/etl/multi_span.h Normal file
View File

@ -0,0 +1,336 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2021 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_MULTI_SPAN_INCLUDED
#define ETL_MULTI_SPAN_INCLUDED
#include "platform.h"
#include "iterator.h"
#include "algorithm.h"
#include "vector.h"
#include "span.h"
///\defgroup multi_multi_span multi_span multi_span
/// Scatter/Gather functionality
///\ingroup containers
namespace etl
{
template <typename T>
class multi_span
{
public:
typedef T element_type;
typedef typename etl::remove_cv<T>::type value_type;
typedef size_t size_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef etl::span<T> span_type;
typedef etl::span<const span_type> span_list_type;
//*************************************************************************
/// Iterator
//*************************************************************************
//class iterator : etl::iterator<etl::forward_iterator_tag, T>
//{
//public:
// friend class const_iterator;
// iterator()
// : p_current()
// , p_end()
// , p_value(ETL_NULLPTR)
// {
// }
// //*****************************************
// iterator& operator ++()
// {
// if (p_current != p_end)
// {
// ++p_value;
// if (p_value == p_current->end())
// {
// while (pcurrent.empty() && (p_current != p_end))
// {
// ++p_current;
// }
// if (p_current != p_end)
// {
// p_value = p_current->begin();
// }
// else
// {
// p_value = ETL_NULLPTR;
// }
// }
// }
// return *this;
// }
// //*****************************************
// iterator operator ++(int)
// {
// iterator temp = *this;
// operator ++();
// return temp;
// }
//private:
// //*****************************************
// iterator(span_list_iterator p_current_, span_list_iterator p_end_)
// : p_current(p_current_)
// , p_end(p_end_)
// , p_value(ETL_NULLPTR)
// {
// p_value = p_current->begin();
// }
// typedef const span_type* span_list_pointer;
// span_list_pointer p_current;
// span_list_pointer p_end;
// pointer p_value;
//};
////*************************************************************************
///// Const Iterator
////*************************************************************************
//class const_iterator : etl::iterator<etl::forward_iterator_tag, const T>
//{
//public:
// friend class imulti_span;
//private:
//};
//typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
//typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
//*************************************************************************
/// Constructor.
//*************************************************************************
ETL_CONSTEXPR multi_span(span_list_type span_list_)
: span_list(span_list_)
{
}
//*************************************************************************
/// Construct from a container or other type that supports
/// data() and size() member functions.
//*************************************************************************
template <typename TContainer>
ETL_CONSTEXPR multi_span(TContainer& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
{
}
//*************************************************************************
/// Construct from a container or other type that supports
/// data() and size() member functions.
//*************************************************************************
template <typename TContainer>
ETL_CONSTEXPR multi_span(const TContainer& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
{
}
//*************************************************************************
/// Constructor.
//*************************************************************************
template <typename TIterator>
ETL_CONSTEXPR multi_span(TIterator begin_, TIterator end_)
: span_list(etl::addressof(*begin_), etl::distance(begin_, end_))
{
}
//*************************************************************************
/// Constructor.
//*************************************************************************
template <typename TIterator>
ETL_CONSTEXPR multi_span(TIterator begin_, size_t length_)
: span_list(etl::addressof(*begin_), length_)
{
}
//*************************************************************************
/// Copy Constructor.
//*************************************************************************
ETL_CONSTEXPR multi_span(const multi_span& other)
: span_list(other.span_list)
{
}
//*************************************************************************
/// Assignment operator
//*************************************************************************
ETL_CONSTEXPR multi_span& operator = (const multi_span & other)
{
span_list = other.span_list;
}
////*************************************************************************
/////
////*************************************************************************
//ETL_CONSTEXPR iterator begin() const
//{
// return iterator();
//}
////*************************************************************************
/////
////*************************************************************************
//ETL_CONSTEXPR iterator end() const
//{
// return iterator();
//}
//*************************************************************************
/// copy
//*************************************************************************
template <typename TIterator>
void copy(TIterator destination)
{
for (span_list_type::iterator sp = span_list.begin(); sp != span_list.end(); ++sp)
{
etl::copy(sp->begin(), sp->end(), destination);
etl::advance(destination, sp->size());
}
}
//*************************************************************************
/// for_each
//*************************************************************************
template <typename TFunctor>
void for_each(TFunctor functor)
{
for (span_list_type::iterator sp = span_list.begin(); sp != span_list.end(); ++sp)
{
etl::for_each(sp->begin(), sp->end(), functor);
}
}
//*************************************************************************
/// transform
//*************************************************************************
template <typename TIterator, typename TFunction>
void transform(TIterator destination, TFunction function)
{
for (span_list_type::iterator sp = span_list.begin();
sp != span_list.end();
++sp)
{
etl::transform(sp->begin(), sp->end(), destination, function);
etl::advance(destination, sp->size());
}
}
//*************************************************************************
/// Returns the number of elements in the multi_span.
//*************************************************************************
ETL_CONSTEXPR14 size_t size() const ETL_NOEXCEPT
{
size_t total_n_spans = 0U;
for (span_list_type::iterator itr = span_list.begin();
itr != span_list.end();
++itr)
{
total_n_spans += itr->size();
}
return total_n_spans;
}
//*************************************************************************
/// Returns <b>true</b> if the multi_span size is zero.
//*************************************************************************
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
{
if (span_list.empty())
{
return true;
}
else
{
return size() == 0U;
}
}
//*************************************************************************
/// Returns the size of the multi_span.
//*************************************************************************
ETL_CONSTEXPR14 size_t size_bytes() const ETL_NOEXCEPT
{
size_t total_n_spans_bytes = 0U;
for (span_list_type::iterator itr = span_list.begin();
itr != span_list.end();
++itr)
{
total_n_spans_bytes += itr->size_bytes();
}
return total_n_spans_bytes;
}
//*************************************************************************
/// Returns the number of spans in the multi_span.
//*************************************************************************
ETL_CONSTEXPR size_t size_spans() const ETL_NOEXCEPT
{
return span_list.size();
}
private:
span_list_type span_list;
};
}
#endif

View File

@ -179,6 +179,8 @@ unittestcpp_dep = dependency('UnitTest++',
disabler: true,
)
threads_dep = dependency('threads')
etl_unit_tests = executable('etl_unit_tests',
include_directories: [
include_directories('test'),
@ -187,7 +189,7 @@ etl_unit_tests = executable('etl_unit_tests',
include_directories('include')
],
sources: etl_test_sources,
dependencies: unittestcpp_dep,
dependencies: [unittestcpp_dep, threads_dep],
cpp_args: [
'-fexceptions',
'-DENABLE_ETL_UNIT_TESTS',

View File

@ -1816,6 +1816,7 @@
<ClInclude Include="..\..\include\etl\message_pool.h" />
<ClInclude Include="..\..\include\etl\multi_array.h" />
<ClInclude Include="..\..\include\etl\multi_range.h" />
<ClInclude Include="..\..\include\etl\multi_span.h" />
<ClInclude Include="..\..\include\etl\multi_vector.h" />
<ClInclude Include="..\..\include\etl\mutex\mutex_clang_sync.h" />
<ClInclude Include="..\..\include\etl\mutex\mutex_cmsis_os2.h" />
@ -8220,6 +8221,7 @@
<ClCompile Include="..\test_multimap.cpp" />
<ClCompile Include="..\test_multiset.cpp" />
<ClCompile Include="..\test_multi_range.cpp" />
<ClCompile Include="..\test_multi_span.cpp" />
<ClCompile Include="..\test_multi_vector.cpp" />
<ClCompile Include="..\test_murmur3.cpp" />
<ClCompile Include="..\test_numeric.cpp" />

View File

@ -1152,6 +1152,9 @@
<ClInclude Include="..\..\include\etl\mutex\mutex_cmsis_os2.h">
<Filter>ETL\Utilities\Mutex</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\multi_span.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp">
@ -3020,6 +3023,9 @@
<ClCompile Include="..\test_multi_vector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\test_multi_span.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\library.properties">
@ -3164,4 +3170,4 @@
<Filter>Resource Files</Filter>
</Natvis>
</ItemGroup>
</Project>
</Project>