mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-26 20:38:45 +08:00
Merge remote-tracking branch 'origin/feature/indirect_vector' into development
This commit is contained in:
commit
5afec98e00
@ -57,8 +57,8 @@ namespace etl
|
||||
template <typename TIterator,
|
||||
typename TCompare>
|
||||
ETLSTD::pair<TIterator, TIterator> minmax_element(TIterator begin,
|
||||
TIterator end,
|
||||
TCompare compare)
|
||||
TIterator end,
|
||||
TCompare compare)
|
||||
{
|
||||
TIterator minimum = begin;
|
||||
TIterator maximum = begin;
|
||||
@ -88,7 +88,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
template <typename TIterator>
|
||||
ETLSTD::pair<TIterator, TIterator> minmax_element(TIterator begin,
|
||||
TIterator end)
|
||||
TIterator end)
|
||||
{
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::value_type value_t;
|
||||
|
||||
@ -102,7 +102,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETLSTD::pair<const T&, const T&> minmax(const T& a,
|
||||
const T& b)
|
||||
const T& b)
|
||||
{
|
||||
return (b < a) ? ETLSTD::pair<const T&, const T&>(b, a) : ETLSTD::pair<const T&, const T&>(a, b);
|
||||
}
|
||||
@ -115,8 +115,8 @@ namespace etl
|
||||
template <typename T,
|
||||
typename TCompare>
|
||||
ETLSTD::pair<const T&, const T&> minmax(const T& a,
|
||||
const T& b,
|
||||
TCompare compare)
|
||||
const T& b,
|
||||
TCompare compare)
|
||||
{
|
||||
return compare(b, a) ? ETLSTD::pair<const T&, const T&>(b, a) : ETLSTD::pair<const T&, const T&>(a, b);
|
||||
}
|
||||
@ -1124,12 +1124,17 @@ namespace etl
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements using shell sort.
|
||||
/// Uses users defined comparison.
|
||||
/// Uses user defined comparison.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator, typename TCompare>
|
||||
void sort(TIterator first, TIterator last, TCompare compare)
|
||||
void shell_sort(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
if (first == last)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
typedef typename ETLSTD::iterator_traits<TIterator>::difference_type difference_t;
|
||||
|
||||
difference_t n = ETLSTD::distance(first, last);
|
||||
@ -1160,9 +1165,77 @@ namespace etl
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator>
|
||||
void shell_sort(TIterator first, TIterator last)
|
||||
{
|
||||
etl::shell_sort(first, last, ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type>());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements using insertion sort.
|
||||
/// Uses user defined comparison.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator, typename TCompare>
|
||||
void insertion_sort(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
for (TIterator itr = first; itr != last; ++itr)
|
||||
{
|
||||
ETLSTD::rotate(ETLSTD::upper_bound(first, itr, *itr, compare), itr, ETLSTD::next(itr));
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements using insertion sort.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator>
|
||||
void insertion_sort(TIterator first, TIterator last)
|
||||
{
|
||||
etl::insertion_sort(first, last, ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type>());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements.
|
||||
/// Uses user defined comparison.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator, typename TCompare>
|
||||
void sort(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
etl::shell_sort(first, last, compare);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator>
|
||||
void sort(TIterator first, TIterator last)
|
||||
{
|
||||
etl::sort(first, last, ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type>());
|
||||
etl::shell_sort(first, last, ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type>());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements.
|
||||
/// Stable.
|
||||
/// Uses user defined comparison.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator, typename TCompare>
|
||||
void stable_sort(TIterator first, TIterator last, TCompare compare)
|
||||
{
|
||||
etl::insertion_sort(first, last, compare);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Sorts the elements.
|
||||
/// Stable.
|
||||
///\ingroup algorithm
|
||||
//***************************************************************************
|
||||
template <typename TIterator>
|
||||
void stable_sort(TIterator first, TIterator last)
|
||||
{
|
||||
etl::insertion_sort(first, last, ETLSTD::less<typename ETLSTD::iterator_traits<TIterator>::value_type>());
|
||||
}
|
||||
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
|
||||
@ -197,7 +197,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
TReturn operator()(TParams... args) const
|
||||
{
|
||||
ETL_ASSERT(invocation.stub != nullptr, ETL_ERROR(delegate_uninitialised));
|
||||
ETL_ASSERT(is_valid(), ETL_ERROR(delegate_uninitialised));
|
||||
|
||||
return (*invocation.stub)(invocation.object, args...);
|
||||
}
|
||||
|
||||
@ -1185,9 +1185,29 @@ namespace etl
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Sort using in-place merge sort algorithm.
|
||||
/// Uses a supplied predicate function or functor.
|
||||
/// This is not my algorithm. I got it off the web somewhere.
|
||||
/// Stable sort using in-place merge sort algorithm.
|
||||
/// Copyright 2001 Simon Tatham.
|
||||
///
|
||||
/// 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 SIMON TATHAM 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.
|
||||
//*************************************************************************
|
||||
template <typename TCompare>
|
||||
void sort(TCompare compare)
|
||||
|
||||
1610
include/etl/indirect_vector.h
Normal file
1610
include/etl/indirect_vector.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -715,9 +715,29 @@ namespace etl
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Sort using in-place merge sort algorithm.
|
||||
/// Uses a supplied predicate function or functor.
|
||||
/// This is not my algorithm. I got it off the web somewhere.
|
||||
/// Stable sort using in-place merge sort algorithm.
|
||||
/// Copyright 2001 Simon Tatham.
|
||||
///
|
||||
/// 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 SIMON TATHAM 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.
|
||||
//*************************************************************************
|
||||
template <typename TCompare>
|
||||
void sort(TCompare compare)
|
||||
|
||||
@ -784,9 +784,29 @@ namespace etl
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Sort using in-place merge sort algorithm.
|
||||
/// Uses a supplied predicate function or functor.
|
||||
/// This is not my algorithm. I got it off the web somewhere.
|
||||
/// Stable sort using in-place merge sort algorithm.
|
||||
/// Copyright 2001 Simon Tatham.
|
||||
///
|
||||
/// 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 SIMON TATHAM 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.
|
||||
//*************************************************************************
|
||||
template <typename TCompare>
|
||||
void sort(TCompare compare)
|
||||
|
||||
@ -1606,9 +1606,29 @@ namespace etl
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Sort using in-place merge sort algorithm.
|
||||
/// Uses a supplied predicate function or functor.
|
||||
/// This is not my algorithm. I got it off the web somewhere.
|
||||
/// Stable sort using in-place merge sort algorithm.
|
||||
/// Copyright 2001 Simon Tatham.
|
||||
///
|
||||
/// 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 SIMON TATHAM 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.
|
||||
//*************************************************************************
|
||||
template <typename TCompare>
|
||||
void sort(TCompare compare)
|
||||
|
||||
@ -691,6 +691,7 @@ namespace etlstd
|
||||
return private_heap::is_heap(first, last - first, compare);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Search
|
||||
template<typename TIterator1, typename TIterator2, typename TCompare>
|
||||
TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last, TCompare compare)
|
||||
@ -735,6 +736,30 @@ namespace etlstd
|
||||
|
||||
return etlstd::search(first, last, search_first, search_last, compare());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Rotate
|
||||
template<typename TIterator>
|
||||
TIterator rotate(TIterator first, TIterator middle, TIterator last)
|
||||
{
|
||||
TIterator next = middle;
|
||||
|
||||
while (first != next)
|
||||
{
|
||||
etlstd::swap(*first++, *next++);
|
||||
|
||||
if (next == last)
|
||||
{
|
||||
next = middle;
|
||||
}
|
||||
else if (first == middle)
|
||||
{
|
||||
middle = next;
|
||||
}
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -370,6 +370,24 @@ namespace etlstd
|
||||
{
|
||||
return itr.operator +(n);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Previous
|
||||
template<typename TIterator>
|
||||
TIterator prev(TIterator itr, typename etlstd::iterator_traits<TIterator>::difference_type n = 1)
|
||||
{
|
||||
etlstd::advance(itr, -n);
|
||||
return itr;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Next
|
||||
template<typename TIterator>
|
||||
TIterator next(TIterator itr, typename etlstd::iterator_traits<TIterator>::difference_type n = 1)
|
||||
{
|
||||
etlstd::advance(itr, n);
|
||||
return itr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -243,8 +243,7 @@ namespace etl
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_fundamental : integral_constant<bool, is_arithmetic<T>::value ||
|
||||
is_void<T>::value ||
|
||||
is_same<std::nullptr_t,
|
||||
typename remove_cv<T>::type>::value> {};
|
||||
is_same<std::nullptr_t, typename remove_cv<T>::type>::value> {};
|
||||
|
||||
/// is_compound
|
||||
///\ingroup type_traits
|
||||
@ -258,25 +257,27 @@ namespace etl
|
||||
|
||||
/// is_pointer
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_pointer : false_type {};
|
||||
template <typename T> struct is_pointer<T*> : true_type {};
|
||||
template<typename T> struct is_pointer_helper : false_type {};
|
||||
template<typename T> struct is_pointer_helper<T*> : true_type {};
|
||||
template<typename T> struct is_pointer : is_pointer_helper<typename remove_cv<T>::type> {};
|
||||
|
||||
/// is_reference
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_reference : false_type {};
|
||||
template <typename T> struct is_reference<T&> : true_type {};
|
||||
template<typename T> struct is_reference_helper : false_type {};
|
||||
template<typename T> struct is_reference_helper<T&> : true_type {};
|
||||
template<typename T> struct is_reference : is_reference_helper<typename remove_cv<T>::type> {};
|
||||
|
||||
/// is_pod
|
||||
/// For C++03, only fundamental and pointers types are recognised.
|
||||
///\ingroup type_traits
|
||||
#if (ETL_CPP11_SUPPORTED && !defined(ARDUINO) && !defined(ETL_STLPORT)) && !defined(ETL_IN_UNIT_TEST) && !defined(ETL_NO_STL)
|
||||
#if (ETL_CPP11_SUPPORTED && !defined(ARDUINO) && !defined(ETL_STLPORT)) && !defined(IN_TYPE_TRAITS_TEST) && !defined(ETL_NO_STL)
|
||||
// For compilers that support C++11
|
||||
template <typename T> struct is_pod : std::is_pod<T> {};
|
||||
#else
|
||||
template <typename T> struct is_pod : etl::integral_constant<bool, etl::is_fundamental<T>::value || etl::is_pointer<T>::value> {};
|
||||
#endif
|
||||
|
||||
#if (ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) && !defined(ETL_STLPORT) && !defined(ETL_IN_UNIT_TEST) && !defined(ETL_NO_STL)
|
||||
#if (ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) && !defined(ETL_STLPORT) && !defined(IN_TYPE_TRAITS_TEST) && !defined(ETL_NO_STL)
|
||||
/// is_trivially_constructible
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_trivially_constructible : std::is_trivially_constructible<T> {};
|
||||
@ -292,6 +293,10 @@ namespace etl
|
||||
/// is_trivially_copy_assignable
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_trivially_copy_assignable : std::is_trivially_copy_assignable<T> {};
|
||||
|
||||
/// is_trivially_copyable
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_trivially_copyable : std::is_trivially_copyable<T> {};
|
||||
#else
|
||||
/// is_trivially_constructible
|
||||
/// For C++03, only POD types are recognised.
|
||||
@ -312,6 +317,11 @@ namespace etl
|
||||
/// For C++03, only POD types are recognised.
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_trivially_copy_assignable : etl::is_pod<T> {};
|
||||
|
||||
/// is_trivially_copyable
|
||||
/// For C++03, only POD types are recognised.
|
||||
///\ingroup type_traits
|
||||
template <typename T> struct is_trivially_copyable : etl::is_pod<T> {};
|
||||
#endif
|
||||
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
|
||||
@ -575,7 +575,7 @@ namespace etl
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Emplaces a value to the vextor at the specified position.
|
||||
/// Emplaces a value to the vector at the specified position.
|
||||
//*************************************************************************
|
||||
#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT)
|
||||
template <typename ... Args>
|
||||
|
||||
1
temp/.gitignore
vendored
Normal file
1
temp/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/Containers - Supporting rvalue references.txt
|
||||
@ -1,984 +0,0 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
http://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 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_MESSAGE_ROUTER__
|
||||
#define __ETL_MESSAGE_ROUTER__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
/// Allow alternative type for message id.
|
||||
#if !defined(ETL_MESSAGE_ID_TYPE)
|
||||
typedef uint_least8_t message_id_t;
|
||||
#else
|
||||
typedef ETL_MESSAGE_ID_TYPE message_id_t;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
class imessage
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~imessage() {}
|
||||
virtual etl::message_id_t get_message_id() const = 0;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
template <const size_t ID_>
|
||||
class message : public imessage
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
ID = ID_
|
||||
};
|
||||
|
||||
//*******************************************
|
||||
etl::message_id_t get_message_id() const
|
||||
{
|
||||
return etl::message_id_t(ID);
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
class imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~imessage_router() {}
|
||||
virtual void receive(const etl::imessage& message) = 0;
|
||||
virtual void receive(imessage_router& source, const etl::imessage& message) = 0;
|
||||
virtual bool accepts(etl::message_id_t id) const = 0;
|
||||
|
||||
//*******************************************
|
||||
bool accepts(const etl::imessage& msg) const
|
||||
{
|
||||
return accepts(msg.get_message_id());
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
void send_message(imessage_router& destination,
|
||||
const etl::imessage& message)
|
||||
{
|
||||
destination.receive(*this, message);
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// This router can be used either as a sink for messages
|
||||
/// or as a producer-only of messages such an interrupt routine.
|
||||
//***************************************************************************
|
||||
class null_message_router : public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
//*******************************************
|
||||
void receive(const etl::imessage& message)
|
||||
{
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
void receive(etl::imessage_router& source, const etl::imessage& message)
|
||||
{
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
static null_message_router& get()
|
||||
{
|
||||
static null_message_router instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Send a message to a router.
|
||||
/// Sets the 'sender' to etl::null_message_router type.
|
||||
//***************************************************************************
|
||||
inline static void send_message(etl::imessage_router& destination,
|
||||
const etl::imessage& message)
|
||||
{
|
||||
destination.receive(message);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Send a message to a router.
|
||||
//***************************************************************************
|
||||
inline static void send_message(etl::imessage_router& source,
|
||||
etl::imessage_router& destination,
|
||||
const etl::imessage& message)
|
||||
{
|
||||
destination.receive(source, message);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// To generate to header file, run this at the command line.
|
||||
// Note: You will need Python and COG installed.
|
||||
//
|
||||
// python -m cogapp -d -e -omessage_router.h -DHandlers=<n> message_router_generator.h
|
||||
// Where <n> is the number of messages to support.
|
||||
//
|
||||
// e.g.
|
||||
// To generate handlers for up to 16 messages...
|
||||
// python -m cogapp -d -e -omessage_router.h -DHandlers=16 message_router_generator.h
|
||||
//
|
||||
// See CreateMessageProcessor.bat
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// The code below has been auto generated. Do not manually edit.
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// The definition for all 16 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
|
||||
class message_router : public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const etl::message_id_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
case T11::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T11&>(msg)); break;
|
||||
case T12::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T12&>(msg)); break;
|
||||
case T13::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T13&>(msg)); break;
|
||||
case T14::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T14&>(msg)); break;
|
||||
case T15::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T15&>(msg)); break;
|
||||
case T16::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T16&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: case T15::ID: case T16::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 15 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9, typename T10, typename T11, typename T12,
|
||||
typename T13, typename T14, typename T15>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
case T11::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T11&>(msg)); break;
|
||||
case T12::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T12&>(msg)); break;
|
||||
case T13::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T13&>(msg)); break;
|
||||
case T14::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T14&>(msg)); break;
|
||||
case T15::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T15&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID: case T15::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 14 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9, typename T10, typename T11, typename T12,
|
||||
typename T13, typename T14>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
case T11::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T11&>(msg)); break;
|
||||
case T12::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T12&>(msg)); break;
|
||||
case T13::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T13&>(msg)); break;
|
||||
case T14::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T14&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID: case T14::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 13 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9, typename T10, typename T11, typename T12,
|
||||
typename T13>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
case T11::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T11&>(msg)); break;
|
||||
case T12::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T12&>(msg)); break;
|
||||
case T13::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T13&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID: case T11::ID: case T12::ID: case T13::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 12 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9, typename T10, typename T11, typename T12>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
case T11::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T11&>(msg)); break;
|
||||
case T12::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T12&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID: case T11::ID: case T12::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 11 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9, typename T10, typename T11>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
case T11::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T11&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID: case T11::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 10 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9, typename T10>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
case T10::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T10&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID: case T10::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 9 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8,
|
||||
typename T9>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, T9, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
case T9::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T9&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
case T9::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 8 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, T8, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
case T8::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T8&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID: case T8::ID:
|
||||
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 7 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, T7, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
case T7::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T7&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID: case T7::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 6 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, T6, void, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
case T6::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T6&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID: case T6::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 5 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, T5, void, void, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
case T5::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T5&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID: case T5::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 4 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3, typename T4>
|
||||
class message_router<TProcessor, T1, T2, T3, T4, void, void, void, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
case T4::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T4&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID: case T4::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 3 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2, typename T3>
|
||||
class message_router<TProcessor, T1, T2, T3, void, void, void, void, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T3&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID: case T3::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
|
||||
class message_packet
|
||||
{
|
||||
public:
|
||||
|
||||
explicit message_packet(const imessage& msg)
|
||||
{
|
||||
const etl::message_id_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: new (&storage) T1(static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: new (&storage) T2(static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: new (&storage) T3(static_cast<const T3&>(msg)); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
~message_packet()
|
||||
{
|
||||
static_cast<const etl::imessage*>(storage).~imessage();
|
||||
}
|
||||
|
||||
message_packet(const message_packet& other)
|
||||
{
|
||||
const etl::message_id_t id = other.get_imessage().get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: new (&storage) T1(static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: new (&storage) T2(static_cast<const T2&>(msg)); break;
|
||||
case T3::ID: new (&storage) T3(static_cast<const T3&>(msg)); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
message_packet& operator = (const message_packet& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
static_cast<const etl::imessage*>(storage).~imessage();
|
||||
new (this) message_packet(other);
|
||||
}
|
||||
}
|
||||
|
||||
const etl::imessage& get_imessage() const
|
||||
{
|
||||
return *reiniterpret_cast<const imessage*>(storage);
|
||||
}
|
||||
|
||||
operator const imessage&() const
|
||||
{
|
||||
return get_imessage();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
etl::aligned_storage<etl::largest<T1, T2, T3>::size, etl::largest_alignment<T1, T2, T3>::value>::type storage;
|
||||
};
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 2 message types.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1, typename T2>
|
||||
class message_router<TProcessor, T1, T2, void, void, void, void, void, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
case T2::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T2&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: case T2::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Specialisation for 1 message type.
|
||||
//***************************************************************************
|
||||
template <typename TProcessor,
|
||||
typename T1>
|
||||
class message_router<TProcessor, T1, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void>
|
||||
: public imessage_router
|
||||
{
|
||||
public:
|
||||
|
||||
void receive(const etl::imessage& msg)
|
||||
{
|
||||
receive(etl::null_message_router::get(), msg);
|
||||
}
|
||||
|
||||
void receive(etl::imessage_router& source, const etl::imessage& msg)
|
||||
{
|
||||
const size_t id = msg.get_message_id();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID: static_cast<TProcessor*>(this)->on_receive(source, static_cast<const T1&>(msg)); break;
|
||||
default: static_cast<TProcessor*>(this)->on_receive_unknown(source, msg); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool accepts(etl::message_id_t id) const
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case T1::ID:
|
||||
return true; break;
|
||||
default:
|
||||
return false; break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -211,6 +211,7 @@
|
||||
<Unit filename="../../include/etl/hash.h" />
|
||||
<Unit filename="../../include/etl/icache.h" />
|
||||
<Unit filename="../../include/etl/ihash.h" />
|
||||
<Unit filename="../../include/etl/indirect_vector.h" />
|
||||
<Unit filename="../../include/etl/instance_count.h" />
|
||||
<Unit filename="../../include/etl/integral_limits.h" />
|
||||
<Unit filename="../../include/etl/intrusive_forward_list.h" />
|
||||
@ -393,6 +394,7 @@
|
||||
<Unit filename="../test_function.cpp" />
|
||||
<Unit filename="../test_functional.cpp" />
|
||||
<Unit filename="../test_hash.cpp" />
|
||||
<Unit filename="../test_indirect_vector.cpp" />
|
||||
<Unit filename="../test_instance_count.cpp" />
|
||||
<Unit filename="../test_integral_limits.cpp" />
|
||||
<Unit filename="../test_intrusive_forward_list.cpp" />
|
||||
|
||||
10
test/data.h
10
test/data.h
@ -77,6 +77,11 @@ public:
|
||||
return !(value < other.value);
|
||||
}
|
||||
|
||||
static bool are_identical(const TestDataDC& lhs, const TestDataDC& rhs)
|
||||
{
|
||||
return (lhs.value == rhs.value) && (lhs.index == rhs.index);
|
||||
}
|
||||
|
||||
T value;
|
||||
int index;
|
||||
};
|
||||
@ -137,6 +142,11 @@ public:
|
||||
return !(value < other.value);
|
||||
}
|
||||
|
||||
static bool are_identical(const TestDataNDC& lhs, const TestDataNDC& rhs)
|
||||
{
|
||||
return (lhs.value == rhs.value) && (lhs.index == rhs.index);
|
||||
}
|
||||
|
||||
T value;
|
||||
int index;
|
||||
};
|
||||
|
||||
@ -70,6 +70,7 @@ SOFTWARE.
|
||||
#define ETL_POLYMORPHIC_STRINGS
|
||||
#define ETL_POLYMORPHIC_POOL
|
||||
#define ETL_POLYMORPHIC_VECTOR
|
||||
#define ETL_POLYMORPHIC_INDIRECT_VECTOR
|
||||
|
||||
//#define ETL_POLYMORPHIC_CONTAINERS
|
||||
|
||||
|
||||
@ -31,6 +31,8 @@ SOFTWARE.
|
||||
#include "etl/algorithm.h"
|
||||
#include "etl/container.h"
|
||||
|
||||
#include "data.h"
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
@ -40,6 +42,7 @@ SOFTWARE.
|
||||
|
||||
namespace
|
||||
{
|
||||
using NDC = TestDataNDC<int>;
|
||||
std::random_device rng;
|
||||
std::mt19937 urng(rng());
|
||||
|
||||
@ -914,6 +917,108 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(stable_sort_default)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1, 1), NDC(2, 1), NDC(3, 1), NDC(2, 2), NDC(3, 2), NDC(4, 1), NDC(2, 3), NDC(3, 3), NDC(5, 1) };
|
||||
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::stable_sort(data1.begin(), data1.end());
|
||||
etl::stable_sort(data2.begin(), data2.end());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin(), NDC::are_identical);
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(stable_sort_greater)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1, 1), NDC(2, 1), NDC(3, 1), NDC(2, 2), NDC(3, 2), NDC(4, 1), NDC(2, 3), NDC(3, 3), NDC(5, 1) };
|
||||
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::stable_sort(data1.begin(), data1.end(), std::greater<NDC>());
|
||||
etl::stable_sort(data2.begin(), data2.end(), std::greater<NDC>());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin(), NDC::are_identical);
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(shell_sort_default)
|
||||
{
|
||||
std::vector<int> data(100, 0);
|
||||
std::iota(data.begin(), data.end(), 1);
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
std::shuffle(data.begin(), data.end(), urng);
|
||||
|
||||
std::vector<int> data1 = data;
|
||||
std::vector<int> data2 = data;
|
||||
|
||||
std::sort(data1.begin(), data1.end());
|
||||
etl::shell_sort(data2.begin(), data2.end());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin());
|
||||
CHECK(is_same);
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(shell_sort_greater)
|
||||
{
|
||||
std::vector<int> data(100, 0);
|
||||
std::iota(data.begin(), data.end(), 1);
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
std::shuffle(data.begin(), data.end(), urng);
|
||||
|
||||
std::vector<int> data1 = data;
|
||||
std::vector<int> data2 = data;
|
||||
|
||||
std::sort(data1.begin(), data1.end(), std::greater<int>());
|
||||
etl::shell_sort(data2.begin(), data2.end(), std::greater<int>());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin());
|
||||
CHECK(is_same);
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(insertion_sort_default)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1, 1), NDC(2, 1), NDC(3, 1), NDC(2, 2), NDC(3, 2), NDC(4, 1), NDC(2, 3), NDC(3, 3), NDC(5, 1) };
|
||||
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::stable_sort(data1.begin(), data1.end());
|
||||
etl::insertion_sort(data2.begin(), data2.end());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin(), NDC::are_identical);
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(insertion_sort_greater)
|
||||
{
|
||||
std::vector<NDC> initial_data = { NDC(1, 1), NDC(2, 1), NDC(3, 1), NDC(2, 2), NDC(3, 2), NDC(4, 1), NDC(2, 3), NDC(3, 3), NDC(5, 1) };
|
||||
|
||||
std::vector<NDC> data1(initial_data);
|
||||
std::vector<NDC> data2(initial_data);
|
||||
|
||||
std::stable_sort(data1.begin(), data1.end(), std::greater<NDC>());
|
||||
etl::insertion_sort(data2.begin(), data2.end(), std::greater<NDC>());
|
||||
|
||||
bool is_same = std::equal(data1.begin(), data1.end(), data2.begin(), NDC::are_identical);
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
TEST(multimax)
|
||||
{
|
||||
|
||||
1581
test/test_indirect_vector.cpp
Normal file
1581
test/test_indirect_vector.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -741,5 +741,23 @@ namespace
|
||||
CHECK_EQUAL(4U, *(data2[3]));
|
||||
CHECK_EQUAL(5U, *(data2[4]));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(rotate)
|
||||
{
|
||||
std::vector<int> initial_data = { 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
for (size_t i = 0; i < initial_data.size(); ++i)
|
||||
{
|
||||
std::vector data1(initial_data);
|
||||
std::vector data2(initial_data);
|
||||
|
||||
std::rotate(data1.data(), data1.data() + i, data1.data() + data1.size());
|
||||
etlstd::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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ namespace
|
||||
{
|
||||
int* itr1 = std::begin(dataA);
|
||||
non_random_iterator<int> itr2 = std::begin(dataA);
|
||||
|
||||
|
||||
std::advance(itr1, 4);
|
||||
etlstd::advance(itr2, 4);
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
@ -92,5 +92,35 @@ namespace
|
||||
etlstd::advance(itr2, -3);
|
||||
CHECK_EQUAL(*itr1, *itr2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(prev)
|
||||
{
|
||||
int data[] = { 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
size_t length = 6U;
|
||||
|
||||
int* itr = &data[0] + length;
|
||||
|
||||
for (size_t i = 1; i <= length; ++i)
|
||||
{
|
||||
CHECK_EQUAL(data[length - i], *etlstd::prev(itr, i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(next)
|
||||
{
|
||||
int data[] = { 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
size_t length = 6U;
|
||||
|
||||
int* itr = &data[0];
|
||||
|
||||
for (size_t i = 1; i <= length; ++i)
|
||||
{
|
||||
CHECK_EQUAL(data[i], *etlstd::next(itr, i));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -28,6 +28,8 @@ SOFTWARE.
|
||||
|
||||
#include "UnitTest++.h"
|
||||
|
||||
#define IN_TYPE_TRAITS_TEST
|
||||
|
||||
#if defined(ETL_COMPILER_GCC)
|
||||
namespace std
|
||||
{
|
||||
|
||||
@ -457,6 +457,7 @@
|
||||
<ClInclude Include="..\..\include\etl\fsm.h" />
|
||||
<ClInclude Include="..\..\include\etl\fsm_generator.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_service.h" />
|
||||
<ClInclude Include="..\..\include\etl\indirect_vector.h" />
|
||||
<ClInclude Include="..\..\include\etl\largest_generator.h" />
|
||||
<ClInclude Include="..\..\include\etl\absolute.h" />
|
||||
<ClInclude Include="..\..\include\etl\macros.h" />
|
||||
@ -672,6 +673,7 @@
|
||||
<ClCompile Include="..\test_delegate_service.cpp" />
|
||||
<ClCompile Include="..\test_forward_list_shared_pool.cpp" />
|
||||
<ClCompile Include="..\test_bit_stream.cpp" />
|
||||
<ClCompile Include="..\test_indirect_vector.cpp" />
|
||||
<ClCompile Include="..\test_list_shared_pool.cpp" />
|
||||
<ClCompile Include="..\test_multi_array.cpp" />
|
||||
<ClCompile Include="..\test_no_stl_algorithm.cpp" />
|
||||
|
||||
@ -786,6 +786,9 @@
|
||||
<ClInclude Include="..\..\include\etl\stl\choose_namespace.h">
|
||||
<Filter>ETL\STL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\indirect_vector.h">
|
||||
<Filter>ETL\Containers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\main.cpp">
|
||||
@ -1241,6 +1244,9 @@
|
||||
<ClCompile Include="..\test_compiler_settings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_indirect_vector.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user