From fc09a7005100918a728adf669c498259d006b3d1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 28 Oct 2018 15:37:46 +0000 Subject: [PATCH 01/13] Merge remote-tracking branch 'origin/development' --- test/test_message_bus.cpp | 3 --- test/test_no_stl_algorithm.cpp | 16 ++++++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/test/test_message_bus.cpp b/test/test_message_bus.cpp index 2bf23e94..483a914e 100644 --- a/test/test_message_bus.cpp +++ b/test/test_message_bus.cpp @@ -205,9 +205,6 @@ namespace int message_unknown_count; }; - etl::imessage_router* p_router; - etl::imessage_bus* p_bus; - SUITE(test_message_router) { //========================================================================= diff --git a/test/test_no_stl_algorithm.cpp b/test/test_no_stl_algorithm.cpp index 36c75673..a41096d2 100644 --- a/test/test_no_stl_algorithm.cpp +++ b/test/test_no_stl_algorithm.cpp @@ -103,11 +103,11 @@ namespace } }; - std::ostream& operator << (std::ostream& os, const Data& data_) - { - os << data_.a << "," << data_.b; - return os; - } +// std::ostream& operator << (std::ostream& os, const Data& data_) +// { +// os << data_.a << "," << data_.b; +// return os; +// } struct Greater : public std::binary_function { @@ -383,7 +383,7 @@ namespace int b = 2; etlstd::swap(a, b); - CHECK_EQUAL(2, a); + CHECK_EQUAL(2, a); CHECK_EQUAL(1, b); } @@ -437,7 +437,7 @@ namespace std::string::iterator itr1 = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.begin()); std::string::iterator itr2 = etlstd::search(haystack.begin(), haystack.end(), needle.begin(), needle.begin()); - + CHECK(itr1 == itr2); } @@ -493,7 +493,7 @@ namespace etlstd::push_heap(data2.begin(), data2.end()); CHECK(std::is_heap(data2.begin(), data2.end())); - + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); } From 8db807f4a1dab9161f2079ab829dcf5d2db3637d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 31 Oct 2018 08:07:00 +0000 Subject: [PATCH 02/13] Added copyright notice --- include/etl/bit_stream.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/include/etl/bit_stream.h b/include/etl/bit_stream.h index c6055ff4..dc8a8285 100644 --- a/include/etl/bit_stream.h +++ b/include/etl/bit_stream.h @@ -1,3 +1,28 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com +Copyright(c) 2018 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_BIT_STREAM_INCLUDED #define ETL_BIT_STREAM_INCLUDED @@ -53,7 +78,7 @@ namespace etl //*************************************************************************** bit_stream(unsigned char* begin_, unsigned char* end_) : pdata(begin_), - length(std::distance(begin_, end_)) + length(std::distance(begin_, end_)) { restart(); } From 64c061e860e573978bf0fc7934562f82bf854e5c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 31 Oct 2018 20:37:53 +0000 Subject: [PATCH 03/13] Merge remote-tracking branch 'origin/development' --- .gitignore | 11 +++++++ CMakeLists.txt | 6 ++-- include/etl/stl/alternate/algorithm.h | 41 ++++++++++++++++++++------- test/CMakeLists.txt | 26 ++++++++++------- 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 07a9f262..ded20f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -236,3 +236,14 @@ pip-log.txt *.session *.tags *.db + +############# +## CLion +############# + +.idea/ + +# CMake +cmake-build-*/ + +unittest-cpp \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c03b3bd..6cfbcd7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,12 @@ project(etl) set(ETL_PROFILE "DEFAULT" CACHE STRING "Defines what profile header to include. See https://www.etlcpp.com/setup.html" ) -option(BUILD_TESTS "Build unit tests" ON) +option(BUILD_TESTS "Build unit tests" OFF) # Note: this will not compile src/c/ecl_timer.c as that c file has a dependence # on ecl_user.h which is provided by clients of this library -add_library(etl +add_library(etl STATIC src/binary.cpp src/crc16.cpp src/crc16_ccitt.cpp @@ -29,8 +29,6 @@ add_library(etl src/error_handler.cpp src/pearson.cpp src/random.cpp - src/private - src/private/pvoidvector.cpp ) target_include_directories(etl PUBLIC diff --git a/include/etl/stl/alternate/algorithm.h b/include/etl/stl/alternate/algorithm.h index f234b132..7bb6ebce 100644 --- a/include/etl/stl/alternate/algorithm.h +++ b/include/etl/stl/alternate/algorithm.h @@ -43,16 +43,35 @@ SOFTWARE. #if defined(ETL_IN_UNIT_TEST) #if !defined(ETLSTD) - #define ETLSTD etlstd +#define ETLSTD etlstd #endif - namespace etlstd +namespace etlstd #else #if !defined(ETLSTD) - #define ETLSTD std +#define ETLSTD std #endif - namespace std +namespace std #endif { + //*************************************************************************** + // advance + template + typename etl::enable_if::iterator_tag, ETLSTD::random_access_iterator_tag>::value, void>::type + advance(TIterator itr, TDistance distance) + { + while (distance-- != 0) + { + ++itr; + } + } + + template + typename etl::enable_if::iterator_tag, ETLSTD::random_access_iterator_tag>::value, void>::type + advance(TIterator itr, TDistance distance) + { + return itr += distance; + } + //*************************************************************************** // copy // Pointer @@ -234,7 +253,7 @@ SOFTWARE. typedef ETLSTD::less::value_type> compare; return ETLSTD::make_pair(ETLSTD::lower_bound(first, last, value, compare()), - ETLSTD::upper_bound(first, last, value, compare())); + ETLSTD::upper_bound(first, last, value, compare())); } //*************************************************************************** @@ -242,7 +261,7 @@ SOFTWARE. template TIterator find_if(TIterator first, TIterator last, TUnaryPredicate predicate) { - while (first != last) + while (first != last) { if (predicate(*first)) { @@ -302,7 +321,7 @@ SOFTWARE. { *first++ = value; } - + return first; } @@ -322,7 +341,7 @@ SOFTWARE. while (first != last) { - if (*first == value) + if (*first == value) { ++n; } @@ -342,7 +361,7 @@ SOFTWARE. while (first != last) { - if (predicate(*first)) + if (predicate(*first)) { ++n; } @@ -473,7 +492,7 @@ SOFTWARE. template TIteratorOut transform(TIteratorIn first1, TIteratorIn last1, TIteratorOut d_first, TUnaryOperation unary_operation) { - while (first1 != last1) + while (first1 != last1) { *d_first++ = unary_operation(*first1++); } @@ -572,7 +591,7 @@ SOFTWARE. value_t value = last[-1]; last[-1] = first[0]; - + private_heap::adjust_heap(first, distance_t(0), distance_t(last - first - 1), value, compare); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9ac85d7a..eea884ba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.5.0) project(etl_unit_tests) -# Bring in the UnitTest++ include directories and libraries -find_package(UnitTest++) +add_definitions(-DETL_DEBUG) + if(NOT UnitTest++_FOUND) - # Add unittest-cpp as an ExternalProject + # Add unittest-cpp as an ExternalProject include(cmake/unit-test_external_project.cmake) add_unittest_cpp() else() @@ -46,7 +46,7 @@ set(TEST_SOURCE_FILES test_enum_type.cpp test_error_handler.cpp test_exception.cpp - test_factory.cpp +# test_factory.cpp test_fixed_iterator.cpp test_flat_map.cpp test_flat_multimap.cpp @@ -120,27 +120,31 @@ set(TEST_SOURCE_FILES test_xor_rotate_checksum.cpp # Compile the source level ecl_timer here as test has provided a ecl_user.h file - ${CMAKE_SOURCE_DIR}/src/c/ecl_timer.c + ${PROJECT_SOURCE_DIR}/../src/c/ecl_timer.c ) + + if (WIN32) # test_error_handler.cpp uses windows APIs that assume the microsoft project # is setup for unicode support. Note: This may have adverse effects on client - # projects and the tests should be updated to be independent of project setup + # projects and the tests should be updated to be independent of project setup ADD_DEFINITIONS(-DUNICODE) ADD_DEFINITIONS(-D_UNICODE) endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") list(APPEND TEST_SOURCE_FILES "test_atomic_gcc_sync.cpp") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions") endif() -add_executable(etl_tests +add_executable(etl_tests ${TEST_SOURCE_FILES} ) target_link_libraries(etl_tests etl UnitTest++) target_include_directories(etl_tests - PUBLIC - ${CMAKE_CURRENT_LIST_DIR} + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} ) # Enable the 'make test' CMake target using the executable defined above @@ -152,6 +156,6 @@ add_test(etl_unit_tests etl_tests) add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose) -# Remaining Tests to be implemented: +# Remaining Tests to be implemented: #1. Enable embedded compile target testing # - test_embedded_compile.cpp From df86158adfb58ae2389527aba4b22c9eea2ef1c6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 11 Nov 2018 20:09:24 +0000 Subject: [PATCH 04/13] Merge remote-tracking branch 'origin/development' --- include/etl/binary.h | 843 +++++++++++++++--- include/etl/crc16.h | 28 +- include/etl/crc16_ccitt.h | 28 +- include/etl/crc16_kermit.h | 28 +- include/etl/crc16_modbus.h | 42 +- include/etl/crc32.h | 44 +- include/etl/crc32_c.h | 36 + include/etl/crc64_ecma.h | 74 +- include/etl/crc8_ccitt.h | 28 +- include/etl/error_handler.h | 46 +- src/error_handler.cpp => include/etl/macros.h | 41 +- include/etl/pearson.h | 26 +- include/etl/private/pvoidvector.h | 539 +++++++++-- include/etl/random.h | 374 +++++++- include/etl/version.h | 13 +- src/binary.cpp | 598 ------------- src/crc16.cpp | 60 -- src/crc16_ccitt.cpp | 60 -- src/crc16_kermit.cpp | 60 -- src/crc16_modbus.cpp | 76 -- src/crc32.cpp | 76 -- src/crc32_c.cpp | 80 -- src/crc64_ecma.cpp | 108 --- src/crc8_ccitt.cpp | 63 -- src/pearson.cpp | 63 -- src/private/pvoidvector.cpp | 551 ------------ src/random.cpp | 413 --------- support/Release notes.txt | 6 +- test/codeblocks/ETL.cbp | 13 - test/test_pearson.cpp | 22 +- test/vs2017/etl.vcxproj | 13 - test/vs2017/etl.vcxproj.filters | 36 - 32 files changed, 1915 insertions(+), 2573 deletions(-) rename src/error_handler.cpp => include/etl/macros.h (52%) delete mode 100644 src/binary.cpp delete mode 100644 src/crc16.cpp delete mode 100644 src/crc16_ccitt.cpp delete mode 100644 src/crc16_kermit.cpp delete mode 100644 src/crc16_modbus.cpp delete mode 100644 src/crc32.cpp delete mode 100644 src/crc32_c.cpp delete mode 100644 src/crc64_ecma.cpp delete mode 100644 src/crc8_ccitt.cpp delete mode 100644 src/pearson.cpp delete mode 100644 src/private/pvoidvector.cpp delete mode 100644 src/random.cpp diff --git a/include/etl/binary.h b/include/etl/binary.h index a0629346..b920d739 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -5,7 +5,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2015 jwellbelove @@ -82,6 +82,7 @@ namespace etl //*************************************************************************** /// Maximum value that can be contained in N bits. + ///\ingroup binary //*************************************************************************** /// Definition for non-zero NBITS. template @@ -104,6 +105,7 @@ namespace etl //*************************************************************************** /// Rotate left. + ///\ingroup binary //*************************************************************************** template T rotate_left(T value) @@ -117,6 +119,7 @@ namespace etl //*************************************************************************** /// Rotate left. + ///\ingroup binary //*************************************************************************** template T rotate_left(T value, size_t distance) @@ -132,6 +135,7 @@ namespace etl //*************************************************************************** /// Rotate right. + ///\ingroup binary //*************************************************************************** template T rotate_right(T value) @@ -145,6 +149,7 @@ namespace etl //*************************************************************************** /// Rotate right. + ///\ingroup binary //*************************************************************************** template T rotate_right(T value, size_t distance) @@ -161,6 +166,7 @@ namespace etl //*************************************************************************** /// Rotate. /// Positive is left, negative is right. + ///\ingroup binary //*************************************************************************** template T rotate(T value, typename etl::make_signed::type distance) @@ -181,36 +187,9 @@ namespace etl return result; } - //*************************************************************************** - /// Reverse bits. - //*************************************************************************** -#if ETL_8BIT_SUPPORT - uint8_t reverse_bits(uint8_t value); - inline int8_t reverse_bits(int8_t value) { return int8_t(reverse_bits(uint8_t(value))); } -#endif - uint16_t reverse_bits(uint16_t value); - inline int16_t reverse_bits(int16_t value) { return int16_t(reverse_bits(uint16_t(value))); } - uint32_t reverse_bits(uint32_t value); - inline int32_t reverse_bits(int32_t value) { return int32_t(reverse_bits(uint32_t(value))); } - uint64_t reverse_bits(uint64_t value); - inline int64_t reverse_bits(int64_t value) { return int64_t(reverse_bits(uint64_t(value))); } - - //*************************************************************************** - /// Reverse bytes. - //*************************************************************************** -#if ETL_8BIT_SUPPORT - inline uint8_t reverse_bytes(uint8_t value) { return value; } - inline int8_t reverse_bytes(int8_t value) { return value; } -#endif - uint16_t reverse_bytes(uint16_t value); - inline int16_t reverse_bytes(int16_t value) { return int16_t(reverse_bytes(uint16_t(value))); } - uint32_t reverse_bytes(uint32_t value); - inline int32_t reverse_bytes(int32_t value) { return int32_t(reverse_bytes(uint32_t(value))); } - uint64_t reverse_bytes(uint64_t value); - inline int64_t reverse_bytes(int64_t value) { return int64_t(reverse_bytes(uint64_t(value))); } - //*************************************************************************** /// Converts binary to Gray code. + ///\ingroup binary //*************************************************************************** template T binary_to_gray(T value) @@ -220,50 +199,9 @@ namespace etl return (value >> 1) ^ value; } - //*************************************************************************** - /// Converts Gray code to binary. - //*************************************************************************** -#if ETL_8BIT_SUPPORT - uint8_t gray_to_binary(uint8_t value); - inline int8_t gray_to_binary(int8_t value) { return int8_t(gray_to_binary(uint8_t(value))); } -#endif - uint16_t gray_to_binary(uint16_t value); - inline int16_t gray_to_binary(int16_t value) { return int16_t(gray_to_binary(uint16_t(value))); } - uint32_t gray_to_binary(uint32_t value); - inline int32_t gray_to_binary(int32_t value) { return int32_t(gray_to_binary(uint32_t(value))); } - uint64_t gray_to_binary(uint64_t value); - inline int64_t gray_to_binary(int64_t value) { return int64_t(gray_to_binary(uint64_t(value))); } - - //*************************************************************************** - /// Count set bits. - //*************************************************************************** -#if ETL_8BIT_SUPPORT - uint_least8_t count_bits(uint8_t value); - inline uint_least8_t count_bits(int8_t value) { return count_bits(uint8_t(value)); } -#endif - uint_least8_t count_bits(uint16_t value); - inline uint_least8_t count_bits(int16_t value) { return count_bits(uint16_t(value)); } - uint_least8_t count_bits(uint32_t value); - inline uint_least8_t count_bits(int32_t value) { return count_bits(uint32_t(value)); } - uint_least8_t count_bits(uint64_t value); - inline uint_least8_t count_bits(int64_t value) { return count_bits(uint64_t(value)); } - - //*************************************************************************** - /// Parity. 0 = even, 1 = odd - //*************************************************************************** -#if ETL_8BIT_SUPPORT - uint_least8_t parity(uint8_t value); - inline uint_least8_t parity(int8_t value) { return parity(uint8_t(value)); } -#endif - uint_least8_t parity(uint16_t value); - inline uint_least8_t parity(int16_t value) { return parity(uint16_t(value)); } - uint_least8_t parity(uint32_t value); - inline uint_least8_t parity(int32_t value) { return parity(uint32_t(value)); } - uint_least8_t parity(uint64_t value); - inline uint_least8_t parity(int64_t value) { return parity(uint64_t(value)); } - //*************************************************************************** /// Fold a binary number down to a set number of bits using XOR. + ///\ingroup binary //*************************************************************************** template TReturn fold_bits(TValue value) @@ -292,6 +230,7 @@ namespace etl //*************************************************************************** /// Sign extend. /// Converts an N bit binary number, where bit N-1 is the sign bit, to a signed integral type. + ///\ingroup binary //*************************************************************************** template TReturn sign_extend(TValue value) @@ -313,6 +252,7 @@ namespace etl /// Sign extend. /// Converts an N bit binary number, where bit N-1 is the sign bit, and SHIFT /// is the right shift amount, to a signed integral type. + ///\ingroup binary //*************************************************************************** template TReturn sign_extend(TValue value) @@ -334,6 +274,7 @@ namespace etl //*************************************************************************** /// Sign extend. /// Converts an N bit binary number, where bit N-1 is the sign bit, to a signed integral type. + ///\ingroup binary //*************************************************************************** template TReturn sign_extend(TValue value, const size_t NBITS) @@ -354,6 +295,7 @@ namespace etl /// Sign extend. /// Converts an N bit binary number, where bit N-1 is the sign bit, and SHIFT /// is the right shift amount, to a signed integral type. + ///\ingroup binary //*************************************************************************** template TReturn sign_extend(TValue value, const size_t NBITS, const size_t SHIFT) @@ -370,24 +312,12 @@ namespace etl return TReturn((value ^ mask) - mask); } - //*************************************************************************** - /// Count trailing zeros. bit. - /// Uses a binary search. - //*************************************************************************** -#if ETL_8BIT_SUPPORT - uint_least8_t count_trailing_zeros(uint8_t value); - inline uint_least8_t count_trailing_zeros(int8_t value) { return count_trailing_zeros(uint8_t(value)); } -#endif - uint_least8_t count_trailing_zeros(uint16_t value); - inline uint_least8_t count_trailing_zeros(int16_t value) { return count_trailing_zeros(uint16_t(value)); } - uint_least8_t count_trailing_zeros(uint32_t value); - inline uint_least8_t count_trailing_zeros(int32_t value) { return count_trailing_zeros(uint32_t(value)); } - uint_least8_t count_trailing_zeros(uint64_t value); - inline uint_least8_t count_trailing_zeros(int64_t value) { return count_trailing_zeros(uint64_t(value)); } + //*************************************************************************** /// Find the position of the first set bit. /// Starts from LSB. + ///\ingroup binary //*************************************************************************** template uint_least8_t first_set_bit_position(T value) @@ -398,6 +328,7 @@ namespace etl //*************************************************************************** /// Find the position of the first clear bit. /// Starts from LSB. + ///\ingroup binary //*************************************************************************** template uint_least8_t first_clear_bit_position(T value) @@ -409,6 +340,7 @@ namespace etl //*************************************************************************** /// Find the position of the first bit that is clear or set. /// Starts from LSB. + ///\ingroup binary //*************************************************************************** template uint_least8_t first_bit_position(bool state, T value) @@ -424,6 +356,7 @@ namespace etl //*************************************************************************** /// Gets the value of the bit at POSITION /// Starts from LSB. + ///\ingroup binary //*************************************************************************** template struct bit @@ -437,6 +370,7 @@ namespace etl //*************************************************************************** /// Fills a value with a bit pattern. Compile time. + ///\ingroup binary //*************************************************************************** template class binary_fill @@ -459,6 +393,7 @@ namespace etl //*************************************************************************** /// Fills a value with a bit pattern. Run time. + ///\ingroup binary //*************************************************************************** template class binary_fill @@ -483,6 +418,7 @@ namespace etl #if ETL_8BIT_SUPPORT //*************************************************************************** /// Detects the presence of zero bytes. Compile time. + ///\ingroup binary //*************************************************************************** template class has_zero_byte @@ -506,6 +442,7 @@ namespace etl //*************************************************************************** /// Detects the presence of zero bytes. Run time. + ///\ingroup binary //*************************************************************************** template <> class has_zero_byte @@ -526,6 +463,7 @@ namespace etl //*************************************************************************** /// Detects the presence of a byte of value N. Compile time. + ///\ingroup binary //*************************************************************************** template class has_byte_n @@ -540,6 +478,7 @@ namespace etl //*************************************************************************** /// Detects the presence of a byte of value N. Partial run time. + ///\ingroup binary //*************************************************************************** template class has_byte_n @@ -555,6 +494,7 @@ namespace etl //*************************************************************************** /// Detects the presence of a byte of value N. Run time. + ///\ingroup binary //*************************************************************************** template <> class has_byte_n<0, void*, (void*)0> @@ -573,6 +513,7 @@ namespace etl /// Merges two values according to a mask. /// Ones in the mask select bits from 'first', zeros select bits from second. /// Mask is a function parameter. + ///\ingroup binary //*************************************************************************** template T binary_merge(const T first, const T second, const T mask) @@ -584,6 +525,7 @@ namespace etl /// Merges two values according to a mask. /// Ones in the mask select bits from 'first', zeros select bits from second. /// Mask is a template parameter. + ///\ingroup binary //*************************************************************************** template T binary_merge(const T first, const T second) @@ -591,56 +533,710 @@ namespace etl return second ^ ((second ^ first) & MASK); } +#if ETL_8BIT_SUPPORT //*************************************************************************** - /// Binary interleave + /// Reverse 8 bits. + ///\ingroup binary + //*************************************************************************** + inline uint8_t reverse_bits(uint8_t value) + { + value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1); + value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2); + value = (value >> 4) | (value << 4); + + return value; + } + + inline int8_t reverse_bits(int8_t value) + { + return int8_t(reverse_bits(uint8_t(value))); + } +#endif + + //*************************************************************************** + /// Reverse 16 bits. + ///\ingroup binary + //*************************************************************************** + inline uint16_t reverse_bits(uint16_t value) + { + value = ((value & 0xAAAA) >> 1) | ((value & 0x5555) << 1); + value = ((value & 0xCCCC) >> 2) | ((value & 0x3333) << 2); + value = ((value & 0xF0F0) >> 4) | ((value & 0x0F0F) << 4); + value = (value >> 8) | (value << 8); + + return value; + } + + inline int16_t reverse_bits(int16_t value) + { + return int16_t(reverse_bits(uint16_t(value))); + } + + //*************************************************************************** + /// Reverse 32 bits. + ///\ingroup binary + //*************************************************************************** + inline uint32_t reverse_bits(uint32_t value) + { + value = ((value & 0xAAAAAAAA) >> 1) | ((value & 0x55555555) << 1); + value = ((value & 0xCCCCCCCC) >> 2) | ((value & 0x33333333) << 2); + value = ((value & 0xF0F0F0F0) >> 4) | ((value & 0x0F0F0F0F) << 4); + value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); + value = (value >> 16) | (value << 16); + + return value; + } + + inline int32_t reverse_bits(int32_t value) + { + return int32_t(reverse_bits(uint32_t(value))); + } + + //*************************************************************************** + /// Reverse 64 bits. + ///\ingroup binary + //*************************************************************************** + inline uint64_t reverse_bits(uint64_t value) + { + value = ((value & 0xAAAAAAAAAAAAAAAA) >> 1) | ((value & 0x5555555555555555) << 1); + value = ((value & 0xCCCCCCCCCCCCCCCC) >> 2) | ((value & 0x3333333333333333) << 2); + value = ((value & 0xF0F0F0F0F0F0F0F0) >> 4) | ((value & 0x0F0F0F0F0F0F0F0F) << 4); + value = ((value & 0xFF00FF00FF00FF00) >> 8) | ((value & 0x00FF00FF00FF00FF) << 8); + value = ((value & 0xFFFF0000FFFF0000) >> 16) | ((value & 0x0000FFFF0000FFFF) << 16); + value = (value >> 32) | (value << 32); + + return value; + } + + inline int64_t reverse_bits(int64_t value) + { + return int64_t(reverse_bits(uint64_t(value))); + } + + //*************************************************************************** + /// Reverse bytes 8 bit. + ///\ingroup binary //*************************************************************************** #if ETL_8BIT_SUPPORT - uint16_t binary_interleave(uint8_t first, uint8_t second); - inline int16_t binary_interleave(int8_t first, int8_t second) { return int16_t(binary_interleave(uint8_t(first), uint8_t(second))); } + inline uint8_t reverse_bytes(uint8_t value) + { + return value; + } + + inline int8_t reverse_bytes(int8_t value) + { + return value; + } #endif - uint32_t binary_interleave(uint16_t first, uint16_t second); - inline int32_t binary_interleave(int16_t first, int16_t second) { return int32_t(binary_interleave(uint16_t(first), uint16_t(second))); } - uint64_t binary_interleave(uint32_t first, uint32_t second); - inline int64_t binary_interleave(int32_t first, int32_t second) { return int64_t(binary_interleave(uint16_t(first), uint16_t(second))); } + + //*************************************************************************** + /// Reverse bytes 16 bit. + ///\ingroup binary + //*************************************************************************** + inline uint16_t reverse_bytes(uint16_t value) + { + value = (value >> 8) | (value << 8); + + return value; + } + + inline int16_t reverse_bytes(int16_t value) + { + return int16_t(reverse_bytes(uint16_t(value))); + } + + //*************************************************************************** + /// Reverse bytes 32 bit. + ///\ingroup binary + //*************************************************************************** + inline uint32_t reverse_bytes(uint32_t value) + { + value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); + value = (value >> 16) | (value << 16); + + return value; + } + + inline int32_t reverse_bytes(int32_t value) + { + return int32_t(reverse_bytes(uint32_t(value))); + } + + //*************************************************************************** + /// Reverse bytes 64 bit. + ///\ingroup binary + //*************************************************************************** + inline uint64_t reverse_bytes(uint64_t value) + { + value = ((value & 0xFF00FF00FF00FF00) >> 8) | ((value & 0x00FF00FF00FF00FF) << 8); + value = ((value & 0xFFFF0000FFFF0000) >> 16) | ((value & 0x0000FFFF0000FFFF) << 16); + value = (value >> 32) | (value << 32); + + return value; + } + + inline int64_t reverse_bytes(int64_t value) + { + return int64_t(reverse_bytes(uint64_t(value))); + } + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Converts Gray code to binary. + ///\ingroup binary + //*************************************************************************** + inline uint8_t gray_to_binary(uint8_t value) + { + value ^= (value >> 4); + value ^= (value >> 2); + value ^= (value >> 1); + + return value; + } + + inline int8_t gray_to_binary(int8_t value) + { + return int8_t(gray_to_binary(uint8_t(value))); + } +#endif + + //*************************************************************************** + /// Converts Gray code to binary. + ///\ingroup binary + //*************************************************************************** + inline uint16_t gray_to_binary(uint16_t value) + { + value ^= (value >> 8); + value ^= (value >> 4); + value ^= (value >> 2); + value ^= (value >> 1); + + return value; + } + + inline int16_t gray_to_binary(int16_t value) + { + return int16_t(gray_to_binary(uint16_t(value))); + } + + //*************************************************************************** + /// Converts Gray code to binary. + ///\ingroup binary + //*************************************************************************** + inline uint32_t gray_to_binary(uint32_t value) + { + value ^= (value >> 16); + value ^= (value >> 8); + value ^= (value >> 4); + value ^= (value >> 2); + value ^= (value >> 1); + + return value; + } + + inline int32_t gray_to_binary(int32_t value) + { + return int32_t(gray_to_binary(uint32_t(value))); + } + + //*************************************************************************** + /// Converts Gray code to binary. + ///\ingroup binary + //*************************************************************************** + inline uint64_t gray_to_binary(uint64_t value) + { + value ^= (value >> 32); + value ^= (value >> 16); + value ^= (value >> 8); + value ^= (value >> 4); + value ^= (value >> 2); + value ^= (value >> 1); + + return value; + } + + inline int64_t gray_to_binary(int64_t value) + { + return int64_t(gray_to_binary(uint64_t(value))); + } + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Count set bits. 8 bits. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_bits(uint8_t value) + { + uint32_t count; + static const int S[] = { 1, 2, 4 }; + static const uint8_t B[] = { 0x55, 0x33, 0x0F }; + + count = value - ((value >> 1) & B[0]); + count = ((count >> S[1]) & B[1]) + (count & B[1]); + count = ((count >> S[2]) + count) & B[2]; + + return uint_least8_t(count); + } + + inline uint_least8_t count_bits(int8_t value) + { + return count_bits(uint8_t(value)); + } + +#endif + + //*************************************************************************** + /// Count set bits. 16 bits. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_bits(uint16_t value) + { + uint32_t count; + static const int S[] = { 1, 2, 4, 8 }; + static const uint16_t B[] = { 0x5555, 0x3333, 0x0F0F, 0x00FF }; + + count = value - ((value >> 1) & B[0]); + count = ((count >> S[1]) & B[1]) + (count & B[1]); + count = ((count >> S[2]) + count) & B[2]; + count = ((count >> S[3]) + count) & B[3]; + + return count; + } + + inline uint_least8_t count_bits(int16_t value) + { + return count_bits(uint16_t(value)); + } + + //*************************************************************************** + /// Count set bits. 32 bits. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_bits(uint32_t value) + { + uint32_t count; + + value = value - ((value >> 1) & 0x55555555); + value = (value & 0x33333333) + ((value >> 2) & 0x33333333); + count = (((value + (value >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; + + return uint_least8_t(count); + } + + inline uint_least8_t count_bits(int32_t value) + { + return count_bits(uint32_t(value)); + } + + //*************************************************************************** + /// Count set bits. 64 bits. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_bits(uint64_t value) + { + uint64_t count; + static const int S[] = { 1, 2, 4, 8, 16, 32 }; + static const uint64_t B[] = { 0x5555555555555555, 0x3333333333333333, 0x0F0F0F0F0F0F0F0F, 0x00FF00FF00FF00FF, 0x0000FFFF0000FFFF, 0x00000000FFFFFFFF }; + + count = value - ((value >> 1) & B[0]); + count = ((count >> S[1]) & B[1]) + (count & B[1]); + count = ((count >> S[2]) + count) & B[2]; + count = ((count >> S[3]) + count) & B[3]; + count = ((count >> S[4]) + count) & B[4]; + count = ((count >> S[5]) + count) & B[5]; + + return uint_least8_t(count); + } + + inline uint_least8_t count_bits(int64_t value) + { + return count_bits(uint64_t(value)); + } + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Parity. 8bits. 0 = even, 1 = odd + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t parity(uint8_t value) + { + value ^= value >> 4; + value &= 0x0F; + return (0x6996 >> value) & 1; + } + + inline uint_least8_t parity(int8_t value) + { + return parity(uint8_t(value)); + } +#endif + + //*************************************************************************** + /// Parity. 16bits. 0 = even, 1 = odd + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t parity(uint16_t value) + { + value ^= value >> 8; + value ^= value >> 4; + value &= 0x0F; + return (0x6996 >> value) & 1; + } + + inline uint_least8_t parity(int16_t value) + { + return parity(uint16_t(value)); + } + + //*************************************************************************** + /// Parity. 32bits. 0 = even, 1 = odd + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t parity(uint32_t value) + { + value ^= value >> 16; + value ^= value >> 8; + value ^= value >> 4; + value &= 0x0F; + return (0x6996 >> value) & 1; + } + + inline uint_least8_t parity(int32_t value) + { + return parity(uint32_t(value)); + } + + //*************************************************************************** + /// Parity. 64bits. 0 = even, 1 = odd + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t parity(uint64_t value) + { + value ^= value >> 32; + value ^= value >> 16; + value ^= value >> 8; + value ^= value >> 4; + value &= 0x0F; + return (0x69966996 >> value) & 1; + } + + inline uint_least8_t parity(int64_t value) + { + return parity(uint64_t(value)); + } + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Count trailing zeros. bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_trailing_zeros(uint8_t value) + { + uint_least8_t count; + + if (value & 0x1) + { + count = 0; + } + else + { + count = 1; + + if ((value & 0xF) == 0) + { + value >>= 4; + count += 4; + } + + if ((value & 0x3) == 0) + { + value >>= 2; + count += 2; + } + + count -= value & 0x1; + } + + return count; + } + + inline uint_least8_t count_trailing_zeros(int8_t value) + { + return count_trailing_zeros(uint8_t(value)); + } +#endif + + //*************************************************************************** + /// Count trailing zeros. 16bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_trailing_zeros(uint16_t value) + { + uint_least8_t count; + + if (value & 0x1) + { + count = 0; + } + else + { + count = 1; + + if ((value & 0xFF) == 0) + { + value >>= 8; + count += 8; + } + + if ((value & 0xF) == 0) + { + value >>= 4; + count += 4; + } + + if ((value & 0x3) == 0) + { + value >>= 2; + count += 2; + } + + count -= value & 0x1; + } + + return count; + } + + inline uint_least8_t count_trailing_zeros(int16_t value) + { + return count_trailing_zeros(uint16_t(value)); + } + + //*************************************************************************** + /// Count trailing zeros. 32bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_trailing_zeros(uint32_t value) + { + uint_least8_t count; + + if (value & 0x1) + { + count = 0; + } + else + { + count = 1; + + if ((value & 0xFFFF) == 0) + { + value >>= 16; + count += 16; + } + + if ((value & 0xFF) == 0) + { + value >>= 8; + count += 8; + } + + if ((value & 0xF) == 0) + { + value >>= 4; + count += 4; + } + + if ((value & 0x3) == 0) + { + value >>= 2; + count += 2; + } + + count -= value & 0x1; + } + + return count; + } + + inline uint_least8_t count_trailing_zeros(int32_t value) + { + return count_trailing_zeros(uint32_t(value)); + } + + //*************************************************************************** + /// Count trailing zeros. 64bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline uint_least8_t count_trailing_zeros(uint64_t value) + { + uint_least8_t count; + + if (value & 0x1) + { + count = 0; + } + else + { + count = 1; + + if ((value & 0xFFFFFFFF) == 0) + { + value >>= 32; + count += 32; + } + + if ((value & 0xFFFF) == 0) + { + value >>= 16; + count += 16; + } + + if ((value & 0xFF) == 0) + { + value >>= 8; + count += 8; + } + + if ((value & 0xF) == 0) + { + value >>= 4; + count += 4; + } + + if ((value & 0x3) == 0) + { + value >>= 2; + count += 2; + } + + count -= value & 0x1; + } + + return count; + } + + inline uint_least8_t count_trailing_zeros(int64_t value) + { + return count_trailing_zeros(uint64_t(value)); + } + +#if ETL_8BIT_SUPPORT + //***************************************************************************** + /// Binary interleave + ///\ingroup binary + //***************************************************************************** + inline uint16_t binary_interleave(uint8_t first, uint8_t second) + { + static const uint16_t mask[] = { 0x5555, 0x3333, 0x0F0F }; + + uint16_t f = first; + uint16_t s = second; + + f = (f | (f << 4)) & mask[2]; + f = (f | (f << 2)) & mask[1]; + f = (f | (f << 1)) & mask[0]; + + s = (s | (s << 4)) & mask[2]; + s = (s | (s << 2)) & mask[1]; + s = (s | (s << 1)) & mask[0]; + + return (f | (s << 1)); + } + + inline int16_t binary_interleave(int8_t first, int8_t second) + { + return int16_t(binary_interleave(uint8_t(first), uint8_t(second))); + } +#endif + + //***************************************************************************** + /// Binary interleave + ///\ingroup binary + //***************************************************************************** + inline uint32_t binary_interleave(uint16_t first, uint16_t second) + { + static const uint32_t mask[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF }; + + uint32_t f = first; + uint32_t s = second; + + f = (f | (f << 8)) & mask[3]; + f = (f | (f << 4)) & mask[2]; + f = (f | (f << 2)) & mask[1]; + f = (f | (f << 1)) & mask[0]; + + s = (s | (s << 8)) & mask[3]; + s = (s | (s << 4)) & mask[2]; + s = (s | (s << 2)) & mask[1]; + s = (s | (s << 1)) & mask[0]; + + return (f | (s << 1)); + } + + inline int32_t binary_interleave(int16_t first, int16_t second) + { + return int32_t(binary_interleave(uint16_t(first), uint16_t(second))); + } + + //***************************************************************************** + /// Binary interleave + ///\ingroup binary + //***************************************************************************** + inline uint64_t binary_interleave(uint32_t first, uint32_t second) + { + static const uint64_t mask[] = { 0x5555555555555555, 0x3333333333333333, 0x0F0F0F0F0F0F0F0F, 0x00FF00FF00FF00FF, 0x0000FFFF0000FFFF }; + + uint64_t f = first; + uint64_t s = second; + + f = (f | (f << 16)) & mask[4]; + f = (f | (f << 8)) & mask[3]; + f = (f | (f << 4)) & mask[2]; + f = (f | (f << 2)) & mask[1]; + f = (f | (f << 1)) & mask[0]; + + s = (s | (s << 16)) & mask[4]; + s = (s | (s << 8)) & mask[3]; + s = (s | (s << 4)) & mask[2]; + s = (s | (s << 2)) & mask[1]; + s = (s | (s << 1)) & mask[0]; + + return (f | (s << 1)); + } + + inline int64_t binary_interleave(int32_t first, int32_t second) + { + return int64_t(binary_interleave(uint16_t(first), uint16_t(second))); + } //*************************************************************************** /// Checks if odd. + ///\ingroup binary //*************************************************************************** - bool is_odd(const unsigned char value); - inline bool is_odd(const char value) { return is_odd((unsigned char)value); } - - bool is_odd(const unsigned short value); - inline bool is_odd(const short value) { return is_odd((unsigned short)value); } - - bool is_odd(const unsigned int value); - inline bool is_odd(const int value) { return is_odd((unsigned int)value); } - - bool is_odd(const unsigned long value); - inline bool is_odd(const long value) { return is_odd((unsigned long)value); } - - bool is_odd(const unsigned long long value); - inline bool is_odd(const long long value) { return is_odd((unsigned long long)value); } + template + typename etl::enable_if::value, bool>::type + is_odd(const T value) + { + return ((static_cast::type>(value) & 1U) != 0U); + } //*************************************************************************** /// Checks if even. + ///\ingroup binary //*************************************************************************** - bool is_even(const unsigned char value); - inline bool is_even(const char value) { return is_even((unsigned char)value); } - - bool is_even(const unsigned short value); - inline bool is_even(const short value) { return is_even((unsigned short)value); } - - bool is_even(const unsigned int value); - inline bool is_even(const int value) { return is_even((unsigned int)value); } - - bool is_even(const unsigned long value); - inline bool is_even(const long value) { return is_even((unsigned long)value); } - - bool is_even(const unsigned long long value); - inline bool is_even(const long long value) { return is_even((unsigned long long)value); } + template + typename etl::enable_if::value, bool>::type + is_even(const T value) + { + return ((static_cast::type>(value) & 1U) == 0U); + } //*************************************************************************** - /// 8 bit binary constants. + /// 8 bit binary byte constants. + ///\ingroup binary //*************************************************************************** enum binary_constant { @@ -902,6 +1498,11 @@ namespace etl b11111111 = 255 }; + + //*************************************************************************** + /// Binary bit constants. + ///\ingroup binary + //*************************************************************************** enum bit_constant { b0 = 0x1, diff --git a/include/etl/crc16.h b/include/etl/crc16.h index e517c77b..2705a01f 100644 --- a/include/etl/crc16.h +++ b/include/etl/crc16.h @@ -47,12 +47,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC16 table - /// \ingroup crc16 - //*************************************************************************** - extern const uint16_t ETL_CRC16[]; - //*************************************************************************** /// CRC16 policy. /// Calculates CRC16 using polynomial 0x8005. @@ -68,7 +62,27 @@ namespace etl inline uint16_t add(uint16_t crc, uint8_t value) const { - return (crc >> 8) ^ ETL_CRC16[(crc ^ value) & 0xFF]; + const uint16_t CRC16[256] = + { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 + }; + + return (crc >> 8) ^ CRC16[(crc ^ value) & 0xFF]; } inline uint16_t final(uint16_t crc) const diff --git a/include/etl/crc16_ccitt.h b/include/etl/crc16_ccitt.h index a9f6c7e9..d068a00c 100644 --- a/include/etl/crc16_ccitt.h +++ b/include/etl/crc16_ccitt.h @@ -47,12 +47,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC-CCITT table - /// \ingroup crc16_ccitt - //*************************************************************************** - extern const uint16_t ETL_CRC_CCITT[]; - //*************************************************************************** /// CRC16 CCITT policy. /// Calculates CRC16 CCITT using polynomial 0x1021 @@ -68,7 +62,27 @@ namespace etl inline uint16_t add(uint16_t crc, uint8_t value) const { - return (crc << 8) ^ ETL_CRC_CCITT[((crc >> 8) ^ value) & 0xFF]; + static const uint16_t CRC_CCITT[] = + { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 + }; + + return (crc << 8) ^ CRC_CCITT[((crc >> 8) ^ value) & 0xFF]; } inline uint16_t final(uint16_t crc) const diff --git a/include/etl/crc16_kermit.h b/include/etl/crc16_kermit.h index baa1456d..ea1d8a6c 100644 --- a/include/etl/crc16_kermit.h +++ b/include/etl/crc16_kermit.h @@ -47,12 +47,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC Kermit table - /// \ingroup crc - //*************************************************************************** - extern const uint16_t ETL_CRC_KERMIT[]; - //*************************************************************************** /// CRC16 Kermit policy. /// Calculates CRC16 Kermit using polynomial 0x1021 @@ -68,7 +62,27 @@ namespace etl inline uint16_t add(uint16_t crc, uint8_t value) const { - return (crc >> 8) ^ ETL_CRC_KERMIT[(crc ^ value) & 0xFF]; + static const uint16_t CRC_KERMIT[] = + { + 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, + 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876, + 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5, + 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974, + 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3, + 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72, + 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1, + 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70, + 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, + 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, + 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, + 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, + 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, + 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, + 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, + 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 + }; + + return (crc >> 8) ^ CRC_KERMIT[(crc ^ value) & 0xFF]; } inline uint16_t final(uint16_t crc) const diff --git a/include/etl/crc16_modbus.h b/include/etl/crc16_modbus.h index f962664a..cd0814ac 100644 --- a/include/etl/crc16_modbus.h +++ b/include/etl/crc16_modbus.h @@ -47,12 +47,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC-MODBUS table - /// \ingroup crc16_modbus - //*************************************************************************** - extern const uint16_t ETL_CRC_MODBUS[]; - //*************************************************************************** /// CRC16 MODBUS policy. /// Calculates CRC16 MODBUS using polynomial 0x @@ -68,6 +62,42 @@ namespace etl inline uint16_t add(uint16_t crc, uint8_t value) const { + static const uint16_t ETL_CRC_MODBUS[] = + { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 + }; + return (crc >> 8) ^ ETL_CRC_MODBUS[(crc ^ value) & 0xFF]; } diff --git a/include/etl/crc32.h b/include/etl/crc32.h index 141c32b4..49cbc0a3 100644 --- a/include/etl/crc32.h +++ b/include/etl/crc32.h @@ -47,12 +47,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC32 table - /// \ingroup crc32 - //*************************************************************************** - extern const uint32_t ETL_CRC32[]; - //*************************************************************************** /// CRC32 policy. /// Calculates CRC32 using polynomial 0x04C11DB7. @@ -68,7 +62,43 @@ namespace etl inline uint32_t add(uint32_t crc, uint8_t value) const { - return (crc >> 8) ^ ETL_CRC32[(crc ^ value) & 0xFF]; + static const uint32_t CRC32[] = + { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D + }; + + return (crc >> 8) ^ CRC32[(crc ^ value) & 0xFF]; } inline uint32_t final(uint32_t crc) const diff --git a/include/etl/crc32_c.h b/include/etl/crc32_c.h index e24cf45c..907c28f7 100644 --- a/include/etl/crc32_c.h +++ b/include/etl/crc32_c.h @@ -68,6 +68,42 @@ namespace etl inline uint32_t add(uint32_t crc, uint8_t value) const { + static const uint32_t CRC32_C[] = + { + 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, + 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L, + 0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL, 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L, + 0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL, + 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L, + 0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL, + 0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL, + 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L, + 0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L, + 0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L, + 0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L, + 0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L, 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L, + 0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L, 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L, + 0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L, + 0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L, + 0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L, + 0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L, + 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL, + 0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL, + 0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L, + 0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL, + 0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL, 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L, + 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L, + 0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL, + 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL, + 0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L, + 0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L, + 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL, + 0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L, + 0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L, 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL, + 0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L, 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL, + 0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL, 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L + }; + return (crc >> 8) ^ CRC32_C[(crc ^ value) & 0xFF]; } diff --git a/include/etl/crc64_ecma.h b/include/etl/crc64_ecma.h index 98bc3c3b..b08c93da 100644 --- a/include/etl/crc64_ecma.h +++ b/include/etl/crc64_ecma.h @@ -47,12 +47,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC64_ECMA table - /// \ingroup crc64_ecma - //*************************************************************************** - extern const uint64_t CRC64_ECMA[]; - //*************************************************************************** /// CRC64 policy. /// Calculates CRC64 ECMA using polynomial 0x42F0E1EBA9EA3693. @@ -68,6 +62,74 @@ namespace etl inline uint64_t add(uint64_t crc, uint8_t value) const { + static const uint64_t CRC64_ECMA[] = + { + 0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, + 0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, + 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, + 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4, + 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, + 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, + 0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, + 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, + 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B, + 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4, + 0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, + 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, + 0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, + 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B, + 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, + 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, + 0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, + 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645, + 0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, + 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB, + 0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, + 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, + 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, + 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14, + 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, + 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, + 0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, + 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425, + 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, + 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874, + 0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, + 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, + 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, + 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7, + 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, + 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, + 0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, + 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648, + 0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, + 0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6, + 0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, + 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879, + 0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, + 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7, + 0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, + 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96, + 0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7, + 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428, + 0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, + 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288, + 0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, + 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36, + 0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, + 0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767, + 0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, + 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9, + 0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, + 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956, + 0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, + 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8, + 0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066, + 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9, + 0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, + 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507 + }; + return (crc << 8) ^ CRC64_ECMA[((crc >> 56) ^ value) & 0xFF]; } diff --git a/include/etl/crc8_ccitt.h b/include/etl/crc8_ccitt.h index 68853a14..ed72fa3d 100644 --- a/include/etl/crc8_ccitt.h +++ b/include/etl/crc8_ccitt.h @@ -48,12 +48,6 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// CRC8 table - /// \ingroup crc8_ccitt - //*************************************************************************** - extern const uint8_t CRC8_CCITT[]; - //*************************************************************************** /// CRC8 CCITT policy. /// Calculates CRC8 CCITT using polynomial 0x07. @@ -69,7 +63,27 @@ namespace etl inline uint8_t add(uint8_t crc, uint8_t value) const { - return CRC8_CCITT[crc ^ value]; + static const uint8_t CRC8_CCITT[256] = + { + 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, + 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, + 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, + 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD, + 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, + 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, + 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A, + 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, + 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, + 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4, + 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, + 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, + 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63, + 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, + 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, + 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3 + }; + + return CRC8_CCITT[crc ^ value]; } inline uint8_t final(uint8_t crc) const diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 12c9ff3e..2119ae82 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -44,6 +44,18 @@ SOFTWARE. namespace etl { + namespace private_error_handler + { + template + struct wrapper + { + static etl::ifunction* p_ifunction; + }; + + template + etl::ifunction* wrapper::p_ifunction = nullptr; + } + //*************************************************************************** /// Error handler for when throwing exceptions is not required. ///\ingroup error_handler @@ -75,12 +87,26 @@ namespace etl } }; - static void set_callback(ifunction& f); - static void error(const etl::exception& e); + //***************************************************************************** + /// Sets the error callback function. + ///\param f A reference to an etl::function object that will handler errors. + //***************************************************************************** + static void set_callback(ifunction& f) + { + private_error_handler::wrapper::p_ifunction = &f; + } - private: - - static ifunction* p_ifunction; + //***************************************************************************** + /// Sends the exception error to the user's handler function. + ///\param e The exception error. + //***************************************************************************** + static void error(const etl::exception& e) + { + if (private_error_handler::wrapper::p_ifunction != nullptr) + { + (*private_error_handler::wrapper::p_ifunction)(e); + } + } }; } @@ -95,12 +121,12 @@ namespace etl ///\ingroup error_handler //*************************************************************************** #if defined(ETL_NO_CHECKS) - #define ETL_ASSERT(b, e) // Does nothing. + #define ETL_ASSERT(b, e) // Does nothing. #elif defined(ETL_THROW_EXCEPTIONS) #if defined(ETL_LOG_ERRORS) - #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e);)}} // If the condition fails, calls the error handler then throws an exception. + #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e);)}} // If the condition fails, calls the error handler then throws an exception. #else - #define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception. + #define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception. #endif #else #if defined(ETL_LOG_ERRORS) @@ -111,9 +137,9 @@ namespace etl #endif #else #if defined(NDEBUG) - #define ETL_ASSERT(b, e) // Does nothing. + #define ETL_ASSERT(b, e) // Does nothing. #else - #define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts. + #define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts. #endif #endif #endif diff --git a/src/error_handler.cpp b/include/etl/macros.h similarity index 52% rename from src/error_handler.cpp rename to include/etl/macros.h index 7f3f3e0c..6406d196 100644 --- a/src/error_handler.cpp +++ b/include/etl/macros.h @@ -5,9 +5,9 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2018 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,33 +28,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#include "etl/platform.h" -#include "etl/error_handler.h" -#include "etl/nullptr.h" +#ifndef ETL_MACROS_INCLUDED +#define ETL_MACROS_INCLUDED -//***************************************************************************** -/// The error function callback pointer. -//***************************************************************************** -etl::ifunction* etl::error_handler::p_ifunction = nullptr; +#define ETL_CONCAT2(X, Y) X##Y +#define ETL_CONCAT(X, Y) ETL_CONCAT2(X, Y) +#define ETL_STRINGIFY2(X) #X +#define ETL_STRINGIFY(X) ETL_STRINGIFY2(X) +#define ETL_WIDE_STRING(X) ETL_CONCAT(L, ETL_STRINGIFY(X)) +#define ETL_U16_STRING(X) ETL_CONCAT(u, ETL_STRINGIFY(X)) +#define ETL_U32_STRING(X) ETL_CONCAT(U, ETL_STRINGIFY(X)) -//***************************************************************************** -/// Sets the error callback function. -///\param f A reference to an etl::function object that will handler errors. -//***************************************************************************** -void etl::error_handler::set_callback(ifunction& f) -{ - p_ifunction = &f; -} - -//***************************************************************************** -/// Sends the exception error to the user's handler function. -///\param e The exception error. -//***************************************************************************** -void etl::error_handler::error(const etl::exception& e) -{ - if (p_ifunction != nullptr) - { - (*p_ifunction)(e); - } -} +#endif diff --git a/include/etl/pearson.h b/include/etl/pearson.h index a7ae1829..459c7f52 100644 --- a/include/etl/pearson.h +++ b/include/etl/pearson.h @@ -51,12 +51,6 @@ ETL_STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support target namespace etl { - //*************************************************************************** - /// Pearson lookup table - /// \ingroup pearson - //*************************************************************************** - extern const uint8_t PEARSON_LOOKUP[]; - //*************************************************************************** /// Calculates a Pearson hash ///\tparam HASH_LENGTH The number of elements in the hash. @@ -122,6 +116,26 @@ namespace etl //************************************************************************* void add(uint8_t value_) { + static const uint8_t PEARSON_LOOKUP[] = + { + 228, 39, 61, 95, 227, 187, 0, 197, 31, 189, 161, 222, 34, 15, 221, 246, + 19, 234, 6, 50, 113, 3, 91, 63, 77, 245, 144, 2, 183, 196, 25, 226, + 97, 126, 48, 59, 217, 4, 100, 145, 12, 88, 203, 149, 80, 154, 38, 27, + 224, 218, 158, 115, 202, 79, 53, 83, 242, 36, 139, 131, 136, 191, 42, 170, + 23, 99, 156, 51, 143, 60, 233, 206, 62, 108, 17, 67, 81, 71, 93, 195, + 26, 231, 247, 96, 24, 200, 176, 209, 152, 212, 138, 165, 75, 185, 130, 248, + 125, 110, 10, 116, 201, 90, 69, 204, 85, 251, 78, 157, 47, 184, 169, 141, + 134, 230, 89, 21, 146, 46, 55, 128, 148, 207, 216, 11, 114, 199, 103, 102, + 166, 244, 5, 104, 225, 160, 132, 28, 172, 65, 121, 140, 153, 119, 198, 210, + 58, 87, 117, 177, 33, 22, 13, 37, 49, 174, 109, 40, 73, 211, 18, 167, + 164, 252, 168, 74, 30, 173, 35, 98, 66, 193, 94, 175, 86, 54, 179, 122, + 220, 151, 192, 29, 133, 254, 155, 127, 240, 232, 190, 180, 8, 68, 236, 20, + 137, 92, 219, 208, 52, 250, 147, 142, 111, 112, 120, 45, 135, 255, 123, 229, + 57, 182, 243, 124, 186, 253, 7, 237, 9, 16, 70, 171, 235, 107, 223, 118, + 215, 178, 194, 181, 43, 188, 106, 105, 64, 241, 84, 238, 159, 44, 32, 76, + 213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82 + }; + if (first) { for (size_t i = 0; i < HASH_LENGTH; ++i) diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index 28fe1bd3..474e2d19 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -45,7 +45,6 @@ SOFTWARE. #include "../stl/iterator.h" #ifdef ETL_COMPILER_GCC -#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" #endif @@ -75,41 +74,246 @@ namespace etl public: - iterator begin(); - const_iterator begin() const; + //********************************************************************* + /// Returns an iterator to the beginning of the vector. + ///\return An iterator to the beginning of the vector. + //********************************************************************* + iterator begin() + { + return p_buffer; + } - iterator end(); - const_iterator end() const; + //********************************************************************* + /// Returns a const_iterator to the beginning of the vector. + ///\return A const iterator to the beginning of the vector. + //********************************************************************* + const_iterator begin() const + { + return const_iterator(p_buffer); + } - const_iterator cbegin() const; - const_iterator cend() const; + //********************************************************************* + /// Returns an iterator to the end of the vector. + ///\return An iterator to the end of the vector. + //********************************************************************* + iterator end() + { + return p_end; + } - reverse_iterator rbegin(); - const_reverse_iterator rbegin() const; + //********************************************************************* + /// Returns a const_iterator to the end of the vector. + ///\return A const iterator to the end of the vector. + //********************************************************************* + const_iterator end() const + { + return const_iterator(p_end); + } - reverse_iterator rend(); - const_reverse_iterator rend() const; + //********************************************************************* + /// Returns a const_iterator to the beginning of the vector. + ///\return A const iterator to the beginning of the vector. + //********************************************************************* + const_iterator cbegin() const + { + return const_iterator(p_buffer); + } - const_reverse_iterator crbegin() const; - const_reverse_iterator crend() const; + //********************************************************************* + /// Returns a const_iterator to the end of the vector. + ///\return A const iterator to the end of the vector. + //********************************************************************* + const_iterator cend() const + { + return const_iterator(p_end); + } - void resize(size_t new_size); - void resize(size_t new_size, value_type value); + //********************************************************************* + /// Returns an reverse iterator to the reverse beginning of the vector. + ///\return Iterator to the reverse beginning of the vector. + //********************************************************************* + reverse_iterator rbegin() + { + return reverse_iterator(end()); + } - reference operator [](size_t i); - const_reference operator [](size_t i) const; + //********************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the vector. + ///\return Const iterator to the reverse beginning of the vector. + //********************************************************************* + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(end()); + } - reference at(size_t i); - const_reference at(size_t i) const; + //********************************************************************* + /// Returns a reverse iterator to the end + 1 of the vector. + ///\return Reverse iterator to the end + 1 of the vector. + //********************************************************************* + reverse_iterator rend() + { + return reverse_iterator(begin()); + } - reference front(); - const_reference front() const; + //********************************************************************* + /// Returns a const reverse iterator to the end + 1 of the vector. + ///\return Const reverse iterator to the end + 1 of the vector. + //********************************************************************* + const_reverse_iterator rend() const + { + return const_reverse_iterator(begin()); + } - reference back(); - const_reference back() const; + //********************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the vector. + ///\return Const reverse iterator to the reverse beginning of the vector. + //********************************************************************* + const_reverse_iterator crbegin() const + { + return const_reverse_iterator(cend()); + } - pointer data(); - const_pointer data() const; + //********************************************************************* + /// Returns a const reverse iterator to the end + 1 of the vector. + ///\return Const reverse iterator to the end + 1 of the vector. + //********************************************************************* + const_reverse_iterator crend() const + { + return const_reverse_iterator(cbegin()); + } + + //********************************************************************* + /// Resizes the vector. + /// If asserts or exceptions are enabled and the new size is larger than the + /// maximum then a vector_full is thrown. + ///\param new_size The new size. + //********************************************************************* + void resize(size_t new_size) + { + ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); + + p_end = p_buffer + new_size; + } + + //********************************************************************* + /// Resizes the vector. + /// If asserts or exceptions are enabled and the new size is larger than the + /// maximum then a vector_full is thrown. + ///\param new_size The new size. + ///\param value The value to fill new elements with. Default = default constructed value. + //********************************************************************* + void resize(size_t new_size, value_type value) + { + ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); + + pointer p_new_end = p_buffer + new_size; + + // Size up if necessary. + if (p_end < p_new_end) + { + std::fill(p_end, p_new_end, value); + } + + p_end = p_new_end; + } + + //********************************************************************* + /// Returns a reference to the value at index 'i' + ///\param i The index. + ///\return A reference to the value at index 'i' + //********************************************************************* + reference operator [](size_t i) + { + return reference(p_buffer[i]); + } + + //********************************************************************* + /// Returns a const reference to the value at index 'i' + ///\param i The index. + ///\return A const reference to the value at index 'i' + //********************************************************************* + const_reference operator [](size_t i) const + { + return const_reference(p_buffer[i]); + } + + //********************************************************************* + /// Returns a reference to the value at index 'i' + /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. + ///\param i The index. + ///\return A reference to the value at index 'i' + //********************************************************************* + reference at(size_t i) + { + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); + return reference(p_buffer[i]); + } + + //********************************************************************* + /// Returns a const reference to the value at index 'i' + /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. + ///\param i The index. + ///\return A const reference to the value at index 'i' + //********************************************************************* + const_reference at(size_t i) const + { + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); + return const_reference(p_buffer[i]); + } + + //********************************************************************* + /// Returns a reference to the first element. + ///\return A reference to the first element. + //********************************************************************* + reference front() + { + return reference(p_buffer[0]); + } + + //********************************************************************* + /// Returns a const reference to the first element. + ///\return A const reference to the first element. + //********************************************************************* + const_reference front() const + { + return const_reference(p_buffer[0]); + } + + //********************************************************************* + /// Returns a reference to the last element. + ///\return A reference to the last element. + //********************************************************************* + reference back() + { + return reference(*(p_end - 1)); + } + + //********************************************************************* + /// Returns a const reference to the last element. + ///\return A const reference to the last element. + //********************************************************************* + const_reference back() const + { + return const_reference(*(p_end - 1)); + } + + //********************************************************************* + /// Returns a pointer to the beginning of the vector data. + ///\return A pointer to the beginning of the vector data. + //********************************************************************* + pointer data() + { + return pointer(p_buffer); + } + + //********************************************************************* + /// Returns a const pointer to the beginning of the vector data. + ///\return A const pointer to the beginning of the vector data. + //********************************************************************* + const_pointer data() const + { + return const_pointer(p_buffer); + } //********************************************************************* /// Assigns values to the vector. @@ -134,16 +338,97 @@ namespace etl } } - void assign(size_t n, value_type value); + //********************************************************************* + /// Assigns values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + ///\param n The number of elements to add. + ///\param value The value to insert for each element. + //********************************************************************* + void assign(size_t n, value_type value) + { + initialise(); - void clear(); + ETL_ASSERT(n <= CAPACITY, ETL_ERROR(vector_full)); - void push_back(value_type value); + for (size_t current_size = 0; current_size < n; ++current_size) + { + *p_end++ = value; + } + } - void pop_back(); + //************************************************************************* + /// Clears the vector. + //************************************************************************* + void clear() + { + initialise(); + } - iterator insert(iterator position, value_type value); - void insert(iterator position, size_t n, value_type value); + //********************************************************************* + /// Inserts a value at the end of the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. + ///\param value The value to add. + //********************************************************************* + void push_back(value_type value) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); +#endif + *p_end++ = value; + } + + //************************************************************************* + /// Removes an element from the end of the vector. + /// Does nothing if the vector is empty. + //************************************************************************* + void pop_back() + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty)); +#endif + --p_end; + } + + //********************************************************************* + /// Inserts a value to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. + ///\param position The position to insert before. + ///\param value The value to insert. + //********************************************************************* + iterator insert(iterator position, value_type value) + { + ETL_ASSERT(size() + 1 <= CAPACITY, ETL_ERROR(vector_full)); + + if (position != end()) + { + ++p_end; + std::copy_backward(position, end() - 1, end()); + *position = value; + } + else + { + *p_end++ = value; + } + + return position; + } + + //********************************************************************* + /// Inserts 'n' values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + ///\param position The position to insert before. + ///\param n The number of elements to add. + ///\param value The value to insert. + //********************************************************************* + void insert(iterator position, size_t n, value_type value) + { + ETL_ASSERT((size() + 1) <= CAPACITY, ETL_ERROR(vector_full)); + + std::copy_backward(position, p_end, p_end + n); + std::fill_n(position, n, value); + + p_end += n; + } //********************************************************************* /// Inserts a range of values to the vector. @@ -165,26 +450,117 @@ namespace etl p_end += count; } - iterator erase(iterator i_element); - iterator erase(iterator first, iterator last); + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(iterator i_element) + { + std::copy(i_element + 1, end(), i_element); + --p_end; - pvoidvector& operator = (const pvoidvector& rhs); + return i_element; + } - size_type size() const; + //********************************************************************* + /// Erases a range of elements. + /// The range includes all the elements between first and last, including the + /// element pointed by first, but not the one pointed by last. + ///\param first Iterator to the first element. + ///\param last Iterator to the last element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(iterator first, iterator last) + { + std::copy(last, end(), first); + size_t n_delete = std::distance(first, last); - bool empty() const; + // Just adjust the count. + p_end -= n_delete; - bool full() const; + return first; + } - size_t available() const; + //************************************************************************* + /// Assignment operator. + //************************************************************************* + etl::pvoidvector& operator = (const etl::pvoidvector& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + + //************************************************************************* + /// Gets the current size of the vector. + ///\return The current size of the vector. + //************************************************************************* + size_type size() const + { + return size_t(p_end - p_buffer); + } + + //************************************************************************* + /// Checks the 'empty' state of the vector. + ///\return true if empty. + //************************************************************************* + bool empty() const + { + return (p_end == p_buffer); + } + + //************************************************************************* + /// Checks the 'full' state of the vector. + ///\return true if full. + //************************************************************************* + bool full() const + { + return size() == CAPACITY; + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return max_size() - size(); + } protected: - pvoidvector(void** p_buffer_, size_t MAX_SIZE); + //********************************************************************* + /// Constructor. + //********************************************************************* + pvoidvector(void** p_buffer_, size_t MAX_SIZE) + : vector_base(MAX_SIZE), + p_buffer(p_buffer_), + p_end(p_buffer_) + { + } - void initialise(); + //********************************************************************* + /// Initialise the vector. + //********************************************************************* + void initialise() + { + p_end = p_buffer; + } - void repair_buffer(void** p_buffer_); + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair_buffer(void** p_buffer_) + { + uintptr_t length = p_end - p_buffer; + + p_buffer = p_buffer_; + p_end = p_buffer_ + length; + } void** p_buffer; void** p_end; @@ -195,20 +571,81 @@ namespace etl pvoidvector(const pvoidvector&); }; - bool operator ==(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); - bool operator !=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); - bool operator <(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); - bool operator >(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); - bool operator <=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); - bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); + //*************************************************************************** + /// Equal operator. + ///\param lhs Reference to the first vector. + ///\param rhs Reference to the second vector. + ///\return true if the arrays are equal, otherwise false + ///\ingroup vector + //*************************************************************************** + inline bool operator ==(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + + //*************************************************************************** + /// Not equal operator. + ///\param lhs Reference to the first vector. + ///\param rhs Reference to the second vector. + ///\return true if the arrays are not equal, otherwise false + ///\ingroup vector + //*************************************************************************** + inline bool operator !=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return !(lhs == rhs); + } + + //*************************************************************************** + /// Less than operator. + ///\param lhs Reference to the first vector. + ///\param rhs Reference to the second vector. + ///\return true if the first vector is lexicographically less than the second, otherwise false + ///\ingroup vector + //*************************************************************************** + inline bool operator <(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + } + + //*************************************************************************** + /// Greater than operator. + ///\param lhs Reference to the first vector. + ///\param rhs Reference to the second vector. + ///\return true if the first vector is lexicographically greater than the second, otherwise false + ///\ingroup vector + //*************************************************************************** + inline bool operator >(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return (rhs < lhs); + } + + //*************************************************************************** + /// Less than or equal operator. + ///\param lhs Reference to the first vector. + ///\param rhs Reference to the second vector. + ///\return true if the first vector is lexicographically less than or equal to the second, otherwise false + ///\ingroup vector + //*************************************************************************** + inline bool operator <=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return !(lhs > rhs); + } + + //*************************************************************************** + /// Greater than or equal operator. + ///\param lhs Reference to the first vector. + ///\param rhs Reference to the second vector. + ///\return true if the first vector is lexicographically greater than or equal to the second, otherwise false + ///\ingroup vector + //*************************************************************************** + inline bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return !(lhs < rhs); + } } #include "minmax_pop.h" -#ifdef ETL_COMPILER_GCC -#pragma GCC diagnostic pop -#endif - #undef ETL_IN_PVOIDVECTOR #endif diff --git a/include/etl/random.h b/include/etl/random.h index 63ee1603..c1523620 100644 --- a/include/etl/random.h +++ b/include/etl/random.h @@ -34,6 +34,7 @@ SOFTWARE. #include #include "platform.h" +#include "binary.h" namespace etl { @@ -62,11 +63,71 @@ namespace etl { public: - random_xorshift(); - explicit random_xorshift(uint32_t seed); - void initialise(uint32_t seed); - uint32_t operator()(); - uint32_t range(uint32_t low, uint32_t high); + //*************************************************************************** + /// Default constructor. + /// Attempts to come up with a unique non-zero seed. + //*************************************************************************** + random_xorshift() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); + initialise(seed); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_xorshift(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + // Add the first four primes to ensure that the seed isn't zero. + state[0] = seed + 3; + state[1] = seed + 5; + state[2] = seed + 7; + state[3] = seed + 11; + } + + //*************************************************************************** + /// Get the next random_xorshift number. + //*************************************************************************** + uint32_t operator()() + { + uint32_t n = state[3]; + n ^= n << 11; + n ^= n >> 8; + state[3] = state[2]; + state[2] = state[1]; + state[1] = state[0]; + n ^= state[0]; + n ^= state[0] >> 19; + state[0] = n; + + return n; + } + + //*************************************************************************** + /// Get the next random_xorshift number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } private: @@ -82,11 +143,60 @@ namespace etl { public: - random_lcg(); - explicit random_lcg(uint32_t seed); - void initialise(uint32_t seed); - uint32_t operator()(); - uint32_t range(uint32_t low, uint32_t high); + //*************************************************************************** + /// Default constructor. + /// Attempts to come up with a unique non-zero seed. + //*************************************************************************** + random_lcg() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); + initialise(seed); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_lcg(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + seed = (seed == 0) ? 1 : seed; + value = (seed > m) ? m : seed; + } + + //*************************************************************************** + /// Get the next random_clcg number. + //*************************************************************************** + uint32_t operator()() + { + value = (a * value) % m; + + return value; + } + + //*************************************************************************** + /// Get the next random_clcg number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } private: @@ -105,11 +215,64 @@ namespace etl { public: - random_clcg(); - explicit random_clcg(uint32_t seed); - void initialise(uint32_t seed); - uint32_t operator()(); - uint32_t range(uint32_t low, uint32_t high); + //*************************************************************************** + /// Default constructor. + /// Attempts to come up with a unique non-zero seed. + //*************************************************************************** + random_clcg() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); + initialise(seed); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_clcg(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + seed = (seed == 0) ? 1 : seed; + value1 = (seed > m1) ? m1 : seed; + value2 = (seed > m1) ? m1 : seed; + } + + //*************************************************************************** + /// Get the next random_clcg number. + //*************************************************************************** + uint32_t operator()() + { + static const uint32_t m = ((m1 > m2) ? m1 : m2); + + value1 = (a1 * value1) % m1; + value2 = (a2 * value2) % m2; + + return (value1 + value2) % m; + } + + //*************************************************************************** + /// Get the next random_clcg number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } private: @@ -132,11 +295,66 @@ namespace etl { public: - random_lsfr(); - explicit random_lsfr(uint32_t seed); - void initialise(uint32_t seed); - uint32_t operator()(); - uint32_t range(uint32_t low, uint32_t high); + //*************************************************************************** + /// Default constructor. + /// Attempts to come up with a unique non-zero seed. + //*************************************************************************** + random_lsfr() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); + initialise(seed); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_lsfr(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + value = seed; + } + + //*************************************************************************** + /// Get the next random_lsfr number. + //*************************************************************************** + uint32_t operator()() + { + static const uint32_t polynomial = 0x80200003; + + value >>= 1; + + if ((value & 1) == 1) + { + value ^= polynomial; + } + + return value; + } + + //*************************************************************************** + /// Get the next random_lsfr number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } private: @@ -151,11 +369,61 @@ namespace etl { public: - random_mwc(); - explicit random_mwc(uint32_t seed); - void initialise(uint32_t seed); - uint32_t operator()(); - uint32_t range(uint32_t low, uint32_t high); + //*************************************************************************** + /// Default constructor. + /// Attempts to come up with a unique non-zero seed. + //*************************************************************************** + random_mwc() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); + initialise(seed); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_mwc(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + value1 = seed; + value2 = seed; + } + + //*************************************************************************** + /// Get the next random_lsfr number. + //*************************************************************************** + uint32_t operator()() + { + value1 = 36969 * (value1 & 0xFFFF) + (value1 >> 16); + value2 = 18000 * (value2 & 0xFFFF) + (value2 >> 16); + + return (value1 << 16) + value2; + } + + //*************************************************************************** + /// Get the next random_lsfr number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } private: @@ -172,11 +440,57 @@ namespace etl { public: - random_pcg(); - explicit random_pcg(uint32_t seed); - void initialise(uint32_t seed); - uint32_t operator()(); - uint32_t range(uint32_t low, uint32_t high); + random_pcg() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + value = static_cast(n); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_pcg(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + value = uint64_t(seed) | (uint64_t(seed) << 32); + } + + //*************************************************************************** + /// Get the next random_lsfr number. + //*************************************************************************** + uint32_t operator()() + { + uint64_t x = value; + unsigned count = (unsigned)(value >> 59); + + value = (x * multiplier) + increment; + x ^= x >> 18; + return etl::rotate_right((uint32_t)(x >> 27), count); + } + + //*************************************************************************** + /// Get the next random_lsfr number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } private: diff --git a/include/etl/version.h b/include/etl/version.h index 65c0c1f1..7b486694 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -31,19 +31,20 @@ SOFTWARE. #ifndef ETL_VERSION_INCLUDED #define ETL_VERSION_INCLUDED -#include +#include "macros.h" ///\defgroup version version /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "13.0.0" -#define ETL_VERSION_W L"13.0.0" -#define ETL_VERSION_U16 u"13.0.0" -#define ETL_VERSION_U32 U"13.0.0" -#define ETL_VERSION_MAJOR 13 +#define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 0 #define ETL_VERSION_PATCH 0 + +#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) +#define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) +#define ETL_VERSION_U16 ETL_U16_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) +#define ETL_VERSION_U32 ETL_U32_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) #define ETL_VERSION_VALUE ((ETL_VERSION_MAJOR * 10000) + (ETL_VERSION_MINOR * 100) + ETL_VERSION_PATCH) #endif diff --git a/src/binary.cpp b/src/binary.cpp deleted file mode 100644 index 073955ed..00000000 --- a/src/binary.cpp +++ /dev/null @@ -1,598 +0,0 @@ -///\file - -/****************************************************************************** -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. -******************************************************************************/ - -#include "etl/platform.h" -#include "etl/binary.h" - -namespace etl -{ -#if ETL_8BIT_SUPPORT - //*************************************************************************** - /// Reverse 8 bits. - //*************************************************************************** - uint8_t reverse_bits(uint8_t value) - { - value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1); - value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2); - value = (value >> 4) | (value << 4); - - return value; - } -#endif - - //*************************************************************************** - /// Reverse 16 bits. - //*************************************************************************** - uint16_t reverse_bits(uint16_t value) - { - value = ((value & 0xAAAA) >> 1) | ((value & 0x5555) << 1); - value = ((value & 0xCCCC) >> 2) | ((value & 0x3333) << 2); - value = ((value & 0xF0F0) >> 4) | ((value & 0x0F0F) << 4); - value = (value >> 8) | (value << 8); - - return value; - } - - //*************************************************************************** - /// Reverse 32 bits. - //*************************************************************************** - uint32_t reverse_bits(uint32_t value) - { - value = ((value & 0xAAAAAAAA) >> 1) | ((value & 0x55555555) << 1); - value = ((value & 0xCCCCCCCC) >> 2) | ((value & 0x33333333) << 2); - value = ((value & 0xF0F0F0F0) >> 4) | ((value & 0x0F0F0F0F) << 4); - value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); - value = (value >> 16) | (value << 16); - - return value; - } - - //*************************************************************************** - /// Reverse 64 bits. - //*************************************************************************** - uint64_t reverse_bits(uint64_t value) - { - value = ((value & 0xAAAAAAAAAAAAAAAAull) >> 1) | ((value & 0x5555555555555555ull) << 1); - value = ((value & 0xCCCCCCCCCCCCCCCCull) >> 2) | ((value & 0x3333333333333333ull) << 2); - value = ((value & 0xF0F0F0F0F0F0F0F0ull) >> 4) | ((value & 0x0F0F0F0F0F0F0F0Full) << 4); - value = ((value & 0xFF00FF00FF00FF00ull) >> 8) | ((value & 0x00FF00FF00FF00FFull) << 8); - value = ((value & 0xFFFF0000FFFF0000ull) >> 16) | ((value & 0x0000FFFF0000FFFFull) << 16); - value = (value >> 32) | (value << 32); - - return value; - } - - //*************************************************************************** - /// Reverse bytes 16 bit. - //*************************************************************************** - uint16_t reverse_bytes(uint16_t value) - { - value = (value >> 8) | (value << 8); - - return value; - } - - //*************************************************************************** - /// Reverse bytes 32 bit. - //*************************************************************************** - uint32_t reverse_bytes(uint32_t value) - { - value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); - value = (value >> 16) | (value << 16); - - return value; - } - - //*************************************************************************** - /// Reverse bytes 64 bit. - //*************************************************************************** - uint64_t reverse_bytes(uint64_t value) - { - value = ((value & 0xFF00FF00FF00FF00ull) >> 8) | ((value & 0x00FF00FF00FF00FFull) << 8); - value = ((value & 0xFFFF0000FFFF0000ull) >> 16) | ((value & 0x0000FFFF0000FFFFull) << 16); - value = (value >> 32) | (value << 32); - - return value; - } - -#if ETL_8BIT_SUPPORT - //*************************************************************************** - /// Converts Gray code to binary. - //*************************************************************************** - uint8_t gray_to_binary(uint8_t value) - { - value ^= (value >> 4); - value ^= (value >> 2); - value ^= (value >> 1); - - return value; - } -#endif - - //*************************************************************************** - /// Converts Gray code to binary. - //*************************************************************************** - uint16_t gray_to_binary(uint16_t value) - { - value ^= (value >> 8); - value ^= (value >> 4); - value ^= (value >> 2); - value ^= (value >> 1); - - return value; - } - - //*************************************************************************** - /// Converts Gray code to binary. - //*************************************************************************** - uint32_t gray_to_binary(uint32_t value) - { - value ^= (value >> 16); - value ^= (value >> 8); - value ^= (value >> 4); - value ^= (value >> 2); - value ^= (value >> 1); - - return value; - } - - //*************************************************************************** - /// Converts Gray code to binary. - //*************************************************************************** - uint64_t gray_to_binary(uint64_t value) - { - value ^= (value >> 32); - value ^= (value >> 16); - value ^= (value >> 8); - value ^= (value >> 4); - value ^= (value >> 2); - value ^= (value >> 1); - - return value; - } - -#if ETL_8BIT_SUPPORT - //*************************************************************************** - /// Count set bits. 8 bits. - //*************************************************************************** - uint_least8_t count_bits(uint8_t value) - { - uint32_t count; - static const int S[] = { 1, 2, 4 }; - static const uint8_t B[] = { 0x55, 0x33, 0x0F }; - - count = value - ((value >> 1) & B[0]); - count = ((count >> S[1]) & B[1]) + (count & B[1]); - count = ((count >> S[2]) + count) & B[2]; - - return uint_least8_t(count); - } -#endif - - //*************************************************************************** - /// Count set bits. 16 bits. - //*************************************************************************** - uint_least8_t count_bits(uint16_t value) - { - uint32_t count; - static const int S[] = { 1, 2, 4, 8 }; - static const uint16_t B[] = { 0x5555, 0x3333, 0x0F0F, 0x00FF }; - - count = value - ((value >> 1) & B[0]); - count = ((count >> S[1]) & B[1]) + (count & B[1]); - count = ((count >> S[2]) + count) & B[2]; - count = ((count >> S[3]) + count) & B[3]; - - return count; - } - - //*************************************************************************** - /// Count set bits. 32 bits. - //*************************************************************************** - uint_least8_t count_bits(uint32_t value) - { - uint32_t count; - - value = value - ((value >> 1) & 0x55555555); - value = (value & 0x33333333) + ((value >> 2) & 0x33333333); - count = (((value + (value >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; - - return uint_least8_t(count); - } - - //*************************************************************************** - /// Count set bits. 64 bits. - //*************************************************************************** - uint_least8_t count_bits(uint64_t value) - { - uint64_t count; - static const int S[] = { 1, 2, 4, 8, 16, 32 }; - static const uint64_t B[] = { 0x5555555555555555ull, 0x3333333333333333ull, 0x0F0F0F0F0F0F0F0Full, 0x00FF00FF00FF00FFull, 0x0000FFFF0000FFFFull, 0x00000000FFFFFFFFull }; - - count = value - ((value >> 1) & B[0]); - count = ((count >> S[1]) & B[1]) + (count & B[1]); - count = ((count >> S[2]) + count) & B[2]; - count = ((count >> S[3]) + count) & B[3]; - count = ((count >> S[4]) + count) & B[4]; - count = ((count >> S[5]) + count) & B[5]; - - return uint_least8_t(count); - } - -#if ETL_8BIT_SUPPORT - //*************************************************************************** - /// Parity. 8bits. 0 = even, 1 = odd - //*************************************************************************** - uint_least8_t parity(uint8_t value) - { - value ^= value >> 4; - value &= 0x0F; - return (0x6996 >> value) & 1; - } -#endif - - //*************************************************************************** - /// Parity. 16bits. 0 = even, 1 = odd - //*************************************************************************** - uint_least8_t parity(uint16_t value) - { - value ^= value >> 8; - value ^= value >> 4; - value &= 0x0F; - return (0x6996 >> value) & 1; - } - - //*************************************************************************** - /// Parity. 32bits. 0 = even, 1 = odd - //*************************************************************************** - uint_least8_t parity(uint32_t value) - { - value ^= value >> 16; - value ^= value >> 8; - value ^= value >> 4; - value &= 0x0F; - return (0x6996 >> value) & 1; - } - - //*************************************************************************** - /// Parity. 64bits. 0 = even, 1 = odd - //*************************************************************************** - uint_least8_t parity(uint64_t value) - { - value ^= value >> 32; - value ^= value >> 16; - value ^= value >> 8; - value ^= value >> 4; - value &= 0x0F; - return (0x69966996 >> value) & 1; - } - -#if ETL_8BIT_SUPPORT - //*************************************************************************** - /// Count trailing zeros. bit. - /// Uses a binary search. - //*************************************************************************** - uint_least8_t count_trailing_zeros(uint8_t value) - { - uint_least8_t count; - - if (value & 0x1) - { - count = 0; - } - else - { - count = 1; - - if ((value & 0xF) == 0) - { - value >>= 4; - count += 4; - } - - if ((value & 0x3) == 0) - { - value >>= 2; - count += 2; - } - - count -= value & 0x1; - } - - return count; - } -#endif - - //*************************************************************************** - /// Count trailing zeros. 16bit. - /// Uses a binary search. - //*************************************************************************** - uint_least8_t count_trailing_zeros(uint16_t value) - { - uint_least8_t count; - - if (value & 0x1) - { - count = 0; - } - else - { - count = 1; - - if ((value & 0xFF) == 0) - { - value >>= 8; - count += 8; - } - - if ((value & 0xF) == 0) - { - value >>= 4; - count += 4; - } - - if ((value & 0x3) == 0) - { - value >>= 2; - count += 2; - } - - count -= value & 0x1; - } - - return count; - } - - //*************************************************************************** - /// Count trailing zeros. 32bit. - /// Uses a binary search. - //*************************************************************************** - uint_least8_t count_trailing_zeros(uint32_t value) - { - uint_least8_t count; - - if (value & 0x1) - { - count = 0; - } - else - { - count = 1; - - if ((value & 0xFFFF) == 0) - { - value >>= 16; - count += 16; - } - - if ((value & 0xFF) == 0) - { - value >>= 8; - count += 8; - } - - if ((value & 0xF) == 0) - { - value >>= 4; - count += 4; - } - - if ((value & 0x3) == 0) - { - value >>= 2; - count += 2; - } - - count -= value & 0x1; - } - - return count; - } - - //*************************************************************************** - /// Count trailing zeros. 64bit. - /// Uses a binary search. - //*************************************************************************** - uint_least8_t count_trailing_zeros(uint64_t value) - { - uint_least8_t count; - - if (value & 0x1) - { - count = 0; - } - else - { - count = 1; - - if ((value & 0xFFFFFFFF) == 0) - { - value >>= 32; - count += 32; - } - - if ((value & 0xFFFF) == 0) - { - value >>= 16; - count += 16; - } - - if ((value & 0xFF) == 0) - { - value >>= 8; - count += 8; - } - - if ((value & 0xF) == 0) - { - value >>= 4; - count += 4; - } - - if ((value & 0x3) == 0) - { - value >>= 2; - count += 2; - } - - count -= value & 0x1; - } - - return count; - } - -#if ETL_8BIT_SUPPORT - //***************************************************************************** - /// Binary interleave - //***************************************************************************** - uint16_t binary_interleave(uint8_t first, uint8_t second) - { - static const uint16_t mask[] = { 0x5555, 0x3333, 0x0F0F }; - - uint16_t f = first; - uint16_t s = second; - - f = (f | (f << 4)) & mask[2]; - f = (f | (f << 2)) & mask[1]; - f = (f | (f << 1)) & mask[0]; - - s = (s | (s << 4)) & mask[2]; - s = (s | (s << 2)) & mask[1]; - s = (s | (s << 1)) & mask[0]; - - return (f | (s << 1)); - } -#endif - - //***************************************************************************** - /// Binary interleave - //***************************************************************************** - uint32_t binary_interleave(uint16_t first, uint16_t second) - { - static const uint32_t mask[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF }; - - uint32_t f = first; - uint32_t s = second; - - f = (f | (f << 8)) & mask[3]; - f = (f | (f << 4)) & mask[2]; - f = (f | (f << 2)) & mask[1]; - f = (f | (f << 1)) & mask[0]; - - s = (s | (s << 8)) & mask[3]; - s = (s | (s << 4)) & mask[2]; - s = (s | (s << 2)) & mask[1]; - s = (s | (s << 1)) & mask[0]; - - return (f | (s << 1)); - } - - //***************************************************************************** - /// Binary interleave - //***************************************************************************** - uint64_t binary_interleave(uint32_t first, uint32_t second) - { - static const uint64_t mask[] = { 0x5555555555555555ull, 0x3333333333333333ull, 0x0F0F0F0F0F0F0F0Full, 0x00FF00FF00FF00FFull, 0x0000FFFF0000FFFFull }; - - uint64_t f = first; - uint64_t s = second; - - f = (f | (f << 16)) & mask[4]; - f = (f | (f << 8)) & mask[3]; - f = (f | (f << 4)) & mask[2]; - f = (f | (f << 2)) & mask[1]; - f = (f | (f << 1)) & mask[0]; - - s = (s | (s << 16)) & mask[4]; - s = (s | (s << 8)) & mask[3]; - s = (s | (s << 4)) & mask[2]; - s = (s | (s << 2)) & mask[1]; - s = (s | (s << 1)) & mask[0]; - - return (f | (s << 1)); - } - - //*************************************************************************** - /// Checks if odd. - //*************************************************************************** - bool is_odd(const unsigned char value) - { - return ((value & 1U) != 0U); - } - - bool is_odd(const unsigned short value) - { - return ((value & 1U) != 0U); - } - - bool is_odd(const unsigned int value) - { - return ((value & 1U) != 0U); - } - - bool is_odd(const unsigned long value) - { - return ((value & 1U) != 0U); - } - - bool is_odd(const unsigned long long value) - { - return ((value & 1U) != 0U); - } - - //*************************************************************************** - /// Checks if even. - //*************************************************************************** - bool is_even(const unsigned char value) - { - return ((value & 1U) == 0U); - } - - bool is_even(const unsigned short value) - { - return ((value & 1U) == 0U); - } - - bool is_even(const unsigned int value) - { - return ((value & 1U) == 0U); - } - - bool is_even(const unsigned long value) - { - return ((value & 1U) == 0U); - } - - bool is_even(const unsigned long long value) - { - return ((value & 1U) == 0U); - } -} - diff --git a/src/crc16.cpp b/src/crc16.cpp deleted file mode 100644 index 512b6ae9..00000000 --- a/src/crc16.cpp +++ /dev/null @@ -1,60 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// CRC16 table - /// \ingroup crc16 - //*************************************************************************** - extern const uint16_t ETL_CRC16[] = - { - 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, - 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, - 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, - 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, - 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, - 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, - 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, - 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, - 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, - 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, - 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, - 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, - 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, - 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, - 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, - 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 - }; -} diff --git a/src/crc16_ccitt.cpp b/src/crc16_ccitt.cpp deleted file mode 100644 index 09cced20..00000000 --- a/src/crc16_ccitt.cpp +++ /dev/null @@ -1,60 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// CRC-CCITT table - /// \ingroup crc16_ccitt - //*************************************************************************** - extern const uint16_t ETL_CRC_CCITT[] = - { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, - 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, - 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, - 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, - 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, - 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, - 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, - 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, - 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 - }; -} diff --git a/src/crc16_kermit.cpp b/src/crc16_kermit.cpp deleted file mode 100644 index 5e89a96f..00000000 --- a/src/crc16_kermit.cpp +++ /dev/null @@ -1,60 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// CRC Kermit table - /// \ingroup crc16_kermit - //*************************************************************************** - extern const uint16_t ETL_CRC_KERMIT[] = - { - 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, - 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876, - 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5, - 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974, - 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3, - 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72, - 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1, - 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70, - 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, - 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, - 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, - 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, - 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, - 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, - 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, - 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 - }; -} diff --git a/src/crc16_modbus.cpp b/src/crc16_modbus.cpp deleted file mode 100644 index 43f02df3..00000000 --- a/src/crc16_modbus.cpp +++ /dev/null @@ -1,76 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2018 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 - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// CRC-MODBUS table - /// \ingroup crc16_modbus - //*************************************************************************** - extern const uint16_t ETL_CRC_MODBUS[] = - { - 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, - 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, - 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, - 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, - 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, - 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, - 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, - 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, - 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, - 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, - 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, - 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, - 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, - 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, - 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, - 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, - 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, - 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, - 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, - 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, - 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, - 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, - 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, - 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, - 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, - 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, - 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, - 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, - 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, - 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, - 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, - 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 - }; -} diff --git a/src/crc32.cpp b/src/crc32.cpp deleted file mode 100644 index 771f2ad3..00000000 --- a/src/crc32.cpp +++ /dev/null @@ -1,76 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// CRC32 table - /// \ingroup crc32 - //*************************************************************************** - extern const uint32_t ETL_CRC32[] = - { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, - 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D - }; -} diff --git a/src/crc32_c.cpp b/src/crc32_c.cpp deleted file mode 100644 index b255af0d..00000000 --- a/src/crc32_c.cpp +++ /dev/null @@ -1,80 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2018 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 - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// ETL_CRC32_C table - /// \ingroup ETL_CRC32_C - //*************************************************************************** - extern const uint32_t ETL_CRC32_C[] = - { - 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, - 0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L, - 0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL, 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L, - 0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL, - 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L, - 0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL, - 0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL, - 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L, - 0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L, - 0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L, - 0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L, - 0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L, 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L, - 0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L, 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L, - 0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L, - 0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L, - 0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L, - 0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L, - 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL, - 0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL, - 0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L, - 0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL, - 0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL, 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L, - 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L, - 0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL, - 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL, - 0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L, - 0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L, - 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL, - 0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, - 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L, - 0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L, - 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL, - 0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L, - 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL, - 0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL, - 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L - }; -} diff --git a/src/crc64_ecma.cpp b/src/crc64_ecma.cpp deleted file mode 100644 index 2a664f84..00000000 --- a/src/crc64_ecma.cpp +++ /dev/null @@ -1,108 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include - -#include "etl/platform.h" - -namespace etl -{ - //*************************************************************************** - /// CRC64_ECMA table - /// \ingroup crc64_ecma - //*************************************************************************** - extern const uint64_t CRC64_ECMA[] = - { - 0x0000000000000000ull, 0x42F0E1EBA9EA3693ull, 0x85E1C3D753D46D26ull, 0xC711223CFA3E5BB5ull, - 0x493366450E42ECDFull, 0x0BC387AEA7A8DA4Cull, 0xCCD2A5925D9681F9ull, 0x8E224479F47CB76Aull, - 0x9266CC8A1C85D9BEull, 0xD0962D61B56FEF2Dull, 0x17870F5D4F51B498ull, 0x5577EEB6E6BB820Bull, - 0xDB55AACF12C73561ull, 0x99A54B24BB2D03F2ull, 0x5EB4691841135847ull, 0x1C4488F3E8F96ED4ull, - 0x663D78FF90E185EFull, 0x24CD9914390BB37Cull, 0xE3DCBB28C335E8C9ull, 0xA12C5AC36ADFDE5Aull, - 0x2F0E1EBA9EA36930ull, 0x6DFEFF5137495FA3ull, 0xAAEFDD6DCD770416ull, 0xE81F3C86649D3285ull, - 0xF45BB4758C645C51ull, 0xB6AB559E258E6AC2ull, 0x71BA77A2DFB03177ull, 0x334A9649765A07E4ull, - 0xBD68D2308226B08Eull, 0xFF9833DB2BCC861Dull, 0x388911E7D1F2DDA8ull, 0x7A79F00C7818EB3Bull, - 0xCC7AF1FF21C30BDEull, 0x8E8A101488293D4Dull, 0x499B3228721766F8ull, 0x0B6BD3C3DBFD506Bull, - 0x854997BA2F81E701ull, 0xC7B97651866BD192ull, 0x00A8546D7C558A27ull, 0x4258B586D5BFBCB4ull, - 0x5E1C3D753D46D260ull, 0x1CECDC9E94ACE4F3ull, 0xDBFDFEA26E92BF46ull, 0x990D1F49C77889D5ull, - 0x172F5B3033043EBFull, 0x55DFBADB9AEE082Cull, 0x92CE98E760D05399ull, 0xD03E790CC93A650Aull, - 0xAA478900B1228E31ull, 0xE8B768EB18C8B8A2ull, 0x2FA64AD7E2F6E317ull, 0x6D56AB3C4B1CD584ull, - 0xE374EF45BF6062EEull, 0xA1840EAE168A547Dull, 0x66952C92ECB40FC8ull, 0x2465CD79455E395Bull, - 0x3821458AADA7578Full, 0x7AD1A461044D611Cull, 0xBDC0865DFE733AA9ull, 0xFF3067B657990C3Aull, - 0x711223CFA3E5BB50ull, 0x33E2C2240A0F8DC3ull, 0xF4F3E018F031D676ull, 0xB60301F359DBE0E5ull, - 0xDA050215EA6C212Full, 0x98F5E3FE438617BCull, 0x5FE4C1C2B9B84C09ull, 0x1D14202910527A9Aull, - 0x93366450E42ECDF0ull, 0xD1C685BB4DC4FB63ull, 0x16D7A787B7FAA0D6ull, 0x5427466C1E109645ull, - 0x4863CE9FF6E9F891ull, 0x0A932F745F03CE02ull, 0xCD820D48A53D95B7ull, 0x8F72ECA30CD7A324ull, - 0x0150A8DAF8AB144Eull, 0x43A04931514122DDull, 0x84B16B0DAB7F7968ull, 0xC6418AE602954FFBull, - 0xBC387AEA7A8DA4C0ull, 0xFEC89B01D3679253ull, 0x39D9B93D2959C9E6ull, 0x7B2958D680B3FF75ull, - 0xF50B1CAF74CF481Full, 0xB7FBFD44DD257E8Cull, 0x70EADF78271B2539ull, 0x321A3E938EF113AAull, - 0x2E5EB66066087D7Eull, 0x6CAE578BCFE24BEDull, 0xABBF75B735DC1058ull, 0xE94F945C9C3626CBull, - 0x676DD025684A91A1ull, 0x259D31CEC1A0A732ull, 0xE28C13F23B9EFC87ull, 0xA07CF2199274CA14ull, - 0x167FF3EACBAF2AF1ull, 0x548F120162451C62ull, 0x939E303D987B47D7ull, 0xD16ED1D631917144ull, - 0x5F4C95AFC5EDC62Eull, 0x1DBC74446C07F0BDull, 0xDAAD56789639AB08ull, 0x985DB7933FD39D9Bull, - 0x84193F60D72AF34Full, 0xC6E9DE8B7EC0C5DCull, 0x01F8FCB784FE9E69ull, 0x43081D5C2D14A8FAull, - 0xCD2A5925D9681F90ull, 0x8FDAB8CE70822903ull, 0x48CB9AF28ABC72B6ull, 0x0A3B7B1923564425ull, - 0x70428B155B4EAF1Eull, 0x32B26AFEF2A4998Dull, 0xF5A348C2089AC238ull, 0xB753A929A170F4ABull, - 0x3971ED50550C43C1ull, 0x7B810CBBFCE67552ull, 0xBC902E8706D82EE7ull, 0xFE60CF6CAF321874ull, - 0xE224479F47CB76A0ull, 0xA0D4A674EE214033ull, 0x67C58448141F1B86ull, 0x253565A3BDF52D15ull, - 0xAB1721DA49899A7Full, 0xE9E7C031E063ACECull, 0x2EF6E20D1A5DF759ull, 0x6C0603E6B3B7C1CAull, - 0xF6FAE5C07D3274CDull, 0xB40A042BD4D8425Eull, 0x731B26172EE619EBull, 0x31EBC7FC870C2F78ull, - 0xBFC9838573709812ull, 0xFD39626EDA9AAE81ull, 0x3A28405220A4F534ull, 0x78D8A1B9894EC3A7ull, - 0x649C294A61B7AD73ull, 0x266CC8A1C85D9BE0ull, 0xE17DEA9D3263C055ull, 0xA38D0B769B89F6C6ull, - 0x2DAF4F0F6FF541ACull, 0x6F5FAEE4C61F773Full, 0xA84E8CD83C212C8Aull, 0xEABE6D3395CB1A19ull, - 0x90C79D3FEDD3F122ull, 0xD2377CD44439C7B1ull, 0x15265EE8BE079C04ull, 0x57D6BF0317EDAA97ull, - 0xD9F4FB7AE3911DFDull, 0x9B041A914A7B2B6Eull, 0x5C1538ADB04570DBull, 0x1EE5D94619AF4648ull, - 0x02A151B5F156289Cull, 0x4051B05E58BC1E0Full, 0x87409262A28245BAull, 0xC5B073890B687329ull, - 0x4B9237F0FF14C443ull, 0x0962D61B56FEF2D0ull, 0xCE73F427ACC0A965ull, 0x8C8315CC052A9FF6ull, - 0x3A80143F5CF17F13ull, 0x7870F5D4F51B4980ull, 0xBF61D7E80F251235ull, 0xFD913603A6CF24A6ull, - 0x73B3727A52B393CCull, 0x31439391FB59A55Full, 0xF652B1AD0167FEEAull, 0xB4A25046A88DC879ull, - 0xA8E6D8B54074A6ADull, 0xEA16395EE99E903Eull, 0x2D071B6213A0CB8Bull, 0x6FF7FA89BA4AFD18ull, - 0xE1D5BEF04E364A72ull, 0xA3255F1BE7DC7CE1ull, 0x64347D271DE22754ull, 0x26C49CCCB40811C7ull, - 0x5CBD6CC0CC10FAFCull, 0x1E4D8D2B65FACC6Full, 0xD95CAF179FC497DAull, 0x9BAC4EFC362EA149ull, - 0x158E0A85C2521623ull, 0x577EEB6E6BB820B0ull, 0x906FC95291867B05ull, 0xD29F28B9386C4D96ull, - 0xCEDBA04AD0952342ull, 0x8C2B41A1797F15D1ull, 0x4B3A639D83414E64ull, 0x09CA82762AAB78F7ull, - 0x87E8C60FDED7CF9Dull, 0xC51827E4773DF90Eull, 0x020905D88D03A2BBull, 0x40F9E43324E99428ull, - 0x2CFFE7D5975E55E2ull, 0x6E0F063E3EB46371ull, 0xA91E2402C48A38C4ull, 0xEBEEC5E96D600E57ull, - 0x65CC8190991CB93Dull, 0x273C607B30F68FAEull, 0xE02D4247CAC8D41Bull, 0xA2DDA3AC6322E288ull, - 0xBE992B5F8BDB8C5Cull, 0xFC69CAB42231BACFull, 0x3B78E888D80FE17Aull, 0x7988096371E5D7E9ull, - 0xF7AA4D1A85996083ull, 0xB55AACF12C735610ull, 0x724B8ECDD64D0DA5ull, 0x30BB6F267FA73B36ull, - 0x4AC29F2A07BFD00Dull, 0x08327EC1AE55E69Eull, 0xCF235CFD546BBD2Bull, 0x8DD3BD16FD818BB8ull, - 0x03F1F96F09FD3CD2ull, 0x41011884A0170A41ull, 0x86103AB85A2951F4ull, 0xC4E0DB53F3C36767ull, - 0xD8A453A01B3A09B3ull, 0x9A54B24BB2D03F20ull, 0x5D45907748EE6495ull, 0x1FB5719CE1045206ull, - 0x919735E51578E56Cull, 0xD367D40EBC92D3FFull, 0x1476F63246AC884Aull, 0x568617D9EF46BED9ull, - 0xE085162AB69D5E3Cull, 0xA275F7C11F7768AFull, 0x6564D5FDE549331Aull, 0x279434164CA30589ull, - 0xA9B6706FB8DFB2E3ull, 0xEB46918411358470ull, 0x2C57B3B8EB0BDFC5ull, 0x6EA7525342E1E956ull, - 0x72E3DAA0AA188782ull, 0x30133B4B03F2B111ull, 0xF7021977F9CCEAA4ull, 0xB5F2F89C5026DC37ull, - 0x3BD0BCE5A45A6B5Dull, 0x79205D0E0DB05DCEull, 0xBE317F32F78E067Bull, 0xFCC19ED95E6430E8ull, - 0x86B86ED5267CDBD3ull, 0xC4488F3E8F96ED40ull, 0x0359AD0275A8B6F5ull, 0x41A94CE9DC428066ull, - 0xCF8B0890283E370Cull, 0x8D7BE97B81D4019Full, 0x4A6ACB477BEA5A2Aull, 0x089A2AACD2006CB9ull, - 0x14DEA25F3AF9026Dull, 0x562E43B4931334FEull, 0x913F6188692D6F4Bull, 0xD3CF8063C0C759D8ull, - 0x5DEDC41A34BBEEB2ull, 0x1F1D25F19D51D821ull, 0xD80C07CD676F8394ull, 0x9AFCE626CE85B507ull - }; -} diff --git a/src/crc8_ccitt.cpp b/src/crc8_ccitt.cpp deleted file mode 100644 index 5a224aff..00000000 --- a/src/crc8_ccitt.cpp +++ /dev/null @@ -1,63 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include - -#include "etl/platform.h" -#include "etl/static_assert.h" - -ETL_STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type"); - -namespace etl -{ - //*************************************************************************** - /// CRC8 table - /// \ingroup crc8_ccitt - //*************************************************************************** - extern const uint8_t CRC8_CCITT[] = - { - 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, - 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, - 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, - 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD, - 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, - 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, - 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A, - 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, - 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, - 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4, - 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, - 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, - 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63, - 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, - 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, - 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3 - }; -} diff --git a/src/pearson.cpp b/src/pearson.cpp deleted file mode 100644 index 7051d254..00000000 --- a/src/pearson.cpp +++ /dev/null @@ -1,63 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2015 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 - -#include "etl/platform.h" -#include "etl/static_assert.h" - -ETL_STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type"); - -namespace etl -{ - //*************************************************************************** - /// Pearson lookup table - /// \ingroup pearson - //*************************************************************************** - extern const uint8_t PEARSON_LOOKUP[] = - { - 228, 39, 61, 95, 227, 187, 0, 197, 31, 189, 161, 222, 34, 15, 221, 246, - 19, 234, 6, 50, 113, 3, 91, 63, 77, 245, 144, 2, 183, 196, 25, 226, - 97, 126, 48, 59, 217, 4, 100, 145, 12, 88, 203, 149, 80, 154, 38, 27, - 224, 218, 158, 115, 202, 79, 53, 83, 242, 36, 139, 131, 136, 191, 42, 170, - 23, 99, 156, 51, 143, 60, 233, 206, 62, 108, 17, 67, 81, 71, 93, 195, - 26, 231, 247, 96, 24, 200, 176, 209, 152, 212, 138, 165, 75, 185, 130, 248, - 125, 110, 10, 116, 201, 90, 69, 204, 85, 251, 78, 157, 47, 184, 169, 141, - 134, 230, 89, 21, 146, 46, 55, 128, 148, 207, 216, 11, 114, 199, 103, 102, - 166, 244, 5, 104, 225, 160, 132, 28, 172, 65, 121, 140, 153, 119, 198, 210, - 58, 87, 117, 177, 33, 22, 13, 37, 49, 174, 109, 40, 73, 211, 18, 167, - 164, 252, 168, 74, 30, 173, 35, 98, 66, 193, 94, 175, 86, 54, 179, 122, - 220, 151, 192, 29, 133, 254, 155, 127, 240, 232, 190, 180, 8, 68, 236, 20, - 137, 92, 219, 208, 52, 250, 147, 142, 111, 112, 120, 45, 135, 255, 123, 229, - 57, 182, 243, 124, 186, 253, 7, 237, 9, 16, 70, 171, 235, 107, 223, 118, - 215, 178, 194, 181, 43, 188, 106, 105, 64, 241, 84, 238, 159, 44, 32, 76, - 213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82 - } ; -} diff --git a/src/private/pvoidvector.cpp b/src/private/pvoidvector.cpp deleted file mode 100644 index dd3e1b5b..00000000 --- a/src/private/pvoidvector.cpp +++ /dev/null @@ -1,551 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://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. -******************************************************************************/ - -#include "../../include/etl/platform.h" -#include "../../include/etl/private/pvoidvector.h" - -//********************************************************************* -/// Returns an iterator to the beginning of the vector. -///\return An iterator to the beginning of the vector. -//********************************************************************* -etl::pvoidvector::iterator etl::pvoidvector::begin() -{ - return p_buffer; -} - -//********************************************************************* -/// Returns a const_iterator to the beginning of the vector. -///\return A const iterator to the beginning of the vector. -//********************************************************************* -etl::pvoidvector::const_iterator etl::pvoidvector::begin() const -{ - return const_iterator(p_buffer); -} - -//********************************************************************* -/// Returns an iterator to the end of the vector. -///\return An iterator to the end of the vector. -//********************************************************************* -etl::pvoidvector::iterator etl::pvoidvector::end() -{ - return p_end; -} - -//********************************************************************* -/// Returns a const_iterator to the end of the vector. -///\return A const iterator to the end of the vector. -//********************************************************************* -etl::pvoidvector::const_iterator etl::pvoidvector::end() const -{ - return const_iterator(p_end); -} - -//********************************************************************* -/// Returns a const_iterator to the beginning of the vector. -///\return A const iterator to the beginning of the vector. -//********************************************************************* -etl::pvoidvector::const_iterator etl::pvoidvector::cbegin() const -{ - return const_iterator(p_buffer); -} - -//********************************************************************* -/// Returns a const_iterator to the end of the vector. -///\return A const iterator to the end of the vector. -//********************************************************************* -etl::pvoidvector::const_iterator etl::pvoidvector::cend() const -{ - return const_iterator(p_end); -} - -//********************************************************************* -/// Returns an reverse iterator to the reverse beginning of the vector. -///\return Iterator to the reverse beginning of the vector. -//********************************************************************* -etl::pvoidvector::reverse_iterator etl::pvoidvector::rbegin() -{ - return reverse_iterator(end()); -} - -//********************************************************************* -/// Returns a const reverse iterator to the reverse beginning of the vector. -///\return Const iterator to the reverse beginning of the vector. -//********************************************************************* -etl::pvoidvector::const_reverse_iterator etl::pvoidvector::rbegin() const -{ - return const_reverse_iterator(end()); -} - -//********************************************************************* -/// Returns a reverse iterator to the end + 1 of the vector. -///\return Reverse iterator to the end + 1 of the vector. -//********************************************************************* -etl::pvoidvector::reverse_iterator etl::pvoidvector::rend() -{ - return reverse_iterator(begin()); -} - -//********************************************************************* -/// Returns a const reverse iterator to the end + 1 of the vector. -///\return Const reverse iterator to the end + 1 of the vector. -//********************************************************************* -etl::pvoidvector::const_reverse_iterator etl::pvoidvector::rend() const -{ - return const_reverse_iterator(begin()); -} - -//********************************************************************* -/// Returns a const reverse iterator to the reverse beginning of the vector. -///\return Const reverse iterator to the reverse beginning of the vector. -//********************************************************************* -etl::pvoidvector::const_reverse_iterator etl::pvoidvector::crbegin() const -{ - return const_reverse_iterator(cend()); -} - -//********************************************************************* -/// Returns a const reverse iterator to the end + 1 of the vector. -///\return Const reverse iterator to the end + 1 of the vector. -//********************************************************************* -etl::pvoidvector::const_reverse_iterator etl::pvoidvector::crend() const -{ - return const_reverse_iterator(cbegin()); -} - -//********************************************************************* -/// Resizes the vector. -/// If asserts or exceptions are enabled and the new size is larger than the -/// maximum then a vector_full is thrown. -///\param new_size The new size. -//********************************************************************* -void etl::pvoidvector::resize(size_t new_size) -{ - ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); - - p_end = p_buffer + new_size; -} - -//********************************************************************* -/// Resizes the vector. -/// If asserts or exceptions are enabled and the new size is larger than the -/// maximum then a vector_full is thrown. -///\param new_size The new size. -///\param value The value to fill new elements with. Default = default constructed value. -//********************************************************************* -void etl::pvoidvector::resize(size_t new_size, etl::pvoidvector::value_type value) -{ - ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); - - pointer p_new_end = p_buffer + new_size; - - // Size up if necessary. - if (p_end < p_new_end) - { - std::fill(p_end, p_new_end, value); - } - - p_end = p_new_end; -} - -//********************************************************************* -/// Returns a reference to the value at index 'i' -///\param i The index. -///\return A reference to the value at index 'i' -//********************************************************************* -etl::pvoidvector::reference etl::pvoidvector::operator [](size_t i) -{ - return reference(p_buffer[i]); -} - -//********************************************************************* -/// Returns a const reference to the value at index 'i' -///\param i The index. -///\return A const reference to the value at index 'i' -//********************************************************************* -etl::pvoidvector::const_reference etl::pvoidvector::operator [](size_t i) const -{ - return const_reference(p_buffer[i]); -} - -//********************************************************************* -/// Returns a reference to the value at index 'i' -/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. -///\param i The index. -///\return A reference to the value at index 'i' -//********************************************************************* -etl::pvoidvector::reference etl::pvoidvector::at(size_t i) -{ - ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return reference(p_buffer[i]); -} - -//********************************************************************* -/// Returns a const reference to the value at index 'i' -/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. -///\param i The index. -///\return A const reference to the value at index 'i' -//********************************************************************* -etl::pvoidvector::const_reference etl::pvoidvector::at(size_t i) const -{ - ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return const_reference(p_buffer[i]); -} - -//********************************************************************* -/// Returns a reference to the first element. -///\return A reference to the first element. -//********************************************************************* -etl::pvoidvector::reference etl::pvoidvector::front() -{ - return reference(p_buffer[0]); -} - -//********************************************************************* -/// Returns a const reference to the first element. -///\return A const reference to the first element. -//********************************************************************* -etl::pvoidvector::const_reference etl::pvoidvector::front() const -{ - return const_reference(p_buffer[0]); -} - -//********************************************************************* -/// Returns a reference to the last element. -///\return A reference to the last element. -//********************************************************************* -etl::pvoidvector::reference etl::pvoidvector::back() -{ - return reference(*(p_end - 1)); -} - -//********************************************************************* -/// Returns a const reference to the last element. -///\return A const reference to the last element. -//********************************************************************* -etl::pvoidvector::const_reference etl::pvoidvector::back() const -{ - return const_reference(*(p_end - 1)); -} - -//********************************************************************* -/// Returns a pointer to the beginning of the vector data. -///\return A pointer to the beginning of the vector data. -//********************************************************************* -etl::pvoidvector::pointer etl::pvoidvector::data() -{ - return pointer(p_buffer); -} - -//********************************************************************* -/// Returns a const pointer to the beginning of the vector data. -///\return A const pointer to the beginning of the vector data. -//********************************************************************* -etl::pvoidvector::const_pointer etl::pvoidvector::data() const -{ - return const_pointer(p_buffer); -} - -//********************************************************************* -/// Assigns values to the vector. -/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. -///\param n The number of elements to add. -///\param value The value to insert for each element. -//********************************************************************* -void etl::pvoidvector::assign(size_t n, etl::pvoidvector::value_type value) -{ - initialise(); - - ETL_ASSERT(n <= CAPACITY, ETL_ERROR(vector_full)); - - for (size_t current_size = 0; current_size < n; ++current_size) - { - *p_end++ = value; - } -} - -//************************************************************************* -/// Clears the vector. -//************************************************************************* -void etl::pvoidvector::clear() -{ - initialise(); -} - -//********************************************************************* -/// Inserts a value at the end of the vector. -/// If asserts or exceptions are enabled, emits vector_full if the vector is already full. -///\param value The value to add. -//********************************************************************* -void etl::pvoidvector::push_back(etl::pvoidvector::value_type value) -{ -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); -#endif - *p_end++ = value; -} - -//************************************************************************* -/// Removes an element from the end of the vector. -/// Does nothing if the vector is empty. -//************************************************************************* -void etl::pvoidvector::pop_back() -{ -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty)); -#endif - --p_end; -} - -//********************************************************************* -/// Inserts a value to the vector. -/// If asserts or exceptions are enabled, emits vector_full if the vector is already full. -///\param position The position to insert before. -///\param value The value to insert. -//********************************************************************* -etl::pvoidvector::iterator etl::pvoidvector::insert(etl::pvoidvector::iterator position, etl::pvoidvector::value_type value) -{ - ETL_ASSERT(size() + 1 <= CAPACITY, ETL_ERROR(vector_full)); - - if (position != end()) - { - ++p_end; - std::copy_backward(position, end() - 1, end()); - *position = value; - } - else - { - *p_end++ = value; - } - - return position; -} - -//********************************************************************* -/// Inserts 'n' values to the vector. -/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. -///\param position The position to insert before. -///\param n The number of elements to add. -///\param value The value to insert. -//********************************************************************* -void etl::pvoidvector::insert(etl::pvoidvector::iterator position, size_t n, etl::pvoidvector::value_type value) -{ - ETL_ASSERT((size() + 1) <= CAPACITY, ETL_ERROR(vector_full)); - - std::copy_backward(position, p_end, p_end + n); - std::fill_n(position, n, value); - - p_end += n; -} - -//********************************************************************* -/// Erases an element. -///\param i_element Iterator to the element. -///\return An iterator pointing to the element that followed the erased element. -//********************************************************************* -etl::pvoidvector::iterator etl::pvoidvector::erase(etl::pvoidvector::iterator i_element) -{ - std::copy(i_element + 1, end(), i_element); - --p_end; - - return i_element; -} - -//********************************************************************* -/// Erases a range of elements. -/// The range includes all the elements between first and last, including the -/// element pointed by first, but not the one pointed by last. -///\param first Iterator to the first element. -///\param last Iterator to the last element. -///\return An iterator pointing to the element that followed the erased element. -//********************************************************************* -etl::pvoidvector::iterator etl::pvoidvector::erase(etl::pvoidvector::iterator first, etl::pvoidvector::iterator last) -{ - std::copy(last, end(), first); - size_t n_delete = std::distance(first, last); - - // Just adjust the count. - p_end -= n_delete; - - return first; -} - -//************************************************************************* -/// Assignment operator. -//************************************************************************* -etl::pvoidvector& etl::pvoidvector::operator = (const etl::pvoidvector& rhs) -{ - if (&rhs != this) - { - assign(rhs.cbegin(), rhs.cend()); - } - - return *this; -} - -//************************************************************************* -/// Gets the current size of the vector. -///\return The current size of the vector. -//************************************************************************* -etl::pvoidvector::size_type etl::pvoidvector::size() const -{ - return size_t(p_end - p_buffer); -} - -//************************************************************************* -/// Checks the 'empty' state of the vector. -///\return true if empty. -//************************************************************************* -bool etl::pvoidvector::empty() const -{ - return (p_end == p_buffer); -} - -//************************************************************************* -/// Checks the 'full' state of the vector. -///\return true if full. -//************************************************************************* -bool etl::pvoidvector::full() const -{ - return size() == CAPACITY; -} - -//************************************************************************* -/// Returns the remaining capacity. -///\return The remaining capacity. -//************************************************************************* -size_t etl::pvoidvector::available() const -{ - return max_size() - size(); -} - -//********************************************************************* -/// Constructor. -//********************************************************************* -etl::pvoidvector::pvoidvector(void** p_buffer_, size_t MAX_SIZE) - : vector_base(MAX_SIZE), - p_buffer(p_buffer_), - p_end(p_buffer_) -{ -} - -//********************************************************************* -/// Initialise the vector. -//********************************************************************* -void etl::pvoidvector::initialise() -{ - p_end = p_buffer; -} - -//************************************************************************* -/// Fix the internal pointers after a low level memory copy. -//************************************************************************* -void etl::pvoidvector::repair_buffer(void** p_buffer_) -{ - uintptr_t length = p_end - p_buffer; - - p_buffer = p_buffer_; - p_end = p_buffer_ + length; -} - -namespace etl -{ - //*************************************************************************** - /// Equal operator. - ///\param lhs Reference to the first vector. - ///\param rhs Reference to the second vector. - ///\return true if the arrays are equal, otherwise false - ///\ingroup vector - //*************************************************************************** - bool operator ==(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) - { - return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin()); - } - - //*************************************************************************** - /// Not equal operator. - ///\param lhs Reference to the first vector. - ///\param rhs Reference to the second vector. - ///\return true if the arrays are not equal, otherwise false - ///\ingroup vector - //*************************************************************************** - bool operator !=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) - { - return !(lhs == rhs); - } - - //*************************************************************************** - /// Less than operator. - ///\param lhs Reference to the first vector. - ///\param rhs Reference to the second vector. - ///\return true if the first vector is lexicographically less than the second, otherwise false - ///\ingroup vector - //*************************************************************************** - inline bool operator <(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) - { - return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); - } - - //*************************************************************************** - /// Greater than operator. - ///\param lhs Reference to the first vector. - ///\param rhs Reference to the second vector. - ///\return true if the first vector is lexicographically greater than the second, otherwise false - ///\ingroup vector - //*************************************************************************** - bool operator >(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) - { - return (rhs < lhs); - } - - //*************************************************************************** - /// Less than or equal operator. - ///\param lhs Reference to the first vector. - ///\param rhs Reference to the second vector. - ///\return true if the first vector is lexicographically less than or equal to the second, otherwise false - ///\ingroup vector - //*************************************************************************** - bool operator <=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) - { - return !(lhs > rhs); - } - - //*************************************************************************** - /// Greater than or equal operator. - ///\param lhs Reference to the first vector. - ///\param rhs Reference to the second vector. - ///\return true if the first vector is lexicographically greater than or equal to the second, otherwise false - ///\ingroup vector - //*************************************************************************** - bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) - { - return !(lhs < rhs); - } -} - diff --git a/src/random.cpp b/src/random.cpp deleted file mode 100644 index d754cf79..00000000 --- a/src/random.cpp +++ /dev/null @@ -1,413 +0,0 @@ -///\file - -/****************************************************************************** -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. -******************************************************************************/ - -#include "etl/platform.h" -#include "etl/random.h" -#include "etl/binary.h" - -namespace etl -{ - //*************************************************************************** - // XOR Shift - //*************************************************************************** - - //*************************************************************************** - /// Default constructor. - /// Attempts to come up with a unique non-zero seed. - //*************************************************************************** - random_xorshift::random_xorshift() - { - // An attempt to come up with a unique non-zero seed, - // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - uint32_t seed = static_cast(n); - initialise(seed); - } - - //*************************************************************************** - /// Constructor with seed value. - ///\param seed The new seed value. - //*************************************************************************** - random_xorshift::random_xorshift(uint32_t seed) - { - initialise(seed); - } - - //*************************************************************************** - /// Initialises the sequence with a new seed value. - ///\param seed The new seed value. - //*************************************************************************** - void random_xorshift::initialise(uint32_t seed) - { - // Add the first four primes to ensure that the seed isn't zero. - state[0] = seed + 3; - state[1] = seed + 5; - state[2] = seed + 7; - state[3] = seed + 11; - } - - //*************************************************************************** - /// Get the next random_xorshift number. - //*************************************************************************** - uint32_t random_xorshift::operator()() - { - uint32_t n = state[3]; - n ^= n << 11; - n ^= n >> 8; - state[3] = state[2]; - state[2] = state[1]; - state[1] = state[0]; - n ^= state[0]; - n ^= state[0] >> 19; - state[0] = n; - - return n; - } - - //*************************************************************************** - /// Get the next random_xorshift number in a specified inclusive range. - //*************************************************************************** - uint32_t random_xorshift::range(uint32_t low, uint32_t high) - { - uint32_t r = high - low + 1; - uint32_t n = operator()(); - n %= r; - n += low; - - return n; - } - - //*************************************************************************** - // Linear Congruential Generator - //*************************************************************************** - - //*************************************************************************** - /// Default constructor. - /// Attempts to come up with a unique non-zero seed. - //*************************************************************************** - random_lcg::random_lcg() - { - // An attempt to come up with a unique non-zero seed, - // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - uint32_t seed = static_cast(n); - initialise(seed); - } - - //*************************************************************************** - /// Constructor with seed value. - ///\param seed The new seed value. - //*************************************************************************** - random_lcg::random_lcg(uint32_t seed) - { - initialise(seed); - } - - //*************************************************************************** - /// Initialises the sequence with a new seed value. - ///\param seed The new seed value. - //*************************************************************************** - void random_lcg::initialise(uint32_t seed) - { - seed = (seed == 0) ? 1 : seed; - value = (seed > m) ? m : seed; - } - - //*************************************************************************** - /// Get the next random_clcg number. - //*************************************************************************** - uint32_t random_lcg::operator()() - { - value = (a * value) % m; - - return value; - } - - //*************************************************************************** - /// Get the next random_clcg number in a specified inclusive range. - //*************************************************************************** - uint32_t random_lcg::range(uint32_t low, uint32_t high) - { - uint32_t r = high - low + 1; - uint32_t n = operator()(); - n %= r; - n += low; - - return n; - } - - //*************************************************************************** - // Combined Linear Congruential Generator - //*************************************************************************** - - //*************************************************************************** - /// Default constructor. - /// Attempts to come up with a unique non-zero seed. - //*************************************************************************** - random_clcg::random_clcg() - { - // An attempt to come up with a unique non-zero seed, - // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - uint32_t seed = static_cast(n); - initialise(seed); - } - - //*************************************************************************** - /// Constructor with seed value. - ///\param seed The new seed value. - //*************************************************************************** - random_clcg::random_clcg(uint32_t seed) - { - initialise(seed); - } - - //*************************************************************************** - /// Initialises the sequence with a new seed value. - ///\param seed The new seed value. - //*************************************************************************** - void random_clcg::initialise(uint32_t seed) - { - seed = (seed == 0) ? 1 : seed; - value1 = (seed > m1) ? m1 : seed; - value2 = (seed > m1) ? m1 : seed; - } - - //*************************************************************************** - /// Get the next random_clcg number. - //*************************************************************************** - uint32_t random_clcg::operator()() - { - static const uint32_t m = ((m1 > m2) ? m1 : m2); - - value1 = (a1 * value1) % m1; - value2 = (a2 * value2) % m2; - - return (value1 + value2) % m; - } - - //*************************************************************************** - /// Get the next random_clcg number in a specified inclusive range. - //*************************************************************************** - uint32_t random_clcg::range(uint32_t low, uint32_t high) - { - uint32_t r = high - low + 1; - uint32_t n = operator()(); - n %= r; - n += low; - - return n; - } - - //*************************************************************************** - // Linear Shift Feedback Register - //*************************************************************************** - - //*************************************************************************** - /// Default constructor. - /// Attempts to come up with a unique non-zero seed. - //*************************************************************************** - random_lsfr::random_lsfr() - { - // An attempt to come up with a unique non-zero seed, - // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - uint32_t seed = static_cast(n); - initialise(seed); - } - - //*************************************************************************** - /// Constructor with seed value. - ///\param seed The new seed value. - //*************************************************************************** - random_lsfr::random_lsfr(uint32_t seed) - { - initialise(seed); - } - - //*************************************************************************** - /// Initialises the sequence with a new seed value. - ///\param seed The new seed value. - //*************************************************************************** - void random_lsfr::initialise(uint32_t seed) - { - value = seed; - } - - //*************************************************************************** - /// Get the next random_lsfr number. - //*************************************************************************** - uint32_t random_lsfr::operator()() - { - static const uint32_t polynomial = 0x80200003; - - value >>= 1; - - if ((value & 1) == 1) - { - value ^= polynomial; - } - - return value; - } - - //*************************************************************************** - /// Get the next random_lsfr number in a specified inclusive range. - //*************************************************************************** - uint32_t random_lsfr::range(uint32_t low, uint32_t high) - { - uint32_t r = high - low + 1; - uint32_t n = operator()(); - n %= r; - n += low; - - return n; - } - - //*************************************************************************** - // Multiply with carry random number generator. - //*************************************************************************** - - //*************************************************************************** - /// Default constructor. - /// Attempts to come up with a unique non-zero seed. - //*************************************************************************** - random_mwc::random_mwc() - { - // An attempt to come up with a unique non-zero seed, - // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - uint32_t seed = static_cast(n); - initialise(seed); - } - - //*************************************************************************** - /// Constructor with seed value. - ///\param seed The new seed value. - //*************************************************************************** - random_mwc::random_mwc(uint32_t seed) - { - initialise(seed); - } - - //*************************************************************************** - /// Initialises the sequence with a new seed value. - ///\param seed The new seed value. - //*************************************************************************** - void random_mwc::initialise(uint32_t seed) - { - value1 = seed; - value2 = seed; - } - - //*************************************************************************** - /// Get the next random_lsfr number. - //*************************************************************************** - uint32_t random_mwc::operator()() - { - value1 = 36969 * (value1 & 0xFFFF) + (value1 >> 16); - value2 = 18000 * (value2 & 0xFFFF) + (value2 >> 16); - - return (value1 << 16) + value2; - } - - //*************************************************************************** - /// Get the next random_lsfr number in a specified inclusive range. - //*************************************************************************** - uint32_t random_mwc::range(uint32_t low, uint32_t high) - { - uint32_t r = high - low + 1; - uint32_t n = operator()(); - n %= r; - n += low; - - return n; - } - - //*************************************************************************** - // Permuted congruential generator. - //*************************************************************************** - - //*************************************************************************** - /// Default constructor. - /// Attempts to come up with a unique non-zero seed. - //*************************************************************************** - random_pcg::random_pcg() - { - // An attempt to come up with a unique non-zero seed, - // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - value = static_cast(n); - } - - //*************************************************************************** - /// Constructor with seed value. - ///\param seed The new seed value. - //*************************************************************************** - random_pcg::random_pcg(uint32_t seed) - { - initialise(seed); - } - - //*************************************************************************** - /// Initialises the sequence with a new seed value. - ///\param seed The new seed value. - //*************************************************************************** - void random_pcg::initialise(uint32_t seed) - { - value = uint64_t(seed) | (uint64_t(seed) << 32); - } - - //*************************************************************************** - /// Get the next random_lsfr number. - //*************************************************************************** - uint32_t random_pcg::operator()() - { - uint64_t x = value; - unsigned count = (unsigned)(value >> 59); - - value = (x * multiplier) + increment; - x ^= x >> 18; - return etl::rotate_right((uint32_t)(x >> 27), count); - } - - //*************************************************************************** - /// Get the next random_lsfr number in a specified inclusive range. - //*************************************************************************** - uint32_t random_pcg::range(uint32_t low, uint32_t high) - { - uint32_t r = high - low + 1; - uint32_t n = operator()(); - n %= r; - n += low; - - return n; - } -} diff --git a/support/Release notes.txt b/support/Release notes.txt index dca882a5..1005e51b 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.0.0 +The ETL is now 'all header'. + =============================================================================== 13.0.0 Added bit stream serialiser/deserialiser @@ -317,4 +321,4 @@ IO Ports Fixed inconsistencies in the dynamic IO port API. Type traits - Added 'conditional_integral_constant' to complement 'conditional' \ No newline at end of file + Added 'conditional_integral_constant' to complement 'conditional' diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 847415b5..2c10f929 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -317,22 +317,9 @@ - - - - - - - - - - - - - diff --git a/test/test_pearson.cpp b/test/test_pearson.cpp index c4416764..1e08bb1b 100644 --- a/test/test_pearson.cpp +++ b/test/test_pearson.cpp @@ -45,7 +45,25 @@ typedef etl::pearson::value_type hash_t; //*************************************************************************** namespace etl { - extern const uint8_t PEARSON_LOOKUP[]; + static const uint8_t PEARSON_LOOKUP[] = + { + 228, 39, 61, 95, 227, 187, 0, 197, 31, 189, 161, 222, 34, 15, 221, 246, + 19, 234, 6, 50, 113, 3, 91, 63, 77, 245, 144, 2, 183, 196, 25, 226, + 97, 126, 48, 59, 217, 4, 100, 145, 12, 88, 203, 149, 80, 154, 38, 27, + 224, 218, 158, 115, 202, 79, 53, 83, 242, 36, 139, 131, 136, 191, 42, 170, + 23, 99, 156, 51, 143, 60, 233, 206, 62, 108, 17, 67, 81, 71, 93, 195, + 26, 231, 247, 96, 24, 200, 176, 209, 152, 212, 138, 165, 75, 185, 130, 248, + 125, 110, 10, 116, 201, 90, 69, 204, 85, 251, 78, 157, 47, 184, 169, 141, + 134, 230, 89, 21, 146, 46, 55, 128, 148, 207, 216, 11, 114, 199, 103, 102, + 166, 244, 5, 104, 225, 160, 132, 28, 172, 65, 121, 140, 153, 119, 198, 210, + 58, 87, 117, 177, 33, 22, 13, 37, 49, 174, 109, 40, 73, 211, 18, 167, + 164, 252, 168, 74, 30, 173, 35, 98, 66, 193, 94, 175, 86, 54, 179, 122, + 220, 151, 192, 29, 133, 254, 155, 127, 240, 232, 190, 180, 8, 68, 236, 20, + 137, 92, 219, 208, 52, 250, 147, 142, 111, 112, 120, 45, 135, 255, 123, 229, + 57, 182, 243, 124, 186, 253, 7, 237, 9, 16, 70, 171, 235, 107, 223, 118, + 215, 178, 194, 181, 43, 188, 106, 105, 64, 241, 84, 238, 159, 44, 32, 76, + 213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82 + }; } //*************************************************************************** @@ -86,7 +104,7 @@ std::ostream& operator <<(std::ostream& os, const hash_t& hash) } namespace -{ +{ SUITE(test_pearson) { //************************************************************************* diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index 5abed724..e1da66ce 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -556,20 +556,7 @@ - - - - - - - - - - - - - diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 8a2ae5cd..615c99b8 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -1004,39 +1004,6 @@ Source Files - - ETL\Private - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Utilities - - - ETL\Utilities - ECL @@ -1058,9 +1025,6 @@ Source Files - - ETL\Maths - UnitTest++ From fe91a72b82eb837519c03d2d52af1b3d57b7b327 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 17 Nov 2018 09:34:28 +0000 Subject: [PATCH 05/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/version.h # support/Release notes.txt --- include/etl/random.h | 70 ++++++++++++++++++++++++++++++++++++++- include/etl/version.h | 2 +- support/Release notes.txt | 4 +++ test/test_random.cpp | 55 ++++++++++++++++++++++++++++++ test/vs2017/.gitignore | 1 + 5 files changed, 130 insertions(+), 2 deletions(-) diff --git a/include/etl/random.h b/include/etl/random.h index c1523620..cffeb4cc 100644 --- a/include/etl/random.h +++ b/include/etl/random.h @@ -1,4 +1,4 @@ -///\file +///\file /****************************************************************************** The MIT License(MIT) @@ -289,6 +289,7 @@ namespace etl //*************************************************************************** /// A 32 bit random number generator. /// Uses a linear shift feedback register. + /// Polynomial 0x80200003 /// https://en.wikipedia.org/wiki/Linear-feedback_shift_register //*************************************************************************** class random_lsfr : public random @@ -499,6 +500,73 @@ namespace etl uint64_t value; }; + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// A 32 bit random number generator. + /// Applies a user supplied 32bit hash to a counter. + /// The hash must implement 'void add(uint8_t)' and 'uint8_t value()' member functions. + //*************************************************************************** + template + class random_hash : public random + { + public: + + random_hash() + { + // An attempt to come up with a unique non-zero seed, + // based on the address of the instance. + uintptr_t n = reinterpret_cast(this); + value = static_cast(n); + } + + //*************************************************************************** + /// Constructor with seed value. + ///\param seed The new seed value. + //*************************************************************************** + random_hash(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. + //*************************************************************************** + void initialise(uint32_t seed) + { + value = seed; + } + + //*************************************************************************** + /// Get the next random_lsfr number. + //*************************************************************************** + uint32_t operator()() + { + ++value; + hash.add(value); + return hash.value(); + } + + //*************************************************************************** + /// Get the next random_lsfr number in a specified inclusive range. + //*************************************************************************** + uint32_t range(uint32_t low, uint32_t high) + { + uint32_t r = high - low + 1; + uint32_t n = operator()(); + n %= r; + n += low; + + return n; + } + + private: + + THash hash; + uint8_t value; + }; +#endif } #endif diff --git a/include/etl/version.h b/include/etl/version.h index 7b486694..58924e6b 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 0 +#define ETL_VERSION_MINOR 1 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/support/Release notes.txt b/support/Release notes.txt index 1005e51b..d611ac55 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.1.0 +Added hash based random number generator + =============================================================================== 14.0.0 The ETL is now 'all header'. diff --git a/test/test_random.cpp b/test/test_random.cpp index 4166c184..66409a78 100644 --- a/test/test_random.cpp +++ b/test/test_random.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include "etl/random.h" +#include "etl/crc32.h" #include #include @@ -357,5 +358,59 @@ namespace CHECK(n <= high); } } + + //========================================================================= + TEST(test_random_hash_sequence) + { + std::vector out1(10000); + etl::random_hash r; + + struct generator + { + generator(etl::random& r_) + : r(r_) + { + } + + uint32_t operator()() + { + return r(); + } + + etl::random& r; + }; + + std::generate(out1.begin(), out1.end(), generator(r)); + + std::ofstream file("random_hash.csv"); + + if (!file.fail()) + { + for (size_t i = 0; i < out1.size(); i += 2) + { + file << out1[i] << "," << out1[i + 1] << "\n"; + } + } + + file.close(); + } + + //========================================================================= + TEST(test_random_hash_range) + { + etl::random_hash r; + + uint32_t low = 1234; + uint32_t high = 9876; + + for (int i = 0; i < 100000; ++i) + { + uint32_t n = r.range(low, high); + + CHECK(n >= low); + CHECK(n <= high); + } + } + }; } diff --git a/test/vs2017/.gitignore b/test/vs2017/.gitignore index ba0b1b50..e3cb4a54 100644 --- a/test/vs2017/.gitignore +++ b/test/vs2017/.gitignore @@ -4,3 +4,4 @@ /random_mwc.csv /random_xorshift.csv /random_pcg.csv +/random_hash.csv From 60e55535e2ade59e5ad0c046c9bb3608b0695d40 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 25 Nov 2018 16:20:52 +0000 Subject: [PATCH 06/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/version.h # support/Release notes.txt --- include/etl/state_chart.h | 21 ++++++++++++++++--- include/etl/version.h | 2 +- support/Release notes.txt | 4 ++++ test/test_state_chart.cpp | 43 +++++++++++++++++++++++++++++++++------ 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/include/etl/state_chart.h b/include/etl/state_chart.h index ba8badfa..e3a33e29 100644 --- a/include/etl/state_chart.h +++ b/include/etl/state_chart.h @@ -93,7 +93,8 @@ namespace etl const state_id_t next_state_id_, void (TObject::* const action_)() = nullptr, bool (TObject::* const guard_)() = nullptr) - : current_state_id(current_state_id_), + : from_any_state(false), + current_state_id(current_state_id_), event_id(event_id_), next_state_id(next_state_id_), action(action_), @@ -101,6 +102,20 @@ namespace etl { } + transition(const event_id_t event_id_, + const state_id_t next_state_id_, + void (TObject::* const action_)() = nullptr, + bool (TObject::* const guard_)() = nullptr) + : from_any_state(true), + current_state_id(0), + event_id(event_id_), + next_state_id(next_state_id_), + action(action_), + guard(guard_) + { + } + + const bool from_any_state; const state_id_t current_state_id; const event_id_t event_id; const state_id_t next_state_id; @@ -227,7 +242,7 @@ namespace etl } //************************************************************************* - /// + /// //************************************************************************* void start(const bool on_entry_initial = true) { @@ -335,7 +350,7 @@ namespace etl bool operator()(const transition& t) const { - return (t.event_id == event_id) && (t.current_state_id == state_id); + return (t.event_id == event_id) && (t.from_any_state || (t.current_state_id == state_id)); } const event_id_t event_id; diff --git a/include/etl/version.h b/include/etl/version.h index 58924e6b..a2603dde 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 1 +#define ETL_VERSION_MINOR 2 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/support/Release notes.txt b/support/Release notes.txt index d611ac55..f7eab330 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.2.0 +Added 'don't care current state' transition entry option. + =============================================================================== 14.1.0 Added hash based random number generator diff --git a/test/test_state_chart.cpp b/test/test_state_chart.cpp index 2760afd0..504cf4e2 100644 --- a/test/test_state_chart.cpp +++ b/test/test_state_chart.cpp @@ -47,7 +47,8 @@ namespace STOP, EMERGENCY_STOP, STOPPED, - SET_SPEED + SET_SPEED, + ABORT }; ETL_DECLARE_ENUM_TYPE(EventId, etl::istate_chart::event_id_t) @@ -56,6 +57,7 @@ namespace ETL_ENUM_TYPE(EMERGENCY_STOP, "Emergency Stop") ETL_ENUM_TYPE(STOPPED, "Stopped") ETL_ENUM_TYPE(SET_SPEED, "Set Speed") + ETL_ENUM_TYPE(ABORT, "Abort") ETL_END_ENUM_TYPE }; @@ -204,19 +206,20 @@ namespace bool guard; - static const etl::array transitionTable; + static const etl::array transitionTable; static const etl::array stateTable; }; //*************************************************************************** - const etl::array MotorControl::transitionTable = + const etl::array MotorControl::transitionTable = { MotorControl::transition(StateId::IDLE, EventId::START, StateId::RUNNING, &MotorControl::OnStart, &MotorControl::Guard), MotorControl::transition(StateId::IDLE, EventId::START, StateId::IDLE, &MotorControl::Null, &MotorControl::NotGuard), MotorControl::transition(StateId::RUNNING, EventId::STOP, StateId::WINDING_DOWN, &MotorControl::OnStop), MotorControl::transition(StateId::RUNNING, EventId::EMERGENCY_STOP, StateId::IDLE, &MotorControl::OnStop), MotorControl::transition(StateId::RUNNING, EventId::SET_SPEED, StateId::RUNNING, &MotorControl::OnSetSpeed), - MotorControl::transition(StateId::WINDING_DOWN, EventId::STOPPED, StateId::IDLE, &MotorControl::OnStopped) + MotorControl::transition(StateId::WINDING_DOWN, EventId::STOPPED, StateId::IDLE, &MotorControl::OnStopped), + MotorControl::transition( EventId::ABORT, StateId::IDLE) }; //*************************************************************************** @@ -282,7 +285,7 @@ namespace CHECK_EQUAL(0, motorControl.stopCount); CHECK_EQUAL(0, motorControl.stoppedCount); CHECK_EQUAL(0, motorControl.windingDown); - + // Send Start event. motorControl.guard = false; motorControl.process_event(EventId::START); @@ -399,7 +402,7 @@ namespace TEST(test_fsm_emergency_stop) { motorControl.ClearStatistics(); - + // Now in Idle state. // Send Start event. @@ -431,5 +434,33 @@ namespace CHECK_EQUAL(0, motorControl.stoppedCount); CHECK_EQUAL(0, motorControl.windingDown); } + + //************************************************************************* + TEST(test_fsm_abort) + { + motorControl.ClearStatistics(); + + // Now in Idle state. + + // Send Start event. + motorControl.process_event(EventId::START); + + // Now in Running state. + + motorControl.process_event(EventId::ABORT); + CHECK_EQUAL(StateId::IDLE, int(motorControl.get_state_id())); + + // Send Start event. + motorControl.process_event(EventId::START); + + // Now in Running state. + + // Send Stop event. + motorControl.process_event(EventId::STOP); + + // Now in WindingDown state. + motorControl.process_event(EventId::ABORT); + CHECK_EQUAL(StateId::IDLE, int(motorControl.get_state_id())); + } }; } From 6a808895a1e5e0fca0bcf9b4a3d18a446d7184c3 Mon Sep 17 00:00:00 2001 From: TimoKroeger Date: Tue, 27 Nov 2018 20:30:48 +0100 Subject: [PATCH 07/13] Fix CMake build by converting etl to a INTERFACE library (#104) The 14.0 release removed all cpp files --- CMakeLists.txt | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cfbcd7c..901d260e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,23 +15,10 @@ set(ETL_PROFILE "DEFAULT" CACHE STRING "Defines what profile header to include. option(BUILD_TESTS "Build unit tests" OFF) +add_library(etl INTERFACE) -# Note: this will not compile src/c/ecl_timer.c as that c file has a dependence -# on ecl_user.h which is provided by clients of this library -add_library(etl STATIC - src/binary.cpp - src/crc16.cpp - src/crc16_ccitt.cpp - src/crc16_kermit.cpp - src/crc32.cpp - src/crc64_ecma.cpp - src/crc8_ccitt.cpp - src/error_handler.cpp - src/pearson.cpp - src/random.cpp - ) target_include_directories(etl - PUBLIC + INTERFACE include include/etl/profiles ) @@ -60,7 +47,7 @@ endif() message(STATUS "Compiling with ETL profile set to: ${ETL_PROFILE}") target_compile_definitions(etl - PUBLIC + INTERFACE ${ETL_PROFILE} ) From 30520892e1b2a4a593d3c3e53f65412225367b40 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Dec 2018 13:32:38 +0000 Subject: [PATCH 08/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/private/pvoidvector.h # include/etl/version.h # support/Release notes.txt --- include/etl/forward_list.h | 240 +++- include/etl/list.h | 15 +- include/etl/state_chart.h | 4 +- include/etl/version.h | 2 +- support/Release notes.txt | 4 + test/codeblocks/ETL.cbp | 1 + test/test_forward_list.cpp | 5 +- test/test_forward_list_shared_pool.cpp | 1779 ++++++++++++++++++++++++ test/vs2017/etl.vcxproj | 1 + test/vs2017/etl.vcxproj.filters | 3 + 10 files changed, 2033 insertions(+), 21 deletions(-) create mode 100644 test/test_forward_list_shared_pool.cpp diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 2032fdb6..c021e465 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -121,6 +121,20 @@ namespace etl } }; + //*************************************************************************** + /// Unsorted exception for the list. + ///\ingroup list + //*************************************************************************** + class forward_list_no_pool : public forward_list_exception + { + public: + + forward_list_no_pool(string_type file_name_, numeric_type line_number_) + : forward_list_exception(ETL_ERROR_TEXT("list:no pool", ETL_FILE"D"), file_name_, line_number_) + { + } + }; + //*************************************************************************** /// The base class for all forward_lists. ///\ingroup forward_list @@ -146,12 +160,39 @@ namespace etl typedef size_t size_type; ///< The type used for determining the size of forward_list. + //************************************************************************* + /// true if the list has a shared pool. + //************************************************************************* + bool has_shared_pool() const + { + return pool_is_shared; + } + //************************************************************************* /// Gets the size of the forward_list. //************************************************************************* size_type size() const { - return p_node_pool->size(); + if (has_shared_pool()) + { + // We have to count what we actually own. + size_type count = 0; + + node_t* p_node = start_node.next; + + while (p_node != nullptr) + { + ++count; + p_node = p_node->next; + } + + return count; + } + else + { + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool)); + return p_node_pool->size(); + } } //************************************************************************* @@ -167,7 +208,15 @@ namespace etl //************************************************************************* bool empty() const { - return p_node_pool->empty(); + if (has_shared_pool()) + { + return (size() == 0); + } + else + { + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool)); + return p_node_pool->empty(); + } } //************************************************************************* @@ -175,6 +224,7 @@ namespace etl //************************************************************************* bool full() const { + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool)); return p_node_pool->full(); } @@ -184,6 +234,7 @@ namespace etl //************************************************************************* size_t available() const { + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool)); return p_node_pool->available(); } @@ -220,9 +271,20 @@ namespace etl //************************************************************************* /// The constructor that is called from derived classes. //************************************************************************* - forward_list_base(etl::ipool& node_pool_, size_type max_size_) + forward_list_base(bool pool_is_shared_) + : p_node_pool(nullptr), + MAX_SIZE(0), + pool_is_shared(pool_is_shared_) + { + } + + //************************************************************************* + /// The constructor that is called from derived classes. + //************************************************************************* + forward_list_base(etl::ipool& node_pool_, size_type max_size_, bool pool_is_shared_) : p_node_pool(&node_pool_), - MAX_SIZE(max_size_) + MAX_SIZE(max_size_), + pool_is_shared(pool_is_shared_) { } @@ -275,10 +337,28 @@ namespace etl left->next = right; } - node_t start_node; ///< The node that acts as the forward_list start. - etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. - const size_type MAX_SIZE; ///< The maximum size of the forward_list. - ETL_DECLARE_DEBUG_COUNT ///< Internal debugging. + //************************************************************************* + /// Set the node pool instance. + //************************************************************************* + void set_node_pool(etl::ipool& node_pool_) + { + p_node_pool = &node_pool_; + MAX_SIZE = p_node_pool->max_size(); + } + + //************************************************************************* + /// Get the node pool instance. + //************************************************************************* + etl::ipool* get_node_pool() + { + return p_node_pool; + } + + node_t start_node; ///< The node that acts as the forward_list start. + etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. + size_type MAX_SIZE; ///< The maximum size of the forward_list. + bool pool_is_shared; ///< If true then the pool is shared between lists. + ETL_DECLARE_DEBUG_COUNT ///< Internal debugging. }; //*************************************************************************** @@ -1224,8 +1304,16 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - iforward_list(etl::ipool& node_pool, size_t max_size_) - : forward_list_base(node_pool, max_size_) + iforward_list(bool pool_is_shared_) + : forward_list_base(pool_is_shared_) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + iforward_list(etl::ipool& node_pool, size_t max_size_, bool pool_is_shared_) + : forward_list_base(node_pool, max_size_, pool_is_shared_) { } @@ -1236,8 +1324,9 @@ namespace etl { if (!empty()) { - if ETL_IF_CONSTEXPR(etl::is_trivially_destructible::value) + if (etl::is_trivially_destructible::value && !has_shared_pool()) { + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool)); p_node_pool->release_all(); ETL_RESET_DEBUG_COUNT } @@ -1376,7 +1465,7 @@ namespace etl /// Default constructor. //************************************************************************* forward_list() - : etl::iforward_list(node_pool, MAX_SIZE) + : etl::iforward_list(node_pool, MAX_SIZE, false) { this->initialise(); } @@ -1385,7 +1474,7 @@ namespace etl /// Construct from size and value. //************************************************************************* explicit forward_list(size_t initial_size, typename etl::iforward_list::parameter_t value = T()) - : etl::iforward_list(node_pool, MAX_SIZE) + : etl::iforward_list(node_pool, MAX_SIZE, false) { this->assign(initial_size, value); } @@ -1394,7 +1483,7 @@ namespace etl /// Copy constructor. //************************************************************************* forward_list(const forward_list& other) - : etl::iforward_list(node_pool, MAX_SIZE) + : etl::iforward_list(node_pool, MAX_SIZE, false) { this->assign(other.cbegin(), other.cend()); } @@ -1404,7 +1493,7 @@ namespace etl //************************************************************************* template forward_list(TIterator first, TIterator last) - : etl::iforward_list(node_pool, MAX_SIZE) + : etl::iforward_list(node_pool, MAX_SIZE, false) { this->assign(first, last); } @@ -1414,7 +1503,7 @@ namespace etl /// Construct from initializer_list. //************************************************************************* forward_list(std::initializer_list init) - : etl::iforward_list(node_pool, MAX_SIZE) + : etl::iforward_list(node_pool, MAX_SIZE, false) { this->assign(init.begin(), init.end()); } @@ -1446,6 +1535,125 @@ namespace etl /// The pool of nodes used in the list. etl::pool::data_node_t, MAX_SIZE> node_pool; }; + + //************************************************************************* + /// A templated forward_list implementation that uses a fixed size pool. + ///\note 'merge' and 'splice_after' and are not supported. + //************************************************************************* + template + class forward_list : public etl::iforward_list + { + public: + + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef size_t size_type; + + typedef typename etl::iforward_list::data_node_t pool_type; + + //************************************************************************* + /// Default constructor. + //************************************************************************* + forward_list() + : etl::iforward_list(true) + { + } + + //************************************************************************* + /// Default constructor. + //************************************************************************* + explicit forward_list(etl::ipool& node_pool) + : etl::iforward_list(node_pool, node_pool.max_size(), true) + { + this->initialise(); + } + + //************************************************************************* + /// Construct from size. + //************************************************************************* + explicit forward_list(size_t initial_size, etl::ipool& node_pool) + : etl::iforward_list(node_pool, node_pool.max_size(), true) + { + this->assign(initial_size, T()); + } + + //************************************************************************* + /// Construct from size and value. + //************************************************************************* + explicit forward_list(size_t initial_size, typename etl::iforward_list::parameter_t value, etl::ipool& node_pool) + : etl::iforward_list(node_pool, node_pool.max_size(), true) + { + this->assign(initial_size, value); + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + forward_list(const forward_list& other) + : etl::iforward_list(*other.p_node_pool, other.p_node_pool->max_size(), true) + { + this->assign(other.cbegin(), other.cend()); + } + + //************************************************************************* + /// Construct from range. + //************************************************************************* + template + forward_list(TIterator first, TIterator last, etl::ipool& node_pool) + : etl::iforward_list(node_pool, node_pool.max_size(), true) + { + this->assign(first, last); + } + +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + forward_list(std::initializer_list init, etl::ipool& node_pool) + : etl::iforward_list(node_pool, node_pool.max_size(), true) + { + this->assign(init.begin(), init.end()); + } +#endif + + //************************************************************************* + /// Destructor. + //************************************************************************* + ~forward_list() + { + this->initialise(); + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + forward_list& operator = (const forward_list& rhs) + { + if (&rhs != this) + { + this->assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + + //************************************************************************* + /// Set the pool instance. + //************************************************************************* + void set_pool(etl::ipool& pool) + { + // Clear the list of any current elements. + if (this->get_node_pool() != nullptr) + { + this->clear(); + } + + this->set_node_pool(pool); + } + }; } //************************************************************************* diff --git a/include/etl/list.h b/include/etl/list.h index eebc9c06..a9c8ca63 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -382,6 +382,14 @@ namespace etl MAX_SIZE = p_node_pool->max_size(); } + //************************************************************************* + /// Get the node pool instance. + //************************************************************************* + etl::ipool* get_node_pool() + { + return p_node_pool; + } + //************************************************************************* /// Destructor. //************************************************************************* @@ -1889,6 +1897,12 @@ namespace etl //************************************************************************* void set_pool(etl::ipool& pool) { + // Clear the list of any current elements. + if (this->get_node_pool() != nullptr) + { + this->clear(); + } + this->set_node_pool(pool); } }; @@ -1973,7 +1987,6 @@ bool operator >=(const etl::ilist& lhs, const etl::ilist& rhs) return !(lhs < rhs); } - #include "private/minmax_pop.h" #undef ETL_FILE diff --git a/include/etl/state_chart.h b/include/etl/state_chart.h index e3a33e29..4602a882 100644 --- a/include/etl/state_chart.h +++ b/include/etl/state_chart.h @@ -313,6 +313,8 @@ namespace etl (object.*(s->on_exit))(); } + current_state_id = next_state_id; + // See if we have a state item for the next state. s = find_state(next_state_id); @@ -321,8 +323,6 @@ namespace etl { (object.*(s->on_entry))(); } - - current_state_id = next_state_id; } t = transition_table.end(); diff --git a/include/etl/version.h b/include/etl/version.h index a2603dde..d734bab6 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 2 +#define ETL_VERSION_MINOR 3 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/support/Release notes.txt b/support/Release notes.txt index f7eab330..0ba6ff69 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.3.0 +etl::forward_list supports shared pools. + =============================================================================== 14.2.0 Added 'don't care current state' transition entry option. diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 2c10f929..9bed99f1 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -361,6 +361,7 @@ + diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 41884fd4..c63e8e44 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -185,7 +185,7 @@ namespace TEST_FIXTURE(SetupFixture, test_const_iterator) { CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC data(compare_data.begin(), compare_data.end()); + const DataNDC data(compare_data.begin(), compare_data.end()); are_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin()); @@ -1110,6 +1110,7 @@ namespace data.move_after(i_first_before, i_last, i_to_before); are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK(are_equal); // Move to nearby. i_first_before = data.begin(); @@ -1134,6 +1135,7 @@ namespace data.move_after(i_first_before, i_last, i_to_before); are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK(are_equal); // Move to same. i_first_before = data.begin(); @@ -1158,6 +1160,7 @@ namespace data.move_after(i_first_before, i_last, i_to_before); are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK(are_equal); // Move to illegal place. i_first_before = data.begin(); diff --git a/test/test_forward_list_shared_pool.cpp b/test/test_forward_list_shared_pool.cpp new file mode 100644 index 00000000..bb4a13d9 --- /dev/null +++ b/test/test_forward_list_shared_pool.cpp @@ -0,0 +1,1779 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 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++.h" +#include "ExtraCheckMacros.h" + +#include "data.h" + +#include "etl/forward_list.h" + +#include +#include +#include +#include +#include +#include + +namespace +{ + SUITE(test_forward_list) + { + const size_t SIZE = 20; + + typedef TestDataDC ItemDC; + typedef TestDataNDC ItemNDC; + + typedef etl::forward_list DataDC; + typedef etl::forward_list DataNDC; + typedef etl::iforward_list IDataNDC; + + typedef etl::forward_list DataInt; + + typedef std::forward_list CompareDataDC; + typedef std::forward_list CompareDataNDC; + typedef std::vector InitialDataNDC; + + typedef etl::pool PoolInt2; + + typedef etl::pool PoolDC; + typedef etl::pool PoolDC2; + typedef etl::pool PoolDC4; + + typedef etl::pool PoolNDC; + typedef etl::pool PoolNDC2; + typedef etl::pool PoolNDC4; + + InitialDataNDC stable_sort_data; + InitialDataNDC unsorted_data; + InitialDataNDC sorted_data; + InitialDataNDC non_unique_data; + InitialDataNDC small_data; + + bool are_equal; + + //************************************************************************* + struct SetupFixture + { + SetupFixture() + { + stable_sort_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) }; + unsorted_data = { ItemNDC("1"), ItemNDC("0"), ItemNDC("3"), ItemNDC("2"), ItemNDC("5"), ItemNDC("4"), ItemNDC("7"), ItemNDC("6"), ItemNDC("9"), ItemNDC("8") }; + sorted_data = { ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3"), ItemNDC("4"), ItemNDC("5"), ItemNDC("6"), ItemNDC("7"), ItemNDC("8"), ItemNDC("9") }; + non_unique_data = { ItemNDC("0"), ItemNDC("0"), ItemNDC("1"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3"), ItemNDC("3"), ItemNDC("3"), ItemNDC("4"), ItemNDC("5") }; + small_data = { ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3"), ItemNDC("4"), ItemNDC("5") }; + } + }; + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor) + { + PoolDC pool; + DataDC data(pool); + + CHECK(data.empty()); + CHECK_EQUAL(data.max_size(), SIZE); + CHECK(data.begin() == data.end()); + CHECK(data.has_shared_pool()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_no_pool_exception) + { + DataNDC data; + + CHECK_THROW(data.push_front(ItemNDC("1")), etl::forward_list_no_pool); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size) + { + PoolDC pool; + const size_t INITIAL_SIZE = 4; + DataDC data1(INITIAL_SIZE, pool); + DataDC data2(INITIAL_SIZE, pool); + + CHECK(!data1.empty()); + CHECK(!data2.empty()); + CHECK_EQUAL(INITIAL_SIZE, data1.size()); + CHECK_EQUAL(INITIAL_SIZE, data2.size()); + CHECK_EQUAL((2 * INITIAL_SIZE), pool.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_excess) + { + PoolDC pool; + CHECK_THROW(DataDC data(SIZE + 1, pool), etl::forward_list_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_value) + { + PoolNDC pool; + const size_t INITIAL_SIZE = 4; + const ItemNDC INITIAL_VALUE("1"); + + std::array compare_data = { ItemNDC("1"), ItemNDC("1"), ItemNDC("1"), ItemNDC("1") }; + + DataNDC data1(INITIAL_SIZE, INITIAL_VALUE, pool); + DataNDC data2(INITIAL_SIZE, INITIAL_VALUE, pool); + + CHECK(!data1.empty()); + CHECK(!data2.empty()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_range) + { + PoolNDC pool; + CompareDataNDC compare(sorted_data.begin(), sorted_data.end()); + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + CHECK(!data1.empty()); + CHECK(!data2.empty()); + + are_equal = std::equal(data1.begin(), data1.end(), compare.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + PoolNDC pool; + CompareDataNDC compare = { ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3") }; + DataNDC data1({ ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3") }, pool); + DataNDC data2({ ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3") }, pool); + + CHECK(!data1.empty()); + CHECK(!data2.empty()); + + are_equal = std::equal(data1.begin(), data1.end(), compare.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST(test_destruct_via_iforward_list) + { + PoolNDC pool; + int current_count = ItemNDC::get_instance_count(); + + DataNDC* pdata1 = new DataNDC(sorted_data.begin(), sorted_data.end(), pool); + CHECK_EQUAL(int(current_count + sorted_data.size()), ItemNDC::get_instance_count()); + + DataNDC* pdata2 = new DataNDC(sorted_data.begin(), sorted_data.end(), pool); + CHECK_EQUAL(int(current_count + sorted_data.size() + sorted_data.size()), ItemNDC::get_instance_count()); + + IDataNDC* pidata1 = pdata1; + delete pidata1; + CHECK_EQUAL(current_count + sorted_data.size(), uint32_t(ItemNDC::get_instance_count())); + + IDataNDC* pidata2 = pdata2; + delete pidata2; + CHECK_EQUAL(current_count, ItemNDC::get_instance_count()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor) + { + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(unsorted_data.begin(), unsorted_data.end(), pool); + DataNDC other_data1(data1); + DataNDC other_data2(data2); + + CHECK(std::equal(data1.begin(), data1.end(), other_data1.begin())); + CHECK(std::equal(data2.begin(), data2.end(), other_data2.begin())); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_iterator) + { + PoolNDC2 pool; + + CompareDataNDC compare_data1(sorted_data.begin(), sorted_data.end()); + CompareDataNDC compare_data2(unsorted_data.begin(), unsorted_data.end()); + DataNDC data1(compare_data1.begin(), compare_data1.end(), pool); + DataNDC data2(compare_data2.begin(), compare_data2.end(), pool); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_iterator) + { + PoolNDC2 pool; + + CompareDataNDC compare_data1(sorted_data.begin(), sorted_data.end()); + CompareDataNDC compare_data2(unsorted_data.begin(), unsorted_data.end()); + const DataNDC data1(compare_data1.begin(), compare_data1.end(), pool); + const DataNDC data2(compare_data2.begin(), compare_data2.end(), pool); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_up) + { + PoolNDC2 pool; + + const size_t INITIAL_SIZE = 4; + const size_t NEW_SIZE = 8; + const ItemDC VALUE1("1"); + const ItemDC VALUE2("2"); + + DataDC data1(INITIAL_SIZE, VALUE1, pool); + data1.resize(NEW_SIZE); + + DataDC data2(INITIAL_SIZE, VALUE2, pool); + data2.resize(NEW_SIZE); + + CompareDataDC compare_data1(INITIAL_SIZE, VALUE1); + compare_data1.resize(NEW_SIZE); + + CompareDataDC compare_data2(INITIAL_SIZE, VALUE2); + compare_data2.resize(NEW_SIZE); + + CHECK_EQUAL(size_t(std::distance(compare_data1.begin(), compare_data1.end())), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare_data2.begin(), compare_data2.end())), data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_up_value) + { + PoolNDC2 pool; + + const size_t INITIAL_SIZE = 4; + const size_t NEW_SIZE = 8; + const ItemNDC VALUE1("1"); + const ItemNDC VALUE2("2"); + + DataNDC data1(INITIAL_SIZE, VALUE1, pool); + data1.resize(NEW_SIZE, VALUE1); + + DataNDC data2(INITIAL_SIZE, VALUE2, pool); + data2.resize(NEW_SIZE, VALUE2); + + CompareDataNDC compare_data1(INITIAL_SIZE, VALUE1); + compare_data1.resize(NEW_SIZE, VALUE1); + + CompareDataNDC compare_data2(INITIAL_SIZE, VALUE2); + compare_data2.resize(NEW_SIZE, VALUE2); + + CHECK_EQUAL(size_t(std::distance(compare_data1.begin(), compare_data1.end())), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare_data2.begin(), compare_data2.end())), data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_excess) + { + PoolNDC2 pool; + + const size_t INITIAL_SIZE = 4; + DataDC data1(INITIAL_SIZE, pool); + DataDC data2(INITIAL_SIZE, pool); + + CHECK_THROW(data1.resize(data1.max_size() + 1), etl::forward_list_full); + CHECK_THROW(data2.resize(data2.max_size() + 1), etl::forward_list_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_down) + { + PoolNDC2 pool; + + const size_t INITIAL_SIZE = 4; + const size_t NEW_SIZE = 2; + const ItemDC VALUE1("1"); + const ItemDC VALUE2("2"); + + DataDC data1(INITIAL_SIZE, VALUE1, pool); + data1.resize(NEW_SIZE); + + DataDC data2(INITIAL_SIZE, VALUE2, pool); + data2.resize(NEW_SIZE); + + CompareDataDC compare_data1(INITIAL_SIZE, VALUE1); + compare_data1.resize(NEW_SIZE, VALUE1); + + CompareDataDC compare_data2(INITIAL_SIZE, VALUE2); + compare_data2.resize(NEW_SIZE, VALUE2); + + CHECK_EQUAL(size_t(std::distance(compare_data1.begin(), compare_data1.end())), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare_data2.begin(), compare_data2.end())), data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_down_value) + { + PoolNDC2 pool; + const size_t INITIAL_SIZE = 4; + const size_t NEW_SIZE = 2; + const ItemNDC VALUE1("1"); + const ItemNDC VALUE2("2"); + + DataNDC data1(INITIAL_SIZE, VALUE1, pool); + data1.resize(NEW_SIZE, VALUE1); + + DataNDC data2(INITIAL_SIZE, VALUE2, pool); + data2.resize(NEW_SIZE, VALUE2); + + CompareDataNDC compare_data1(INITIAL_SIZE, VALUE1); + compare_data1.resize(NEW_SIZE, VALUE1); + + CompareDataNDC compare_data2(INITIAL_SIZE, VALUE2); + compare_data2.resize(NEW_SIZE, VALUE2); + + CHECK_EQUAL(size_t(std::distance(compare_data1.begin(), compare_data1.end())), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare_data2.begin(), compare_data2.end())), data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_clear) + { + PoolNDC2 pool; + + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + data1.clear(); + CHECK(data1.empty()); + CHECK(!data2.empty()); + + data2.clear(); + CHECK(data1.empty()); + CHECK(data2.empty()); + + // Do it again to check that clear() didn't screw up the internals. + data1.assign(sorted_data.begin(), sorted_data.end()); + CHECK_EQUAL(sorted_data.size(), data1.size()); + data2.assign(sorted_data.begin(), sorted_data.end()); + CHECK_EQUAL(sorted_data.size(), data2.size()); + data1.clear(); + CHECK_EQUAL(size_t(0), data1.size()); + data2.clear(); + CHECK_EQUAL(size_t(0), data2.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_clear_pod) + { + PoolInt2 pool; + DataInt data1(SIZE, 1, pool); + DataInt data2(SIZE, 2, pool); + + data1.clear(); + CHECK(data1.empty()); + CHECK(!data2.empty()); + + data2.clear(); + CHECK(data1.empty()); + CHECK(data2.empty()); + + // Do it again to check that clear() didn't screw up the internals. + data1.resize(SIZE); + CHECK_EQUAL(SIZE, data1.size()); + data1.clear(); + CHECK_EQUAL(size_t(0), data1.size()); + + data2.resize(SIZE); + CHECK_EQUAL(SIZE, data2.size()); + data2.clear(); + CHECK_EQUAL(size_t(0), data2.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range) + { + PoolNDC2 pool; + DataNDC data1(SIZE, ItemNDC("1"), pool); + DataNDC data2(SIZE, ItemNDC("2"), pool); + + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + + // Do it twice. We should only get one copy. + data1.assign(compare_data.begin(), compare_data.end()); + data1.assign(compare_data.begin(), compare_data.end()); + + data2.assign(compare_data.begin(), compare_data.end()); + data2.assign(compare_data.begin(), compare_data.end()); + + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_size_value) + { + const size_t INITIAL_SIZE = 4; + const ItemNDC VALUE0("0"); + const ItemNDC VALUE1("1"); + const ItemNDC VALUE2("2"); + + PoolNDC2 pool; + DataNDC data1(SIZE, VALUE0, pool); + DataNDC data2(SIZE, VALUE0, pool); + + CompareDataNDC compare_data1(INITIAL_SIZE, VALUE1); + CompareDataNDC compare_data2(INITIAL_SIZE, VALUE2); + + // Do it twice. We should only get one copy. + data1.assign(INITIAL_SIZE, VALUE1); + data1.assign(INITIAL_SIZE, VALUE1); + + data2.assign(INITIAL_SIZE, VALUE2); + data2.assign(INITIAL_SIZE, VALUE2); + + CHECK_EQUAL(size_t(std::distance(compare_data1.begin(), compare_data1.end())), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare_data2.begin(), compare_data2.end())), data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) + { + const ItemNDC VALUE("1"); + + PoolNDC pool; + DataNDC data(pool); + + CHECK_THROW(data.assign(data.max_size() + 1, VALUE), etl::forward_list_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_after_position_value) + { + const size_t INITIAL_SIZE = 4; + const ItemNDC VALUE("1"); + const ItemNDC INSERT_VALUE("2"); + + CompareDataNDC compare_data(INITIAL_SIZE, VALUE); + + PoolNDC2 pool; + DataNDC data1(INITIAL_SIZE, VALUE, pool); + DataNDC data2(INITIAL_SIZE, VALUE, pool); + + size_t offset = 2; + + DataNDC::iterator i_data1 = data1.begin(); + std::advance(i_data1, offset); + + DataNDC::iterator i_data2 = data2.begin(); + std::advance(i_data2, offset); + + CompareDataNDC::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, offset); + + data1.insert_after(i_data1, INSERT_VALUE); + data2.insert_after(i_data2, INSERT_VALUE); + compare_data.insert_after(i_compare_data, INSERT_VALUE); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + offset = 0; + + i_data1 = data1.begin(); + std::advance(i_data1, offset); + + i_data2 = data2.begin(); + std::advance(i_data2, offset); + + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, offset); + + data1.insert_after(i_data1, INSERT_VALUE); + data2.insert_after(i_data2, INSERT_VALUE); + compare_data.insert_after(i_compare_data, INSERT_VALUE); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_after_position_size_value) + { + const size_t INITIAL_SIZE = 4; + const ItemNDC VALUE("1"); + const ItemNDC INSERT_VALUE("2"); + + CompareDataNDC compare_data(INITIAL_SIZE, VALUE); + PoolNDC2 pool; + DataNDC data1(INITIAL_SIZE, VALUE, pool); + DataNDC data2(INITIAL_SIZE, VALUE, pool); + + size_t offset = 2; + + DataNDC::iterator i_data1 = data1.begin(); + std::advance(i_data1, offset); + + DataNDC::iterator i_data2 = data2.begin(); + std::advance(i_data2, offset); + + CompareDataNDC::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, offset); + + data1.insert_after(i_data1, 2, INSERT_VALUE); + data2.insert_after(i_data2, 2, INSERT_VALUE); + compare_data.insert_after(i_compare_data, 2, INSERT_VALUE); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + offset = 0; + + i_data1 = data1.begin(); + std::advance(i_data1, offset); + + i_data2 = data2.begin(); + std::advance(i_data2, offset); + + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, offset); + + data1.insert_after(i_data1, 2, INSERT_VALUE); + data2.insert_after(i_data2, 2, INSERT_VALUE); + compare_data.insert_after(i_compare_data, 2, INSERT_VALUE); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_after_range) + { + std::vector test1 = { ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3"), ItemNDC("4") }; + std::vector test2 = { ItemNDC("5"), ItemNDC("6"), ItemNDC("7"), ItemNDC("8"), ItemNDC("9") }; + + CompareDataNDC compare_data(test1.begin(), test1.end()); + PoolNDC2 pool; + DataNDC data1(test1.begin(), test1.end(), pool); + DataNDC data2(test1.begin(), test1.end(), pool); + + compare_data.insert_after(compare_data.before_begin(), test2.begin(), test2.end()); + data1.insert_after(data1.before_begin(), test2.begin(), test2.end()); + data2.insert_after(data2.before_begin(), test2.begin(), test2.end()); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + compare_data.assign(test1.begin(), test1.end()); + data1.assign(test1.begin(), test1.end()); + data2.assign(test1.begin(), test1.end()); + + CompareDataNDC::iterator icd = compare_data.begin(); + DataNDC::iterator id1 = data1.begin(); + DataNDC::iterator id2 = data2.begin(); + + std::advance(icd, 3); + std::advance(id1, 3); + std::advance(id2, 3); + + compare_data.insert_after(icd, test2.begin(), test2.end()); + data1.insert_after(id1, test2.begin(), test2.end()); + data2.insert_after(id2, test2.begin(), test2.end()); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_push_front) + { + CompareDataNDC compare_data; + PoolNDC2 pool; + DataNDC data1(pool); + DataNDC data2(pool); + + compare_data.push_front(ItemNDC("1")); + compare_data.push_front(ItemNDC("2")); + compare_data.push_front(ItemNDC("3")); + compare_data.push_front(ItemNDC("4")); + compare_data.push_front(ItemNDC("5")); + compare_data.push_front(ItemNDC("6")); + + CHECK_NO_THROW(data1.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("2"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("3"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("4"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("5"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("6"))); + + CHECK_NO_THROW(data2.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("2"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("3"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("4"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("5"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("6"))); + + CHECK_EQUAL(6U, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + CHECK_EQUAL(6U, data2.size()); + CHECK_EQUAL(6, std::distance(data2.begin(), data2.end())); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size()); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_front) + { + CompareDataNDC compare_data; + PoolNDC2 pool; + DataNDC data1(pool); + DataNDC data2(pool); + + compare_data.emplace_front("1"); + compare_data.emplace_front("2"); + compare_data.emplace_front("3"); + compare_data.emplace_front("4"); + compare_data.emplace_front("5"); + compare_data.emplace_front("6"); + + CHECK_NO_THROW(data1.emplace_front("1")); + CHECK_NO_THROW(data1.emplace_front("2")); + CHECK_NO_THROW(data1.emplace_front("3")); + CHECK_NO_THROW(data1.emplace_front("4")); + CHECK_NO_THROW(data1.emplace_front("5")); + CHECK_NO_THROW(data1.emplace_front("6")); + + CHECK_NO_THROW(data2.emplace_front("1")); + CHECK_NO_THROW(data2.emplace_front("2")); + CHECK_NO_THROW(data2.emplace_front("3")); + CHECK_NO_THROW(data2.emplace_front("4")); + CHECK_NO_THROW(data2.emplace_front("5")); + CHECK_NO_THROW(data2.emplace_front("6")); + + CHECK_EQUAL(6U, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + CHECK_EQUAL(6U, data2.size()); + CHECK_EQUAL(6, std::distance(data2.begin(), data2.end())); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size()); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_after) + { + CompareDataNDC compare_data; + PoolNDC2 pool; + DataNDC data1(pool); + DataNDC data2(pool); + + CompareDataNDC::iterator itc; + + itc = compare_data.before_begin(); + compare_data.emplace_after(itc, "1"); + compare_data.emplace_after(itc, "2"); + + ++itc; + compare_data.emplace_after(itc, "3"); + compare_data.emplace_after(itc, "4"); + + ++itc; + compare_data.emplace_after(itc, "5"); + compare_data.emplace_after(itc, "6"); + + DataNDC::iterator itd1; + DataNDC::iterator itd2; + + itd1 = data1.before_begin(); + itd2 = data2.before_begin(); + CHECK_NO_THROW(data1.emplace_after(itd1, "1")); + CHECK_NO_THROW(data1.emplace_after(itd1, "2")); + CHECK_NO_THROW(data2.emplace_after(itd2, "1")); + CHECK_NO_THROW(data2.emplace_after(itd2, "2")); + + ++itd1; + ++itd2; + CHECK_NO_THROW(data1.emplace_after(itd1, "3")); + CHECK_NO_THROW(data1.emplace_after(itd1, "4")); + CHECK_NO_THROW(data2.emplace_after(itd2, "3")); + CHECK_NO_THROW(data2.emplace_after(itd2, "4")); + + ++itd1; + ++itd2; + CHECK_NO_THROW(data1.emplace_after(itd1, "5")); + CHECK_NO_THROW(data1.emplace_after(itd1, "6")); + CHECK_NO_THROW(data2.emplace_after(itd2, "5")); + CHECK_NO_THROW(data2.emplace_after(itd2, "6")); + + CHECK_EQUAL(6U, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + CHECK_EQUAL(6U, data2.size()); + CHECK_EQUAL(6, std::distance(data2.begin(), data2.end())); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size()); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_front_const) + { + PoolNDC2 pool; + const DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + const DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + CHECK_EQUAL(ItemNDC("0"), data1.front()); + CHECK_EQUAL(ItemNDC("0"), data2.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_before_begin_const) + { + PoolNDC2 pool; + const DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + const DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::const_iterator itr1 = data1.before_begin(); + ++itr1; + + DataNDC::const_iterator itr2 = data2.before_begin(); + ++itr2; + + are_equal = std::equal(data1.begin(), data1.end(), itr1); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), itr2); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_push_front_excess) + { + PoolNDC pool; + DataNDC data1(pool); + DataNDC data2(pool); + + CHECK_NO_THROW(data1.push_front(ItemNDC("0"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("2"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("3"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("4"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("5"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("6"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("7"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("8"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("9"))); + + CHECK_NO_THROW(data2.push_front(ItemNDC("0"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("2"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("3"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("4"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("5"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("6"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("7"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("8"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("9"))); + + CHECK_THROW(data1.push_front(ItemNDC("10")), etl::forward_list_full); + CHECK_THROW(data2.push_front(ItemNDC("10")), etl::forward_list_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_push_front_pop_front) + { + PoolNDC pool; + DataNDC data1(pool); + DataNDC data2(pool); + + for (size_t i = 0; i < 2 * data1.max_size(); ++i) + { + CHECK_NO_THROW(data1.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("2"))); + data1.pop_front(); + data2.pop_front(); + } + + CHECK(data1.empty()); + CHECK(data2.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_pop_front_empty) + { + PoolNDC pool; + DataNDC data1(pool); + DataNDC data2(pool); + + CHECK_NO_THROW(data1.push_front(ItemNDC("0"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("2"))); + CHECK_NO_THROW(data1.push_front(ItemNDC("3"))); + + CHECK_NO_THROW(data2.push_front(ItemNDC("0"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("1"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("2"))); + CHECK_NO_THROW(data2.push_front(ItemNDC("3"))); + + data1.pop_front(); + data1.pop_front(); + data1.pop_front(); + data1.pop_front(); + + data2.pop_front(); + data2.pop_front(); + data2.pop_front(); + data2.pop_front(); + + CHECK_THROW(data1.pop_front(), etl::forward_list_empty); + CHECK_THROW(data2.pop_front(), etl::forward_list_empty); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_after_single) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::iterator i_data1 = data1.begin(); + std::advance(i_data1, 2); + + DataNDC::iterator i_data2 = data2.begin(); + std::advance(i_data2, 2); + + CompareDataNDC::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 2); + + i_compare_data = compare_data.erase_after(i_compare_data); + i_data1 = data1.erase_after(i_data1); + i_data2 = data2.erase_after(i_data2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + CHECK(*i_compare_data == *i_data1); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + CHECK(*i_compare_data == *i_data2); + + i_compare_data = compare_data.erase_after(compare_data.begin()); + i_data1 = data1.erase_after(data1.begin()); + i_data2 = data2.erase_after(data2.begin()); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = *i_data1 == *i_compare_data; + CHECK(are_equal); + + are_equal = *i_data2 == *i_compare_data; + CHECK(are_equal); + + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + //std::advance(i_compare_data, compare_data.size() - 1); + i_compare_data = compare_data.erase_after(i_compare_data); + + i_data1 = data1.begin(); + i_data2 = data2.begin(); + //std::advance(i_data, data.size() - 1); + i_data1 = data1.erase_after(i_data1); + i_data2 = data2.erase_after(i_data2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = *i_data1 == *i_compare_data; + CHECK(are_equal); + + are_equal = *i_data2 == *i_compare_data; + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_after_range) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::iterator i_data1_1 = data1.begin(); + std::advance(i_data1_1, 2); + + DataNDC::iterator i_data1_2 = data1.begin(); + std::advance(i_data1_2, 4); + + DataNDC::iterator i_data2_1 = data2.begin(); + std::advance(i_data2_1, 2); + + DataNDC::iterator i_data2_2 = data2.begin(); + std::advance(i_data2_2, 4); + + CompareDataNDC::iterator i_compare_data_1 = compare_data.begin(); + std::advance(i_compare_data_1, 2); + + CompareDataNDC::iterator i_compare_data_2 = compare_data.begin(); + std::advance(i_compare_data_2, 4); + + CompareDataNDC::iterator i_compare_result = compare_data.erase_after(i_compare_data_1, i_compare_data_2); + + DataNDC::iterator i_result1 = data1.erase_after(i_data1_1, i_data1_2); + DataNDC::iterator i_result2 = data2.erase_after(i_data2_1, i_data2_2); + + CHECK_EQUAL(*i_compare_result, *i_result1); + CHECK_EQUAL(*i_compare_result, *i_result2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_after_range_end) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::iterator i_data1 = data1.begin(); + std::advance(i_data1, 4); + + DataNDC::iterator i_data2 = data2.begin(); + std::advance(i_data2, 4); + + CompareDataNDC::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 4); + + compare_data.erase_after(i_compare_data, compare_data.end()); + + DataNDC::iterator i_result1 = data1.erase_after(i_data1, data1.end()); + DataNDC::iterator i_result2 = data2.erase_after(i_data2, data2.end()); + + CHECK(i_result1 == data1.end()); + CHECK(i_result2 == data2.end()); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_after_all) + { + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + data1.erase_after(data1.before_begin(), data1.end()); + + CHECK(data1.empty()); + CHECK(!data2.empty()); + + data2.erase_after(data2.before_begin(), data2.end()); + + CHECK(data1.empty()); + CHECK(data2.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_front) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + CHECK_EQUAL(compare_data.front(), data1.front()); + CHECK_EQUAL(compare_data.front(), data2.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC4 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + DataNDC other_data1(pool); + DataNDC other_data2(pool); + + other_data1 = data1; + other_data2 = data2; + + CHECK_EQUAL(data1.size(), other_data1.size()); + CHECK_EQUAL(data2.size(), other_data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), other_data1.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), other_data2.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(pool); + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), data1.end(), data2.begin()); + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC other_data(data1); + + other_data = other_data; + + CHECK_EQUAL(data1.size(), other_data.size()); + + are_equal = std::equal(data1.begin(), data1.end(), other_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_unique_empty) + { + CompareDataNDC compare_data; + PoolNDC2 pool; + DataNDC data1(pool); + DataNDC data2(pool); + + compare_data.unique(); + data1.unique(); + data2.unique(); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_unique) + { + CompareDataNDC compare_data(non_unique_data.begin(), non_unique_data.end()); + PoolNDC2 pool; + DataNDC data1(non_unique_data.begin(), non_unique_data.end(), pool); + DataNDC data2(non_unique_data.begin(), non_unique_data.end(), pool); + + compare_data.unique(); + data1.unique(); + data2.unique(); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_remove) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + compare_data.remove(ItemNDC("7")); + data1.remove(ItemNDC("7")); + data2.remove(ItemNDC("7")); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_remove_if) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + compare_data.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); + data1.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); + data2.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_reverse) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + compare_data.reverse(); + data1.reverse(); + data2.reverse(); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); + CHECK_EQUAL(data1.size(), size_t(std::distance(data1.begin(), data1.end()))); + + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size()); + CHECK_EQUAL(data2.size(), size_t(std::distance(data2.begin(), data2.end()))); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_reverse_empty) + { + CompareDataNDC compare_data; + PoolNDC2 pool; + DataNDC data1(pool); + DataNDC data2(pool); + + compare_data.reverse(); + data1.reverse(); + data2.reverse(); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_sort) + { + CompareDataNDC compare_data(unsorted_data.begin(), unsorted_data.end()); + PoolNDC2 pool; + DataNDC data1(unsorted_data.begin(), unsorted_data.end(), pool); + DataNDC data2(unsorted_data.begin(), unsorted_data.end(), pool); + + compare_data.sort(); + data1.sort(); + data2.sort(); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_stable_sort) + { + std::list compare_data(stable_sort_data.begin(), stable_sort_data.end()); + PoolNDC2 pool; + DataNDC data1(stable_sort_data.begin(), stable_sort_data.end(), pool); + DataNDC data2(stable_sort_data.begin(), stable_sort_data.end(), pool); + + compare_data.sort(); + data1.sort(); + data2.sort(); + + std::list::const_iterator citr = compare_data.begin(); + DataNDC::const_iterator d1itr = data1.begin(); + DataNDC::const_iterator d2itr = data2.begin(); + + while (d1itr != data1.end()) + { + CHECK_EQUAL(citr->index, d1itr->index); + + ++citr; + ++d1itr; + } + + citr = compare_data.begin(); + + while (d2itr != data2.end()) + { + CHECK_EQUAL(citr->index, d2itr->index); + + ++citr; + ++d2itr; + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_sort_empty) + { + CompareDataNDC compare_data; + PoolNDC2 pool; + DataNDC data1(pool); + DataNDC data2(pool); + + compare_data.sort(); + data1.sort(); + data2.sort(); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_move) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::const_iterator i_from_before1; + DataNDC::const_iterator i_to_before1; + DataNDC::const_iterator i_from_before2; + DataNDC::const_iterator i_to_before2; + CompareDataNDC::const_iterator i_compare_from_before; + CompareDataNDC::const_iterator i_compare_to_before; + + // Move to the beginning. + i_from_before1 = data1.begin(); + std::advance(i_from_before1, 5); + + i_to_before1 = data1.before_begin(); + + i_from_before1 = data1.begin(); + std::advance(i_from_before1, 5); + + i_to_before1 = data1.before_begin(); + + i_from_before2 = data2.begin(); + std::advance(i_from_before2, 5); + + i_to_before2 = data2.before_begin(); + + i_from_before2 = data2.begin(); + std::advance(i_from_before2, 5); + + i_to_before2 = data2.before_begin(); + + i_compare_from_before = compare_data.begin(); + std::advance(i_compare_from_before, 5); + + i_compare_to_before = compare_data.before_begin(); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); + data1.move_after(i_from_before1, i_to_before1); + data2.move_after(i_from_before2, i_to_before2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to the end. + i_from_before1 = data1.begin(); + std::advance(i_from_before1, 5); + + i_to_before1 = data1.begin(); + std::advance(i_to_before1, 9); + + i_from_before2 = data2.begin(); + std::advance(i_from_before2, 5); + + i_to_before2 = data2.begin(); + std::advance(i_to_before2, 9); + + i_compare_from_before = compare_data.begin(); + std::advance(i_compare_from_before, 5); + + i_compare_to_before = compare_data.begin(); + std::advance(i_compare_to_before, 9); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); + data1.move_after(i_from_before1, i_to_before1); + data2.move_after(i_from_before2, i_to_before2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to nearby. + i_from_before1 = data1.begin(); + std::advance(i_from_before1, 3); + + i_to_before1 = data1.begin(); + std::advance(i_to_before1, 7); + + i_from_before2 = data2.begin(); + std::advance(i_from_before2, 3); + + i_to_before2 = data2.begin(); + std::advance(i_to_before2, 7); + + i_compare_from_before = compare_data.begin(); + std::advance(i_compare_from_before, 3); + + i_compare_to_before = compare_data.begin(); + std::advance(i_compare_to_before, 7); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); + data1.move_after(i_from_before1, i_to_before1); + data2.move_after(i_from_before2, i_to_before2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to same. + i_from_before1 = data1.begin(); + std::advance(i_from_before1, 3); + + i_to_before1 = data1.begin(); + std::advance(i_to_before1, 3); + + i_from_before2 = data2.begin(); + std::advance(i_from_before2, 3); + + i_to_before2 = data2.begin(); + std::advance(i_to_before2, 3); + + i_compare_from_before = compare_data.begin(); + std::advance(i_compare_from_before, 3); + + i_compare_to_before = compare_data.begin(); + std::advance(i_compare_to_before, 3); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); + data1.move_after(i_from_before1, i_to_before1); + data2.move_after(i_from_before2, i_to_before2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_move_range) + { + CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end()); + PoolNDC2 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::const_iterator i_first_before1; + DataNDC::const_iterator i_last1; + DataNDC::const_iterator i_to_before1; + DataNDC::const_iterator i_first_before2; + DataNDC::const_iterator i_last2; + DataNDC::const_iterator i_to_before2; + CompareDataNDC::const_iterator i_compare_first_before; + CompareDataNDC::const_iterator i_compare_last; + CompareDataNDC::const_iterator i_compare_to_before; + + // Move to the beginning. + i_first_before1 = data1.begin(); + std::advance(i_first_before1, 4); + + i_last1 = i_first_before1; + std::advance(i_last1, 4); + + i_to_before1 = data1.before_begin(); + + i_first_before2 = data2.begin(); + std::advance(i_first_before2, 4); + + i_last2 = i_first_before2; + std::advance(i_last2, 4); + + i_to_before2 = data2.before_begin(); + + i_compare_first_before = compare_data.begin(); + std::advance(i_compare_first_before, 4); + + i_compare_last = i_compare_first_before; + std::advance(i_compare_last, 4); + + i_compare_to_before = compare_data.before_begin(); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_first_before, i_compare_last); + data1.move_after(i_first_before1, i_last1, i_to_before1); + data2.move_after(i_first_before2, i_last2, i_to_before2); + + 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()); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to the end. + i_first_before1 = data1.begin(); + std::advance(i_first_before1, 4); + + i_last1 = i_first_before1; + std::advance(i_last1, 4); + + i_to_before1 = data1.begin(); + std::advance(i_to_before1, 9); + + i_first_before2 = data2.begin(); + std::advance(i_first_before2, 4); + + i_last2 = i_first_before2; + std::advance(i_last2, 4); + + i_to_before2 = data2.begin(); + std::advance(i_to_before2, 9); + + i_compare_first_before = compare_data.begin(); + std::advance(i_compare_first_before, 4); + + i_compare_last = i_compare_first_before; + std::advance(i_compare_last, 4); + + i_compare_to_before = compare_data.begin(); + std::advance(i_compare_to_before, 9); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_first_before, i_compare_last); + data1.move_after(i_first_before1, i_last1, i_to_before1); + data2.move_after(i_first_before2, i_last2, i_to_before2); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to nearby. + i_first_before1 = data1.begin(); + std::advance(i_first_before1, 4); + + i_last1 = i_first_before1; + std::advance(i_last1, 4); + + i_to_before1 = data1.begin(); + std::advance(i_to_before1, 2); + + i_first_before2 = data2.begin(); + std::advance(i_first_before2, 4); + + i_last2 = i_first_before2; + std::advance(i_last2, 4); + + i_to_before2 = data2.begin(); + std::advance(i_to_before2, 2); + + i_compare_first_before = compare_data.begin(); + std::advance(i_compare_first_before, 4); + + i_compare_last = i_compare_first_before; + std::advance(i_compare_last, 4); + + i_compare_to_before = compare_data.begin(); + std::advance(i_compare_to_before, 2); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_first_before, i_compare_last); + data1.move_after(i_first_before1, i_last1, i_to_before1); + data2.move_after(i_first_before2, i_last2, i_to_before2); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to same. + i_first_before1 = data1.begin(); + std::advance(i_first_before1, 4); + + i_last1 = i_first_before1; + std::advance(i_last1, 4); + + i_to_before1 = data1.begin(); + std::advance(i_to_before1, 4); + + i_first_before2 = data2.begin(); + std::advance(i_first_before2, 4); + + i_last2 = i_first_before2; + std::advance(i_last2, 4); + + i_to_before2 = data2.begin(); + std::advance(i_to_before2, 4); + + i_compare_first_before = compare_data.begin(); + std::advance(i_compare_first_before, 4); + + i_compare_last = i_compare_first_before; + std::advance(i_compare_last, 4); + + i_compare_to_before = compare_data.begin(); + std::advance(i_compare_to_before, 4); + + compare_data.splice_after(i_compare_to_before, compare_data, i_compare_first_before, i_compare_last); + data1.move_after(i_first_before1, i_last1, i_to_before1); + data2.move_after(i_first_before2, i_last2, i_to_before2); + + are_equal = std::equal(data1.begin(), data1.end(), compare_data.begin()); + CHECK(are_equal); + + are_equal = std::equal(data2.begin(), data2.end(), compare_data.begin()); + CHECK(are_equal); + + // Move to illegal place. + i_first_before1 = data1.begin(); + std::advance(i_first_before1, 2); + i_last1 = i_first_before1; + std::advance(i_last1, 3); + i_to_before1 = i_first_before1; + std::advance(i_to_before1, 2); + + i_first_before2 = data2.begin(); + std::advance(i_first_before2, 2); + i_last2 = i_first_before2; + std::advance(i_last2, 3); + i_to_before2 = i_first_before2; + std::advance(i_to_before2, 2); + + CHECK_THROW(data1.move_after(i_first_before1, i_last1, i_to_before1), etl::forward_list_iterator); + CHECK_THROW(data2.move_after(i_first_before2, i_last2, i_to_before2), etl::forward_list_iterator); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_binary_comparisons) + { + PoolDC4 pool; + DataNDC data1(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data2(sorted_data.begin(), sorted_data.end(), pool); + DataNDC data3(unsorted_data.begin(), unsorted_data.end(), pool); + + CHECK(data1 == data2); + CHECK(data1 != data3); + CHECK(data1 < data3); + CHECK(data3 > data1); + } + }; +} diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index e1da66ce..72650a15 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -561,6 +561,7 @@ + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 615c99b8..5cf73014 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -1115,6 +1115,9 @@ Source Files + + Source Files + Source Files From bb9b07a837fe89b06523ab90390baa9bcaafc4a3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 9 Dec 2018 12:15:42 +0000 Subject: [PATCH 09/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/private/pvoidvector.h --- include/etl/deque.h | 111 +++++++++++++ include/etl/flat_map.h | 12 +- include/etl/flat_multimap.h | 22 +++ include/etl/flat_multiset.h | 20 +++ include/etl/flat_set.h | 37 ++++- include/etl/forward_list.h | 35 ++++ include/etl/list.h | 81 +++++++--- include/etl/pool.h | 15 -- include/etl/priority_queue.h | 21 +++ include/etl/queue.h | 19 +++ include/etl/queue_mpmc_mutex.h | 191 ++++++++++++++++++++++ include/etl/queue_spsc_atomic.h | 119 ++++++++++++++ include/etl/queue_spsc_isr.h | 211 +++++++++++++++++++++++++ include/etl/stack.h | 17 ++ include/etl/variant.h | 35 ++-- include/etl/vector.h | 56 +++++-- test/CMakeLists.txt | 3 +- test/test_queue_memory_model_small.cpp | 2 + test/test_queue_mpmc_mutex.cpp | 32 +++- test/test_queue_mpmc_mutex_small.cpp | 32 +++- test/test_queue_spsc_atomic.cpp | 53 +++++++ test/test_queue_spsc_atomic_small.cpp | 53 +++++++ test/test_queue_spsc_isr.cpp | 53 +++++++ test/test_queue_spsc_isr_small.cpp | 53 +++++++ test/test_vector_non_trivial.cpp | 101 ++++++++++++ 25 files changed, 1306 insertions(+), 78 deletions(-) diff --git a/include/etl/deque.h b/include/etl/deque.h index a021f722..49b783ec 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -916,6 +916,74 @@ namespace etl return position; } + //************************************************************************* + /// Emplaces data into the deque. + /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is full. + ///\param insert_position>The insert position. + //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + template + iterator emplace(const_iterator insert_position, Args && ... args) + { + iterator position(insert_position.index, *this, p_buffer); + + ETL_ASSERT(!full(), ETL_ERROR(deque_full)); + + void* p; + + if (insert_position == begin()) + { + --_begin; + p = etl::addressof(*_begin); + ++current_size; + ETL_INCREMENT_DEBUG_COUNT + position = _begin; + } + else if (insert_position == end()) + { + p = etl::addressof(*_end); + ++_end; + ++current_size; + ETL_INCREMENT_DEBUG_COUNT + position = _end - 1; + } + else + { + // Are we closer to the front? + if (std::distance(_begin, position) < std::distance(position, _end - 1)) + { + // Construct the _begin. + create_element_front(*_begin); + + // Move the values. + std::copy(_begin + 1, position, _begin); + + // Write the new value. + --position; + (*position).~T(); + p = etl::addressof(*position); + } + else + { + // Construct the _end. + create_element_back(*(_end - 1)); + + // Move the values. + std::copy_backward(position, _end - 2, _end - 1); + + // Write the new value. + (*position).~T(); + p = etl::addressof(*position); + } + } + + ::new (p) T(std::forward(args)...); + + return position; + } + +#else + //************************************************************************* /// Emplaces data into the deque. /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is full. @@ -1175,6 +1243,7 @@ namespace etl return position; } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Inserts 'n' copies of a value into the deque. @@ -1508,6 +1577,26 @@ namespace etl create_element_back(item); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Emplaces an item to the back of the deque. + /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. + //************************************************************************* + template + void emplace_back(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif + + ::new (&(*_end)) T(std::forward(args)...); + ++_end; + ++current_size; + ETL_INCREMENT_DEBUG_COUNT + } + +#else + //************************************************************************* /// Emplaces an item to the back of the deque. /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. @@ -1575,6 +1664,7 @@ namespace etl ++current_size; ETL_INCREMENT_DEBUG_COUNT } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Removes the oldest item from the deque. @@ -1600,6 +1690,26 @@ namespace etl create_element_front(item); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Emplaces an item to the front of the deque. + /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. + //************************************************************************* + template + void emplace_front(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif + + --_begin; + ::new (&(*_begin)) T(std::forward(args)...); + ++current_size; + ETL_INCREMENT_DEBUG_COUNT + } + +#else + //************************************************************************* /// Emplaces an item to the front of the deque. /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. @@ -1667,6 +1777,7 @@ namespace etl ++current_size; ETL_INCREMENT_DEBUG_COUNT } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Removes the oldest item from the deque. diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 7184590c..2f9771bc 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -347,20 +347,22 @@ namespace etl //************************************************************************* std::pair emplace(const value_type& value) { - return insert(value); + return emplace(value.first, value.second); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Emplaces a value to the map. //************************************************************************* - std::pair emplace(const key_type& key, const mapped_type& value) + template + std::pair emplace(const key_type& key, Args && ... args) { ETL_ASSERT(!full(), ETL_ERROR(flat_map_full)); // Create it. value_type* pvalue = storage.allocate(); ::new ((void*)etl::addressof(pvalue->first)) key_type(key); - ::new ((void*)etl::addressof(pvalue->second)) mapped_type(value); + ::new ((void*)etl::addressof(pvalue->second)) mapped_type(std::forward(args)...); iterator i_element = lower_bound(key); @@ -381,6 +383,8 @@ namespace etl return result; } +#else + //************************************************************************* /// Emplaces a value to the map. //************************************************************************* @@ -509,6 +513,8 @@ namespace etl return result; } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //********************************************************************* /// Erases an element. ///\param key The key to erase. diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index 8244862f..54eed72f 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -320,6 +320,26 @@ namespace etl return refmap_t::insert_at(i_element, *pvalue); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Emplaces a value to the map. + //************************************************************************* + template + std::pair emplace(const key_type& key, Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(flat_multimap_full)); + + // Create it. + value_type* pvalue = storage.allocate(); + ::new ((void*)etl::addressof(pvalue->first)) key_type(key); + ::new ((void*)etl::addressof(pvalue->second)) mapped_type(std::forward(args)...); + iterator i_element = lower_bound(key); + ETL_INCREMENT_DEBUG_COUNT + + return refmap_t::insert_at(i_element, *pvalue); + } + +#else //************************************************************************* /// Emplaces a value to the map. //************************************************************************* @@ -392,6 +412,8 @@ namespace etl return refmap_t::insert_at(i_element, *pvalue); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //********************************************************************* /// Erases an element. ///\param key The key to erase. diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 27d232a7..4c9e1bb9 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -281,6 +281,25 @@ namespace etl //************************************************************************* /// Emplaces a value to the set. //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + template + std::pair emplace(Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(flat_multiset_full)); + + // Create it. + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(std::forward(args)...); + + iterator i_element = lower_bound(*pvalue); + + ETL_INCREMENT_DEBUG_COUNT + return std::pair(refset_t::insert_at(i_element, *pvalue)); + } +#else + //************************************************************************* + /// Emplaces a value to the set. + //************************************************************************* template std::pair emplace(const T1& value1) { @@ -349,6 +368,7 @@ namespace etl ETL_INCREMENT_DEBUG_COUNT return std::pair(refset_t::insert_at(i_element, *pvalue)); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //********************************************************************* /// Erases an element. diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index bb1b4dbe..17e08554 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -284,6 +284,40 @@ namespace etl //************************************************************************* /// Emplaces a value to the set. //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + template + std::pair emplace(Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(flat_set_full)); + + std::pair result; + + // Create it. + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(std::forward(args)...); + + iterator i_element = lower_bound(*pvalue); + + // Doesn't already exist? + if ((i_element == end() || (*i_element != *pvalue))) + { + ETL_INCREMENT_DEBUG_COUNT + result = refset_t::insert_at(i_element, *pvalue); + } + else + { + // Destroy it. + pvalue->~value_type(); + storage.release(pvalue); + result = std::pair(end(), false); + } + + return result; + } +#else + //************************************************************************* + /// Emplaces a value to the set. + //************************************************************************* template std::pair emplace(const T1& value1) { @@ -295,7 +329,7 @@ namespace etl value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(value1); - iterator i_element = lower_bound(*pvalue); + iterator i_element = lower_bound(*pvalue); // Doesn't already exist? if ((i_element == end() || (*i_element != *pvalue))) @@ -412,6 +446,7 @@ namespace etl return result; } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //********************************************************************* /// Erases an element. diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index c021e465..9881a394 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -719,6 +719,22 @@ namespace etl insert_node_after(start_node, data_node); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Emplaces a value to the front of the list.. + //************************************************************************* + template + void emplace_front(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); +#endif + data_node_t* p_data_node = p_node_pool->allocate(); + ::new (&(p_data_node->value)) T(std::forward(args)...); + ETL_INCREMENT_DEBUG_COUNT + insert_node_after(start_node, *p_data_node); + } +#else //************************************************************************* /// Emplaces a value to the front of the list.. //************************************************************************* @@ -778,6 +794,7 @@ namespace etl ETL_INCREMENT_DEBUG_COUNT insert_node_after(start_node, *p_data_node); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Removes a value from the front of the forward_list. @@ -855,6 +872,23 @@ namespace etl return iterator(&data_node); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Emplaces a value to the forward_list after the specified position. + //************************************************************************* + template + iterator emplace_after(iterator position, Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); + + data_node_t* p_data_node = p_node_pool->allocate(); + ::new (&(p_data_node->value)) T(std::forward(args)...); + ETL_INCREMENT_DEBUG_COUNT + insert_node_after(*position.p_node, *p_data_node); + + return iterator(p_data_node); + } +#else //************************************************************************* /// Emplaces a value to the forward_list after the specified position. //************************************************************************* @@ -918,6 +952,7 @@ namespace etl return iterator(p_data_node); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Inserts 'n' copies of a value to the forward_list after the specified position. diff --git a/include/etl/list.h b/include/etl/list.h index a9c8ca63..ed539543 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -851,8 +851,26 @@ namespace etl insert_node(get_head(), allocate_data_node(value)); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* - /// Emplaces a value to the front of the list.. + /// Emplaces a value to the front of the list. + //************************************************************************* + template + void emplace_front(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(list_full)); +#endif + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(list_no_pool)); + + data_node_t* p_data_node = p_node_pool->allocate(); + ::new (&(p_data_node->value)) T(std::forward(args)...); + ETL_INCREMENT_DEBUG_COUNT + insert_node(get_head(), *p_data_node); + } +#else + //************************************************************************* + /// Emplaces a value to the front of the list. //************************************************************************* template void emplace_front(const T1& value1) @@ -869,7 +887,7 @@ namespace etl } //************************************************************************* - /// Emplaces a value to the front of the list.. + /// Emplaces a value to the front of the list. //************************************************************************* template void emplace_front(const T1& value1, const T2& value2) @@ -886,7 +904,7 @@ namespace etl } //************************************************************************* - /// Emplaces a value to the front of the list.. + /// Emplaces a value to the front of the list. //************************************************************************* template void emplace_front(const T1& value1, const T2& value2, const T3& value3) @@ -903,7 +921,7 @@ namespace etl } //************************************************************************* - /// Emplaces a value to the front of the list.. + /// Emplaces a value to the front of the list. //************************************************************************* template void emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) @@ -918,6 +936,7 @@ namespace etl ETL_INCREMENT_DEBUG_COUNT insert_node(get_head(), *p_data_node); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Removes a value from the front of the list. @@ -932,7 +951,7 @@ namespace etl } //************************************************************************* - /// Pushes a value to the back of the list.. + /// Pushes a value to the back of the list. //************************************************************************* void push_back(parameter_t value) { @@ -943,8 +962,23 @@ namespace etl } //************************************************************************* - /// Emplaces a value to the back of the list.. + /// Emplaces a value to the back of the list. //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + template + void emplace_back(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(list_full)); +#endif + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(list_no_pool)); + + data_node_t* p_data_node = p_node_pool->allocate(); + ::new (&(p_data_node->value)) T(std::forward(args)...); + ETL_INCREMENT_DEBUG_COUNT + insert_node(terminal_node, *p_data_node); + } +#else template void emplace_back(const T1& value1) { @@ -959,9 +993,6 @@ namespace etl insert_node(terminal_node, *p_data_node); } - //************************************************************************* - /// Emplaces a value to the back of the list.. - //************************************************************************* template void emplace_back(const T1& value1, const T2& value2) { @@ -976,9 +1007,6 @@ namespace etl insert_node(terminal_node, *p_data_node); } - //************************************************************************* - /// Emplaces a value to the back of the list.. - //************************************************************************* template void emplace_back(const T1& value1, const T2& value2, const T3& value3) { @@ -993,9 +1021,6 @@ namespace etl insert_node(terminal_node, *p_data_node); } - //************************************************************************* - /// Emplaces a value to the back of the list.. - //************************************************************************* template void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { @@ -1009,6 +1034,7 @@ namespace etl ETL_INCREMENT_DEBUG_COUNT insert_node(terminal_node, *p_data_node); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Removes a value from the back of the list. @@ -1038,6 +1064,21 @@ namespace etl //************************************************************************* /// Emplaces a value to the list at the specified position. //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + template + iterator emplace(iterator position, Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(list_full)); + ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(list_no_pool)); + + data_node_t* p_data_node = p_node_pool->allocate(); + ::new (&(p_data_node->value)) T(std::forward(args)...); + ETL_INCREMENT_DEBUG_COUNT + insert_node(*position.p_node, *p_data_node); + + return iterator(*p_data_node); + } +#else template iterator emplace(iterator position, const T1& value1) { @@ -1052,9 +1093,6 @@ namespace etl return iterator(*p_data_node); } - //************************************************************************* - /// Emplaces a value to the list at the specified position. - //************************************************************************* template iterator emplace(iterator position, const T1& value1, const T2& value2) { @@ -1069,9 +1107,6 @@ namespace etl return iterator(*p_data_node); } - //************************************************************************* - /// Emplaces a value to the list at the specified position. - //************************************************************************* template iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3) { @@ -1086,9 +1121,6 @@ namespace etl return iterator(*p_data_node); } - //************************************************************************* - /// Emplaces a value to the list at the specified position. - //************************************************************************* template iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) { @@ -1102,6 +1134,7 @@ namespace etl return iterator(*p_data_node); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Inserts 'n' copies of a value to the list at the specified position. diff --git a/include/etl/pool.h b/include/etl/pool.h index a79f04bf..be56bd70 100644 --- a/include/etl/pool.h +++ b/include/etl/pool.h @@ -173,11 +173,6 @@ namespace etl return p; } - //************************************************************************* - /// Allocate storage for an object from the pool and create with 2 parameters. - /// If asserts or exceptions are enabled and there are no more free items an - /// etl::pool_no_allocation if thrown, otherwise a nullptr is returned. - //************************************************************************* template T* create(const T1& value1, const T2& value2) { @@ -191,11 +186,6 @@ namespace etl return p; } - //************************************************************************* - /// Allocate storage for an object from the pool and create with 3 parameters. - /// If asserts or exceptions are enabled and there are no more free items an - /// etl::pool_no_allocation if thrown, otherwise a nullptr is returned. - //************************************************************************* template T* create(const T1& value1, const T2& value2, const T3& value3) { @@ -209,11 +199,6 @@ namespace etl return p; } - //************************************************************************* - /// Allocate storage for an object from the pool and create with 4 parameters. - /// If asserts or exceptions are enabled and there are no more free items an - /// etl::pool_no_allocation if thrown, otherwise a nullptr is returned. - //************************************************************************* template T* create(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { diff --git a/include/etl/priority_queue.h b/include/etl/priority_queue.h index 02eb6922..8614716a 100644 --- a/include/etl/priority_queue.h +++ b/include/etl/priority_queue.h @@ -48,6 +48,8 @@ SOFTWARE. #undef ETL_FILE #define ETL_FILE "12" +#define ETL_PRIORITY_QUEUE_FORCE_CPP03 1 + //***************************************************************************** ///\defgroup queue queue /// A priority queue with the capacity defined at compile time, @@ -168,6 +170,24 @@ namespace etl std::push_heap(container.begin(), container.end(), compare); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_PRIORITY_QUEUE_FORCE_CPP03 + //************************************************************************* + /// Emplaces a value to the queue. + /// If asserts or exceptions are enabled, throws an etl::priority_queue_full + /// is the priority queue is already full. + ///\param value The value to push to the queue. + //************************************************************************* + template + void emplace(Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(etl::priority_queue_full)); + + // Put element at end + container.emplace_back(std::forward(args)...); + // Make elements in container into heap + std::push_heap(container.begin(), container.end(), compare); + } +#else //************************************************************************* /// Emplaces a value to the queue. /// If asserts or exceptions are enabled, throws an etl::priority_queue_full @@ -235,6 +255,7 @@ namespace etl // Make elements in container into heap std::push_heap(container.begin(), container.end(), compare); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Assigns values to the priority queue. diff --git a/include/etl/queue.h b/include/etl/queue.h index c57ca47d..ecd7ef0d 100644 --- a/include/etl/queue.h +++ b/include/etl/queue.h @@ -49,6 +49,8 @@ SOFTWARE. #undef ETL_FILE #define ETL_FILE "13" +#define ETL_QUEUE_FORCE_CPP03 1 + //***************************************************************************** ///\defgroup queue queue /// A First-in / first-out queue with the capacity defined at compile time, @@ -316,6 +318,22 @@ namespace etl add_in(); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_FORCE_CPP03 + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + ///\param value The value to use to construct the item to push to the queue. + //************************************************************************* + template + void emplace(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(queue_full)); +#endif + ::new (&p_buffer[in]) T(std::forward(args)...); + add_in(); + } +#else //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. @@ -375,6 +393,7 @@ namespace etl ::new (&p_buffer[in]) T(value1, value2, value3, value4); add_in(); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Clears the queue to the empty state. diff --git a/include/etl/queue_mpmc_mutex.h b/include/etl/queue_mpmc_mutex.h index 35279d11..2b10cf83 100644 --- a/include/etl/queue_mpmc_mutex.h +++ b/include/etl/queue_mpmc_mutex.h @@ -44,6 +44,8 @@ SOFTWARE. #undef ETL_FILE #define ETL_FILE "48" +#define ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03 0 + namespace etl { template @@ -162,6 +164,88 @@ namespace etl return result; } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03 + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(Args&&... args) + { + access.lock(); + + bool result = emplace_implementation(std::forward(args)...); + + access.unlock(); + + return result; + } +#else + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1) + { + access.lock(); + + bool result = emplace_implementation(value1); + + access.unlock(); + + return result; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2) + { + access.lock(); + + bool result = emplace_implementation(value1, value2); + + access.unlock(); + + return result; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2, const T3& value3) + { + access.lock(); + + bool result = emplace_implementation(value1, value2, value3); + + access.unlock(); + + return result; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + { + access.lock(); + + bool result = emplace_implementation(value1, value2, value3, value4); + + access.unlock(); + + return result; + } +#endif + //************************************************************************* /// Pop a value from the queue. //************************************************************************* @@ -294,6 +378,113 @@ namespace etl return false; } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_MPMC_MUTEX_FORCE_CPP03 + //************************************************************************* + /// Constructs a value in the queue 'in place'. + //************************************************************************* + template + bool emplace_implementation(Args&&... args) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(std::forward(args)...); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } +#else + //************************************************************************* + /// Constructs a value in the queue 'in place'. + //************************************************************************* + template + bool emplace_implementation(const T1& value1) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + //************************************************************************* + template + bool emplace_implementation(const T1& value1, const T2& value2) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1, value2); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + //************************************************************************* + template + bool emplace_implementation(const T1& value1, const T2& value2, const T3& value3) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1, value2, value3); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + //************************************************************************* + template + bool emplace_implementation(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1, value2, value3, value4); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } +#endif + //************************************************************************* /// Pop a value from the queue. //************************************************************************* diff --git a/include/etl/queue_spsc_atomic.h b/include/etl/queue_spsc_atomic.h index 44eeb918..925a4672 100644 --- a/include/etl/queue_spsc_atomic.h +++ b/include/etl/queue_spsc_atomic.h @@ -44,6 +44,8 @@ SOFTWARE. #undef ETL_FILE #define ETL_FILE "47" +#define ETL_QUEUE_ATOMIC_FORCE_CPP03 0 + namespace etl { template @@ -222,6 +224,123 @@ namespace etl return false; } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_ATOMIC_FORCE_CPP03 + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(Args&&... args) + { + size_type write_index = write.load(etl::memory_order_relaxed); + size_type next_index = get_next_index(write_index, RESERVED); + + if (next_index != read.load(etl::memory_order_acquire)) + { + ::new (&p_buffer[write_index]) T(std::forward(args)...); + + write.store(next_index, etl::memory_order_release); + + return true; + } + + // Queue is full. + return false; + } +#else + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1) + { + size_type write_index = write.load(etl::memory_order_relaxed); + size_type next_index = get_next_index(write_index, RESERVED); + + if (next_index != read.load(etl::memory_order_acquire)) + { + ::new (&p_buffer[write_index]) T(value1); + + write.store(next_index, etl::memory_order_release); + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2) + { + size_type write_index = write.load(etl::memory_order_relaxed); + size_type next_index = get_next_index(write_index, RESERVED); + + if (next_index != read.load(etl::memory_order_acquire)) + { + ::new (&p_buffer[write_index]) T(value1, value2); + + write.store(next_index, etl::memory_order_release); + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2, const T3& value3) + { + size_type write_index = write.load(etl::memory_order_relaxed); + size_type next_index = get_next_index(write_index, RESERVED); + + if (next_index != read.load(etl::memory_order_acquire)) + { + ::new (&p_buffer[write_index]) T(value1, value2, value3); + + write.store(next_index, etl::memory_order_release); + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + { + size_type write_index = write.load(etl::memory_order_relaxed); + size_type next_index = get_next_index(write_index, RESERVED); + + if (next_index != read.load(etl::memory_order_acquire)) + { + ::new (&p_buffer[write_index]) T(value1, value2, value3, value4); + + write.store(next_index, etl::memory_order_release); + + return true; + } + + // Queue is full. + return false; + } +#endif + //************************************************************************* /// Pop a value from the queue. //************************************************************************* diff --git a/include/etl/queue_spsc_isr.h b/include/etl/queue_spsc_isr.h index d09f6c37..2ff961d3 100644 --- a/include/etl/queue_spsc_isr.h +++ b/include/etl/queue_spsc_isr.h @@ -43,6 +43,8 @@ SOFTWARE. #undef ETL_FILE #define ETL_FILE "46" +#define ETL_QUEUE_ISR_FORCE_CPP03 0 + namespace etl { template @@ -69,6 +71,19 @@ namespace etl return push_implementation(value); } + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + ///\param value The value to use to construct the item to push to the queue. + //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_ISR_FORCE_CPP03 + template + bool emplace_from_isr(Args&&... args) + { + return emplace_implementation(std::forward(args)...); + } +#endif + //************************************************************************* /// Pop a value from the queue from an ISR //************************************************************************* @@ -179,6 +194,120 @@ namespace etl return false; } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_ISR_FORCE_CPP03 + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + ///\param value The value to use to construct the item to push to the queue. + //************************************************************************* + template + bool emplace_implementation(Args&&... args) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(std::forward(args)...); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } +#else + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace_implementation(const T1& value1) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace_implementation(const T1& value1, const T2& value2) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1, value2); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace_implementation(const T1& value1, const T2& value2, const T3& value3) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1, value2, value3); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace_implementation(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + { + if (current_size != MAX_SIZE) + { + ::new (&p_buffer[write_index]) T(value1, value2, value3, value4); + + write_index = get_next_index(write_index, MAX_SIZE); + + ++current_size; + + return true; + } + + // Queue is full. + return false; + } + +#endif + //************************************************************************* /// Pop a value from the queue. //************************************************************************* @@ -299,6 +428,88 @@ namespace etl return result; } + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_QUEUE_ISR_FORCE_CPP03 + template + bool emplace(Args&&... args) + { + TAccess::lock(); + + bool result = this->emplace_implementation(std::forward(args)...); + + TAccess::unlock(); + + return result; + } +#else + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1) + { + TAccess::lock(); + + bool result = this->emplace_implementation(value1); + + TAccess::unlock(); + + return result; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2) + { + TAccess::lock(); + + bool result = this->emplace_implementation(value1, value2); + + TAccess::unlock(); + + return result; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2, const T3& value3) + { + TAccess::lock(); + + bool result = this->emplace_implementation(value1, value2, value3); + + TAccess::unlock(); + + return result; + } + + //************************************************************************* + /// Constructs a value in the queue 'in place'. + /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. + //************************************************************************* + template + bool emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + { + TAccess::lock(); + + bool result = this->emplace_implementation(value1, value2, value3, value4); + + TAccess::unlock(); + + return result; + } +#endif + //************************************************************************* /// Pop a value from the queue. //************************************************************************* diff --git a/include/etl/stack.h b/include/etl/stack.h index dfe0fa04..ee372178 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -262,6 +262,22 @@ namespace etl ::new (&p_buffer[top_index]) T(value); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Constructs a value in the stack place'. + /// If asserts or exceptions are enabled, throws an etl::stack_full if the stack is already full. + ///\param value The value to push to the stack. + //************************************************************************* + template + void emplace(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(stack_full)); +#endif + base_t::add_in(); + ::new (&p_buffer[top_index]) T(std::forward(args)...); + } +#else //************************************************************************* /// Constructs a value in the stack place'. /// If asserts or exceptions are enabled, throws an etl::stack_full if the stack is already full. @@ -321,6 +337,7 @@ namespace etl base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2, value3, value4); } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Gets a const reference to the value at the top of the stack.
diff --git a/include/etl/variant.h b/include/etl/variant.h index 26e9c124..8c5e404a 100644 --- a/include/etl/variant.h +++ b/include/etl/variant.h @@ -51,6 +51,8 @@ SOFTWARE. #undef ETL_FILE #define ETL_FILE "24" +#define ETL_VARIANT_FORCE_CPP03 1 + //***************************************************************************** ///\defgroup variant variant /// A class that can contain one a several specified types in a type safe manner. @@ -711,7 +713,22 @@ namespace etl type_id = other.type_id; } -#if !ETL_CPP11_SUPPORTED || defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_VARIANT_FORCE_CPP03 + //************************************************************************* + /// Emplace with variadic constructor parameters. + //************************************************************************* + template + T& emplace(Args&&... args) + { + ETL_STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); + + destruct_current(); + ::new (static_cast(data)) T(std::forward(args)...); + type_id = Type_Id_Lookup::type_id; + + return *static_cast(data); + } +#else //*************************************************************************** /// Emplace with one constructor parameter. //*************************************************************************** @@ -769,22 +786,6 @@ namespace etl ::new (static_cast(data)) T(value1, value2, value3, value4); type_id = Type_Id_Lookup::type_id; - return *static_cast(data); - } - -#else - //************************************************************************* - /// Emplace with variadic constructor parameters. - //************************************************************************* - template - T& emplace(Args&&... args) - { - ETL_STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); - - destruct_current(); - ::new (static_cast(data)) T(std::forward(args)...); - type_id = Type_Id_Lookup::type_id; - return *static_cast(data); } #endif diff --git a/include/etl/vector.h b/include/etl/vector.h index 3e0f9a2d..724712e8 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -63,6 +63,8 @@ SOFTWARE. #pragma GCC diagnostic ignored "-Wunused-variable" #endif +#define ETL_VECTOR_FORCE_CPP03 1 + //***************************************************************************** ///\defgroup vector vector /// A vector with the capacity defined at compile time. @@ -411,6 +413,23 @@ namespace etl create_back(value); } +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_VECTOR_FORCE_CPP03 + //********************************************************************* + /// Constructs a value at the end of the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. + ///\param value The value to add. + //********************************************************************* + template + void emplace_back(Args && ... args) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); +#endif + ::new (p_end) T(std::forward(args)...); + ++p_end; + ETL_INCREMENT_DEBUG_COUNT + } +#else //********************************************************************* /// Constructs a value at the end of the vector. /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. @@ -474,6 +493,7 @@ namespace etl ++p_end; ETL_INCREMENT_DEBUG_COUNT } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_VECTOR_FORCE_CPP03 //************************************************************************* /// Removes an element from the end of the vector. @@ -514,6 +534,32 @@ namespace etl //************************************************************************* /// Emplaces a value to the vextor at the specified position. //************************************************************************* +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + template + iterator emplace(iterator position, Args && ... args) + { + ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + + void* p; + + if (position == end()) + { + p = p_end++; + ETL_INCREMENT_DEBUG_COUNT + } + else + { + p = etl::addressof(*position); + create_back(back()); + std::copy_backward(position, p_end - 1, p_end); + (*position).~T(); + } + + ::new (p) T(std::forward(args)...); + + return position; + } +#else template iterator emplace(iterator position, const T1& value1) { @@ -539,9 +585,6 @@ namespace etl return position; } - //************************************************************************* - /// Emplaces a value to the vextor at the specified position. - //************************************************************************* template iterator emplace(iterator position, const T1& value1, const T2& value2) { @@ -567,9 +610,6 @@ namespace etl return position; } - //************************************************************************* - /// Emplaces a value to the vextor at the specified position. - //************************************************************************* template iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3) { @@ -595,9 +635,6 @@ namespace etl return position; } - //************************************************************************* - /// Emplaces a value to the vextor at the specified position. - //************************************************************************* template iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) { @@ -622,6 +659,7 @@ namespace etl return position; } +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //********************************************************************* /// Inserts 'n' values to the vector. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eea884ba..05f96eaf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -46,7 +46,6 @@ set(TEST_SOURCE_FILES test_enum_type.cpp test_error_handler.cpp test_exception.cpp -# test_factory.cpp test_fixed_iterator.cpp test_flat_map.cpp test_flat_multimap.cpp @@ -119,6 +118,8 @@ set(TEST_SOURCE_FILES test_xor_checksum.cpp test_xor_rotate_checksum.cpp + ${CMAKE_SOURCE_DIR}/src/crc16_modbus.cpp + # Compile the source level ecl_timer here as test has provided a ecl_user.h file ${PROJECT_SOURCE_DIR}/../src/c/ecl_timer.c ) diff --git a/test/test_queue_memory_model_small.cpp b/test/test_queue_memory_model_small.cpp index ab6adfbe..d4ac3dbe 100644 --- a/test/test_queue_memory_model_small.cpp +++ b/test/test_queue_memory_model_small.cpp @@ -349,6 +349,8 @@ namespace queue.emplace('c', 3, 5.6); queue.emplace('d', 4, 7.8); + CHECK_EQUAL(4U, queue.size()); + CHECK(queue.front() == Item('a', 1, 1.2)); queue.pop(); CHECK(queue.front() == Item('b', 2, 3.4)); diff --git a/test/test_queue_mpmc_mutex.cpp b/test/test_queue_mpmc_mutex.cpp index 75c1be5c..9b907476 100644 --- a/test/test_queue_mpmc_mutex.cpp +++ b/test/test_queue_mpmc_mutex.cpp @@ -69,10 +69,10 @@ namespace int d; }; -// bool operator ==(const Data& lhs, const Data& rhs) -// { -// return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); -// } + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } // std::ostream& operator <<(std::ostream& os, const Data& data) // { @@ -143,6 +143,30 @@ namespace CHECK(!queue.pop(i)); } + //************************************************************************* + TEST(test_multiple_emplace) + { + etl::queue_mpmc_mutex queue; + + queue.emplace(1); + queue.emplace(1, 2); + queue.emplace(1, 2, 3); + queue.emplace(1, 2, 3, 4); + + CHECK_EQUAL(4U, queue.size()); + + Data popped; + + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + } + //************************************************************************* TEST(test_size_push_pop_iqueue) { diff --git a/test/test_queue_mpmc_mutex_small.cpp b/test/test_queue_mpmc_mutex_small.cpp index 0c57c332..fdc44f70 100644 --- a/test/test_queue_mpmc_mutex_small.cpp +++ b/test/test_queue_mpmc_mutex_small.cpp @@ -74,10 +74,10 @@ namespace typedef etl::queue_mpmc_mutex QueueInt255; -// bool operator ==(const Data& lhs, const Data& rhs) -// { -// return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); -// } + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } // std::ostream& operator <<(std::ostream& os, const Data& data) // { @@ -148,6 +148,30 @@ namespace CHECK(!queue.pop(i)); } + //************************************************************************* + TEST(test_multiple_emplace) + { + etl::queue_mpmc_mutex queue; + + queue.emplace(1); + queue.emplace(1, 2); + queue.emplace(1, 2, 3); + queue.emplace(1, 2, 3, 4); + + Data popped; + + CHECK_EQUAL(4U, queue.size()); + + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + } + //************************************************************************* TEST(test_size_push_pop_iqueue) { diff --git a/test/test_queue_spsc_atomic.cpp b/test/test_queue_spsc_atomic.cpp index 1d49cca4..074ac7e2 100644 --- a/test/test_queue_spsc_atomic.cpp +++ b/test/test_queue_spsc_atomic.cpp @@ -42,6 +42,35 @@ SOFTWARE. namespace { + struct Data + { + Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4) + : a(a_), + b(b_), + c(c_), + d(d_) + { + } + + Data() + : a(0), + b(0), + c(0), + d(0) + { + } + + int a; + int b; + int c; + int d; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } + SUITE(test_queue_atomic) { //************************************************************************* @@ -188,6 +217,30 @@ namespace CHECK(!queue.pop()); } + //************************************************************************* + TEST(test_multiple_emplace) + { + etl::queue_spsc_atomic queue; + + queue.emplace(1); + queue.emplace(1, 2); + queue.emplace(1, 2, 3); + queue.emplace(1, 2, 3, 4); + + CHECK_EQUAL(4U, queue.size()); + + Data popped; + + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + } + //************************************************************************* TEST(test_clear) { diff --git a/test/test_queue_spsc_atomic_small.cpp b/test/test_queue_spsc_atomic_small.cpp index fd8a5274..c6e6e7a3 100644 --- a/test/test_queue_spsc_atomic_small.cpp +++ b/test/test_queue_spsc_atomic_small.cpp @@ -42,6 +42,35 @@ SOFTWARE. namespace { + struct Data + { + Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4) + : a(a_), + b(b_), + c(c_), + d(d_) + { + } + + Data() + : a(0), + b(0), + c(0), + d(0) + { + } + + int a; + int b; + int c; + int d; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } + typedef etl::queue_spsc_atomic QueueInt; typedef etl::iqueue_spsc_atomic IQueueInt; @@ -206,6 +235,30 @@ namespace CHECK_EQUAL(254U, queue.size()); } + //************************************************************************* + TEST(test_multiple_emplace) + { + etl::queue_spsc_atomic queue; + + queue.emplace(1); + queue.emplace(1, 2); + queue.emplace(1, 2, 3); + queue.emplace(1, 2, 3, 4); + + CHECK_EQUAL(4U, queue.size()); + + Data popped; + + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + } + //************************************************************************* TEST(test_clear) { diff --git a/test/test_queue_spsc_isr.cpp b/test/test_queue_spsc_isr.cpp index 00623103..56516beb 100644 --- a/test/test_queue_spsc_isr.cpp +++ b/test/test_queue_spsc_isr.cpp @@ -69,6 +69,35 @@ namespace bool Access::called_lock; bool Access::called_unlock; + struct Data + { + Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4) + : a(a_), + b(b_), + c(c_), + d(d_) + { + } + + Data() + : a(0), + b(0), + c(0), + d(0) + { + } + + int a; + int b; + int c; + int d; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } + SUITE(test_queue_isr) { //************************************************************************* @@ -374,6 +403,30 @@ namespace CHECK(!queue.pop_from_isr()); } + //************************************************************************* + TEST(test_multiple_emplace) + { + etl::queue_spsc_isr queue; + + queue.emplace(1); + queue.emplace(1, 2); + queue.emplace(1, 2, 3); + queue.emplace(1, 2, 3, 4); + + CHECK_EQUAL(4U, queue.size()); + + Data popped; + + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + } + //************************************************************************* TEST(test_clear) { diff --git a/test/test_queue_spsc_isr_small.cpp b/test/test_queue_spsc_isr_small.cpp index 3895b3d0..ca5f4f22 100644 --- a/test/test_queue_spsc_isr_small.cpp +++ b/test/test_queue_spsc_isr_small.cpp @@ -69,6 +69,35 @@ namespace bool Access::called_lock; bool Access::called_unlock; + struct Data + { + Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4) + : a(a_), + b(b_), + c(c_), + d(d_) + { + } + + Data() + : a(0), + b(0), + c(0), + d(0) + { + } + + int a; + int b; + int c; + int d; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); + } + typedef etl::queue_spsc_isr QueueInt; typedef etl::iqueue_spsc_isr IQueueInt; @@ -392,6 +421,30 @@ namespace CHECK_EQUAL(255U, queue.size()); } + //************************************************************************* + TEST(test_multiple_emplace) + { + etl::queue_spsc_isr queue; + + queue.emplace(1); + queue.emplace(1, 2); + queue.emplace(1, 2, 3); + queue.emplace(1, 2, 3, 4); + + CHECK_EQUAL(4U, queue.size()); + + Data popped; + + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + queue.pop(popped); + CHECK(popped == Data(1, 2, 3, 4)); + } + //************************************************************************* TEST(test_clear) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 2c6d3b2c..ab87b66e 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -571,6 +571,107 @@ namespace CHECK(is_equal); } + //************************************************************************* + // To test the CPP03 versions then ETL_TEST_VECTOR_CPP11 must be set to 0 in vector.h + TEST_FIXTURE(SetupFixture, test_emplace_back_multiple) + { + class Data + { + public: + std::string a; + size_t b; + double c; + const char *d; + Data(std::string w) : a(w), b(0), c(0.0), d(0){} + Data(std::string w, size_t x) : a(w), b(x), c(0.0), d(0){} + Data(std::string w, size_t x, double y) : a(w), b(x), c(y), d(0){} + Data(std::string w, size_t x, double y, const char *z) : a(w), b(x), c(y), d(z){} + bool operator == (const Data &other) const + { + return (a == other.a) && (b == other.b) && (c == other.c) && (d == other.d); + } + }; + + std::vector compare_data; + etl::vector data; + + std::string s; + for (size_t i = 0; i < SIZE; ++i) + { + s += "x"; + + // 4 arguments + compare_data.emplace_back(s, i, static_cast(i) + 0.1234, "emplace_back"); + data.emplace_back(s, i, static_cast(i) + 0.1234, "emplace_back"); + + // 3 arguments + compare_data.emplace_back(s, i, static_cast(i) + 0.1234); + data.emplace_back(s, i, static_cast(i) + 0.1234); + + // 2 arguments + compare_data.emplace_back(s, i); + data.emplace_back(s, i); + + // 1 argument + compare_data.emplace_back(s); + data.emplace_back(s); + } + + CHECK_EQUAL(compare_data.size(), data.size()); + + const bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + // The C++11 variadic version uses non-const rvalue references so has the ability + // to emplace non-const reference members, the pre-C++11 const reference overloads + // does not have the ability to pass const reference parameters to non-const + // constructor parameters (like the members in Data below) + // So this is only tested on C++11 onwards + TEST_FIXTURE(SetupFixture, test_emplace_back_non_const_references) + { +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) && !ETL_VECTOR_FORCE_CPP03 + class Data + { + public: + std::string &a; + size_t &b; + double &c; + const char *d; + Data(std::string &w, size_t &x, double &y, const char *z) : a(w), b(x), c(y), d(z){} + bool operator == (const Data &other) const + { + return (a == other.a) && (b == other.b) && (c == other.c) && (d == other.d); + } + }; + + std::vector compare_data; + etl::vector data; + + std::string a = "test_test_test"; + size_t b = 9999; + double c = 123.456; + const char *d = "abcdefghijklmnopqrstuvwxyz"; + for (size_t i = 0; i < SIZE; ++i) + { + data.emplace_back(a, b, c, d); + compare_data.emplace_back(a, b, c, d); + } + + CHECK_EQUAL(compare_data.size(), data.size()); + + const bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); +#endif // ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { From f2f23395cde34704686233094d9619ad8d06453a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 9 Dec 2018 12:32:31 +0000 Subject: [PATCH 10/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/private/pvoidvector.h # include/etl/version.h # support/Release notes.txt --- include/etl/version.h | 2 +- support/Release notes.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/etl/version.h b/include/etl/version.h index d734bab6..f80f9f29 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 3 +#define ETL_VERSION_MINOR 4 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/support/Release notes.txt b/support/Release notes.txt index 0ba6ff69..a7aaf553 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.4.0 +Added C++03/C++11 emplace for deque, priority_queue, queues, stack, variant & vector. + =============================================================================== 14.3.0 etl::forward_list supports shared pools. From dcb1e753588982dc74182bb5348196cd52779501 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Dec 2018 22:18:41 +0000 Subject: [PATCH 11/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/deque.h # include/etl/private/pvoidvector.h # include/etl/version.h # support/Release notes.txt --- include/etl/deque.h | 155 ++++++++++++++++++++++++++ include/etl/stl/alternate/algorithm.h | 26 +++++ include/etl/stl/alternate/utility.h | 37 +++--- include/etl/version.h | 2 +- support/Release notes.txt | 5 + test/test_deque.cpp | 65 ++++++++++- test/test_no_stl_algorithm.cpp | 95 ++++++++++++++++ 7 files changed, 368 insertions(+), 17 deletions(-) diff --git a/include/etl/deque.h b/include/etl/deque.h index 49b783ec..fa9d657a 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -38,6 +38,7 @@ SOFTWARE. #include "stl/algorithm.h" #include "stl/iterator.h" +#include "stl/utility.h" #include "container.h" #include "alignment.h" @@ -916,6 +917,60 @@ namespace etl return position; } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Inserts data into the deque. + /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is full. + ///\param insert_position>The insert position. + ///\param value>The value to insert. + //************************************************************************* + iterator insert(const_iterator insert_position, value_type&& value) + { + iterator position(insert_position.index, *this, p_buffer); + + ETL_ASSERT(!full(), ETL_ERROR(deque_full)); + + if (insert_position == begin()) + { + create_element_front(std::move(value)); + position = _begin; + } + else if (insert_position == end()) + { + create_element_back(std::move(value)); + position = _end - 1; + } + else + { + // Are we closer to the front? + if (std::distance(_begin, position) < std::distance(position, _end - 1)) + { + // Construct the _begin. + create_element_front(std::move(*_begin)); + + // Move the values. + std::move(_begin + 1, position, _begin); + + // Write the new value. + *--position = std::move(value); + } + else + { + // Construct the _end. + create_element_back(std::move(*(_end - 1))); + + // Move the values. + std::move_backward(position, _end - 2, _end - 1); + + // Write the new value. + *position = std::move(value); + } + } + + return position; + } +#endif + //************************************************************************* /// Emplaces data into the deque. /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is full. @@ -1577,6 +1632,21 @@ namespace etl create_element_back(item); } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Adds an item to the back of the deque. + /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. + ///\param item The item to push to the deque. + //************************************************************************* + void push_back(T&& item) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif + create_element_back(std::move(item)); + } +#endif + #if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Emplaces an item to the back of the deque. @@ -1690,6 +1760,21 @@ namespace etl create_element_front(item); } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Adds an item to the front of the deque. + /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. + ///\param item The item to push to the deque. + //************************************************************************* + void push_front(T&& item) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(deque_full)); +#endif + create_element_front(std::move(item)); + } +#endif + #if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Emplaces an item to the front of the deque. @@ -1999,6 +2084,30 @@ namespace etl ETL_INCREMENT_DEBUG_COUNT } +#if ETL_CPP11_SUPPORTED + //********************************************************************* + /// Create a new element with a default value at the front. + //********************************************************************* + void create_element_front(T&& value) + { + --_begin; + ::new (&(*_begin)) T(std::move(value)); + ++current_size; + ETL_INCREMENT_DEBUG_COUNT + } + + //********************************************************************* + /// Create a new element with a value at the back + //********************************************************************* + void create_element_back(T&& value) + { + ::new (&(*_end)) T(std::move(value)); + ++_end; + ++current_size; + ETL_INCREMENT_DEBUG_COUNT + } +#endif + //********************************************************************* /// Destroy an element at the front. //********************************************************************* @@ -2129,6 +2238,29 @@ namespace etl } } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move constructor. + //************************************************************************* + deque(deque&& other) + : etl::ideque(reinterpret_cast(&buffer[0]), MAX_SIZE, BUFFER_SIZE) + { + if (this != &other) + { + this->initialise(); + + typename etl::ideque::iterator itr = other.begin(); + while (itr != other.end()) + { + this->push_back(std::move(*itr)); + ++itr; + } + + other.initialise(); + } + } +#endif + //************************************************************************* /// Assigns data to the deque. //************************************************************************* @@ -2172,6 +2304,29 @@ namespace etl return *this; } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move assignment operator. + //************************************************************************* + deque& operator =(deque&& rhs) + { + if (&rhs != this) + { + this->clear(); + typename etl::ideque::iterator itr = rhs.begin(); + while (itr != rhs.end()) + { + this->push_back(std::move(*itr)); + ++itr; + } + + rhs.initialise(); + } + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/stl/alternate/algorithm.h b/include/etl/stl/alternate/algorithm.h index 7bb6ebce..c0e1dba9 100644 --- a/include/etl/stl/alternate/algorithm.h +++ b/include/etl/stl/alternate/algorithm.h @@ -162,6 +162,32 @@ namespace std return de; } + //*************************************************************************** + // move + template + TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db) + { + while (sb != se) + { + *db++ = std::move(*sb++); + } + + return db; + } + + //*************************************************************************** + // move_backward + template + TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + { + while (sb != se) + { + *(--de) = std::move(*(--se)); + } + + return de; + } + //*************************************************************************** // lower_bound template diff --git a/include/etl/stl/alternate/utility.h b/include/etl/stl/alternate/utility.h index 41cf3dec..5bdce60b 100644 --- a/include/etl/stl/alternate/utility.h +++ b/include/etl/stl/alternate/utility.h @@ -1,4 +1,4 @@ -///\file + ///\file /****************************************************************************** The MIT License(MIT) @@ -32,6 +32,7 @@ SOFTWARE. #define ETL_STL_ALTERNATE_UTILITY_INCLUDED #include "../../platform.h" +#include "../../type_traits.h" #if defined(ETL_IN_UNIT_TEST) #if !defined(ETLSTD) @@ -48,7 +49,7 @@ SOFTWARE. #if !defined(ETL_COMPILER_ARM6) //****************************************************************************** template - struct pair + struct pair { typedef T1 first_type; typedef T2 second_type; @@ -57,27 +58,27 @@ SOFTWARE. T2 second; pair() - : first(T1()), - second(T2()) + : first(T1()), + second(T2()) { } - pair(const T1& a, const T2& b) - : first(a), + pair(const T1& a, const T2& b) + : first(a), second(b) { } template - pair(const pair& other) - : first(other.first), - second(other.second) + pair(const pair& other) + : first(other.first), + second(other.second) { } - pair(const pair& other) - : first(other.first), - second(other.second) + pair(const pair& other) + : first(other.first), + second(other.second) { } @@ -99,7 +100,7 @@ SOFTWARE. return pair(a, b); } -#if !defined(ETL_COMPILER_ARM6) +#if !defined(ETL_COMPILER_ARM6) //****************************************************************************** template inline void swap(pair& a, pair& b) @@ -121,7 +122,7 @@ SOFTWARE. } template - inline bool operator <(const pair& a, const pair& b) + inline bool operator <(const pair& a, const pair& b) { return (a.first < b.first) || (!(b.first < a.first) && (a.second < b.second)); @@ -145,6 +146,14 @@ SOFTWARE. return !(a < b); } #endif + +#if ETL_CPP11_SUPPORTED + template + constexpr typename etl::remove_reference::type&& move(T&& t) noexcept + { + return static_cast::type&&>(t); + } +#endif } #endif diff --git a/include/etl/version.h b/include/etl/version.h index f80f9f29..8cf86d59 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 4 +#define ETL_VERSION_MINOR 5 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/support/Release notes.txt b/support/Release notes.txt index a7aaf553..263b614f 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +14.5.0 +Added move algorithms and utility to 'alternate' STL. +Added rvalue reference API to etl::deque. + =============================================================================== 14.4.0 Added C++03/C++11 emplace for deque, priority_queue, queues, stack, variant & vector. diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 5e344a30..bd57e81f 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -39,6 +39,7 @@ SOFTWARE. #include #include #include +#include namespace { @@ -88,7 +89,6 @@ namespace std::vector int_data1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; std::vector int_data2 = { 15, 16, 17, 18 }; - //************************************************************************* TEST(test_constructor) { @@ -145,7 +145,7 @@ namespace CHECK_EQUAL(compare_data.size(), data.size()); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } - + //************************************************************************* TEST(test_copy_constructor) { @@ -1688,5 +1688,66 @@ namespace CHECK(!is_equal); } + + //************************************************************************* + TEST(test_move) + { + const size_t SIZE = 10U; + typedef etl::deque, SIZE> Data; + + Data data1; + + std::unique_ptr p1(new uint32_t(1U)); + std::unique_ptr p2(new uint32_t(2U)); + std::unique_ptr p3(new uint32_t(3U)); + std::unique_ptr p4(new uint32_t(4U)); + std::unique_ptr p5(new uint32_t(5U)); + + // Move items to data1. + data1.push_front(std::move(p1)); + data1.push_back(std::move(p2)); + data1.insert(data1.begin(), std::move(p3)); + data1.insert(data1.begin() + 1, std::move(p4)); + data1.insert(data1.end(), std::move(p5)); + + const size_t ACTUAL_SIZE = data1.size(); + + CHECK(!bool(p1)); + CHECK(!bool(p2)); + CHECK(!bool(p3)); + CHECK(!bool(p4)); + CHECK(!bool(p5)); + + CHECK_EQUAL(3U, *(*(data1.begin() + 0))); + CHECK_EQUAL(4U, *(*(data1.begin() + 1))); + CHECK_EQUAL(1U, *(*(data1.begin() + 2))); + CHECK_EQUAL(2U, *(*(data1.begin() + 3))); + CHECK_EQUAL(5U, *(*(data1.begin() + 4))); + + // Move constructor. + Data data2(std::move(data1)); + + CHECK_EQUAL(3U, *(*(data2.begin() + 0))); + CHECK_EQUAL(4U, *(*(data2.begin() + 1))); + CHECK_EQUAL(1U, *(*(data2.begin() + 2))); + CHECK_EQUAL(2U, *(*(data2.begin() + 3))); + CHECK_EQUAL(5U, *(*(data2.begin() + 4))); + + CHECK(data1.empty()); + CHECK_EQUAL(ACTUAL_SIZE, data2.size()); + + // Move assignment. + Data data3; + data3 = std::move(data2); + + CHECK_EQUAL(3U, *(*(data3.begin() + 0))); + CHECK_EQUAL(4U, *(*(data3.begin() + 1))); + CHECK_EQUAL(1U, *(*(data3.begin() + 2))); + CHECK_EQUAL(2U, *(*(data3.begin() + 3))); + CHECK_EQUAL(5U, *(*(data3.begin() + 4))); + + CHECK(data2.empty()); + CHECK_EQUAL(ACTUAL_SIZE, data3.size()); + } }; } diff --git a/test/test_no_stl_algorithm.cpp b/test/test_no_stl_algorithm.cpp index a41096d2..b6a3ed1f 100644 --- a/test/test_no_stl_algorithm.cpp +++ b/test/test_no_stl_algorithm.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include #include #include +#include #include "no_stl_test_iterators.h" @@ -646,5 +647,99 @@ namespace bool isEqual = std::equal(std::begin(dataD1), std::end(dataD1), std::begin(dataD2)); CHECK(isEqual); } + + //************************************************************************* + TEST(move) + { + typedef std::vector> Data; + + Data data1; + + // Create some data. + std::unique_ptr p1(new uint32_t(1U)); + std::unique_ptr p2(new uint32_t(2U)); + std::unique_ptr p3(new uint32_t(3U)); + std::unique_ptr p4(new uint32_t(4U)); + std::unique_ptr p5(new uint32_t(5U)); + + // Fill data1. + data1.push_back(std::move(p1)); + data1.push_back(std::move(p2)); + data1.push_back(std::move(p3)); + data1.push_back(std::move(p4)); + data1.push_back(std::move(p5)); + + Data data2; + + // Move to data2. + etlstd::move(data1.begin(), data1.end(), std::back_inserter(data2)); + + // Old data now empty. + CHECK(!bool(p1)); + CHECK(!bool(p2)); + CHECK(!bool(p3)); + CHECK(!bool(p4)); + CHECK(!bool(p5)); + + CHECK_EQUAL(1U, *(data2[0])); + CHECK_EQUAL(2U, *(data2[1])); + CHECK_EQUAL(3U, *(data2[2])); + CHECK_EQUAL(4U, *(data2[3])); + CHECK_EQUAL(5U, *(data2[4])); + } + + //************************************************************************* + TEST(move_backward) + { + typedef std::vector> Data; + + Data data1; + + // Create some data. + std::unique_ptr p1(new uint32_t(1U)); + std::unique_ptr p2(new uint32_t(2U)); + std::unique_ptr p3(new uint32_t(3U)); + std::unique_ptr p4(new uint32_t(4U)); + std::unique_ptr p5(new uint32_t(5U)); + + // Fill data1. + data1.push_back(std::move(p1)); + data1.push_back(std::move(p2)); + data1.push_back(std::move(p3)); + data1.push_back(std::move(p4)); + data1.push_back(std::move(p5)); + + Data data2; + + // Create some data. + std::unique_ptr p6(new uint32_t(6U)); + std::unique_ptr p7(new uint32_t(7U)); + std::unique_ptr p8(new uint32_t(8U)); + std::unique_ptr p9(new uint32_t(9U)); + std::unique_ptr p10(new uint32_t(10U)); + + // Fill data2. + data2.push_back(std::move(p6)); + data2.push_back(std::move(p7)); + data2.push_back(std::move(p8)); + data2.push_back(std::move(p9)); + data2.push_back(std::move(p10)); + + // Overwrite data2 with data1. + etlstd::move_backward(data1.begin(), data1.end(), data2.end()); + + // Old data now empty. + CHECK(!bool(p1)); + CHECK(!bool(p2)); + CHECK(!bool(p3)); + CHECK(!bool(p4)); + CHECK(!bool(p5)); + + CHECK_EQUAL(1U, *(data2[0])); + CHECK_EQUAL(2U, *(data2[1])); + CHECK_EQUAL(3U, *(data2[2])); + CHECK_EQUAL(4U, *(data2[3])); + CHECK_EQUAL(5U, *(data2[4])); + } }; } From b8d1447395a1d5f9e8db99a5c142a1a12f505b72 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 17 Dec 2018 19:14:00 +0000 Subject: [PATCH 12/13] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/version.h # support/Release notes.txt --- include/etl/deque.h | 12 +++++------- include/etl/version.h | 2 +- support/Release notes.txt | 4 ++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/etl/deque.h b/include/etl/deque.h index fa9d657a..b829da5d 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -238,8 +238,6 @@ namespace etl protected: - typedef typename etl::parameter_type::type parameter_t; - //************************************************************************* /// Test for an iterator. //************************************************************************* @@ -1624,7 +1622,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. ///\param item The item to push to the deque. //************************************************************************* - void push_back(parameter_t item) + void push_back(const T& item) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1752,7 +1750,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. ///\param item The item to push to the deque. //************************************************************************* - void push_front(parameter_t item) + void push_front(const T& item) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -2065,7 +2063,7 @@ namespace etl //********************************************************************* /// Create a new element with a default value at the front. //********************************************************************* - void create_element_front(parameter_t value) + void create_element_front(const T& value) { --_begin; ::new (&(*_begin)) T(value); @@ -2076,7 +2074,7 @@ namespace etl //********************************************************************* /// Create a new element with a value at the back //********************************************************************* - void create_element_back(parameter_t value) + void create_element_back(const T& value) { ::new (&(*_end)) T(value); ++_end; @@ -2274,7 +2272,7 @@ namespace etl //************************************************************************* /// Assigns data to the deque. //************************************************************************* - explicit deque(size_t n, typename etl::ideque::parameter_t value = value_type()) + explicit deque(size_t n, const T& value = value_type()) : etl::ideque(reinterpret_cast(&buffer[0]), MAX_SIZE, BUFFER_SIZE) { this->assign(n, value); diff --git a/include/etl/version.h b/include/etl/version.h index 8cf86d59..cb340a46 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 5 -#define ETL_VERSION_PATCH 0 +#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_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) diff --git a/support/Release notes.txt b/support/Release notes.txt index 263b614f..e2fa249f 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.5.1 +Fixed deque pushes for literals. + =============================================================================== 14.5.0 Added move algorithms and utility to 'alternate' STL. From 6c7be9f5930be7477a824127776a964c490fc680 Mon Sep 17 00:00:00 2001 From: kiciek Date: Thu, 20 Dec 2018 15:23:51 +0100 Subject: [PATCH 13/13] Fix/cmakelists (#106) * remove absent file from CMakelists File was propably semi-automaticaly added by CLion IDE * Add gitlab pipeline badge --- README.md | 1 + test/CMakeLists.txt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index cfbd3f07..801ee65c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Embedded Template Library (ETL) ------------------------- AppVeyor [![Build status](https://ci.appveyor.com/api/projects/status/b7jgecv7unqjw4u0/branch/master?svg=true)](https://ci.appveyor.com/project/jwellbelove/etl/branch/master) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) +![build status](https://gitlab.com/ETLCPP/etl/badges/master/build.svg) **Motivation** diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 05f96eaf..690e669e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -118,8 +118,6 @@ set(TEST_SOURCE_FILES test_xor_checksum.cpp test_xor_rotate_checksum.cpp - ${CMAKE_SOURCE_DIR}/src/crc16_modbus.cpp - # Compile the source level ecl_timer here as test has provided a ecl_user.h file ${PROJECT_SOURCE_DIR}/../src/c/ecl_timer.c )