From bee78ab4c63bcc1eca1603e5a3dbb9fd06dfd41d Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 30 Sep 2016 14:38:40 +0100 Subject: [PATCH 001/168] Initial implementation of intrusive stack. Uncompiled & untested. --- src/intrusive_stack.h | 138 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/intrusive_stack.h diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h new file mode 100644 index 00000000..025dac89 --- /dev/null +++ b/src/intrusive_stack.h @@ -0,0 +1,138 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_INTRUSIVE_STACK__ +#define __ETL_INTRUSIVE_STACK__ + +#include + +#include "type_traits.h" +#include "parameter_type.h" +#include "error_handler.h" + +namespace etl +{ + //*************************************************************************** + ///\ingroup stack + /// An intrusive stack. Stores elements derived from etl::forward_link + /// \warning This stack cannot be used for concurrent access from multiple threads. + /// \tparam TValue The type of value that the stack holds. + /// \tparam TLink The link type that the value is derived from. + //*************************************************************************** + template > + class intrusive_stack + { + public: + + // Node typedef. + typedef TLink link_type; + + // STL style typedefs. + typedef TValue value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + + public: + + //************************************************************************* + /// Constructor + //************************************************************************* + intrusive_stack() + : p_top(&base) + { + + } + + //************************************************************************* + /// Gets a reference to the value at the top of the stack. + /// Undefined behaviour if the stack is empty. + /// \return A reference to the value at the top of the stack. + //************************************************************************* + reference top() + { + return *p_top; + } + + //************************************************************************* + /// Adds a value to the stack. + ///\param value The value to push to the stack. + //************************************************************************* + void push(link_type& value) + { + etl::link(p_top, value); + p_top = &value; + } + + //************************************************************************* + /// Gets a const reference to the value at the top of the stack.
+ /// \return A const reference to the value at the top of the stack. + //************************************************************************* + const_reference top() const + { + return *p_top; + } + + //************************************************************************* + /// Clears the stack to the empty state. + //************************************************************************* + void clear() + { + unlink(base, *p_top); + } + + //************************************************************************* + /// Removes the oldest item from the top of the stack. + /// Does nothing if the stack is already empty. + //************************************************************************* + void pop() + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(p_top != &base, ETL_ERROR(intrusive_stack_empty)); +#endif + link_type* p_previous = p_top->etl_previous; + unlink(p_top); + p_top = p_previous; + } + + private: + + // Disable copy construction and assignment. + intrusive_stack(const intrusive_stack&); + intrusive_stack& operator = (const intrusive_stack& rhs) + + link_type base; // The base of the stack. + link_type* p_top; // The current top of the stack. + }; +} + +#endif From 59ab675836f7d937cb8cb329f42f49adad1a2397 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 20 Aug 2016 21:22:07 +0100 Subject: [PATCH 002/168] Removed tabs --- src/ibasic_string.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ibasic_string.h b/src/ibasic_string.h index 275f0328..b788117a 100644 --- a/src/ibasic_string.h +++ b/src/ibasic_string.h @@ -148,7 +148,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return reverse_iterator(end()); + return reverse_iterator(end()); } //********************************************************************* @@ -157,7 +157,7 @@ namespace etl //********************************************************************* const_reverse_iterator rbegin() const { - return const_reverse_iterator(end()); + return const_reverse_iterator(end()); } //********************************************************************* @@ -184,7 +184,7 @@ namespace etl //********************************************************************* const_reverse_iterator crbegin() const { - return const_reverse_iterator(cend()); + return const_reverse_iterator(cend()); } //********************************************************************* @@ -193,7 +193,7 @@ namespace etl //********************************************************************* const_reverse_iterator crend() const { - return const_reverse_iterator(cbegin()); + return const_reverse_iterator(cbegin()); } //********************************************************************* From 79bbf860f6c5fcb7c6b9342bfc9f1659d24c0372 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 29 Aug 2016 14:18:53 +0100 Subject: [PATCH 003/168] Tabs to spaces --- src/intrusive_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intrusive_list.h b/src/intrusive_list.h index c4050db9..005c1511 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -341,7 +341,7 @@ namespace etl const value_type* p_value; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Constructor. From 14e387afdcd5e4ec97560cd756a6cdd7e1ff2cdf Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 29 Aug 2016 14:19:08 +0100 Subject: [PATCH 004/168] Tabs to spaces --- src/iforward_list.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/iforward_list.h b/src/iforward_list.h index b663ad8e..0f418209 100644 --- a/src/iforward_list.h +++ b/src/iforward_list.h @@ -256,7 +256,7 @@ namespace etl const Node* p_node; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Gets the beginning of the forward_list. @@ -348,7 +348,7 @@ namespace etl //************************************************************************* /// Assigns a range of values to the forward_list. - /// If asserts or exceptions are enabled throws etl::forward_list_full if the forward_list does not have enough free space. + /// If asserts or exceptions are enabled throws etl::forward_list_full if the forward_list does not have enough free space. /// If ETL_THROW_EXCEPTIONS & _DEBUG are defined throws forward_list_iterator if the iterators are reversed. //************************************************************************* template @@ -707,7 +707,7 @@ namespace etl if (is_trivial_list()) { - return; + return; } while (true) @@ -746,32 +746,32 @@ namespace etl // Decide whether the next node of merge comes from left or right. if (left_size == 0) { - // Left is empty. The node must come from right. - p_node = p_right; + // Left is empty. The node must come from right. + p_node = p_right; ++p_right; --right_size; - } + } else if (right_size == 0 || p_right == end()) { - // Right is empty. The node must come from left. - p_node = p_left; + // Right is empty. The node must come from left. + p_node = p_left; ++p_left; --left_size; - } + } else if (compare(*p_left, *p_right)) { - // First node of left is lower or same. The node must come from left. - p_node = p_left; + // First node of left is lower or same. The node must come from left. + p_node = p_left; ++p_left; --left_size; - } + } else { - // First node of right is lower. The node must come from right. - p_node = p_right; + // First node of right is lower. The node must come from right. + p_node = p_right; ++p_right; --right_size; - } + } // Add the next node to the merged head. if (p_head == before_begin()) From 1a9607c46e314d3c7b9c9c3b587a3181092d3ce8 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 8 Nov 2016 15:43:23 +0000 Subject: [PATCH 005/168] Changed default element size from uint8_t to uint_least8_t --- src/ibitset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ibitset.h b/src/ibitset.h index ee2747f8..b207c7a8 100644 --- a/src/ibitset.h +++ b/src/ibitset.h @@ -85,7 +85,7 @@ namespace etl // The type used for each element in the array. #if !defined(ETL_BITSET_ELEMENT_TYPE) - typedef uint8_t element_t; + typedef uint_least8_t element_t; #else typedef ETL_BITSET_ELEMENT_TYPE element_t; #endif From f4630351a222a739b27295b5bf97418769cb9e3e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Oct 2016 08:57:14 +0100 Subject: [PATCH 006/168] Tans to spaces --- src/intrusive_forward_list.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 21ea1ed2..7268216f 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -324,7 +324,7 @@ namespace etl const value_type* p_value; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Constructor. @@ -657,7 +657,7 @@ namespace etl if (is_trivial_list()) { - return; + return; } while (true) @@ -696,32 +696,32 @@ namespace etl // Decide whether the next link of merge comes from left or right. if (left_size == 0) { - // Left is empty. The link must come from right. - i_link = i_right; + // Left is empty. The link must come from right. + i_link = i_right; ++i_right; --right_size; - } + } else if (right_size == 0 || i_right == end()) { - // Right is empty. The link must come from left. - i_link = i_left; + // Right is empty. The link must come from left. + i_link = i_left; ++i_left; --left_size; - } + } else if (compare(*i_left, *i_right)) { - // First link of left is lower or same. The link must come from left. - i_link = i_left; + // First link of left is lower or same. The link must come from left. + i_link = i_left; ++i_left; --left_size; - } + } else { - // First link of right is lower. The link must come from right. - i_link = i_right; + // First link of right is lower. The link must come from right. + i_link = i_right; ++i_right; --right_size; - } + } // Add the next link to the merged head. if (i_head == before_begin()) From 6edd27698ffe5dfc9a2501d2d2d49683b1c62f24 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Oct 2016 08:58:00 +0100 Subject: [PATCH 007/168] Added default constructors to automatically clear links. --- src/intrusive_links.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/intrusive_links.h b/src/intrusive_links.h index 00ebb14f..47e46a22 100644 --- a/src/intrusive_links.h +++ b/src/intrusive_links.h @@ -114,6 +114,11 @@ namespace etl OPTION = OPTION_ }; + forward_link_base() + { + clear(); + } + void clear() { etl_next = nullptr; @@ -329,6 +334,11 @@ namespace etl OPTION = OPTION_ }; + bidirectional_link_base() + { + clear(); + } + void clear() { etl_previous = nullptr; @@ -662,6 +672,11 @@ namespace etl OPTION = OPTION_ }; + tree_link_base() + { + clear(); + } + void clear() { etl_parent = nullptr; From 31d6defffe42d64729e532b6e94b510e7d8da82c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Oct 2016 09:31:37 +0100 Subject: [PATCH 008/168] Counter type for intrusive containers. Specializations for slow and fast count types. --- src/private/counter_type.h | 139 +++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/private/counter_type.h diff --git a/src/private/counter_type.h b/src/private/counter_type.h new file mode 100644 index 00000000..df94fbe8 --- /dev/null +++ b/src/private/counter_type.h @@ -0,0 +1,139 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_COUNTER_TYPE__ +#define __ETL_COUNTER_TYPE__ + +#include + +#include "../intrusive_links.h" + +namespace etl +{ + //************************************************************************* + /// Counter type based on intrusive link count option. + //************************************************************************* + template + class counter_type + { + }; + + //************************************************************************* + /// Slow type. + //************************************************************************* + template <> + class counter_type + { + public: + + counter_type& operator ++() + { + return *this; + } + + counter_type& operator --() + { + return *this; + } + + counter_type& operator =(size_t new_count) + { + return *this; + } + + counter_type& operator +=(size_t diff) + { + return *this; + } + + counter_type& operator -=(size_t diff) + { + return *this; + } + + size_t get_count() const + { + return 0; + } + }; + + //************************************************************************* + /// Fast type. + //************************************************************************* + template <> + class counter_type + { + public: + + counter_type() + : count(0) + { + } + + counter_type& operator ++() + { + ++count; + return *this; + } + + counter_type& operator --() + { + --count; + return *this; + } + + counter_type& operator =(size_t new_count) + { + count = new_count; + return *this; + } + + counter_type& operator +=(size_t diff) + { + count += diff; + return *this; + } + + counter_type& operator -=(size_t diff) + { + count -= diff; + return *this; + } + + size_t get_count() const + { + return count; + } + + size_t count; + }; +} + +#endif From c477d481336e7de28d462efd68c6d581313bfac5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:22:21 +0000 Subject: [PATCH 009/168] New intrusive stack --- src/intrusive_stack.h | 120 +++++++++++++--- test/test_intrusive_stack.cpp | 248 ++++++++++++++++++++++++++++++++++ 2 files changed, 349 insertions(+), 19 deletions(-) create mode 100644 test/test_intrusive_stack.cpp diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h index 025dac89..d7c43c24 100644 --- a/src/intrusive_stack.h +++ b/src/intrusive_stack.h @@ -34,11 +34,40 @@ SOFTWARE. #include #include "type_traits.h" -#include "parameter_type.h" #include "error_handler.h" +#include "intrusive_links.h" +#include "private/counter_type.h" namespace etl { + //*************************************************************************** + /// Exception base for intrusive stack + ///\ingroup intrusive_stack + //*************************************************************************** + class intrusive_stack_exception : public etl::exception + { + public: + + intrusive_stack_exception(string_type what, string_type file_name, numeric_type line_number) + : exception(what, file_name, line_number) + { + } + }; + + //*************************************************************************** + /// intrusive_stack empty exception. + ///\ingroup intrusive_stack + //*************************************************************************** + class intrusive_stack_empty : public intrusive_stack_exception + { + public: + + intrusive_stack_empty(string_type file_name, numeric_type line_number) + : intrusive_stack_exception(ETL_ERROR_TEXT("intrusive_stack:empty", ETL_FILE"A"), file_name, line_number) + { + } + }; + //*************************************************************************** ///\ingroup stack /// An intrusive stack. Stores elements derived from etl::forward_link @@ -46,7 +75,7 @@ namespace etl /// \tparam TValue The type of value that the stack holds. /// \tparam TLink The link type that the value is derived from. //*************************************************************************** - template > + template class intrusive_stack { public: @@ -62,15 +91,20 @@ namespace etl typedef const value_type& const_reference; typedef size_t size_type; - public: + enum + { + // The count option is based on the type of link. + COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || (TLink::OPTION == etl::link_option::CHECKED)) ? + etl::count_option::SLOW_COUNT : + etl::count_option::FAST_COUNT + }; //************************************************************************* /// Constructor //************************************************************************* intrusive_stack() - : p_top(&base) + : p_top(nullptr) { - } //************************************************************************* @@ -80,7 +114,7 @@ namespace etl //************************************************************************* reference top() { - return *p_top; + return *static_cast(p_top); } //************************************************************************* @@ -89,8 +123,29 @@ namespace etl //************************************************************************* void push(link_type& value) { - etl::link(p_top, value); + if (p_top != nullptr) + { + etl::link(value, p_top); + } + p_top = &value; + + ++current_size; + } + + //************************************************************************* + /// Removes the oldest item from the top of the stack. + /// Undefined behaviour if the stack is already empty. + //************************************************************************* + void pop() + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!empty(), ETL_ERROR(intrusive_stack_empty)); +#endif + link_type* p_next = p_top->etl_next; + p_top->clear(); + p_top = p_next; + --current_size; } //************************************************************************* @@ -107,31 +162,58 @@ namespace etl //************************************************************************* void clear() { - unlink(base, *p_top); + while (!empty()) + { + pop(); + } + current_size = 0; } //************************************************************************* - /// Removes the oldest item from the top of the stack. - /// Does nothing if the stack is already empty. + /// Checks if the stack is in the empty state. //************************************************************************* - void pop() + bool empty() const { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(p_top != &base, ETL_ERROR(intrusive_stack_empty)); -#endif - link_type* p_previous = p_top->etl_previous; - unlink(p_top); - p_top = p_previous; + return p_top == nullptr; + } + + //************************************************************************* + /// Returns the number of elements. + //************************************************************************* + size_t size() const + { + if (COUNT_OPTION == etl::count_option::SLOW_COUNT) + { + size_t count = 0; + + if (p_top != nullptr) + { + link_type* p_link = p_top; + + while (p_link != nullptr) + { + ++count; + p_link = p_link->etl_next; + } + } + + return count; + } + else + { + return current_size.get_count(); + } } private: // Disable copy construction and assignment. intrusive_stack(const intrusive_stack&); - intrusive_stack& operator = (const intrusive_stack& rhs) + intrusive_stack& operator = (const intrusive_stack& rhs); - link_type base; // The base of the stack. link_type* p_top; // The current top of the stack. + + etl::counter_type current_size; ///< Counts the number of elements in the list. }; } diff --git a/test/test_intrusive_stack.cpp b/test/test_intrusive_stack.cpp new file mode 100644 index 00000000..cec894da --- /dev/null +++ b/test/test_intrusive_stack.cpp @@ -0,0 +1,248 @@ +/****************************************************************************** +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 "../src/intrusive_stack.h" +#include "../src/intrusive_links.h" + +#include + +namespace +{ + enum + { + DEFAULT, + AUTO, + CHECKED + }; + + etl::forward_link link; + + typedef etl::forward_link default_link; + typedef etl::forward_link checked_link; + + struct Data : public default_link, public checked_link + { + Data(int i) + : i(i) + { + + } + + int i; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return lhs.i == rhs.i; + } + + std::ostream& operator << (std::ostream& os, const Data& data) + { + os << data.i; + return os; + } + + std::vector data = + { + Data(1), Data(2), Data(3), Data(4), Data(5), Data(6), Data(7), Data(8) + }; + + SUITE(test_intrusive_stack) + { + //************************************************************************* + TEST(test_constructor) + { + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + + CHECK(stackD.empty()); + CHECK(stackC.empty()); + + CHECK_EQUAL(0, stackD.size()); + CHECK_EQUAL(0, stackC.size()); + } + + //************************************************************************* + TEST(test_empty) + { + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + + Data data1(1); + Data data2(2); + + CHECK(stackD.empty()); + CHECK(stackC.empty()); + + stackD.push(data1); + stackC.push(data2); + + CHECK(!stackD.empty()); + CHECK(!stackC.empty()); + + data1.checked_link::clear(); + data2.checked_link::clear(); + } + + //************************************************************************* + TEST(test_size) + { + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + + Data data1(1); + Data data2(2); + Data data3(3); + + stackD.push(data1); + stackD.push(data2); + stackD.push(data3); + + stackC.push(data1); + stackC.push(data2); + + CHECK_EQUAL(3U, stackD.size()); + CHECK_EQUAL(2U, stackC.size()); + + data1.checked_link::clear(); + data2.checked_link::clear(); + } + + //************************************************************************* + TEST(test_clear) + { + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + + Data data1(1); + Data data2(2); + Data data3(3); + + stackD.push(data1); + stackD.push(data2); + stackD.push(data3); + + stackC.push(data1); + stackC.push(data2); + + stackD.clear(); + stackC.clear(); + + CHECK(stackD.empty()); + CHECK(stackC.empty()); + } + + //************************************************************************* + TEST(test_push) + { + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + + Data data1(1); + Data data2(2); + Data data3(3); + + stackD.push(data1); + CHECK_EQUAL(stackD.top(), data1); + + stackD.push(data2); + CHECK_EQUAL(stackD.top(), data2); + + stackD.push(data3); + CHECK_EQUAL(stackD.top(), data3); + + stackC.push(data1); + CHECK_EQUAL(stackC.top(), data1); + + stackC.push(data2); + CHECK_EQUAL(stackC.top(), data2); + + data1.checked_link::clear(); + data2.checked_link::clear(); + } + + + //************************************************************************* + TEST(test_pop) + { + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + + Data data1(1); + Data data2(2); + Data data3(3); + + stackD.push(data1); + stackD.push(data2); + stackD.push(data3); + + stackC.push(data1); + stackC.push(data2); + + CHECK_EQUAL(stackD.top(), data3); + stackD.pop(); + CHECK_EQUAL(stackD.top(), data2); + stackD.pop(); + CHECK_EQUAL(stackD.top(), data1); + stackD.pop(); + CHECK(stackD.empty()); + + CHECK_EQUAL(stackC.top(), data2); + stackC.pop(); + CHECK_EQUAL(stackC.top(), data1); + stackC.pop(); + CHECK(stackC.empty()); + + data1.checked_link::clear(); + data2.checked_link::clear(); + } + + //************************************************************************* + TEST(test_top_const) + { + etl::intrusive_stack stackD; + const etl::intrusive_stack& stackDR = stackD; + + Data data1(1); + Data data2(2); + Data data3(3); + + stackD.push(data1); + stackD.push(data2); + stackD.push(data3); + + CHECK_EQUAL(stackD.top(), stackDR.top()); + stackD.pop(); + CHECK_EQUAL(stackD.top(), stackDR.top()); + stackD.pop(); + CHECK_EQUAL(stackD.top(), stackDR.top()); + } + }; +} From e7ecc17a786486a55777c9bd670882762d959dae Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:23:06 +0000 Subject: [PATCH 010/168] Untabify --- src/type_traits.h | 24 ++++++++++++------------ src/variant.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/type_traits.h b/src/type_traits.h index bef809ae..605aa63d 100644 --- a/src/type_traits.h +++ b/src/type_traits.h @@ -47,15 +47,15 @@ namespace etl template struct integral_constant { - static const T value = VALUE; + static const T value = VALUE; - typedef T value_type; + typedef T value_type; typedef integral_constant type; - operator value_type() const - { - return value; - } + operator value_type() const + { + return value; + } }; /// integral_constant specialisations @@ -250,9 +250,9 @@ namespace etl #else template <> struct make_signed { - typedef etl::conditional::type>::type>::type type; + typedef etl::conditional::type>::type>::type type; }; #endif template <> struct make_signed { typedef short type; }; @@ -277,9 +277,9 @@ namespace etl #else template <> struct make_unsigned { - typedef etl::conditional::type>::type>::type type; + typedef etl::conditional::type>::type>::type type; }; #endif template <> struct make_unsigned { typedef unsigned int type; }; diff --git a/src/variant.h b/src/variant.h index 2e8522ec..38492c4f 100644 --- a/src/variant.h +++ b/src/variant.h @@ -46,7 +46,7 @@ SOFTWARE. #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 940 - #pragma diag_suppress 111 + #pragma diag_suppress 111 #endif #undef ETL_FILE From 10674d52c07e9758acad2c41f2b52bee01103377 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:23:52 +0000 Subject: [PATCH 011/168] Removed build platform defines. Added 'no 8bit types' define --- src/platform.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/platform.h b/src/platform.h index 13650550..d6cb9159 100644 --- a/src/platform.h +++ b/src/platform.h @@ -28,19 +28,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ +#include +#include "static_assert.h" + // Define the platform. -// For FreeRTOS you must define ETL_PLATFORM_FREERTOS in the project settings. -#if defined(__linux__) -#define ETL_PLATFORM_LINUX -#elif defined(WIN32) || defined(WIN64) -#define ETL_PLATFORM_WINDOWS -#elif defined(__VXWORKS__) || defined(_WRS_VXWORKS_MAJOR) -#define ETL_PLATFORM_VXWORKS -#elif defined(__QNX__) || defined(__QNXNTO__) -#define ETL_PLATFORM_QNX -#elif defined(_WIN32_WCE) -#define ETL_PLATFORM_WINDOWS_CE -#else +// The target platform will normally be defined as a compiler pre-processor directive. +// Defines ETL_PLATFORM_GENERIC if a recognised platform is not declared. +#if !defined(ETL_PLATFORM_LINUX) && !defined(ETL_PLATFORM_WINDOWS) && !defined(ETL_PLATFORM_WINDOWS_CE) && !defined(ETL_PLATFORM_VXWORKS) && !defined(ETL_PLATFORM_QNX) +#pragma message("ETL: Using generic platform") #define ETL_PLATFORM_GENERIC #endif @@ -63,11 +58,15 @@ SOFTWARE. #define ETL_COMPILER_GENERIC #endif +// Check to see if the compiler supports nullptr and large character types. #if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER < 1600)) || \ defined(ETL_COMPILER_KEIL) || \ defined(ETL_COMPILER_TI_MSP430) || \ defined(ETL_COMPILER_IAR) || \ (defined(ETL_COMPILER_GCC) && (__cplusplus < 201103L)) -#define NO_NULLPTR_SUPPORT -#define NO_LARGE_CHAR_SUPPORT +#define ETL_ETL_NO_NULLPTR_SUPPORT +#define ETL_ETL_NO_LARGE_CHAR_SUPPORT #endif + +// Some targets do not support 8bit or even 16bit types. +#define ETL_8BIT_SUPPORT ((sizeof(uint_least8_t) != sizeof(uint16_t)) && (sizeof(uint_least8_t) != sizeof(uint32_t))) From b468c8b3a46709b38b0a2a40b88aad0ef855f93a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:24:12 +0000 Subject: [PATCH 012/168] Added ETL_ prefix --- src/nullptr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nullptr.h b/src/nullptr.h index 84979c79..fb523714 100644 --- a/src/nullptr.h +++ b/src/nullptr.h @@ -37,7 +37,7 @@ SOFTWARE. /// A definition of nullptr for compilers that don't support it as standard. ///\ingroup utilities -#if defined(NO_NULLPTR_SUPPORT) +#if defined(ETL_NO_NULLPTR_SUPPORT) namespace std { //***************************************************************************** From e75f4bd248f5403ed229764618ab8e6edc186b5c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:25:09 +0000 Subject: [PATCH 013/168] Changed 'Does nothing' comment to 'Undefined behavior' --- src/ibasic_string.h | 11 ++++++----- src/ipriority_queue.h | 13 +++++-------- src/iqueue.h | 2 +- src/istack.h | 2 +- src/ivector.h | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ibasic_string.h b/src/ibasic_string.h index b788117a..34c6ba95 100644 --- a/src/ibasic_string.h +++ b/src/ibasic_string.h @@ -460,14 +460,15 @@ namespace etl //************************************************************************* /// Removes an element from the end of the string. - /// Does nothing if the string is empty. + /// Undefined behaviour if the string is empty. //************************************************************************* void pop_back() { - if (current_size > 0) - { - p_buffer[--current_size] = 0; - } +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!empty(), ETL_ERROR(string_empty)); +#endif + + p_buffer[--current_size] = 0; } //********************************************************************* diff --git a/src/ipriority_queue.h b/src/ipriority_queue.h index fd3cb832..74a11cfd 100644 --- a/src/ipriority_queue.h +++ b/src/ipriority_queue.h @@ -180,17 +180,14 @@ namespace etl //************************************************************************* /// Removes the oldest value from the back of the priority queue. - /// Does nothing if the priority queue is already empty. + /// Undefined behaviour if the priority queue is already empty. //************************************************************************* void pop() { - if (!empty()) - { - // Move largest element to end - std::pop_heap(container.begin(), container.end(), TCompare()); - // Actually remove largest element at end - container.pop_back(); - } + // Move largest element to end + std::pop_heap(container.begin(), container.end(), TCompare()); + // Actually remove largest element at end + container.pop_back(); } //************************************************************************* diff --git a/src/iqueue.h b/src/iqueue.h index 0f55963c..8d8751f2 100644 --- a/src/iqueue.h +++ b/src/iqueue.h @@ -162,7 +162,7 @@ namespace etl //************************************************************************* /// Removes the oldest value from the back of the queue. - /// Does nothing if the queue is already empty. + /// Undefined behaviour if the queue is already empty. //************************************************************************* void pop() { diff --git a/src/istack.h b/src/istack.h index 35e8107c..d742f452 100644 --- a/src/istack.h +++ b/src/istack.h @@ -135,7 +135,7 @@ namespace etl //************************************************************************* /// Removes the oldest item from the top of the stack. - /// Does nothing if the stack is already empty. + /// Undefined behaviour if the stack is already empty. //************************************************************************* void pop() { diff --git a/src/ivector.h b/src/ivector.h index 0dfe8491..a186a4a7 100644 --- a/src/ivector.h +++ b/src/ivector.h @@ -475,7 +475,7 @@ namespace etl //************************************************************************* /// Removes an element from the end of the vector. - /// Does nothing if the vector is empty. + /// Undefined behaviour if the vector is empty. //************************************************************************* void pop_back() { From 1c0561753565a95dff3a0a1bd7c419bd5c8d23a6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:26:19 +0000 Subject: [PATCH 014/168] Moved counter type to common class. Changed some parameter names. --- src/intrusive_list.h | 172 ++++++++++--------------------------------- 1 file changed, 38 insertions(+), 134 deletions(-) diff --git a/src/intrusive_list.h b/src/intrusive_list.h index 005c1511..9e151c8f 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -49,6 +49,7 @@ SOFTWARE. #include "intrusive_links.h" #include "static_assert.h" #include "algorithm.h" +#include "private/counter_type.h" #undef ETL_FILE #define ETL_FILE "21" @@ -351,6 +352,14 @@ namespace etl initialise(); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~intrusive_list() + { + clear(); + } + //************************************************************************* /// Constructor from range //************************************************************************* @@ -413,6 +422,11 @@ namespace etl //************************************************************************* void clear() { + if (TLink::OPTION == etl::link_option::CHECKED) + { + erase(begin(), end()); + } + initialise(); } @@ -537,33 +551,21 @@ namespace etl //************************************************************************* /// Inserts a value to the intrusive_list before the specified position. - /// Checks that the value is unlinked if CHECKED //************************************************************************* iterator insert(iterator position, value_type& value) { - if (TLink::OPTION == etl::link_option::CHECKED) - { - ETL_ASSERT(!value.TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); - } - insert_link(position.p_value->link_type::etl_previous, value); return iterator(value); } //************************************************************************* /// Inserts a range of values to the intrusive_list after the specified position. - /// Checks that the values are unlinked if CHECKED. //************************************************************************* template void insert(iterator position, TIterator first, TIterator last) { while (first != last) { - if (TLink::OPTION == etl::link_option::CHECKED) - { - ETL_ASSERT(!position.p_value->TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); - } - // Set up the next free link. insert_link(*position.p_value->link_type::etl_previous, *first++); } @@ -844,21 +846,21 @@ namespace etl //************************************************************************* /// Splice another list into this one. //************************************************************************* - void splice(iterator position, list_type& list) + void splice(iterator position, list_type& other) { // No point splicing to ourself! - if (&list != this) + if (&other != this) { - if (!list.empty()) + if (!other.empty()) { - link_type& first = *list.get_head(); - link_type& last = *list.get_tail(); + link_type& first = *other.get_head(); + link_type& last = *other.get_tail(); if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - if (&list != this) + if (&other != this) { - current_size += list.size(); + current_size += other.size(); } } @@ -868,7 +870,7 @@ namespace etl etl::link(before, first); etl::link(last, after); - list.clear(); + other.initialise(); } } } @@ -876,7 +878,7 @@ namespace etl //************************************************************************* /// Splice an element from another list into this one. //************************************************************************* - void splice(iterator position, list_type& list, iterator isource) + void splice(iterator position, list_type& other, iterator isource) { link_type& before = *position.p_value->link_type::etl_previous; @@ -885,10 +887,10 @@ namespace etl if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - if (&list != this) + if (&other != this) { ++current_size; - --list.current_size; + --other.current_size; } } } @@ -896,17 +898,17 @@ namespace etl //************************************************************************* /// Splice a range of elements from another list into this one. //************************************************************************* - void splice(iterator position, list_type& list, iterator begin_, iterator end_) + void splice(iterator position, list_type& other, iterator begin_, iterator end_) { - if (!list.empty()) + if (!other.empty()) { if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - if (&list != this) + if (&other != this) { size_t n = std::distance(begin_, end_); current_size += n; - list.current_size -= n; + other.current_size -= n; } } @@ -926,26 +928,26 @@ namespace etl //************************************************************************* /// Merge another list into this one. Both lists should be sorted. //************************************************************************* - void merge(list_type& list) + void merge(list_type& other) { - merge(list, std::less()); + merge(other, std::less()); } //************************************************************************* /// Merge another list into this one. Both lists should be sorted. //************************************************************************* template - void merge(list_type& list, TCompare compare) + void merge(list_type& other, TCompare compare) { - if (!list.empty()) + if (!other.empty()) { #if _DEBUG - ETL_ASSERT(etl::is_sorted(list.begin(), list.end(), compare), ETL_ERROR(intrusive_list_unsorted)); + ETL_ASSERT(etl::is_sorted(other.begin(), other.end(), compare), ETL_ERROR(intrusive_list_unsorted)); ETL_ASSERT(etl::is_sorted(begin(), end(), compare), ETL_ERROR(intrusive_list_unsorted)); #endif - value_type* other_begin = static_cast(list.get_head()); - value_type* other_end = static_cast(&list.terminal_link); + value_type* other_begin = static_cast(other.get_head()); + value_type* other_end = static_cast(&other.terminal_link); value_type* begin = static_cast(get_head()); value_type* end = static_cast(&terminal_link); @@ -979,10 +981,10 @@ namespace etl if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - current_size += list.size(); + current_size += other.size(); } - list.clear(); + other.initialise(); } } @@ -991,104 +993,6 @@ namespace etl /// The link that acts as the intrusive_list start & end. link_type terminal_link; - //************************************************************************* - /// Counter type based on count option. - //************************************************************************* - template - class counter_type - { - }; - - //************************************************************************* - /// Slow type. - //************************************************************************* - template - class counter_type - { - public: - - counter_type& operator ++() - { - return *this; - } - - counter_type& operator --() - { - return *this; - } - - counter_type& operator =(size_t new_count) - { - return *this; - } - - counter_type& operator +=(size_t diff) - { - return *this; - } - - counter_type& operator -=(size_t diff) - { - return *this; - } - - size_t get_count() const - { - return 0; - } - }; - - //************************************************************************* - /// Fast type. - //************************************************************************* - template - class counter_type - { - public: - - counter_type() - : count(0) - { - } - - counter_type& operator ++() - { - ++count; - return *this; - } - - counter_type& operator --() - { - --count; - return *this; - } - - counter_type& operator =(size_t new_count) - { - count = new_count; - return *this; - } - - counter_type& operator +=(size_t diff) - { - count += diff; - return *this; - } - - counter_type& operator -=(size_t diff) - { - count -= diff; - return *this; - } - - size_t get_count() const - { - return count; - } - - size_t count; - }; - counter_type current_size; ///< Counts the number of elements in the list. //************************************************************************* From e9c17deb3ff91591e50fa938e052bc733d4b5d4b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:27:21 +0000 Subject: [PATCH 015/168] Removed AUTO specialisations for forward and tree links. --- src/intrusive_links.h | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/intrusive_links.h b/src/intrusive_links.h index 47e46a22..eb0bf522 100644 --- a/src/intrusive_links.h +++ b/src/intrusive_links.h @@ -146,17 +146,10 @@ namespace etl // There is no valid specialisation for auto link //****************************************************************** template - struct forward_link - : public __private_intrusive_links__::forward_link_base, ID_, etl::link_option::AUTO> - { - forward_link() - { - this->clear(); - } - }; + struct forward_link; //****************************************************************** - // Specialisation for checked unlink option. + // Specialisation for checked link option. // An error will be generated if the links are valid when the object // is destroyed. //****************************************************************** @@ -171,7 +164,7 @@ namespace etl ~forward_link() { - assert(this->etl_next != nullptr); + assert(this->etl_next == nullptr); } }; @@ -708,14 +701,7 @@ namespace etl // There is no valid specialisation for auto link //****************************************************************** template - struct tree_link - : public __private_intrusive_links__::tree_link_base, ID_, etl::link_option::AUTO> - { - tree_link() - { - this->clear(); - } - }; + struct tree_link; //****************************************************************** // Specialisation for checked unlink option. @@ -733,9 +719,9 @@ namespace etl ~tree_link() { - assert(this->etl_parent != nullptr); - assert(this->etl_left != nullptr); - assert(this->etl_right != nullptr); + assert(this->etl_parent == nullptr); + assert(this->etl_left == nullptr); + assert(this->etl_right == nullptr); } }; From e768015be7a4d7d8037bf66ee3eeb62656227cbc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:27:33 +0000 Subject: [PATCH 016/168] Moved counter type to common class. Changed some parameter names. --- src/intrusive_forward_list.h | 179 ++++++++--------------------------- 1 file changed, 41 insertions(+), 138 deletions(-) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 7268216f..3bec7fd4 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -48,6 +48,7 @@ SOFTWARE. #include "error_handler.h" #include "intrusive_links.h" #include "algorithm.h" +#include "private/counter_type.h" #undef ETL_FILE #define ETL_FILE "20" @@ -334,6 +335,14 @@ namespace etl initialise(); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~intrusive_forward_list() + { + clear(); + } + //************************************************************************* /// Constructor from range //************************************************************************* @@ -412,6 +421,11 @@ namespace etl //************************************************************************* void clear() { + if (TLink::OPTION == etl::link_option::CHECKED) + { + erase_after(before_begin(), end()); + } + initialise(); } @@ -503,33 +517,21 @@ namespace etl //************************************************************************* /// Inserts a value to the intrusive_forward_list after the specified position. - /// Checks that the value is unlinked if CHECKED. //************************************************************************* iterator insert_after(iterator position, value_type& value) { - if (TLink::OPTION == etl::link_option::CHECKED) - { - ETL_ASSERT(!value.TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); - } - insert_link_after(*position.p_value, value); return iterator(value); } //************************************************************************* /// Inserts a range of values to the intrusive_forward_list after the specified position. - /// Checks that the values are unlinked if CHECKED. //************************************************************************* template void insert_after(iterator position, TIterator first, TIterator last) { while (first != last) { - if (TLink::OPTION == etl::link_option::CHECKED) - { - ETL_ASSERT(!position.p_value->TLink::is_linked(), ETL_ERROR(etl::not_unlinked_exception)); - } - // Set up the next free link. insert_link_after(*position.p_value, *first++); ++position; @@ -548,10 +550,10 @@ namespace etl remove_link_after(*position.p_value); - if (TLink::OPTION == etl::link_option::CHECKED) - { - position.p_value->TLink::clear(); - } + //if (TLink::OPTION == etl::link_option::CHECKED) + //{ + // position.p_value->TLink::clear(); + //} return next; } @@ -825,20 +827,21 @@ namespace etl //************************************************************************* /// Splice another list into this one. //************************************************************************* - void splice_after(iterator position, etl::intrusive_forward_list& list) + void splice_after(iterator position, etl::intrusive_forward_list& other) { // No point splicing to ourself! - if (&list != this) + if (&other != this) { - if (!list.empty()) + if (!other.empty()) { - link_type& first = list.get_head(); + link_type& first = other.get_head(); + other.initialise(); if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - if (&list != this) + if (&other != this) { - current_size += list.size(); + current_size += other.size(); } } @@ -854,8 +857,6 @@ namespace etl } etl::link(last, after); - - list.clear(); } } } @@ -863,7 +864,7 @@ namespace etl //************************************************************************* /// Splice an element from another list into this one. //************************************************************************* - void splice(iterator position, etl::intrusive_forward_list& list, iterator isource) + void splice(iterator position, etl::intrusive_forward_list& other, iterator isource) { link_type& before = *position.p_value; @@ -872,10 +873,10 @@ namespace etl if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - if (&list != this) + if (&other != this) { ++current_size; - --list.current_size; + --other.current_size; } } } @@ -883,17 +884,17 @@ namespace etl //************************************************************************* /// Splice a range of elements from another list into this one. //************************************************************************* - void splice_after(iterator position, etl::intrusive_forward_list& list, iterator begin_, iterator end_) + void splice_after(iterator position, etl::intrusive_forward_list& other, iterator begin_, iterator end_) { - if (!list.empty()) + if (!other.empty()) { if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - if (&list != this) + if (&other != this) { size_t n = std::distance(begin_, end_) - 1; current_size += n; - list.current_size -= n; + other.current_size -= n; } } @@ -905,7 +906,7 @@ namespace etl last = last->link_type::etl_next; } - // Unlink from the source list. + // Unlink from the source other. link_type* first_next = first->link_type::etl_next; etl::unlink_after(*first, *last); @@ -919,25 +920,25 @@ namespace etl //************************************************************************* /// Merge another list into this one. Both lists should be sorted. //************************************************************************* - void merge(list_type& list) + void merge(list_type& other) { - merge(list, std::less()); + merge(other, std::less()); } //************************************************************************* /// Merge another list into this one. Both lists should be sorted. //************************************************************************* template - void merge(list_type& list, TCompare compare) + void merge(list_type& other, TCompare compare) { - if (!list.empty()) + if (!other.empty()) { #if _DEBUG - ETL_ASSERT(etl::is_sorted(list.begin(), list.end(), compare), ETL_ERROR(intrusive_forward_list_unsorted)); + ETL_ASSERT(etl::is_sorted(other.begin(), other.end(), compare), ETL_ERROR(intrusive_forward_list_unsorted)); ETL_ASSERT(etl::is_sorted(begin(), end(), compare), ETL_ERROR(intrusive_forward_list_unsorted)); #endif - value_type* other_begin = static_cast(&list.get_head()); + value_type* other_begin = static_cast(&other.get_head()); value_type* other_terminal = nullptr; value_type* before = static_cast(&start_link); @@ -980,10 +981,10 @@ namespace etl if (COUNT_OPTION == etl::count_option::FAST_COUNT) { - current_size += list.size(); + current_size += other.size(); } - list.clear(); + other.initialise(); } } @@ -991,104 +992,6 @@ namespace etl link_type start_link; ///< The link that acts as the intrusive_forward_list start. - //************************************************************************* - /// Counter type based on count option. - //************************************************************************* - template - class counter_type - { - }; - - //************************************************************************* - /// Slow type. - //************************************************************************* - template - class counter_type - { - public: - - counter_type& operator ++() - { - return *this; - } - - counter_type& operator --() - { - return *this; - } - - counter_type& operator =(size_t new_count) - { - return *this; - } - - counter_type& operator +=(size_t diff) - { - return *this; - } - - counter_type& operator -=(size_t diff) - { - return *this; - } - - size_t get_count() const - { - return 0; - } - }; - - //************************************************************************* - /// Fast type. - //************************************************************************* - template - class counter_type - { - public: - - counter_type() - : count(0) - { - } - - counter_type& operator ++() - { - ++count; - return *this; - } - - counter_type& operator --() - { - --count; - return *this; - } - - counter_type& operator =(size_t new_count) - { - count = new_count; - return *this; - } - - counter_type& operator +=(size_t diff) - { - count += diff; - return *this; - } - - counter_type& operator -=(size_t diff) - { - count -= diff; - return *this; - } - - size_t get_count() const - { - return count; - } - - size_t count; - }; - counter_type current_size; ///< Counts the number of elements in the list. //************************************************************************* From aaf8df66c19f67944f5772c5158698792aef275f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:27:45 +0000 Subject: [PATCH 017/168] Added ETL_ prefix --- src/char_traits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/char_traits.h b/src/char_traits.h index 6caab98a..21afb8cb 100644 --- a/src/char_traits.h +++ b/src/char_traits.h @@ -44,7 +44,7 @@ SOFTWARE. //***************************************************************************** // Define the large character types if necessary. -#ifdef NO_LARGE_CHAR_SUPPORT +#ifdef ETL_NO_LARGE_CHAR_SUPPORT typedef int16_t char16_t; typedef int32_t char32_t; #endif From d39a74bc6e53212516e2374eff0efd18b58b4404 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:27:56 +0000 Subject: [PATCH 018/168] Changed 'Does nothing' comment to 'Undefined behavior' --- src/private/pvoidvector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/private/pvoidvector.h b/src/private/pvoidvector.h index 67fdd4ef..165d0c32 100644 --- a/src/private/pvoidvector.h +++ b/src/private/pvoidvector.h @@ -392,7 +392,7 @@ namespace etl //************************************************************************* /// Removes an element from the end of the vector. - /// Does nothing if the vector is empty. + /// Undefined behaviour if the vector is empty. //************************************************************************* void pop_back() { From 3f107f4141a55cad3e4a32485205f4b272f86c58 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:28:40 +0000 Subject: [PATCH 019/168] Removed AUTO links for forward links from test --- test/test_intrusive_links.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index adc54cec..bb2251cf 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -40,9 +40,9 @@ namespace //******************************************************* typedef etl::forward_link<0> FirstFLink; typedef etl::forward_link<1> SecondFLink; - typedef etl::forward_link<2, etl::link_option::AUTO> ThirdFLinkAuto; + typedef etl::forward_link<2, etl::link_option::CHECKED> ThirdFLinkChecked; - struct FData : public FirstFLink, public SecondFLink, public ThirdFLinkAuto + struct FData : public FirstFLink, public SecondFLink, public ThirdFLinkChecked { FData(int value) : value(value) @@ -349,17 +349,22 @@ namespace CHECK(data2.SecondFLink::etl_next == &data0); CHECK(data0.SecondFLink::etl_next == nullptr); - // Check auto link. - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + // Check checked link. + etl::link(data0, data1); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - etl::unlink_after(data1); + etl::unlink_after(data1); - CHECK(data0.ThirdFLinkAuto::etl_next == &data1); - CHECK(data1.ThirdFLinkAuto::etl_next == &data3); - CHECK(data3.ThirdFLinkAuto::etl_next == nullptr); + CHECK(data0.ThirdFLinkChecked::etl_next == &data1); + CHECK(data1.ThirdFLinkChecked::etl_next == &data3); + CHECK(data3.ThirdFLinkChecked::etl_next == nullptr); + + data0.ThirdFLinkChecked::clear(); + data1.ThirdFLinkChecked::clear(); + data2.ThirdFLinkChecked::clear(); + data3.ThirdFLinkChecked::clear(); } //************************************************************************* From 70dcd71eb6273005b42a4967d613b626750f0859 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:28:54 +0000 Subject: [PATCH 020/168] Removed AUTO links for forward links from test --- test/test_intrusive_forward_list.cpp | 345 ++++++++++++++++++++++----- 1 file changed, 291 insertions(+), 54 deletions(-) diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index aaf9179f..089b005c 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -45,7 +45,7 @@ typedef TestDataNDC ItemNDC; namespace { - typedef etl::forward_link<0, etl::link_option::AUTO> FirstLink; + typedef etl::forward_link<0, etl::link_option::CHECKED> FirstLink; typedef etl::forward_link<1> SecondLink; //*************************************************************************** @@ -259,58 +259,73 @@ namespace ////************************************************************************* TEST_FIXTURE(SetupFixture, test_two_lists_different) { - std::list compare0; - std::list compare1; - - DataNDC0 data0; - DataNDC1 data1; + int i = 0; - ItemNDCNode node0("0"); - ItemNDCNode node1("1"); - ItemNDCNode node2("2"); - ItemNDCNode node3("3"); - ItemNDCNode node4("4"); - ItemNDCNode node5("5"); - ItemNDCNode node6("6"); - ItemNDCNode node7("7"); + { + std::list compare0; + std::list compare1; + { + ItemNDCNode node0("0"); + ItemNDCNode node1("1"); + ItemNDCNode node2("2"); + ItemNDCNode node3("3"); + ItemNDCNode node4("4"); + ItemNDCNode node5("5"); + ItemNDCNode node6("6"); + ItemNDCNode node7("7"); - compare0.push_front(node0); - compare0.push_front(node1); - compare0.push_front(node2); - compare0.push_front(node4); - compare0.push_front(node6); - compare0.push_front(node7); - - data0.push_front(node0); - data0.push_front(node1); - data0.push_front(node2); - data0.push_front(node4); - data0.push_front(node6); - data0.push_front(node7); + { + DataNDC0 data0; + DataNDC1 data1; - are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data0.size()); - CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); - compare1.push_front(node0); - compare1.push_front(node1); - compare1.push_front(node3); - compare1.push_front(node4); - compare1.push_front(node5); - compare1.push_front(node7); - data1.push_front(node0); - data1.push_front(node1); - data1.push_front(node3); - data1.push_front(node4); - data1.push_front(node5); - data1.push_front(node7); + compare0.push_front(node0); + compare0.push_front(node1); + compare0.push_front(node2); + compare0.push_front(node4); + compare0.push_front(node6); + compare0.push_front(node7); - are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data1.size()); - CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + compare1.push_front(node0); + compare1.push_front(node1); + compare1.push_front(node3); + compare1.push_front(node4); + compare1.push_front(node5); + compare1.push_front(node7); + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node4); + data0.push_front(node6); + data0.push_front(node7); + + data1.push_front(node0); + data1.push_front(node1); + data1.push_front(node3); + data1.push_front(node4); + data1.push_front(node5); + data1.push_front(node7); + + are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); + CHECK(are_equal); + CHECK_EQUAL(6, data0.size()); + CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + + are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); + CHECK(are_equal); + CHECK_EQUAL(6, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + } + + size_t temp = compare0.size(); + } + + size_t temp = compare0.size(); + } + + i = 1; } //************************************************************************* @@ -331,9 +346,9 @@ namespace std::forward_list::iterator i_compare_data = compare_data.begin(); std::advance(i_compare_data, offset); - data0.insert_after(i_data, INSERT_VALUE1); compare_data.insert_after(i_compare_data, INSERT_VALUE1); - + data0.insert_after(i_data, INSERT_VALUE1); + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); @@ -354,8 +369,16 @@ namespace std::forward_list temp(data0.begin(), data0.end()); - data0.insert_after(i_data, INSERT_VALUE2); compare_data.insert_after(i_compare_data, INSERT_VALUE2); + data0.insert_after(i_data, INSERT_VALUE2); + + // Clear the nodes in the temp list. + std::forward_list::iterator itr = temp.begin(); + while (itr != temp.end()) + { + itr->FirstLink::clear(); + ++itr; + } temp.assign(data0.begin(), data0.end()); @@ -368,6 +391,22 @@ namespace CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + + // Clear the nodes in the compare list. + itr = compare_data.begin(); + while (itr != compare_data.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + // Clear the nodes in the temp list. + itr = temp.begin(); + while (itr != temp.end()) + { + itr->FirstLink::clear(); + ++itr; + } } //************************************************************************* @@ -391,6 +430,13 @@ namespace CHECK_EQUAL(test1.size(), data1.size()); CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); + std::forward_list::iterator itr = compare.begin(); + while (itr != compare.end()) + { + itr->FirstLink::clear(); + ++itr; + } + compare.assign(test1.begin(), test1.end()); data0.assign(test1.begin(), test1.end()); @@ -412,6 +458,22 @@ namespace CHECK(are_equal); CHECK_EQUAL(test1.size(), data1.size()); CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); + + // Clear the nodes in the compare list. + itr = compare.begin(); + while (itr != compare.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + // Clear the nodes in the out list. + itr = out.begin(); + while (itr != out.end()) + { + itr->FirstLink::clear(); + ++itr; + } } //************************************************************************* @@ -441,10 +503,20 @@ namespace CHECK_NO_THROW(data0.push_front(node5)); CHECK_NO_THROW(data0.push_front(node6)); - are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); - CHECK(are_equal); + //are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + //CHECK(are_equal); CHECK_EQUAL(6, data0.size()); CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + + // Clear the nodes in the compare list. + std::list::iterator itr = compare_data.begin(); + while (itr != compare_data.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); } //************************************************************************* @@ -497,6 +569,9 @@ namespace CHECK_EQUAL(6, data1.size()); CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); CHECK(!data1.empty()); + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -557,6 +632,16 @@ namespace are_equal = *i_data == *i_compare_data; CHECK(are_equal); + + //std::forward_list::iterator itr = compare_data.begin(); + //while (itr != compare_data.end()) + //{ + // itr->FirstLink::clear(); + // ++itr; + //} + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -593,6 +678,9 @@ namespace CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -623,6 +711,9 @@ namespace CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -761,16 +852,25 @@ namespace DataNDC0 data0(sorted_data.begin(), sorted_data.end()); DataNDC0 data1(sorted_data2.begin(), sorted_data2.end()); + size_t i0 = data0.size(); + size_t i1 = data0.size(); + DataNDC0::iterator idata_destination = data0.begin(); - std::advance(idata_destination, 3); + std::advance(idata_destination, 1); + + size_t t1 = data0.size(); std::forward_list compare0(data0.begin(), data0.end()); std::forward_list compare1(data1.begin(), data1.end()); std::forward_list::iterator icompare_destination = compare0.begin(); - std::advance(icompare_destination, 3); + std::advance(icompare_destination, 1); data0.splice_after(idata_destination, data1); + + size_t t2 = data0.size(); + size_t t3 = data1.size(); + compare0.splice_after(icompare_destination, compare1); are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); @@ -778,6 +878,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare1.begin(); + while (itr != compare1.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -802,6 +919,15 @@ namespace CHECK(are_equal); CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); } //************************************************************************* @@ -841,6 +967,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare1.begin(); + while (itr != compare1.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -877,6 +1020,15 @@ namespace CHECK(are_equal); CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); } //************************************************************************* @@ -898,6 +1050,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare1.begin(); + while (itr != compare1.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data1.clear(); } //************************************************************************* @@ -919,6 +1088,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare2.begin(), compare2.end()), data2.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare2.begin(); + while (itr != compare2.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data2.clear(); } //************************************************************************* @@ -940,6 +1126,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare3.begin(), compare3.end()), data3.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare3.begin(); + while (itr != compare3.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data3.clear(); } //************************************************************************* @@ -961,6 +1164,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare4.begin(), compare4.end()), data4.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare4.begin(); + while (itr != compare4.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data4.clear(); } //************************************************************************* @@ -988,6 +1208,23 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + + std::forward_list::iterator itr = compare0.begin(); + while (itr != compare0.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + itr = compare1.begin(); + while (itr != compare1.end()) + { + itr->FirstLink::clear(); + ++itr; + } + + data0.clear(); + data1.clear(); } }; } From 82c1b9a7958e1db094d3943a7c43fcb3d3ea9ff1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:29:32 +0000 Subject: [PATCH 021/168] Removed 'pop excess' tests. --- test/test_priority_queue.cpp | 4 ---- test/test_string_char.cpp | 14 -------------- test/test_string_u16.cpp | 14 -------------- test/test_string_u32.cpp | 14 -------------- test/test_string_wchar_t.cpp | 14 -------------- 5 files changed, 60 deletions(-) diff --git a/test/test_priority_queue.cpp b/test/test_priority_queue.cpp index f38dffa0..a911fa1f 100644 --- a/test/test_priority_queue.cpp +++ b/test/test_priority_queue.cpp @@ -294,10 +294,6 @@ namespace priority_queue.pop(); compare_priority_queue.pop(); CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size()); - - // Go one beyond (which we handle without throwing) - priority_queue.pop(); - CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size()); } //************************************************************************* diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 265ace9b..a715f42c 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -635,20 +635,6 @@ namespace CHECK(is_equal); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_pop_back_excess) - { - Text text; - - text.resize(2); - - text.pop_back(); - text.pop_back(); - - text.pop_back(); - CHECK(text.empty()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 89c56788..07bed379 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -635,20 +635,6 @@ namespace CHECK(is_equal); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_pop_back_excess) - { - Text text; - - text.resize(2); - - text.pop_back(); - text.pop_back(); - - text.pop_back(); - CHECK(text.empty()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index cd8e87e9..abd21bfc 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -635,20 +635,6 @@ namespace CHECK(is_equal); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_pop_back_excess) - { - Text text; - - text.resize(2); - - text.pop_back(); - text.pop_back(); - - text.pop_back(); - CHECK(text.empty()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 2b968918..bd32385b 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -635,20 +635,6 @@ namespace CHECK(is_equal); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_pop_back_excess) - { - Text text; - - text.resize(2); - - text.pop_back(); - text.pop_back(); - - text.pop_back(); - CHECK(text.empty()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { From 3f6fea58a19820798df5ddf61ce39434197d9739 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:30:38 +0000 Subject: [PATCH 022/168] Added either support or compiler error messages when the platform does not support 8 bit data types. --- src/alignment.h | 2 +- src/crc8_ccitt.cpp | 5 +++++ src/frame_check_sequence.h | 3 +++ src/pearson.cpp | 6 ++++++ src/pearson.h | 2 ++ src/radix.h | 2 +- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/alignment.h b/src/alignment.h index 69ebbf54..668208f8 100644 --- a/src/alignment.h +++ b/src/alignment.h @@ -174,7 +174,7 @@ namespace etl union { - uint8_t data[LENGTH]; + uint_least8_t data[LENGTH]; typename etl::type_with_alignment::type __etl_alignment_type__; // A POD type that has the same alignment as ALIGNMENT. }; }; diff --git a/src/crc8_ccitt.cpp b/src/crc8_ccitt.cpp index 1919d21d..3ab90ceb 100644 --- a/src/crc8_ccitt.cpp +++ b/src/crc8_ccitt.cpp @@ -30,6 +30,11 @@ SOFTWARE. #include +#include "platform.h" +#include "static_assert.h" + +STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type"); + namespace etl { //*************************************************************************** diff --git a/src/frame_check_sequence.h b/src/frame_check_sequence.h index 74dc7744..8d30941f 100644 --- a/src/frame_check_sequence.h +++ b/src/frame_check_sequence.h @@ -29,10 +29,13 @@ SOFTWARE. #include +#include "platform.h" #include "static_assert.h" #include "type_traits.h" #include "binary.h" +STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type"); + ///\defgroup frame_check_sequence Frame check sequence calculation ///\ingroup maths diff --git a/src/pearson.cpp b/src/pearson.cpp index ce4742dd..a10940b4 100644 --- a/src/pearson.cpp +++ b/src/pearson.cpp @@ -30,6 +30,11 @@ SOFTWARE. #include +#include "platform.h" +#include "static_assert.h" + +STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type"); + namespace etl { //*************************************************************************** @@ -56,3 +61,4 @@ namespace etl 213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82 } ; } + diff --git a/src/pearson.h b/src/pearson.h index 4952d889..b724f05a 100644 --- a/src/pearson.h +++ b/src/pearson.h @@ -41,6 +41,8 @@ SOFTWARE. #include "array.h" #include "container.h" +STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type"); + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/src/radix.h b/src/radix.h index 61b56360..48c8ac1c 100644 --- a/src/radix.h +++ b/src/radix.h @@ -53,7 +53,7 @@ namespace etl hex = 16 }; - DECLARE_ENUM_TYPE(radix, uint8_t) + DECLARE_ENUM_TYPE(radix, uint_least8_t) ENUM_TYPE(undefined, "undefined") ENUM_TYPE(binary, "binary") ENUM_TYPE(octal, "octal") From daaf3fe0131a5c4edc717a61811e4083f1758bf7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:30:54 +0000 Subject: [PATCH 023/168] Added new files. --- test/vs2015/etl.vcxproj | 6 +++++- test/vs2015/etl.vcxproj.filters | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index 793faf35..87e98819 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -70,7 +70,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CNSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;ETL_PLATFORM_WINDOWS;%(PreprocessorDefinitions) ../../../unittest-cpp @@ -185,6 +185,7 @@ + @@ -208,6 +209,7 @@ + @@ -246,6 +248,7 @@ + @@ -359,6 +362,7 @@ + diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index 715746e3..e8fbae31 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -519,6 +519,15 @@ ETL\Utilities + + ETL\Containers + + + ETL\Private + + + ETL\Maths + @@ -806,6 +815,9 @@ ETL\Private + + Source Files + From 59cc02588cad15882aed7701b7214d0843af9648 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 16:47:04 +0000 Subject: [PATCH 024/168] Corrected const top() --- src/intrusive_stack.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h index d7c43c24..0fc0cb61 100644 --- a/src/intrusive_stack.h +++ b/src/intrusive_stack.h @@ -117,6 +117,15 @@ namespace etl return *static_cast(p_top); } + //************************************************************************* + /// Gets a const reference to the value at the top of the stack.
+ /// \return A const reference to the value at the top of the stack. + //************************************************************************* + const_reference top() const + { + return *static_cast(p_top); + } + //************************************************************************* /// Adds a value to the stack. ///\param value The value to push to the stack. @@ -148,15 +157,6 @@ namespace etl --current_size; } - //************************************************************************* - /// Gets a const reference to the value at the top of the stack.
- /// \return A const reference to the value at the top of the stack. - //************************************************************************* - const_reference top() const - { - return *p_top; - } - //************************************************************************* /// Clears the stack to the empty state. //************************************************************************* From 020a834d62909945581c17f492982e6431917839 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 17:21:21 +0000 Subject: [PATCH 025/168] Converted to use etl:frame_check_sequence --- src/fnv_1.h | 344 +++++++++++++++------------------------------------- 1 file changed, 101 insertions(+), 243 deletions(-) diff --git a/src/fnv_1.h b/src/fnv_1.h index 5ae00dac..ce787651 100644 --- a/src/fnv_1.h +++ b/src/fnv_1.h @@ -37,6 +37,8 @@ SOFTWARE. #include "static_assert.h" #include "type_traits.h" #include "ihash.h" +#include "frame_check_sequence.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 @@ -47,22 +49,49 @@ SOFTWARE. namespace etl { + //*************************************************************************** + /// fnv_1 policy. + /// Calculates FNV1. + //*************************************************************************** + struct fnv_1_policy_64 + { + typedef uint64_t value_type; + + inline uint64_t initial() const + { + return OFFSET_BASIS; + } + + inline uint64_t add(uint64_t hash, uint8_t value) const + { + hash *= PRIME; + hash ^= value; + return hash; + } + + inline uint64_t final(uint64_t hash) const + { + return hash; + } + + static const uint64_t OFFSET_BASIS = 0xCBF29CE484222325; + static const uint64_t PRIME = 0x00000100000001b3; + }; + //*************************************************************************** /// Calculates the fnv_1_64 hash. ///\ingroup fnv_1_64 //*************************************************************************** - class fnv_1_64 + class fnv_1_64 : public etl::frame_check_sequence { public: - typedef uint64_t value_type; - //************************************************************************* /// Default constructor. //************************************************************************* fnv_1_64() { - reset(); + this->reset(); } //************************************************************************* @@ -73,90 +102,54 @@ namespace etl template fnv_1_64(TIterator begin, const TIterator end) { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); + this->reset(); + this->add(begin, end); + } + }; + + //*************************************************************************** + /// fnv_1a policy. + /// Calculates FNV1A. + //*************************************************************************** + struct fnv_1a_policy_64 + { + typedef uint64_t value_type; - reset(); - while (begin != end) - { - hash *= PRIME; - hash ^= *begin++; - } + inline uint64_t initial() const + { + return OFFSET_BASIS; } - //************************************************************************* - /// Resets the CRC to the initial state. - //************************************************************************* - void reset() + inline uint64_t add(uint64_t hash, uint8_t value) const { - hash = OFFSET_BASIS; - } - - //************************************************************************* - /// Adds a range. - /// \param begin - /// \param end - //************************************************************************* - template - void add(TIterator begin, const TIterator end) - { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); - - while (begin != end) - { - hash *= PRIME; - hash ^= *begin++; - } - } - - //************************************************************************* - /// \param value The char to add to the fnv_1_64. - //************************************************************************* - void add(uint8_t value) - { - hash *= PRIME; hash ^= value; + hash *= PRIME; + return hash; } - //************************************************************************* - /// Gets the fnv_1_64 value. - //************************************************************************* - value_type value() const + inline uint64_t final(uint64_t hash) const { return hash; } - //************************************************************************* - /// Conversion operator to value_type. - //************************************************************************* - operator value_type () const - { - return hash; - } - - private: - - value_type hash; - static const uint64_t OFFSET_BASIS = 0xCBF29CE484222325; static const uint64_t PRIME = 0x00000100000001b3; }; - + //*************************************************************************** /// Calculates the fnv_1a_64 hash. ///\ingroup fnv_1a_64 //*************************************************************************** - class fnv_1a_64 + class fnv_1a_64 : public etl::frame_check_sequence { public: - typedef uint64_t value_type; - //************************************************************************* /// Default constructor. //************************************************************************* fnv_1a_64() { - reset(); + this->reset(); } //************************************************************************* @@ -167,90 +160,54 @@ namespace etl template fnv_1a_64(TIterator begin, const TIterator end) { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); + this->reset(); + this->add(begin, end); + } + }; - reset(); - while (begin != end) - { - hash ^= *begin++; - hash *= PRIME; - } + //*************************************************************************** + /// fnv_1 policy. + /// Calculates FNV1. + //*************************************************************************** + struct fnv_1_policy_32 + { + typedef uint32_t value_type; + + inline uint32_t initial() const + { + return OFFSET_BASIS; } - //************************************************************************* - /// Resets the CRC to the initial state. - //************************************************************************* - void reset() + inline uint32_t add(uint32_t hash, uint8_t value) const { - hash = OFFSET_BASIS; - } - - //************************************************************************* - /// Adds a range. - /// \param begin - /// \param end - //************************************************************************* - template - void add(TIterator begin, const TIterator end) - { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); - - while (begin != end) - { - hash ^= *begin++; - hash *= PRIME; - } - } - - //************************************************************************* - /// \param value The char to add to the fnv_1a_64. - //************************************************************************* - void add(uint8_t value) - { - hash ^= value; hash *= PRIME; + hash ^= value; + return hash; } - //************************************************************************* - /// Gets the fnv_1a_64 value. - //************************************************************************* - value_type value() const + inline uint32_t final(uint32_t hash) const { return hash; } - //************************************************************************* - /// Conversion operator to value_type. - //************************************************************************* - operator value_type () const - { - return hash; - } - - private: - - value_type hash; - - static const uint64_t OFFSET_BASIS = 0xCBF29CE484222325; - static const uint64_t PRIME = 0x00000100000001b3; + static const uint32_t OFFSET_BASIS = 0x811C9DC5; + static const uint32_t PRIME = 0x01000193; }; //*************************************************************************** /// Calculates the fnv_1_32 hash. ///\ingroup fnv_1_32 //*************************************************************************** - class fnv_1_32 + class fnv_1_32 : public etl::frame_check_sequence { public: - typedef uint32_t value_type; - //************************************************************************* /// Default constructor. //************************************************************************* fnv_1_32() { - reset(); + this->reset(); } //************************************************************************* @@ -261,70 +218,36 @@ namespace etl template fnv_1_32(TIterator begin, const TIterator end) { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); + this->reset(); + this->add(begin, end); + } + }; + + //*************************************************************************** + /// fnv_1a policy. + /// Calculates FNV1A. + //*************************************************************************** + struct fnv_1a_policy_32 + { + typedef uint32_t value_type; - reset(); - while (begin != end) - { - hash *= PRIME; - hash ^= *begin++; - } + inline uint32_t initial() const + { + return OFFSET_BASIS; } - //************************************************************************* - /// Resets the CRC to the initial state. - //************************************************************************* - void reset() + inline uint32_t add(uint32_t hash, uint8_t value) const { - hash = OFFSET_BASIS; - } - - //************************************************************************* - /// Adds a range. - /// \param begin - /// \param end - //************************************************************************* - template - void add(TIterator begin, const TIterator end) - { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); - - while (begin != end) - { - hash *= PRIME; - hash ^= *begin++; - } - } - - //************************************************************************* - /// \param value The char to add to the fnv_1_32. - //************************************************************************* - void add(uint8_t value) - { - hash *= PRIME; hash ^= value; + hash *= PRIME; + return hash; } - //************************************************************************* - /// Gets the fnv_1_32 value. - //************************************************************************* - value_type value() const + inline uint32_t final(uint32_t hash) const { return hash; } - //************************************************************************* - /// Conversion operator to value_type. - //************************************************************************* - operator value_type () const - { - return hash; - } - - private: - - value_type hash; - static const uint32_t OFFSET_BASIS = 0x811C9DC5; static const uint32_t PRIME = 0x01000193; }; @@ -333,18 +256,16 @@ namespace etl /// Calculates the fnv_1a_32 hash. ///\ingroup fnv_1a_32 //*************************************************************************** - class fnv_1a_32 + class fnv_1a_32 : public etl::frame_check_sequence { public: - typedef uint32_t value_type; - //************************************************************************* /// Default constructor. //************************************************************************* fnv_1a_32() { - reset(); + this->reset(); } //************************************************************************* @@ -355,72 +276,9 @@ namespace etl template fnv_1a_32(TIterator begin, const TIterator end) { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); - - reset(); - while (begin != end) - { - hash ^= *begin++; - hash *= PRIME; - } + this->reset(); + this->add(begin, end); } - - //************************************************************************* - /// Resets the CRC to the initial state. - //************************************************************************* - void reset() - { - hash = OFFSET_BASIS; - } - - //************************************************************************* - /// Adds a range. - /// \param begin - /// \param end - //************************************************************************* - template - void add(TIterator begin, const TIterator end) - { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Type not supported"); - - while (begin != end) - { - hash ^= *begin++; - hash *= PRIME; - } - } - - //************************************************************************* - /// \param value The char to add to the fnv_1a_32. - //************************************************************************* - void add(uint8_t value) - { - hash ^= value; - hash *= PRIME; - } - - //************************************************************************* - /// Gets the fnv_1a_32 value. - //************************************************************************* - value_type value() const - { - return hash; - } - - //************************************************************************* - /// Conversion operator to value_type. - //************************************************************************* - operator value_type () const - { - return hash; - } - - private: - - value_type hash; - - static const uint32_t OFFSET_BASIS = 0x811C9DC5; - static const uint32_t PRIME = 0x01000193; }; } From 0a8e3c8fdf370fede6d0c41a7281817454226a25 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Nov 2016 18:18:04 +0000 Subject: [PATCH 026/168] Added either support or compiler error messages when the platform does not support 8 bit data types. --- src/binary.h | 9 +++++++ src/debounce.h | 2 +- src/endian.h | 6 ++--- src/platform.h | 7 ++--- src/private/map_base.h | 10 +++---- src/private/multimap_base.h | 14 +++++----- src/private/multiset_base.h | 14 +++++----- src/private/set_base.h | 8 +++--- src/variant.h | 52 ++++++++++++++++++------------------- 9 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/binary.h b/src/binary.h index 3a1be615..fb99de13 100644 --- a/src/binary.h +++ b/src/binary.h @@ -44,6 +44,7 @@ SOFTWARE. #include "log.h" #include "power.h" #include "smallest.h" +#include "platform.h" namespace etl { @@ -170,6 +171,7 @@ namespace etl return result; } +#if ETL_8BIT_SUPPORT //*************************************************************************** /// Reverse 8 bits. //*************************************************************************** @@ -183,6 +185,7 @@ namespace etl return value; } +#endif //*************************************************************************** /// Reverse 16 bits. @@ -282,6 +285,7 @@ namespace etl return (value >> 1) ^ value; } +#if ETL_8BIT_SUPPORT //*************************************************************************** /// Converts Gray code to binary. //*************************************************************************** @@ -295,6 +299,7 @@ namespace etl return value; } +#endif //*************************************************************************** /// Converts Gray code to binary. @@ -344,6 +349,7 @@ namespace etl return value; } +#if ETL_8BIT_SUPPORT //*************************************************************************** /// Count set bits. 8 bits. //*************************************************************************** @@ -361,6 +367,7 @@ namespace etl return count; } +#endif //*************************************************************************** /// Count set bits. 16 bits. @@ -422,6 +429,7 @@ namespace etl return size_t(count); } +#if ETL_8BIT_SUPPORT //*************************************************************************** /// Parity. 8bits. 0 = even, 1 = odd //*************************************************************************** @@ -433,6 +441,7 @@ namespace etl value &= 0x0F; return (0x6996 >> value) & 1; } +#endif //*************************************************************************** /// Parity. 16bits. 0 = even, 1 = odd diff --git a/src/debounce.h b/src/debounce.h index 531b584d..729451f2 100644 --- a/src/debounce.h +++ b/src/debounce.h @@ -116,7 +116,7 @@ namespace etl REPEATING = 16 }; - uint8_t state; + uint_least8_t state; /// The state count. uint16_t count; diff --git a/src/endian.h b/src/endian.h index d905d8e1..35ad8d34 100644 --- a/src/endian.h +++ b/src/endian.h @@ -68,7 +68,7 @@ namespace etl struct endianness { endianness() - : ETL_ENDIAN_TEST(0x0011) + : ETL_ENDIAN_TEST(0x0011223344556677) { } @@ -79,12 +79,12 @@ namespace etl operator endian() const { - return (*reinterpret_cast(&ETL_ENDIAN_TEST) == 0x11) ? endian::little : endian::big; + return (*reinterpret_cast(&ETL_ENDIAN_TEST) == 0x44556677) ? endian::little : endian::big; } private: - const uint16_t ETL_ENDIAN_TEST; + const uint64_t ETL_ENDIAN_TEST; }; } diff --git a/src/platform.h b/src/platform.h index d6cb9159..d08bccc7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -29,7 +29,7 @@ SOFTWARE. ******************************************************************************/ #include -#include "static_assert.h" +#include // Define the platform. // The target platform will normally be defined as a compiler pre-processor directive. @@ -68,5 +68,6 @@ SOFTWARE. #define ETL_ETL_NO_LARGE_CHAR_SUPPORT #endif -// Some targets do not support 8bit or even 16bit types. -#define ETL_8BIT_SUPPORT ((sizeof(uint_least8_t) != sizeof(uint16_t)) && (sizeof(uint_least8_t) != sizeof(uint32_t))) +// Some targets do not support 8bit types. +#define ETL_8BIT_SUPPORT (CHAR_BIT == 8) + diff --git a/src/private/map_base.h b/src/private/map_base.h index 539554a1..f23de8da 100644 --- a/src/private/map_base.h +++ b/src/private/map_base.h @@ -194,9 +194,9 @@ namespace etl children[1] = nullptr; } - Node* children[2]; - uint8_t weight; - uint8_t dir; + Node* children[2]; + uint_least8_t weight; + uint_least8_t dir; }; //************************************************************************* @@ -276,7 +276,7 @@ namespace etl //************************************************************************* /// Rotate two nodes at the position provided the to balance the tree //************************************************************************* - void rotate_2node(Node*& position, uint8_t dir) + void rotate_2node(Node*& position, uint_least8_t dir) { // A C A B // B C -> A E OR B C -> D A @@ -306,7 +306,7 @@ namespace etl //************************************************************************* /// Rotate three nodes at the position provided the to balance the tree //************************************************************************* - void rotate_3node(Node*& position, uint8_t dir, uint8_t third) + void rotate_3node(Node*& position, uint_least8_t dir, uint_least8_t third) { // __A__ __E__ __A__ __D__ // _B_ C -> B A OR B _C_ -> A C diff --git a/src/private/multimap_base.h b/src/private/multimap_base.h index 02b85f94..39afb67c 100644 --- a/src/private/multimap_base.h +++ b/src/private/multimap_base.h @@ -162,9 +162,9 @@ namespace etl protected: - static const uint8_t kLeft = 0; - static const uint8_t kRight = 1; - static const uint8_t kNeither = 2; + static const uint_least8_t kLeft = 0; + static const uint_least8_t kRight = 1; + static const uint_least8_t kNeither = 2; //************************************************************************* /// The node element in the multimap. @@ -194,8 +194,8 @@ namespace etl Node* parent; Node* children[2]; - uint8_t weight; - uint8_t dir; + uint_least8_t weight; + uint_least8_t dir; }; //************************************************************************* @@ -275,7 +275,7 @@ namespace etl //************************************************************************* /// Rotate two nodes at the position provided the to balance the tree //************************************************************************* - void rotate_2node(Node*& position, uint8_t dir) + void rotate_2node(Node*& position, uint_least8_t dir) { // A C A B // B C -> A E OR B C -> D A @@ -316,7 +316,7 @@ namespace etl //************************************************************************* /// Rotate three nodes at the position provided the to balance the tree //************************************************************************* - void rotate_3node(Node*& position, uint8_t dir, uint8_t third) + void rotate_3node(Node*& position, uint_least8_t dir, uint_least8_t third) { // __A__ __E__ __A__ __D__ // _B_ C -> B A OR B _C_ -> A C diff --git a/src/private/multiset_base.h b/src/private/multiset_base.h index 5b9a1d36..cad7120c 100644 --- a/src/private/multiset_base.h +++ b/src/private/multiset_base.h @@ -162,9 +162,9 @@ namespace etl protected: - static const uint8_t kLeft = 0; - static const uint8_t kRight = 1; - static const uint8_t kNeither = 2; + static const uint_least8_t kLeft = 0; + static const uint_least8_t kRight = 1; + static const uint_least8_t kNeither = 2; //************************************************************************* /// The node element in the multiset. @@ -194,8 +194,8 @@ namespace etl Node* parent; Node* children[2]; - uint8_t weight; - uint8_t dir; + uint_least8_t weight; + uint_least8_t dir; }; //************************************************************************* @@ -482,7 +482,7 @@ namespace etl //************************************************************************* /// Rotate two nodes at the position provided the to balance the tree //************************************************************************* - void rotate_2node(Node*& position, uint8_t dir) + void rotate_2node(Node*& position, uint_least8_t dir) { // A C A B // B C -> A E OR B C -> D A @@ -523,7 +523,7 @@ namespace etl //************************************************************************* /// Rotate three nodes at the position provided the to balance the tree //************************************************************************* - void rotate_3node(Node*& position, uint8_t dir, uint8_t third) + void rotate_3node(Node*& position, uint_least8_t dir, uint_least8_t third) { // __A__ __E__ __A__ __D__ // _B_ C -> B A OR B _C_ -> A C diff --git a/src/private/set_base.h b/src/private/set_base.h index 32a72c2f..b0b85b45 100644 --- a/src/private/set_base.h +++ b/src/private/set_base.h @@ -194,8 +194,8 @@ namespace etl } Node* children[2]; - uint8_t weight; - uint8_t dir; + uint_least8_t weight; + uint_least8_t dir; }; //************************************************************************* @@ -348,7 +348,7 @@ namespace etl //************************************************************************* /// Rotate two nodes at the position provided the to balance the tree //************************************************************************* - void rotate_2node(Node*& position, uint8_t dir) + void rotate_2node(Node*& position, uint_least8_t dir) { // A C A B // B C -> A E OR B C -> D A @@ -378,7 +378,7 @@ namespace etl //************************************************************************* /// Rotate three nodes at the position provided the to balance the tree //************************************************************************* - void rotate_3node(Node*& position, uint8_t dir, uint8_t third) + void rotate_3node(Node*& position, uint_least8_t dir, uint_least8_t third) { // __A__ __E__ __A__ __D__ // _B_ C -> B A OR B _C_ -> A C diff --git a/src/variant.h b/src/variant.h index 38492c4f..c57465b9 100644 --- a/src/variant.h +++ b/src/variant.h @@ -132,7 +132,7 @@ namespace etl //*************************************************************************** /// The type used for ids. //*************************************************************************** - typedef uint8_t type_id_t; + typedef uint_least8_t type_id_t; //*************************************************************************** /// The id a unsupported types. @@ -196,15 +196,15 @@ namespace etl template struct Type_Id_Lookup { - static const uint8_t type_id = etl::is_same::value ? 0 : - etl::is_same::value ? 1 : - etl::is_same::value ? 2 : - etl::is_same::value ? 3 : - etl::is_same::value ? 4 : - etl::is_same::value ? 5 : - etl::is_same::value ? 6 : - etl::is_same::value ? 7 : - UNSUPPORTED_TYPE_ID; + static const uint_least8_t type_id = etl::is_same::value ? 0 : + etl::is_same::value ? 1 : + etl::is_same::value ? 2 : + etl::is_same::value ? 3 : + etl::is_same::value ? 4 : + etl::is_same::value ? 5 : + etl::is_same::value ? 6 : + etl::is_same::value ? 7 : + UNSUPPORTED_TYPE_ID; }; //*************************************************************************** @@ -424,7 +424,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -440,7 +440,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -465,7 +465,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -480,7 +480,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -504,7 +504,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -518,7 +518,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -541,7 +541,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -554,7 +554,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -576,7 +576,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -588,7 +588,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -609,7 +609,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -620,7 +620,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -640,7 +640,7 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { switch (typeId) { @@ -650,7 +650,7 @@ namespace etl } } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { switch (typeId) { @@ -669,12 +669,12 @@ namespace etl { public: - TBase& operator()(uint8_t* p_data, uint8_t typeId) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { return reinterpret_cast(*p_data); } - const TBase& operator()(uint8_t* p_data, uint8_t typeId) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { return reinterpret_cast(*p_data); } From 562d59faf02895918575bb613a1fee352a015c13 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 14 Nov 2016 16:45:01 +0000 Subject: [PATCH 027/168] Initial callback template class. Untested. --- src/callback.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/callback.h diff --git a/src/callback.h b/src/callback.h new file mode 100644 index 00000000..1fccd5c6 --- /dev/null +++ b/src/callback.h @@ -0,0 +1,74 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_CALLBACK__ +#define __ETL_CALLBACK__ + +namespace etl +{ + template + class callback + { + private: + + // Creates a parameter type unique to this ID. + template + struct parameter + { + parameter(T value) + : value(value) + { + } + + typedef T value_type; + + T value; + + private: + + parameter(); + }; + + // Specialisation for void. + template + struct parameter + { + typedef void value_type; + }; + + public: + + typedef parameter type; + + virtual void etl_callback(type p = type()) = 0; + }; +} + +#endif \ No newline at end of file From 670de34441e9e987b1e7af43ccaf0c5a70757dae Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 14 Nov 2016 16:45:26 +0000 Subject: [PATCH 028/168] Initial callback template class. Untested. --- src/callback.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/callback.h b/src/callback.h index 1fccd5c6..73f4fdb1 100644 --- a/src/callback.h +++ b/src/callback.h @@ -28,6 +28,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ +#error In Development. Do not use. + #ifndef __ETL_CALLBACK__ #define __ETL_CALLBACK__ From e5e3a6a4fce57387edbdbc841afa4161321dca7f Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 14 Nov 2016 16:54:05 +0000 Subject: [PATCH 029/168] Added more comments --- src/callback.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/callback.h b/src/callback.h index 73f4fdb1..0111c492 100644 --- a/src/callback.h +++ b/src/callback.h @@ -35,6 +35,13 @@ SOFTWARE. namespace etl { + //*************************************************************************** + /// A callback class designed to be multiply inherited by other client classes. + /// The class is parameterised with a callback parameter type and a unique id. + /// The unique id allows muliple callbacks with the same parameter type. + ///\tparam TParameter The callback parameter type. + ///\tparam ID The unique id for this callback. + //*************************************************************************** template class callback { From 1171d7e5556acc4508dc7513b4656b18b5d0df13 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 16 Nov 2016 13:04:04 +0000 Subject: [PATCH 030/168] Modified Jenkins hash to use frame_check_sequence classes. --- src/jenkins.h | 191 +++++++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 86 deletions(-) diff --git a/src/jenkins.h b/src/jenkins.h index 7dace164..0c500e3c 100644 --- a/src/jenkins.h +++ b/src/jenkins.h @@ -50,24 +50,96 @@ SOFTWARE. namespace etl { //*************************************************************************** - /// Calculates the jenkins hash. - ///\ingroup jenkins + /// Jenkins32 policy. + /// Calculates 32 bit Jenkins hash. //*************************************************************************** - template - class jenkins + struct jenkins32_policy + { + typedef uint32_t value_type; + + inline uint32_t initial() const + { + is_finalised = false; + + return 0; + } + + inline uint32_t add(uint8_t hash, uint8_t value) const + { + ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); + + hash += value; + hash += (hash << 10); + hash ^= (hash >> 6); + + return hash; + } + + inline uint32_t final(uint8_t hash) const + { + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + is_finalised = true; + + return hash; + } + + bool is_finalised; + }; + + //*************************************************************************** + /// Jenkins64 policy. + /// Calculates 32 bit Jenkins hash. + //*************************************************************************** + struct jenkins64_policy + { + typedef uint64_t value_type; + + inline uint64_t initial() const + { + is_finalised = false; + + return 0; + } + + inline uint64_t add(uint8_t hash, uint8_t value) const + { + ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); + + hash += value; + hash += (hash << 10); + hash ^= (hash >> 6); + + return hash; + } + + inline uint64_t final(uint8_t hash) const + { + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + is_finalised = true; + + return hash; + } + + bool is_finalised; + }; + + //************************************************************************* + /// Jenkins32 + //************************************************************************* + class jenkins32 : public etl::frame_check_sequence { public: - STATIC_ASSERT((etl::is_same::value || etl::is_same::value), "Only 32 & 64 bit types supported"); - - typedef THash value_type; - //************************************************************************* /// Default constructor. //************************************************************************* - jenkins() + jenkins32() { - reset(); + this->reset(); } //************************************************************************* @@ -76,92 +148,39 @@ namespace etl /// \param end End of the range. //************************************************************************* template - jenkins(TIterator begin, const TIterator end) + jenkins32(TIterator begin, const TIterator end) { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Incompatible type"); + this->reset(); + this->add(begin, end); + } + }; - reset(); + //************************************************************************* + /// Jenkins64 + //************************************************************************* + class jenkins64 : public etl::frame_check_sequence + { + public: - while (begin != end) - { - hash += *begin++; - hash += (hash << 10); - hash ^= (hash >> 6); - } + //************************************************************************* + /// Default constructor. + //************************************************************************* + jenkins64() + { + this->reset(); } //************************************************************************* - /// Resets the CRC to the initial state. - //************************************************************************* - void reset() - { - hash = 0; - is_finalised = false; - } - - //************************************************************************* - /// Adds a range. - /// \param begin - /// \param end + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. //************************************************************************* template - void add(TIterator begin, const TIterator end) + jenkins64(TIterator begin, const TIterator end) { - STATIC_ASSERT(sizeof(typename std::iterator_traits::value_type) == 1, "Incompatible type"); - ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); - - while (begin != end) - { - hash += *begin++; - hash += (hash << 10); - hash ^= (hash >> 6); - } + this->reset(); + this->add(begin, end); } - - //************************************************************************* - /// \param value The char to add to the jenkins. - //************************************************************************* - void add(uint8_t value) - { - ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); - - hash += value; - hash += (hash << 10); - hash ^= (hash >> 6); - } - - //************************************************************************* - /// Gets the jenkins value. - //************************************************************************* - value_type value() - { - finalise(); - return hash; - } - - //************************************************************************* - /// Conversion operator to value_type. - //************************************************************************* - operator value_type () - { - return value(); - } - - private: - - void finalise() - { - if (!is_finalised) - { - hash += (hash << 3); - hash ^= (hash >> 11); - hash += (hash << 15); - is_finalised = true; - } - } - - value_type hash; - bool is_finalised; }; } From ae2e4609b22ea1ba31ced8f3bde6481b78301861 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 16 Nov 2016 13:06:16 +0000 Subject: [PATCH 031/168] Added hash functions for strings. --- src/string.h | 17 +++++++++++++++++ src/u16string.h | 17 +++++++++++++++++ src/u32string.h | 17 +++++++++++++++++ src/wstring.h | 17 +++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/src/string.h b/src/string.h index 3f5bfb80..055c1fc9 100644 --- a/src/string.h +++ b/src/string.h @@ -33,6 +33,7 @@ SOFTWARE. #include "platform.h" #include "basic_string.h" +#include "hash.h" #if defined(ETL_COMPILER_MICROSOFT) #undef min @@ -180,6 +181,22 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; + + //*************************************************************************** + /// Specialisation for string. + ///\ingroup hash + //*************************************************************************** + template <> + struct hash + { + size_t operator ()(const string& s) const + { + uint8_t* p_begin = &s[0]; + uint8_t* p_end = &s[s.size()]; + + return etl::__private_hash__::generic_hash(p_begin, p_end); + } + }; } #if defined(ETL_COMPILER_MICROSOFT) diff --git a/src/u16string.h b/src/u16string.h index a7ca2b57..138fa916 100644 --- a/src/u16string.h +++ b/src/u16string.h @@ -33,6 +33,7 @@ SOFTWARE. #include "platform.h" #include "basic_string.h" +#include "hash.h" #if defined(ETL_COMPILER_MICROSOFT) #undef min @@ -180,6 +181,22 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; + + //*************************************************************************** + /// Specialisation for u16string. + ///\ingroup hash + //*************************************************************************** + template <> + struct hash + { + size_t operator ()(const u16string& s) const + { + uint8_t* p_begin = &s[0]; + uint8_t* p_end = &s[s.size()]; + + return etl::__private_hash__::generic_hash(p_begin, p_end); + } + }; } #if defined(ETL_COMPILER_MICROSOFT) diff --git a/src/u32string.h b/src/u32string.h index 5890f1c7..8280fbba 100644 --- a/src/u32string.h +++ b/src/u32string.h @@ -33,6 +33,7 @@ SOFTWARE. #include "platform.h" #include "basic_string.h" +#include "hash.h" #if defined(ETL_COMPILER_MICROSOFT) #undef min @@ -180,6 +181,22 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; + + //*************************************************************************** + /// Specialisation for u32string. + ///\ingroup hash + //*************************************************************************** + template <> + struct hash + { + size_t operator ()(const u32string& s) const + { + uint8_t* p_begin = &s[0]; + uint8_t* p_end = &s[s.size()]; + + return etl::__private_hash__::generic_hash(p_begin, p_end); + } + }; } #if defined(ETL_COMPILER_MICROSOFT) diff --git a/src/wstring.h b/src/wstring.h index 8019a29f..94bebc6b 100644 --- a/src/wstring.h +++ b/src/wstring.h @@ -33,6 +33,7 @@ SOFTWARE. #include "platform.h" #include "basic_string.h" +#include "hash.h" #if defined(ETL_COMPILER_MICROSOFT) #undef min @@ -181,6 +182,22 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; + + //*************************************************************************** + /// Specialisation for wstring. + ///\ingroup hash + //*************************************************************************** + template <> + struct hash + { + size_t operator ()(const wstring& s) const + { + uint8_t* p_begin = &s[0]; + uint8_t* p_end = &s[s.size()]; + + return etl::__private_hash__::generic_hash(p_begin, p_end); + } + }; } #if defined(ETL_COMPILER_MICROSOFT) From ad0e3c4f8d9d94c6dc79ff12256854b296c0baab Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 16 Nov 2016 14:04:19 +0000 Subject: [PATCH 032/168] Added +-*/ operators. Added bool conversion operator. Added ! operator. get() returns const reference. --- src/type_def.h | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/type_def.h b/src/type_def.h index 66d6156e..707a0732 100644 --- a/src/type_def.h +++ b/src/type_def.h @@ -40,11 +40,11 @@ namespace etl /// Usage: ///\code /// // Short form. - /// ETL_TYPEDEF(int, mytype); + /// ETL_TYPEDEF(int, mytype_t); /// /// // Long form. /// class mytype_t_tag; - /// typedef etl::type_def mytype_t_tag; + /// typedef etl::type_def mytype_t; ///\endcode //************************************************************************* template @@ -79,6 +79,18 @@ namespace etl return value; } + //********************************************************************* + explicit operator bool() const + { + return static_cast(value); + } + + //********************************************************************* + bool operator !() const + { + return !bool(value); + } + //********************************************************************* type_def& operator ++() { @@ -243,11 +255,35 @@ namespace etl } //********************************************************************* - TValue get() const + const TValue& get() const { return value; } + //********************************************************************* + friend type_def operator +(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value + rhs.value); + } + + //********************************************************************* + friend type_def operator -(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value - rhs.value); + } + + //********************************************************************* + friend type_def operator *(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value * rhs.value); + } + + //********************************************************************* + friend type_def operator /(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value / rhs.value); + } + //********************************************************************* friend bool operator <(const type_def& lhs, const type_def& rhs) { From 98b0c888eab94469d3a8f0d55223c7f54c872aa4 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 8 Dec 2016 10:47:30 +0000 Subject: [PATCH 033/168] Possible fix for 'strict aliasing' warnings. --- src/hash.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hash.h b/src/hash.h index 3d02ab9b..a89aa9b4 100644 --- a/src/hash.h +++ b/src/hash.h @@ -32,6 +32,7 @@ SOFTWARE. #define __ETL_HASH__ #include +#include // The default hash calculation. #include "fnv_1.h" @@ -322,7 +323,9 @@ namespace etl { if (sizeof(size_t) == sizeof(v)) { - return *reinterpret_cast(&v); + size_t t; + memcpy(&t, &v, sizeof(size_t)); + return t; } else { @@ -344,7 +347,9 @@ namespace etl { if (sizeof(size_t) == sizeof(v)) { - return *reinterpret_cast(&v); + size_t t; + memcpy(&t, &v, sizeof(size_t)); + return t; } else { @@ -366,7 +371,9 @@ namespace etl { if (sizeof(size_t) == sizeof(v)) { - return *reinterpret_cast(&v); + size_t t; + memcpy(&t, &v, sizeof(size_t)); + return t; } else { @@ -387,7 +394,9 @@ namespace etl { if (sizeof(size_t) == sizeof(T*)) { - return reinterpret_cast(v); + size_t t; + memcpy(&t, &v, sizeof(size_t)); + return t; } else { From caf6cbf2737fd6ac33735293ec197cf29b04a189 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 8 Dec 2016 11:22:44 +0000 Subject: [PATCH 034/168] Possible fix for 'strict aliasing' warnings. --- src/hash.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hash.h b/src/hash.h index a89aa9b4..2a3f8ddc 100644 --- a/src/hash.h +++ b/src/hash.h @@ -230,9 +230,9 @@ namespace etl template<> struct hash { - // If it fits into a size_t. size_t operator ()(long v) const { + // If it's the same size as a size_t. if (sizeof(size_t) >= sizeof(v)) { return static_cast(v); @@ -252,9 +252,9 @@ namespace etl template<> struct hash { - // If it fits into a size_t. size_t operator ()(long long v) const { + // If it's the same size as a size_t. if (sizeof(size_t) >= sizeof(v)) { return static_cast(v); @@ -274,9 +274,9 @@ namespace etl template<> struct hash { - // If it fits into a size_t. size_t operator ()(unsigned long v) const { + // If it's the same size as a size_t. if (sizeof(size_t) >= sizeof(v)) { return static_cast(v); @@ -296,9 +296,9 @@ namespace etl template<> struct hash { - // If it fits into a size_t. size_t operator ()(unsigned long long v) const { + // If it's the same size as a size_t. if (sizeof(size_t) >= sizeof(v)) { return static_cast(v); @@ -318,9 +318,9 @@ namespace etl template<> struct hash { - // If it's the same size as a size_t. size_t operator ()(float v) const { + // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(v)) { size_t t; @@ -342,9 +342,9 @@ namespace etl template<> struct hash { - // If it's the same size as a size_t. size_t operator ()(double v) const { + // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(v)) { size_t t; @@ -366,9 +366,9 @@ namespace etl template<> struct hash { - // If it's the same size as a size_t. size_t operator ()(long double v) const { + // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(v)) { size_t t; @@ -392,6 +392,7 @@ namespace etl { size_t operator ()(const T* v) const { + // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(T*)) { size_t t; From f2ec22e8f404f362928000c22a4e68932a0e2e03 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 8 Dec 2016 11:23:01 +0000 Subject: [PATCH 035/168] Fix 'shadow' warning. --- src/function.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/function.h b/src/function.h index caf7b4c9..6e1053da 100644 --- a/src/function.h +++ b/src/function.h @@ -200,8 +200,8 @@ namespace etl /// Constructor. ///\param p_function Pointer to the function. //************************************************************************* - function(void(*p_function)(void)) - : p_function(p_function) + function(void(*p_function_)(void)) + : p_function(p_function_) { } From 1aa6b33d067f24337dc46186c8931ba8c569c4d0 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 12 Dec 2016 10:42:56 +0000 Subject: [PATCH 036/168] Fixed unused parameter warning. --- src/exception.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/exception.h b/src/exception.h index 52369caa..3b39f1e9 100644 --- a/src/exception.h +++ b/src/exception.h @@ -35,7 +35,7 @@ SOFTWARE. /// The base class for all ETL exceptions. ///\ingroup utilities -namespace etl +namespace etl { //*************************************************************************** ///\ingroup exception @@ -66,6 +66,7 @@ namespace etl : reason(reason), line(line) { + (void)file; } #endif From db375602d43d1db3d370c3203167b9e3feedf122 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 12 Dec 2016 10:54:30 +0000 Subject: [PATCH 037/168] Added destructor to release all remaining items in the pool. --- src/ipool.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ipool.h b/src/ipool.h index 34c4e7d2..ad3c16d1 100644 --- a/src/ipool.h +++ b/src/ipool.h @@ -46,7 +46,7 @@ namespace etl //*************************************************************************** template class ipool : public pool_base - { + { public: typedef T value_type; @@ -358,7 +358,7 @@ namespace etl return result; } - + //************************************************************************* /// Release an object in the pool. /// If asserts or exceptions are enabled and the object does not belong to this @@ -505,6 +505,14 @@ namespace etl { } + //************************************************************************* + /// Destructor + //************************************************************************* + ~ipool() + { + release_all(); + } + private: // Disable copy construction and assignment. From 0bd7da7aaee32566e865de43c23c56acfed9c3e2 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 12 Dec 2016 11:01:53 +0000 Subject: [PATCH 038/168] Added destructor to release all remaining items in the vector. --- src/vector.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/vector.h b/src/vector.h index 86a4998e..06c45d89 100644 --- a/src/vector.h +++ b/src/vector.h @@ -115,6 +115,14 @@ namespace etl ivector::assign(other.begin(), other.end()); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~vector() + { + ivector::clear(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* From ada67f1bebfab08373af952a5dd84dd4502b2b61 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 12 Dec 2016 11:07:37 +0000 Subject: [PATCH 039/168] Added destructor to release current item. --- src/variant.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/variant.h b/src/variant.h index c57465b9..613c3c61 100644 --- a/src/variant.h +++ b/src/variant.h @@ -717,6 +717,14 @@ namespace etl { } + //*************************************************************************** + /// Destructor. + //*************************************************************************** + ~variant() + { + destruct_current(); + } + //*************************************************************************** /// Assignment operator for T1 type. ///\param value The value to assign. From 28cd028b5e3a5fba4eb567556953fa5c8159a942 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 13 Dec 2016 09:35:32 +0000 Subject: [PATCH 040/168] Updated macros. Added compilers to list. --- src/platform.h | 50 +++++++++++++++++++++++++++++---------------- src/static_assert.h | 17 ++++++++------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/platform.h b/src/platform.h index d08bccc7..a8e5e544 100644 --- a/src/platform.h +++ b/src/platform.h @@ -31,31 +31,39 @@ SOFTWARE. #include #include -// Define the platform. -// The target platform will normally be defined as a compiler pre-processor directive. -// Defines ETL_PLATFORM_GENERIC if a recognised platform is not declared. -#if !defined(ETL_PLATFORM_LINUX) && !defined(ETL_PLATFORM_WINDOWS) && !defined(ETL_PLATFORM_WINDOWS_CE) && !defined(ETL_PLATFORM_VXWORKS) && !defined(ETL_PLATFORM_QNX) -#pragma message("ETL: Using generic platform") -#define ETL_PLATFORM_GENERIC -#endif - // Define the compiler. #if defined(__IAR_SYSTEMS_ICC__) -#define ETL_COMPILER_IAR + #define ETL_COMPILER_IAR #elif defined(__KEIL__) && !defined(__GNUC__) -#define ETL_COMPILER_KEIL + #define ETL_COMPILER_KEIL #elif defined(__ghs__) -#define ETL_COMPILER_GREEN_HILLS + #define ETL_COMPILER_GREEN_HILLS #elif defined(__INTEL_COMPILER) -#define ETL_COMPILER_INTEL + #define ETL_COMPILER_INTEL #elif defined(_MSC_VER) -#define ETL_COMPILER_MICROSOFT + #define ETL_COMPILER_MICROSOFT #elif defined(__GNUC__) -#define ETL_COMPILER_GCC + #define ETL_COMPILER_GCC #elif defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) -#define ETL_COMPILER_TI_MSP430 + #define ETL_COMPILER_TI_MSP430 +#elif defined(_MRI) + #define ETL_COMPILER_MICROTEC +#elif defined(__HIGHC__) + #define ETL_COMPILER_METAWARE_HIGH +#elif defined(__llvm__) + #define ETL_COMPILER_LLVM +#elif defined(__KCC_VERSION) + #define ETL_COMPILER_KAI +#elif defined(_COMO__) + #define ETL_COMPILER_COMEAU +#elif defined(__BORLANDC__) + #define ETL_COMPILER_BORLAND +#elif defined(__CC_ARM) + #define ETL_COMPILER_ARM +#elif defined(__MRC__) + #define ETL_COMPILER_MPW #else -#define ETL_COMPILER_GENERIC + #define ETL_COMPILER_GENERIC #endif // Check to see if the compiler supports nullptr and large character types. @@ -64,8 +72,14 @@ SOFTWARE. defined(ETL_COMPILER_TI_MSP430) || \ defined(ETL_COMPILER_IAR) || \ (defined(ETL_COMPILER_GCC) && (__cplusplus < 201103L)) -#define ETL_ETL_NO_NULLPTR_SUPPORT -#define ETL_ETL_NO_LARGE_CHAR_SUPPORT + #define ETL_ETL_NO_NULLPTR_SUPPORT + #define ETL_ETL_NO_LARGE_CHAR_SUPPORT +#endif + +// Check to see if the compiler supports static_assert. +#if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER >= 1600) || \ + (defined(ETL_COMPILER_GCC) && (__cplusplus >= 201103L)) +#define ETL_STATIC_ASSERT_SUPPORTED #endif // Some targets do not support 8bit types. diff --git a/src/static_assert.h b/src/static_assert.h index 575b9c2b..ced509aa 100644 --- a/src/static_assert.h +++ b/src/static_assert.h @@ -31,9 +31,7 @@ SOFTWARE. #include "platform.h" -#if defined(ETL_COMPILER_MICROSOFT) - #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message) -#elif defined(ETL_COMPILER_GCC) +#if defined(ETL_STATIC_ASSERT_SUPPORTED) #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message) #else template @@ -42,12 +40,13 @@ SOFTWARE. template <> struct STATIC_ASSERT_FAILED {}; - #define ETL_FCAT(a,b) a##b - #define ETL_ACAT(a,b) ETL_FCAT(a,b) - #define STATIC_ASSERT(cond,msg) \ - enum \ - { ETL_ACAT(dummy,__LINE__)=sizeof(STATIC_ASSERT_FAILED<(bool)(cond)>) \ - } + #define ETL_SA1(a,b) a##b + #define ETL_SA2(a,b) ETL_SA1(a,b) + #define STATIC_ASSERT(Condition, Message) \ + enum \ + { \ + ETL_SA2(dummy, __LINE__) = sizeof(STATIC_ASSERT_FAILED<(bool)(Condition)>) \ + } #endif #endif From 195b34f77532d1df1f9d6e6ba18ae7cc786b715a Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 13 Dec 2016 09:36:23 +0000 Subject: [PATCH 041/168] Fixed compile errors. --- src/jenkins.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/jenkins.h b/src/jenkins.h index 0c500e3c..3cffc790 100644 --- a/src/jenkins.h +++ b/src/jenkins.h @@ -39,9 +39,10 @@ SOFTWARE. #include "type_traits.h" #include "error_handler.h" #include "ihash.h" +#include "frame_check_sequence.h" #if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 +#pragma diag_suppress 1300 #endif ///\defgroup jenkins Jenkins 32 & 64 bit hash calculations @@ -57,7 +58,7 @@ namespace etl { typedef uint32_t value_type; - inline uint32_t initial() const + inline uint32_t initial() { is_finalised = false; @@ -75,7 +76,7 @@ namespace etl return hash; } - inline uint32_t final(uint8_t hash) const + inline uint32_t final(uint8_t hash) { hash += (hash << 3); hash ^= (hash >> 11); @@ -96,7 +97,7 @@ namespace etl { typedef uint64_t value_type; - inline uint64_t initial() const + inline uint64_t initial() { is_finalised = false; @@ -114,7 +115,7 @@ namespace etl return hash; } - inline uint64_t final(uint8_t hash) const + inline uint64_t final(uint8_t hash) { hash += (hash << 3); hash ^= (hash >> 11); From 315e4c4d4fb66f78924d46b8f6330e3fb580d128 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 13 Dec 2016 09:37:06 +0000 Subject: [PATCH 042/168] Removed const from value funtions. --- src/frame_check_sequence.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frame_check_sequence.h b/src/frame_check_sequence.h index 8d30941f..0a1aabc7 100644 --- a/src/frame_check_sequence.h +++ b/src/frame_check_sequence.h @@ -53,9 +53,9 @@ namespace etl typedef TPolicy policy_type; typedef typename policy_type::value_type value_type; - + STATIC_ASSERT(etl::is_unsigned::value, "Signed frame check type not supported"); - + //************************************************************************* /// Default constructor. //************************************************************************* @@ -113,7 +113,7 @@ namespace etl //************************************************************************* /// Gets the FCS value. //************************************************************************* - value_type value() const + value_type value() { return policy.final(frame_check); } @@ -121,7 +121,7 @@ namespace etl //************************************************************************* /// Conversion operator to value_type. //************************************************************************* - operator value_type () const + operator value_type () { return policy.final(frame_check); } From 98a09ca07cc6e8341a8900addec210c896acde97 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 13 Dec 2016 09:46:03 +0000 Subject: [PATCH 043/168] Missing closing ) --- src/platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform.h b/src/platform.h index a8e5e544..cfbb4eed 100644 --- a/src/platform.h +++ b/src/platform.h @@ -77,7 +77,7 @@ SOFTWARE. #endif // Check to see if the compiler supports static_assert. -#if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER >= 1600) || \ +#if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER >= 1600)) || \ (defined(ETL_COMPILER_GCC) && (__cplusplus >= 201103L)) #define ETL_STATIC_ASSERT_SUPPORTED #endif From 9f9791b9c1cacaf0004e77046e61b792d74c99db Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 14 Dec 2016 11:25:33 +0000 Subject: [PATCH 044/168] Initial code for intrusive_queue. --- src/intrusive_queue.h | 256 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 src/intrusive_queue.h diff --git a/src/intrusive_queue.h b/src/intrusive_queue.h new file mode 100644 index 00000000..6889d784 --- /dev/null +++ b/src/intrusive_queue.h @@ -0,0 +1,256 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_INTRUSIVE_QUEUE__ +#define __ETL_INTRUSIVE_QUEUE__ + +#error In Development. Do not use. + +#include + +#include "type_traits.h" +#include "error_handler.h" +#include "intrusive_links.h" +#include "private/counter_type.h" + +namespace etl +{ + //*************************************************************************** + /// Exception base for intrusive queue + ///\ingroup intrusive_queue + //*************************************************************************** + class intrusive_queue_exception : public etl::exception + { + public: + + intrusive_queue_exception(string_type what, string_type file_name, numeric_type line_number) + : exception(what, file_name, line_number) + { + } + }; + + //*************************************************************************** + /// intrusive_queue empty exception. + ///\ingroup intrusive_queue + //*************************************************************************** + class intrusive_queue_empty : public intrusive_queue_exception + { + public: + + intrusive_queue_empty(string_type file_name, numeric_type line_number) + : intrusive_queue_exception(ETL_ERROR_TEXT("intrusive_queue:empty", ETL_FILE"A"), file_name, line_number) + { + } + }; + + //*************************************************************************** + ///\ingroup queue + /// An intrusive queue. Stores elements derived from etl::forward_link + /// \warning This queue cannot be used for concurrent access from multiple threads. + /// \tparam TValue The type of value that the queue holds. + /// \tparam TLink The link type that the value is derived from. + //*************************************************************************** + template + class intrusive_queue + { + public: + + // Node typedef. + typedef TLink link_type; + + // STL style typedefs. + typedef TValue value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + + enum + { + // The count option is based on the type of link. + COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || (TLink::OPTION == etl::link_option::CHECKED)) ? + etl::count_option::SLOW_COUNT : + etl::count_option::FAST_COUNT + }; + + //************************************************************************* + /// Constructor + //************************************************************************* + intrusive_queue() + : p_front(nullptr), + p_back(nullptr) + { + } + + //************************************************************************* + /// Gets a reference to the value at the front of the queue. + /// Undefined behaviour if the queue is empty. + /// \return A reference to the value at the front of the queue. + //************************************************************************* + reference front() + { + return *static_cast(p_front); + } + + //************************************************************************* + /// Gets a reference to the value at the back of the queue. + /// Undefined behaviour if the queue is empty. + /// \return A reference to the value at the back of the queue. + //************************************************************************* + reference back() + { + return *static_cast(p_back); + } + + //************************************************************************* + /// Gets a const reference to the value at the front of the queue. + /// Undefined behaviour if the queue is empty. + /// \return A const reference to the value at the front of the queue. + //************************************************************************* + const_reference front() const + { + return *static_cast(p_front); + } + + //************************************************************************* + /// Gets a reference to the value at the back of the queue. + /// Undefined behaviour if the queue is empty. + /// \return A reference to the value at the back of the queue. + //************************************************************************* + const_reference back() const + { + return *static_cast(p_back); + } + + //************************************************************************* + /// Adds a value to the queue. + ///\param value The value to push to the queue. + //************************************************************************* + void push(link_type& value) + { + if (p_back != nullptr) + { + etl::link(p_front, value); + } + else + { + p_front = &value; + } + + p_back = &value; + + ++current_size; + } + + //************************************************************************* + /// Removes the oldest item from the queue. + /// Undefined behaviour if the queue is already empty. + //************************************************************************* + void pop() + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!empty(), ETL_ERROR(intrusive_queue_empty)); +#endif + link_type* p_next = p_front->etl_next; + p_front->clear(); + p_front = p_next; + + // Now empty? + if (p_front == nullptr) + { + p_back == nullptr; + } + + --current_size; + } + + //************************************************************************* + /// Clears the queue to the empty state. + //************************************************************************* + void clear() + { + while (!empty()) + { + pop(); + } + current_size = 0; + } + + //************************************************************************* + /// Checks if the queue is in the empty state. + //************************************************************************* + bool empty() const + { + return p_front == nullptr; + } + + //************************************************************************* + /// Returns the number of elements. + //************************************************************************* + size_t size() const + { + if (COUNT_OPTION == etl::count_option::SLOW_COUNT) + { + size_t count = 0; + + if (p_front != nullptr) + { + link_type* p_link = p_front; + + while (p_link != nullptr) + { + ++count; + p_link = p_link->etl_next; + } + } + + return count; + } + else + { + return current_size.get_count(); + } + } + + private: + + // Disable copy construction and assignment. + intrusive_queue(const intrusive_queue&); + intrusive_queue& operator = (const intrusive_queue& rhs); + + link_type* p_front; // The current front of the queue. + link_type* p_back; // The current back of the queue. + + etl::counter_type current_size; ///< Counts the number of elements in the list. + }; +} + +#endif From 2cb60e43a4456c9df97facbd2cb81e385e2b0775 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 14 Dec 2016 12:53:51 +0000 Subject: [PATCH 045/168] Added ETL_FILE defines. --- src/intrusive_queue.h | 4 ++++ src/intrusive_stack.h | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/intrusive_queue.h b/src/intrusive_queue.h index 6889d784..69a530d9 100644 --- a/src/intrusive_queue.h +++ b/src/intrusive_queue.h @@ -40,6 +40,8 @@ SOFTWARE. #include "intrusive_links.h" #include "private/counter_type.h" +#define ETL_FILE "29" + namespace etl { //*************************************************************************** @@ -253,4 +255,6 @@ namespace etl }; } +#undef ETL_FILE + #endif diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h index 0fc0cb61..787f2dba 100644 --- a/src/intrusive_stack.h +++ b/src/intrusive_stack.h @@ -38,6 +38,8 @@ SOFTWARE. #include "intrusive_links.h" #include "private/counter_type.h" +#define ETL_FILE "28" + namespace etl { //*************************************************************************** @@ -95,7 +97,7 @@ namespace etl { // The count option is based on the type of link. COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || (TLink::OPTION == etl::link_option::CHECKED)) ? - etl::count_option::SLOW_COUNT : + etl::count_option::SLOW_COUNT : etl::count_option::FAST_COUNT }; @@ -136,7 +138,7 @@ namespace etl { etl::link(value, p_top); } - + p_top = &value; ++current_size; @@ -217,4 +219,6 @@ namespace etl }; } +#undef ETL_FILE + #endif From 42f81f0fa8dd7b2026e3c5774c039d5c77822d61 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 14 Dec 2016 12:54:30 +0000 Subject: [PATCH 046/168] Modified ETL_FILE definition. --- src/private/string_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/private/string_base.h b/src/private/string_base.h index f3e84212..7807448f 100644 --- a/src/private/string_base.h +++ b/src/private/string_base.h @@ -42,7 +42,7 @@ SOFTWARE. #include "../exception.h" #include "../error_handler.h" -#define ETL_FILE "24" +#define ETL_FILE "27" #ifdef ETL_COMPILER_MICROSOFT #undef max From 676097f8b94ef746b68185554669219129f11949 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 14 Dec 2016 12:55:18 +0000 Subject: [PATCH 047/168] Linux compatible filename case. --- test/murmurhash3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/murmurhash3.cpp b/test/murmurhash3.cpp index 75a6110e..eb453366 100644 --- a/test/murmurhash3.cpp +++ b/test/murmurhash3.cpp @@ -7,7 +7,7 @@ // compile and run any of them on any platform, but your performance with the // non-native version will be less than optimal. -#include "MurmurHash3.h" +#include "murmurhash3.h" //----------------------------------------------------------------------------- // Platform-specific functions and macros From 4bab3ab6d452ee532955166de072ff88cdf05655 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 14 Dec 2016 12:58:08 +0000 Subject: [PATCH 048/168] Updated error numbers --- src/file_error_numbers.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/file_error_numbers.txt b/src/file_error_numbers.txt index db9728cc..48b14101 100644 --- a/src/file_error_numbers.txt +++ b/src/file_error_numbers.txt @@ -23,4 +23,7 @@ 23 iunordered_set, iunordered_multiset 24 variant 25 iunordered_multimap -26 iunordered_multiset \ No newline at end of file +26 iunordered_multiset +27 string_base +28 intrusive_stack +29 intrusive_queue \ No newline at end of file From d5aeff4a8ed87a8325468062cb293014ff148890 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 15 Dec 2016 09:30:09 +0000 Subject: [PATCH 049/168] Added etl::exchange --- src/utility.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/utility.h diff --git a/src/utility.h b/src/utility.h new file mode 100644 index 00000000..d660ef4d --- /dev/null +++ b/src/utility.h @@ -0,0 +1,49 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_UTILITY__ +#define __ETL_UTILITY__ + +///\defgroup utility utility +///\ingroup utilities + +namespace etl +{ + template + T exchange(T& object, U& new_value) + { + T old_value = object; + object = new_value; + return old_value; + } +} + +#endif + From ed785da11b229c442ec6e6a5cade4e10deb7bb45 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 15 Dec 2016 14:15:06 +0000 Subject: [PATCH 050/168] Added const version of exchange. Added exchange tests --- src/utility.h | 8 ++++++ test/test_utility.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 test/test_utility.cpp diff --git a/src/utility.h b/src/utility.h index d660ef4d..19772936 100644 --- a/src/utility.h +++ b/src/utility.h @@ -43,6 +43,14 @@ namespace etl object = new_value; return old_value; } + + template + T exchange(T& object, const U& new_value) + { + T old_value = object; + object = new_value; + return old_value; + } } #endif diff --git a/test/test_utility.cpp b/test/test_utility.cpp new file mode 100644 index 00000000..fad3bc26 --- /dev/null +++ b/test/test_utility.cpp @@ -0,0 +1,61 @@ +/****************************************************************************** +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 "../src/utility.h" + +namespace +{ + SUITE(test_utility) + { + //========================================================================= + TEST(test_exchange) + { + int a = 1; + int b = 2; + int c = etl::exchange(a, b); // c = a, a = b + + CHECK_EQUAL(2, a); + CHECK_EQUAL(2, b); + CHECK_EQUAL(1, c); + } + + //========================================================================= + TEST(test_exchange_const) + { + int a = 1; + const int b = 2; + int c = etl::exchange(a, b); // c = a, a = b + + CHECK_EQUAL(2, a); + CHECK_EQUAL(2, b); + CHECK_EQUAL(1, c); + } + }; +} From 8c1f678ac946c2218e98649cb06c855757f1c0c1 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 16 Dec 2016 14:24:37 +0000 Subject: [PATCH 051/168] Created 'ratio.h' Added as_const to 'utility.h' --- src/ratio.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/utility.h | 8 +++++ 2 files changed, 102 insertions(+) create mode 100644 src/ratio.h diff --git a/src/ratio.h b/src/ratio.h new file mode 100644 index 00000000..c0f03436 --- /dev/null +++ b/src/ratio.h @@ -0,0 +1,94 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_RATIO__ +#define __ETL_RATIO__ + +#include + +///\defgroup ratio ratio +///\ingroup utilities + +namespace etl +{ + template + struct ratio + { + static const std::intmax_t num = NUM; + static const std::intmax_t den = DEN; + }; + + #if INT_MAX > INT32_MAX + typedef ratio<1, 1000000000000000000000000> yocto; + typedef ratio<1, 1000000000000000000000> zepto; + typedef ratio<1, 1000000000000000000> atto + typedef ratio<1, 1000000000000000> femto + typedef ratio<1, 1000000000000> pico; + #endif + + #if (INT_MAX >= INT32_MAX) + typedef ratio<1, 1000000000> nano; + typedef ratio<1, 1000000> micro; + #endif + + #if (INT_MAX >= INT16_MAX) + typedef ratio<1, 1000> milli; + typedef ratio<1, 100> centi; + typedef ratio<1, 10> deci; + typedef ratio<10, 1> deca; + typedef ratio<100, 1> hecto + typedef ratio<1000, 1> kilo + #endif + + #if (INT_MAX >= INT32_MAX) + typedef ratio<1000000, 1> mega; + typedef ratio<1000000000, 1> giga; + #endif + + #if INT_MAX > INT32_MAX + typedef ratio<1000000000000, 1> tera; + typedef ratio<1000000000000000, 1> peta; + typedef ratio<1000000000000000000, 1> exa; + typedef ratio<1000000000000000000000, 1> zetta; + typedef ratio<1000000000000000000000000, 1> yotta; + #endif + + /// An approximation of PI to 6 digits. + typedef ratio<355, 113> ratio_pi; + + /// An approximation of root 2. + typedef ratio<239, 169> ratio_root2; + + /// An approximation of e. + typedef ratio<326, 120> ratio_e; +} + +#endif + diff --git a/src/utility.h b/src/utility.h index 19772936..1b1c2347 100644 --- a/src/utility.h +++ b/src/utility.h @@ -31,6 +31,8 @@ SOFTWARE. #ifndef __ETL_UTILITY__ #define __ETL_UTILITY__ +#include "type_traits.h" + ///\defgroup utility utility ///\ingroup utilities @@ -51,6 +53,12 @@ namespace etl object = new_value; return old_value; } + + template + etl::add_const_t& as_const(T& t) + { + return t; + } } #endif From d58f675722f190bbb9395b496c85e3c4fd72e185 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:40:29 +0000 Subject: [PATCH 052/168] Added hash functions --- src/callback.h | 6 +- src/fnv_1.h | 28 +-- src/hash.h | 60 +++-- src/ibasic_string.h | 6 +- src/iforward_list.h | 30 +-- src/intrusive_forward_list.h | 30 +-- src/intrusive_links.h | 3 +- src/intrusive_list.h | 2 +- src/ipriority_queue.h | 10 +- src/iqueue.h | 2 +- src/istack.h | 2 +- src/ivector.h | 2 +- src/pearson.cpp | 1 - src/private/ivectorpointer.h | 47 +++- src/private/map_base.h | 28 +-- src/private/pvoidvector.h | 16 +- src/string.h | 17 +- src/type_def.h | 42 +--- src/type_traits.h | 46 ++-- src/u16string.h | 17 +- src/u32string.h | 17 +- src/variant.h | 71 ++++-- src/wstring.h | 17 +- test/test_intrusive_forward_list.cpp | 343 +++++---------------------- test/test_intrusive_links.cpp | 7 +- test/test_variant.cpp | 16 ++ test/vs2015/etl.vcxproj | 16 +- test/vs2015/etl.vcxproj.filters | 6 - 28 files changed, 353 insertions(+), 535 deletions(-) diff --git a/src/callback.h b/src/callback.h index 0111c492..805e3bec 100644 --- a/src/callback.h +++ b/src/callback.h @@ -28,8 +28,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#error In Development. Do not use. - #ifndef __ETL_CALLBACK__ #define __ETL_CALLBACK__ @@ -37,8 +35,8 @@ namespace etl { //*************************************************************************** /// A callback class designed to be multiply inherited by other client classes. - /// The class is parameterised with a callback parameter type and a unique id. - /// The unique id allows muliple callbacks with the same parameter type. + /// The class is parametrised with a callback parameter type and a unique id. + /// The unique id allows multiple callbacks with the same parameter type. ///\tparam TParameter The callback parameter type. ///\tparam ID The unique id for this callback. //*************************************************************************** diff --git a/src/fnv_1.h b/src/fnv_1.h index ce787651..c9799196 100644 --- a/src/fnv_1.h +++ b/src/fnv_1.h @@ -106,17 +106,17 @@ namespace etl this->add(begin, end); } }; - + //*************************************************************************** /// fnv_1a policy. /// Calculates FNV1A. //*************************************************************************** struct fnv_1a_policy_64 - { + { typedef uint64_t value_type; inline uint64_t initial() const - { + { return OFFSET_BASIS; } @@ -124,7 +124,7 @@ namespace etl { hash ^= value; hash *= PRIME; - return hash; + return hash; } inline uint64_t final(uint64_t hash) const @@ -135,7 +135,7 @@ namespace etl static const uint64_t OFFSET_BASIS = 0xCBF29CE484222325; static const uint64_t PRIME = 0x00000100000001b3; }; - + //*************************************************************************** /// Calculates the fnv_1a_64 hash. ///\ingroup fnv_1a_64 @@ -170,11 +170,11 @@ namespace etl /// Calculates FNV1. //*************************************************************************** struct fnv_1_policy_32 - { - typedef uint32_t value_type; - - inline uint32_t initial() const { + typedef uint32_t value_type; + + inline uint32_t initial() const + { return OFFSET_BASIS; } @@ -182,7 +182,7 @@ namespace etl { hash *= PRIME; hash ^= value; - return hash; + return hash; } inline uint32_t final(uint32_t hash) const @@ -222,17 +222,17 @@ namespace etl this->add(begin, end); } }; - + //*************************************************************************** /// fnv_1a policy. /// Calculates FNV1A. //*************************************************************************** struct fnv_1a_policy_32 - { + { typedef uint32_t value_type; inline uint32_t initial() const - { + { return OFFSET_BASIS; } @@ -240,7 +240,7 @@ namespace etl { hash ^= value; hash *= PRIME; - return hash; + return hash; } inline uint32_t final(uint32_t hash) const diff --git a/src/hash.h b/src/hash.h index 2a3f8ddc..39408f3a 100644 --- a/src/hash.h +++ b/src/hash.h @@ -50,9 +50,9 @@ namespace etl /// Hash to use when size_t is 16 bits. /// T is always expected to be size_t. //************************************************************************* - template + template typename enable_if::type - generic_hash(uint8_t* begin, uint8_t* end) + generic_hash(const uint8_t* begin, const uint8_t* end) { uint32_t h = fnv_1a_32(begin, end); @@ -63,9 +63,9 @@ namespace etl /// Hash to use when size_t is 32 bits. /// T is always expected to be size_t. //************************************************************************* - template + template typename enable_if::type - generic_hash(uint8_t* begin, uint8_t* end) + generic_hash(const uint8_t* begin, const uint8_t* end) { return fnv_1a_32(begin, end); } @@ -74,9 +74,9 @@ namespace etl /// Hash to use when size_t is 64 bits. /// T is always expected to be size_t. //************************************************************************* - template + template typename enable_if::type - generic_hash(uint8_t* begin, uint8_t* end) + generic_hash(const uint8_t* begin, const uint8_t* end) { return fnv_1a_64(begin, end); } @@ -323,9 +323,15 @@ namespace etl // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(v)) { - size_t t; - memcpy(&t, &v, sizeof(size_t)); - return t; + union + { + size_t s; + float v; + } u; + + u.v = v; + + return u.s; } else { @@ -347,9 +353,15 @@ namespace etl // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(v)) { - size_t t; - memcpy(&t, &v, sizeof(size_t)); - return t; + union + { + size_t s; + double v; + } u; + + u.v = v; + + return u.s; } else { @@ -371,9 +383,15 @@ namespace etl // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(v)) { - size_t t; - memcpy(&t, &v, sizeof(size_t)); - return t; + union + { + size_t s; + long double v; + } u; + + u.v = v; + + return u.s; } else { @@ -395,9 +413,15 @@ namespace etl // If it's the same size as a size_t. if (sizeof(size_t) == sizeof(T*)) { - size_t t; - memcpy(&t, &v, sizeof(size_t)); - return t; + union + { + size_t s; + const T* v; + } u; + + u.v = v; + + return u.s; } else { diff --git a/src/ibasic_string.h b/src/ibasic_string.h index 34c6ba95..85bd6d9c 100644 --- a/src/ibasic_string.h +++ b/src/ibasic_string.h @@ -36,7 +36,7 @@ SOFTWARE. #include #include #include -#include +#include #include "private/string_base.h" #include "platform.h" @@ -460,7 +460,7 @@ namespace etl //************************************************************************* /// Removes an element from the end of the string. - /// Undefined behaviour if the string is empty. + /// Does nothing if the string is empty. //************************************************************************* void pop_back() { @@ -468,7 +468,7 @@ namespace etl ETL_ASSERT(!empty(), ETL_ERROR(string_empty)); #endif - p_buffer[--current_size] = 0; + p_buffer[--current_size] = 0; } //********************************************************************* diff --git a/src/iforward_list.h b/src/iforward_list.h index 0f418209..b663ad8e 100644 --- a/src/iforward_list.h +++ b/src/iforward_list.h @@ -256,7 +256,7 @@ namespace etl const Node* p_node; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Gets the beginning of the forward_list. @@ -348,7 +348,7 @@ namespace etl //************************************************************************* /// Assigns a range of values to the forward_list. - /// If asserts or exceptions are enabled throws etl::forward_list_full if the forward_list does not have enough free space. + /// If asserts or exceptions are enabled throws etl::forward_list_full if the forward_list does not have enough free space. /// If ETL_THROW_EXCEPTIONS & _DEBUG are defined throws forward_list_iterator if the iterators are reversed. //************************************************************************* template @@ -707,7 +707,7 @@ namespace etl if (is_trivial_list()) { - return; + return; } while (true) @@ -746,32 +746,32 @@ namespace etl // Decide whether the next node of merge comes from left or right. if (left_size == 0) { - // Left is empty. The node must come from right. - p_node = p_right; + // Left is empty. The node must come from right. + p_node = p_right; ++p_right; --right_size; - } + } else if (right_size == 0 || p_right == end()) { - // Right is empty. The node must come from left. - p_node = p_left; + // Right is empty. The node must come from left. + p_node = p_left; ++p_left; --left_size; - } + } else if (compare(*p_left, *p_right)) { - // First node of left is lower or same. The node must come from left. - p_node = p_left; + // First node of left is lower or same. The node must come from left. + p_node = p_left; ++p_left; --left_size; - } + } else { - // First node of right is lower. The node must come from right. - p_node = p_right; + // First node of right is lower. The node must come from right. + p_node = p_right; ++p_right; --right_size; - } + } // Add the next node to the merged head. if (p_head == before_begin()) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 3bec7fd4..fa275352 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -325,7 +325,7 @@ namespace etl const value_type* p_value; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Constructor. @@ -659,7 +659,7 @@ namespace etl if (is_trivial_list()) { - return; + return; } while (true) @@ -698,32 +698,32 @@ namespace etl // Decide whether the next link of merge comes from left or right. if (left_size == 0) { - // Left is empty. The link must come from right. - i_link = i_right; + // Left is empty. The link must come from right. + i_link = i_right; ++i_right; --right_size; - } + } else if (right_size == 0 || i_right == end()) { - // Right is empty. The link must come from left. - i_link = i_left; + // Right is empty. The link must come from left. + i_link = i_left; ++i_left; --left_size; - } + } else if (compare(*i_left, *i_right)) { - // First link of left is lower or same. The link must come from left. - i_link = i_left; + // First link of left is lower or same. The link must come from left. + i_link = i_left; ++i_left; --left_size; - } + } else { - // First link of right is lower. The link must come from right. - i_link = i_right; + // First link of right is lower. The link must come from right. + i_link = i_right; ++i_right; --right_size; - } + } // Add the next link to the merged head. if (i_head == before_begin()) @@ -906,7 +906,7 @@ namespace etl last = last->link_type::etl_next; } - // Unlink from the source other. + // Unlink from the source list. link_type* first_next = first->link_type::etl_next; etl::unlink_after(*first, *last); diff --git a/src/intrusive_links.h b/src/intrusive_links.h index eb0bf522..823a6dc2 100644 --- a/src/intrusive_links.h +++ b/src/intrusive_links.h @@ -149,7 +149,7 @@ namespace etl struct forward_link; //****************************************************************** - // Specialisation for checked link option. + // Specialisation for checked unlink option. // An error will be generated if the links are valid when the object // is destroyed. //****************************************************************** @@ -669,7 +669,6 @@ namespace etl { clear(); } - void clear() { etl_parent = nullptr; diff --git a/src/intrusive_list.h b/src/intrusive_list.h index 9e151c8f..2da75417 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -342,7 +342,7 @@ namespace etl const value_type* p_value; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Constructor. diff --git a/src/ipriority_queue.h b/src/ipriority_queue.h index 74a11cfd..8e58300a 100644 --- a/src/ipriority_queue.h +++ b/src/ipriority_queue.h @@ -180,14 +180,14 @@ namespace etl //************************************************************************* /// Removes the oldest value from the back of the priority queue. - /// Undefined behaviour if the priority queue is already empty. + /// Does nothing if the priority queue is already empty. //************************************************************************* void pop() { - // Move largest element to end - std::pop_heap(container.begin(), container.end(), TCompare()); - // Actually remove largest element at end - container.pop_back(); + // Move largest element to end + std::pop_heap(container.begin(), container.end(), TCompare()); + // Actually remove largest element at end + container.pop_back(); } //************************************************************************* diff --git a/src/iqueue.h b/src/iqueue.h index 8d8751f2..0f55963c 100644 --- a/src/iqueue.h +++ b/src/iqueue.h @@ -162,7 +162,7 @@ namespace etl //************************************************************************* /// Removes the oldest value from the back of the queue. - /// Undefined behaviour if the queue is already empty. + /// Does nothing if the queue is already empty. //************************************************************************* void pop() { diff --git a/src/istack.h b/src/istack.h index d742f452..35e8107c 100644 --- a/src/istack.h +++ b/src/istack.h @@ -135,7 +135,7 @@ namespace etl //************************************************************************* /// Removes the oldest item from the top of the stack. - /// Undefined behaviour if the stack is already empty. + /// Does nothing if the stack is already empty. //************************************************************************* void pop() { diff --git a/src/ivector.h b/src/ivector.h index a186a4a7..0dfe8491 100644 --- a/src/ivector.h +++ b/src/ivector.h @@ -475,7 +475,7 @@ namespace etl //************************************************************************* /// Removes an element from the end of the vector. - /// Undefined behaviour if the vector is empty. + /// Does nothing if the vector is empty. //************************************************************************* void pop_back() { diff --git a/src/pearson.cpp b/src/pearson.cpp index a10940b4..94c5ec0f 100644 --- a/src/pearson.cpp +++ b/src/pearson.cpp @@ -61,4 +61,3 @@ namespace etl 213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82 } ; } - diff --git a/src/private/ivectorpointer.h b/src/private/ivectorpointer.h index 13c4512b..1aae4e5c 100644 --- a/src/private/ivectorpointer.h +++ b/src/private/ivectorpointer.h @@ -35,7 +35,7 @@ SOFTWARE. #error This header is a private element of etl::ivector #endif -#include "private/pvoidvector.h" +#include "pvoidvector.h" namespace etl { @@ -456,7 +456,7 @@ namespace etl template bool operator ==(const etl::ivector& lhs, const etl::ivector& rhs) { - return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin()); + return pvoidvector_equal(lhs, rhs); } //*************************************************************************** @@ -469,7 +469,7 @@ namespace etl template bool operator !=(const etl::ivector& lhs, const etl::ivector& rhs) { - return !(lhs == rhs); + return pvoidvector_not_equal(lhs, rhs); } //*************************************************************************** @@ -482,7 +482,7 @@ namespace etl template bool operator <(const etl::ivector& lhs, const etl::ivector& rhs) { - return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + return pvoidvector_less_than(lhs, rhs); } //*************************************************************************** @@ -495,7 +495,7 @@ namespace etl template bool operator >(const etl::ivector& lhs, const etl::ivector& rhs) { - return (rhs < lhs); + return pvoidvector_greater_than(lhs, rhs); } //*************************************************************************** @@ -508,7 +508,7 @@ namespace etl template bool operator <=(const etl::ivector& lhs, const etl::ivector& rhs) { - return !(lhs > rhs); + return pvoidvector_less_than_equal(lhs, rhs); } //*************************************************************************** @@ -521,7 +521,40 @@ namespace etl template bool operator >=(const etl::ivector& lhs, const etl::ivector& rhs) { - return !(lhs < rhs); + return pvoidvector_greater_than_equal(lhs, rhs); + } + + //*************************************************************************** + // Helper functions + //*************************************************************************** + inline bool pvoidvector_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return operator ==(lhs, rhs); + } + + inline bool pvoidvector_not_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return operator !=(lhs, rhs); + } + + inline bool pvoidvector_less_than(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return operator <(lhs, rhs); + } + + inline bool pvoidvector_greater_than(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return operator >(lhs, rhs); + } + + inline bool pvoidvector_less_than_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return operator <=(lhs, rhs); + } + + inline bool pvoidvector_greater_than_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs) + { + return operator >=(lhs, rhs); } } diff --git a/src/private/map_base.h b/src/private/map_base.h index f23de8da..2ac3256f 100644 --- a/src/private/map_base.h +++ b/src/private/map_base.h @@ -178,8 +178,8 @@ namespace etl /// Constructor //*********************************************************************** Node() : - weight(kNeither), - dir(kNeither) + weight(uint_least8_t(kNeither)), + dir(uint_least8_t(kNeither)) { } @@ -188,13 +188,13 @@ namespace etl //*********************************************************************** void mark_as_leaf() { - weight = kNeither; - dir = kNeither; + weight = uint_least8_t(kNeither); + dir = uint_least8_t(kNeither); children[0] = nullptr; children[1] = nullptr; } - Node* children[2]; + Node* children[2]; uint_least8_t weight; uint_least8_t dir; }; @@ -222,12 +222,12 @@ namespace etl while (weight_node) { // Keep going until we reach a terminal node (dir == kNeither) - if (kNeither != weight_node->dir) + if (uint_least8_t(kNeither) != weight_node->dir) { // Does this insert balance the previous weight factor value? if (weight_node->weight == 1 - weight_node->dir) { - weight_node->weight = kNeither; + weight_node->weight = uint_least8_t(kNeither); } else { @@ -245,14 +245,14 @@ namespace etl } // while(weight_node) // Step 2: Update weight for critical_node or rotate tree to balance node - if (kNeither == critical_node->weight) + if (uint_least8_t(kNeither) == critical_node->weight) { critical_node->weight = critical_node->dir; } // If direction is different than weight, then it will now be balanced else if (critical_node->dir != critical_node->weight) { - critical_node->weight = kNeither; + critical_node->weight = uint_least8_t(kNeither); } // Rotate is required to balance the tree at the critical node else @@ -296,11 +296,11 @@ namespace etl // New root now becomes parent of current position new_root->children[1 - dir] = position; // Clear weight factor from current position - position->weight = kNeither; + position->weight = uint_least8_t(kNeither); // Newly detached right now becomes current position position = new_root; // Clear weight factor from new root - position->weight = kNeither; + position->weight = uint_least8_t(kNeither); } //************************************************************************* @@ -323,7 +323,7 @@ namespace etl // Capture new root (either E or D depending on dir) Node* new_root = position->children[dir]->children[1 - dir]; // Set weight factor for B or C based on F or G existing and being a different than dir - position->children[dir]->weight = third != kNeither && third != dir ? dir : kNeither; + position->children[dir]->weight = third != uint_least8_t(kNeither) && third != dir ? dir : uint_least8_t(kNeither); // Detach new root from its tree (replace with new roots child) position->children[dir]->children[1 - dir] = @@ -331,7 +331,7 @@ namespace etl // Attach current left tree to new root new_root->children[dir] = position->children[dir]; // Set weight factor for A based on F or G - position->weight = third != kNeither && third == dir ? 1 - dir : kNeither; + position->weight = third != uint_least8_t(kNeither) && third == dir ? 1 - dir : uint_least8_t(kNeither); // Move new root's right tree to current roots left tree position->children[dir] = new_root->children[1 - dir]; @@ -340,7 +340,7 @@ namespace etl // Replace current position with new root position = new_root; // Clear weight factor for new current position - position->weight = kNeither; + position->weight = uint_least8_t(kNeither); } //************************************************************************* diff --git a/src/private/pvoidvector.h b/src/private/pvoidvector.h index 165d0c32..010b47c0 100644 --- a/src/private/pvoidvector.h +++ b/src/private/pvoidvector.h @@ -392,7 +392,7 @@ namespace etl //************************************************************************* /// Removes an element from the end of the vector. - /// Undefined behaviour if the vector is empty. + /// Does nothing if the vector is empty. //************************************************************************* void pop_back() { @@ -616,6 +616,20 @@ namespace etl // Disable copy construction. pvoidvector(const pvoidvector&); }; + + bool pvoidvector_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); + bool pvoidvector_not_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); + bool pvoidvector_less_than(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); + bool pvoidvector_greater_than(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); + bool pvoidvector_less_than_equal(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); + bool pvoidvector_greater_than_equal(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); + bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs); } #ifdef ETL_COMPILER_MICROSOFT diff --git a/src/string.h b/src/string.h index 055c1fc9..26f1fbdf 100644 --- a/src/string.h +++ b/src/string.h @@ -182,19 +182,16 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; - //*************************************************************************** - /// Specialisation for string. - ///\ingroup hash - //*************************************************************************** + //************************************************************************* + /// Hash function. + //************************************************************************* template <> - struct hash + struct hash { - size_t operator ()(const string& s) const + size_t operator()(const etl::istring& text) const { - uint8_t* p_begin = &s[0]; - uint8_t* p_end = &s[s.size()]; - - return etl::__private_hash__::generic_hash(p_begin, p_end); + return etl::__private_hash__::generic_hash<>(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); } }; } diff --git a/src/type_def.h b/src/type_def.h index 707a0732..66d6156e 100644 --- a/src/type_def.h +++ b/src/type_def.h @@ -40,11 +40,11 @@ namespace etl /// Usage: ///\code /// // Short form. - /// ETL_TYPEDEF(int, mytype_t); + /// ETL_TYPEDEF(int, mytype); /// /// // Long form. /// class mytype_t_tag; - /// typedef etl::type_def mytype_t; + /// typedef etl::type_def mytype_t_tag; ///\endcode //************************************************************************* template @@ -79,18 +79,6 @@ namespace etl return value; } - //********************************************************************* - explicit operator bool() const - { - return static_cast(value); - } - - //********************************************************************* - bool operator !() const - { - return !bool(value); - } - //********************************************************************* type_def& operator ++() { @@ -255,35 +243,11 @@ namespace etl } //********************************************************************* - const TValue& get() const + TValue get() const { return value; } - //********************************************************************* - friend type_def operator +(const type_def& lhs, const type_def& rhs) - { - return type_def(lhs.value + rhs.value); - } - - //********************************************************************* - friend type_def operator -(const type_def& lhs, const type_def& rhs) - { - return type_def(lhs.value - rhs.value); - } - - //********************************************************************* - friend type_def operator *(const type_def& lhs, const type_def& rhs) - { - return type_def(lhs.value * rhs.value); - } - - //********************************************************************* - friend type_def operator /(const type_def& lhs, const type_def& rhs) - { - return type_def(lhs.value / rhs.value); - } - //********************************************************************* friend bool operator <(const type_def& lhs, const type_def& rhs) { diff --git a/src/type_traits.h b/src/type_traits.h index 605aa63d..776bfda0 100644 --- a/src/type_traits.h +++ b/src/type_traits.h @@ -47,15 +47,15 @@ namespace etl template struct integral_constant { - static const T value = VALUE; + static const T value = VALUE; - typedef T value_type; + typedef T value_type; typedef integral_constant type; - operator value_type() const - { - return value; - } + operator value_type() const + { + return value; + } }; /// integral_constant specialisations @@ -242,19 +242,16 @@ namespace etl template struct make_signed { typedef T type; }; template <> struct make_signed { typedef signed char type; }; template <> struct make_signed { typedef signed char type; }; -#if defined(ETL_COMPILER_GCC) + template <> struct make_signed { - typedef wchar_t type; + typedef typename etl::conditional::type>::type type; }; -#else - template <> struct make_signed - { - typedef etl::conditional::type>::type>::type type; - }; -#endif + template <> struct make_signed { typedef short type; }; template <> struct make_signed { typedef int type; }; template <> struct make_signed { typedef long type; }; @@ -269,19 +266,16 @@ namespace etl template <> struct make_unsigned { typedef unsigned char type; }; template <> struct make_unsigned { typedef unsigned char type; }; template <> struct make_unsigned { typedef unsigned short type; }; -#if defined(ETL_COMPILER_GCC) && !defined(ETL_PLATFORM_LINUX) + template <> struct make_unsigned { - typedef wchar_t type; + typedef typename etl::conditional::type>::type type; }; -#else - template <> struct make_unsigned - { - typedef etl::conditional::type>::type>::type type; - }; -#endif + template <> struct make_unsigned { typedef unsigned int type; }; template <> struct make_unsigned { typedef unsigned long type; }; template <> struct make_unsigned { typedef unsigned long long type; }; diff --git a/src/u16string.h b/src/u16string.h index 138fa916..95766d2b 100644 --- a/src/u16string.h +++ b/src/u16string.h @@ -182,19 +182,16 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; - //*************************************************************************** - /// Specialisation for u16string. - ///\ingroup hash - //*************************************************************************** + //************************************************************************* + /// Hash function. + //************************************************************************* template <> - struct hash + struct hash { - size_t operator ()(const u16string& s) const + size_t operator()(const etl::iu16string& text) const { - uint8_t* p_begin = &s[0]; - uint8_t* p_end = &s[s.size()]; - - return etl::__private_hash__::generic_hash(p_begin, p_end); + return etl::__private_hash__::generic_hash<>(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); } }; } diff --git a/src/u32string.h b/src/u32string.h index 8280fbba..4493acad 100644 --- a/src/u32string.h +++ b/src/u32string.h @@ -182,19 +182,16 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; - //*************************************************************************** - /// Specialisation for u32string. - ///\ingroup hash - //*************************************************************************** + //************************************************************************* + /// Hash function. + //************************************************************************* template <> - struct hash + struct hash { - size_t operator ()(const u32string& s) const + size_t operator()(const etl::iu32string& text) const { - uint8_t* p_begin = &s[0]; - uint8_t* p_end = &s[s.size()]; - - return etl::__private_hash__::generic_hash(p_begin, p_end); + return etl::__private_hash__::generic_hash<>(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); } }; } diff --git a/src/variant.h b/src/variant.h index 613c3c61..767432a8 100644 --- a/src/variant.h +++ b/src/variant.h @@ -225,6 +225,14 @@ namespace etl public: + //*************************************************************************** + /// Destructor. + //*************************************************************************** + ~variant() + { + destruct_current(); + } + //************************************************************************* //**** Reader types ******************************************************* //************************************************************************* @@ -712,17 +720,21 @@ namespace etl ///\param other The other variant object to copy. //*************************************************************************** variant(const variant& other) - : data(other.data), - type_id(other.type_id) { - } + switch (other.type_id) + { + case 0: new(static_cast(data)) T1(other.get()); break; + case 1: new(static_cast(data)) T2(other.get()); break; + case 2: new(static_cast(data)) T3(other.get()); break; + case 3: new(static_cast(data)) T4(other.get()); break; + case 4: new(static_cast(data)) T5(other.get()); break; + case 5: new(static_cast(data)) T6(other.get()); break; + case 6: new(static_cast(data)) T7(other.get()); break; + case 7: new(static_cast(data)) T8(other.get()); break; + default: break; + } - //*************************************************************************** - /// Destructor. - //*************************************************************************** - ~variant() - { - destruct_current(); + type_id = other.type_id; } //*************************************************************************** @@ -734,18 +746,37 @@ namespace etl { STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); - // Assigning the same type as last time? - if (type_id == Type_Id_Lookup::type_id) + destruct_current(); + new(static_cast(data)) T(value); + type_id = Type_Id_Lookup::type_id; + + return *this; + } + + //*************************************************************************** + /// Assignment operator for variant type. + ///\param other The variant to assign. + //*************************************************************************** + variant& operator =(const variant& other) + { + if (this != &other) { - // Do a simple copy. - *static_cast(data) = value; - } - else - { - // We must destruct the old type, as the new one is different. destruct_current(); - new(static_cast(data)) T(value); - type_id = Type_Id_Lookup::type_id; + + switch (other.type_id) + { + case 0: new(static_cast(data)) T1(other.get()); break; + case 1: new(static_cast(data)) T2(other.get()); break; + case 2: new(static_cast(data)) T3(other.get()); break; + case 3: new(static_cast(data)) T4(other.get()); break; + case 4: new(static_cast(data)) T5(other.get()); break; + case 5: new(static_cast(data)) T6(other.get()); break; + case 6: new(static_cast(data)) T7(other.get()); break; + case 7: new(static_cast(data)) T8(other.get()); break; + default: break; + } + + type_id = other.type_id; } return *this; @@ -923,6 +954,8 @@ namespace etl case 7: { static_cast(data)->~T8(); break; } default: { break; } } + + type_id = UNSUPPORTED_TYPE_ID; } //*************************************************************************** diff --git a/src/wstring.h b/src/wstring.h index 94bebc6b..6633173c 100644 --- a/src/wstring.h +++ b/src/wstring.h @@ -183,19 +183,16 @@ namespace etl value_type buffer[MAX_SIZE + 1]; }; - //*************************************************************************** - /// Specialisation for wstring. - ///\ingroup hash - //*************************************************************************** + //************************************************************************* + /// Hash function. + //************************************************************************* template <> - struct hash + struct hash { - size_t operator ()(const wstring& s) const + size_t operator()(const etl::iwstring& text) const { - uint8_t* p_begin = &s[0]; - uint8_t* p_end = &s[s.size()]; - - return etl::__private_hash__::generic_hash(p_begin, p_end); + return etl::__private_hash__::generic_hash<>(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); } }; } diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 089b005c..46ce13b7 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -259,73 +259,58 @@ namespace ////************************************************************************* TEST_FIXTURE(SetupFixture, test_two_lists_different) { - int i = 0; + std::list compare0; + std::list compare1; + + DataNDC0 data0; + DataNDC1 data1; - { - std::list compare0; - std::list compare1; - { - ItemNDCNode node0("0"); - ItemNDCNode node1("1"); - ItemNDCNode node2("2"); - ItemNDCNode node3("3"); - ItemNDCNode node4("4"); - ItemNDCNode node5("5"); - ItemNDCNode node6("6"); - ItemNDCNode node7("7"); + ItemNDCNode node0("0"); + ItemNDCNode node1("1"); + ItemNDCNode node2("2"); + ItemNDCNode node3("3"); + ItemNDCNode node4("4"); + ItemNDCNode node5("5"); + ItemNDCNode node6("6"); + ItemNDCNode node7("7"); - { - DataNDC0 data0; - DataNDC1 data1; + compare0.push_front(node0); + compare0.push_front(node1); + compare0.push_front(node2); + compare0.push_front(node4); + compare0.push_front(node6); + compare0.push_front(node7); + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node4); + data0.push_front(node6); + data0.push_front(node7); + are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); + CHECK(are_equal); + CHECK_EQUAL(6, data0.size()); + CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + compare1.push_front(node0); + compare1.push_front(node1); + compare1.push_front(node3); + compare1.push_front(node4); + compare1.push_front(node5); + compare1.push_front(node7); - compare0.push_front(node0); - compare0.push_front(node1); - compare0.push_front(node2); - compare0.push_front(node4); - compare0.push_front(node6); - compare0.push_front(node7); + data1.push_front(node0); + data1.push_front(node1); + data1.push_front(node3); + data1.push_front(node4); + data1.push_front(node5); + data1.push_front(node7); - compare1.push_front(node0); - compare1.push_front(node1); - compare1.push_front(node3); - compare1.push_front(node4); - compare1.push_front(node5); - compare1.push_front(node7); - - data0.push_front(node0); - data0.push_front(node1); - data0.push_front(node2); - data0.push_front(node4); - data0.push_front(node6); - data0.push_front(node7); - - data1.push_front(node0); - data1.push_front(node1); - data1.push_front(node3); - data1.push_front(node4); - data1.push_front(node5); - data1.push_front(node7); - - are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data0.size()); - CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); - - are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data1.size()); - CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); - } - - size_t temp = compare0.size(); - } - - size_t temp = compare0.size(); - } - - i = 1; + are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); + CHECK(are_equal); + CHECK_EQUAL(6, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); } //************************************************************************* @@ -346,9 +331,9 @@ namespace std::forward_list::iterator i_compare_data = compare_data.begin(); std::advance(i_compare_data, offset); - compare_data.insert_after(i_compare_data, INSERT_VALUE1); data0.insert_after(i_data, INSERT_VALUE1); - + compare_data.insert_after(i_compare_data, INSERT_VALUE1); + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); @@ -369,16 +354,8 @@ namespace std::forward_list temp(data0.begin(), data0.end()); - compare_data.insert_after(i_compare_data, INSERT_VALUE2); data0.insert_after(i_data, INSERT_VALUE2); - - // Clear the nodes in the temp list. - std::forward_list::iterator itr = temp.begin(); - while (itr != temp.end()) - { - itr->FirstLink::clear(); - ++itr; - } + compare_data.insert_after(i_compare_data, INSERT_VALUE2); temp.assign(data0.begin(), data0.end()); @@ -391,22 +368,6 @@ namespace CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); - - // Clear the nodes in the compare list. - itr = compare_data.begin(); - while (itr != compare_data.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - // Clear the nodes in the temp list. - itr = temp.begin(); - while (itr != temp.end()) - { - itr->FirstLink::clear(); - ++itr; - } } //************************************************************************* @@ -430,13 +391,6 @@ namespace CHECK_EQUAL(test1.size(), data1.size()); CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); - std::forward_list::iterator itr = compare.begin(); - while (itr != compare.end()) - { - itr->FirstLink::clear(); - ++itr; - } - compare.assign(test1.begin(), test1.end()); data0.assign(test1.begin(), test1.end()); @@ -458,22 +412,6 @@ namespace CHECK(are_equal); CHECK_EQUAL(test1.size(), data1.size()); CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); - - // Clear the nodes in the compare list. - itr = compare.begin(); - while (itr != compare.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - // Clear the nodes in the out list. - itr = out.begin(); - while (itr != out.end()) - { - itr->FirstLink::clear(); - ++itr; - } } //************************************************************************* @@ -503,20 +441,10 @@ namespace CHECK_NO_THROW(data0.push_front(node5)); CHECK_NO_THROW(data0.push_front(node6)); - //are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); - //CHECK(are_equal); + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + CHECK(are_equal); CHECK_EQUAL(6, data0.size()); CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); - - // Clear the nodes in the compare list. - std::list::iterator itr = compare_data.begin(); - while (itr != compare_data.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); } //************************************************************************* @@ -569,9 +497,6 @@ namespace CHECK_EQUAL(6, data1.size()); CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); CHECK(!data1.empty()); - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -632,16 +557,6 @@ namespace are_equal = *i_data == *i_compare_data; CHECK(are_equal); - - //std::forward_list::iterator itr = compare_data.begin(); - //while (itr != compare_data.end()) - //{ - // itr->FirstLink::clear(); - // ++itr; - //} - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -678,9 +593,6 @@ namespace CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -711,9 +623,6 @@ namespace CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -852,25 +761,16 @@ namespace DataNDC0 data0(sorted_data.begin(), sorted_data.end()); DataNDC0 data1(sorted_data2.begin(), sorted_data2.end()); - size_t i0 = data0.size(); - size_t i1 = data0.size(); - DataNDC0::iterator idata_destination = data0.begin(); - std::advance(idata_destination, 1); - - size_t t1 = data0.size(); + std::advance(idata_destination, 3); std::forward_list compare0(data0.begin(), data0.end()); std::forward_list compare1(data1.begin(), data1.end()); std::forward_list::iterator icompare_destination = compare0.begin(); - std::advance(icompare_destination, 1); + std::advance(icompare_destination, 3); data0.splice_after(idata_destination, data1); - - size_t t2 = data0.size(); - size_t t3 = data1.size(); - compare0.splice_after(icompare_destination, compare1); are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); @@ -878,23 +778,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare1.begin(); - while (itr != compare1.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -919,15 +802,6 @@ namespace CHECK(are_equal); CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); } //************************************************************************* @@ -967,23 +841,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare1.begin(); - while (itr != compare1.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -1020,15 +877,6 @@ namespace CHECK(are_equal); CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); } //************************************************************************* @@ -1050,23 +898,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare1.begin(); - while (itr != compare1.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data1.clear(); } //************************************************************************* @@ -1088,23 +919,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare2.begin(), compare2.end()), data2.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare2.begin(); - while (itr != compare2.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data2.clear(); } //************************************************************************* @@ -1126,23 +940,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare3.begin(), compare3.end()), data3.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare3.begin(); - while (itr != compare3.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data3.clear(); } //************************************************************************* @@ -1164,23 +961,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare4.begin(), compare4.end()), data4.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare4.begin(); - while (itr != compare4.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data4.clear(); } //************************************************************************* @@ -1208,23 +988,6 @@ namespace CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); - - std::forward_list::iterator itr = compare0.begin(); - while (itr != compare0.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - itr = compare1.begin(); - while (itr != compare1.end()) - { - itr->FirstLink::clear(); - ++itr; - } - - data0.clear(); - data1.clear(); } }; } diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index bb2251cf..9351497b 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -349,7 +349,7 @@ namespace CHECK(data2.SecondFLink::etl_next == &data0); CHECK(data0.SecondFLink::etl_next == nullptr); - // Check checked link. + // Check auto link. etl::link(data0, data1); etl::link(data1, data2); etl::link(data2, data3); @@ -360,11 +360,6 @@ namespace CHECK(data0.ThirdFLinkChecked::etl_next == &data1); CHECK(data1.ThirdFLinkChecked::etl_next == &data3); CHECK(data3.ThirdFLinkChecked::etl_next == nullptr); - - data0.ThirdFLinkChecked::clear(); - data1.ThirdFLinkChecked::clear(); - data2.ThirdFLinkChecked::clear(); - data3.ThirdFLinkChecked::clear(); } //************************************************************************* diff --git a/test/test_variant.cpp b/test/test_variant.cpp index 12967dc7..8583c239 100644 --- a/test/test_variant.cpp +++ b/test/test_variant.cpp @@ -192,6 +192,22 @@ namespace CHECK(variant_2.is_valid()); } + //************************************************************************* + TEST(test_assign_from_variant2) + { + std::string text("Some Text"); + int integer(99); + test_variant_3a variant_1; + test_variant_3a variant_2; + + variant_1 = text; + variant_2 = integer; + variant_2 = variant_1; + + CHECK_EQUAL(text, variant_2.get()); + CHECK(variant_2.is_valid()); + } + //************************************************************************* TEST(test_assignment_incorrect_type_exception) { diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index 87e98819..c671e270 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -70,7 +70,7 @@ Level3 Disabled - WIN32;_DEBUG;_CNSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;ETL_PLATFORM_WINDOWS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions) ../../../unittest-cpp @@ -185,7 +185,6 @@ - @@ -248,7 +247,6 @@ - @@ -359,9 +357,15 @@ - - - + + true + + + true + + + true + diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index e8fbae31..244fdd50 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -522,12 +522,6 @@ ETL\Containers - - ETL\Private - - - ETL\Maths -
From 4974d578e0917b7802b5431c18908cfd3d8e6ae3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:41:08 +0000 Subject: [PATCH 053/168] Removed trailing spaces --- src/type_traits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/type_traits.h b/src/type_traits.h index 776bfda0..71768f09 100644 --- a/src/type_traits.h +++ b/src/type_traits.h @@ -245,9 +245,9 @@ namespace etl template <> struct make_signed { - typedef typename etl::conditional::type>::type type; }; From 618ca469605fac3814392a7e828f84e6457a4b26 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:41:26 +0000 Subject: [PATCH 054/168] Added comments --- src/utility.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/utility.h b/src/utility.h index 1b1c2347..81a27a17 100644 --- a/src/utility.h +++ b/src/utility.h @@ -38,6 +38,9 @@ SOFTWARE. namespace etl { + //*************************************************************************** + /// exchange + //*************************************************************************** template T exchange(T& object, U& new_value) { @@ -46,6 +49,9 @@ namespace etl return old_value; } + //*************************************************************************** + /// exchange (const) + //*************************************************************************** template T exchange(T& object, const U& new_value) { @@ -54,8 +60,11 @@ namespace etl return old_value; } + //*************************************************************************** + /// as_const + //*************************************************************************** template - etl::add_const_t& as_const(T& t) + typename etl::add_const::type& as_const(T& t) { return t; } From 74ee81908af80858c343d2b19842bfa34ea8c557 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:43:03 +0000 Subject: [PATCH 055/168] Added best_fit_int_type Added smallest_int_for_value Added smallest_uint_for_value --- src/smallest.h | 109 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/src/smallest.h b/src/smallest.h index 6419c607..d3a4b947 100644 --- a/src/smallest.h +++ b/src/smallest.h @@ -154,6 +154,48 @@ namespace etl { typedef uint_least64_t type; }; + + //************************************************************************* + // Determine the type to hold the number of bits based on the index. + //************************************************************************* + template + struct best_fit_int_type; + + //************************************************************************* + // Less than or equal to 8 bits. + //************************************************************************* + template <> + struct best_fit_int_type<0> + { + typedef int_least8_t type; + }; + + //************************************************************************* + // 9 to 16 bits. + //************************************************************************* + template <> + struct best_fit_int_type<1> + { + typedef int_least16_t type; + }; + + //************************************************************************* + // 17 to 31 bits. + //************************************************************************* + template <> + struct best_fit_int_type<2> + { + typedef int_least32_t type; + }; + + //************************************************************************* + // Greater than 32 bits. + //************************************************************************* + template <> + struct best_fit_int_type<3> + { + typedef int_least64_t type; + }; } //*************************************************************************** @@ -168,12 +210,77 @@ namespace etl private: // Determines the index of the best unsigned type for the required number of bits. - static const int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + ((NBITS > 16) ? 1 : 0) + ((NBITS > 32) ? 1 : 0); + static const int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + + ((NBITS > 16) ? 1 : 0) + + ((NBITS > 32) ? 1 : 0); public: typedef typename __private_smallest__::best_fit_uint_type::type type; }; + + //*************************************************************************** + /// Template to determine the smallest signed int type that can contain a + /// value with the specified number of bits. + /// Defines 'type' which is the type of the smallest signed integer. + ///\ingroup smallest + //*************************************************************************** + template + struct smallest_int_for_bits + { + private: + + // Determines the index of the best unsigned type for the required number of bits. + static const int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + + ((NBITS > 16) ? 1 : 0) + + ((NBITS > 32) ? 1 : 0); + + public: + + typedef typename __private_smallest__::best_fit_int_type::type type; + }; + + //*************************************************************************** + /// Template to determine the smallest unsigned int type that can contain the + /// specified unsigned value. + /// Defines 'type' which is the type of the smallest unsigned integer. + ///\ingroup smallest + //*************************************************************************** + template + struct smallest_uint_for_value + { + private: + + // Determines the index of the best unsigned type for the required value. + static const int TYPE_INDEX = ((VALUE > UINT8_MAX) ? 1 : 0) + + ((VALUE > UINT16_MAX) ? 1 : 0) + + ((VALUE > UINT32_MAX) ? 1 : 0); + + public: + + typedef typename __private_smallest__::best_fit_uint_type::type type; + }; + + //*************************************************************************** + /// Template to determine the smallest int type that can contain the + /// specified signed value. + /// Defines 'type' which is the type of the smallest signed integer. + ///\ingroup smallest + //*************************************************************************** + template + struct smallest_int_for_value + { + private: + + // Determines the index of the best signed type for the required value. + static const int TYPE_INDEX = (((VALUE > INT8_MAX) || (VALUE < INT8_MIN)) ? 1 : 0) + + (((VALUE > INT16_MAX) || (VALUE < INT16_MIN)) ? 1 : 0) + + (((VALUE > INT32_MAX) || (VALUE < INT32_MIN)) ? 1 : 0); + + public: + + typedef typename __private_smallest__::best_fit_int_type::type type; + }; } #endif From 65b064a8b76f3d6763cf342fe7148746eb8f4010 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:43:30 +0000 Subject: [PATCH 056/168] Modified debug #defines --- src/optional.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/optional.h b/src/optional.h index 3fb1c47c..7795a8c8 100644 --- a/src/optional.h +++ b/src/optional.h @@ -218,7 +218,7 @@ namespace etl //*************************************************************************** T* operator ->() { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -230,7 +230,7 @@ namespace etl //*************************************************************************** const T* operator ->() const { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -242,7 +242,7 @@ namespace etl //*************************************************************************** T& operator *() { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -254,7 +254,7 @@ namespace etl //*************************************************************************** const T& operator *() const { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -274,7 +274,7 @@ namespace etl //*************************************************************************** T& value() { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -286,7 +286,7 @@ namespace etl //*************************************************************************** const T& value() const { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif From b04516d2583c1f7133eb8ecedf0bcacedc129325 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:43:55 +0000 Subject: [PATCH 057/168] Changed uint8_t to value_type --- src/jenkins.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jenkins.h b/src/jenkins.h index 3cffc790..b5e50833 100644 --- a/src/jenkins.h +++ b/src/jenkins.h @@ -65,7 +65,7 @@ namespace etl return 0; } - inline uint32_t add(uint8_t hash, uint8_t value) const + inline uint32_t add(value_type hash, uint8_t value) const { ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); @@ -76,7 +76,7 @@ namespace etl return hash; } - inline uint32_t final(uint8_t hash) + inline uint32_t final(value_type hash) { hash += (hash << 3); hash ^= (hash >> 11); @@ -104,7 +104,7 @@ namespace etl return 0; } - inline uint64_t add(uint8_t hash, uint8_t value) const + inline uint64_t add(value_type hash, uint8_t value) const { ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); @@ -115,7 +115,7 @@ namespace etl return hash; } - inline uint64_t final(uint8_t hash) + inline uint64_t final(value_type hash) { hash += (hash << 3); hash ^= (hash >> 11); From 5a0c830f006eabc0ae1f1e6b562f325718522e25 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:50:57 +0000 Subject: [PATCH 058/168] Modified debug #defines --- src/ivector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ivector.h b/src/ivector.h index 0dfe8491..de7c5cd8 100644 --- a/src/ivector.h +++ b/src/ivector.h @@ -382,7 +382,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(static_cast(count) <= MAX_SIZE, ETL_ERROR(vector_full)); #endif From 77859ad023347741cf40a986da90fdd5339fef52 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:51:19 +0000 Subject: [PATCH 059/168] Modified debug #defines --- src/ipriority_queue.h | 2 +- src/iunordered_map.h | 2 +- src/iunordered_multimap.h | 2 +- src/iunordered_multiset.h | 2 +- src/iunordered_set.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ipriority_queue.h b/src/ipriority_queue.h index 8e58300a..2992acc5 100644 --- a/src/ipriority_queue.h +++ b/src/ipriority_queue.h @@ -167,7 +167,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(priority_queue_iterator)); ETL_ASSERT(static_cast(count) <= max_size(), ETL_ERROR(priority_queue_full)); diff --git a/src/iunordered_map.h b/src/iunordered_map.h index e8447fa6..2c1ff1bb 100644 --- a/src/iunordered_map.h +++ b/src/iunordered_map.h @@ -736,7 +736,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_map_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_map_full)); diff --git a/src/iunordered_multimap.h b/src/iunordered_multimap.h index 2d2ba701..6b62924a 100644 --- a/src/iunordered_multimap.h +++ b/src/iunordered_multimap.h @@ -630,7 +630,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_multimap_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_multimap_full)); diff --git a/src/iunordered_multiset.h b/src/iunordered_multiset.h index 995836b5..29a75fc3 100644 --- a/src/iunordered_multiset.h +++ b/src/iunordered_multiset.h @@ -625,7 +625,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_multiset_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_multiset_full)); diff --git a/src/iunordered_set.h b/src/iunordered_set.h index e11ac9c6..af6c90c8 100644 --- a/src/iunordered_set.h +++ b/src/iunordered_set.h @@ -625,7 +625,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_set_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_set_full)); From 430248fdf1696c559b871b8a1d773bdcbc3519d7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:52:06 +0000 Subject: [PATCH 060/168] Removed support for auto and checked links. --- src/intrusive_forward_list.h | 115 +++------ src/intrusive_links.h | 486 ++++++++++++++++------------------- src/intrusive_list.h | 84 ++---- src/intrusive_queue.h | 52 +--- src/intrusive_stack.h | 41 +-- 5 files changed, 302 insertions(+), 476 deletions(-) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index fa275352..8acd26ed 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -146,13 +146,6 @@ namespace etl typedef const value_type& const_reference; typedef size_t size_type; - enum - { - // The count option is based on the type of link. - COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || - (TLink::OPTION == etl::link_option::CHECKED)) ? etl::count_option::SLOW_COUNT : etl::count_option::FAST_COUNT - }; - typedef intrusive_forward_list list_type; //************************************************************************* @@ -325,7 +318,7 @@ namespace etl const value_type* p_value; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Constructor. @@ -421,11 +414,6 @@ namespace etl //************************************************************************* void clear() { - if (TLink::OPTION == etl::link_option::CHECKED) - { - erase_after(before_begin(), end()); - } - initialise(); } @@ -452,7 +440,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(intrusive_forward_list_iterator_exception)); #endif @@ -546,14 +534,11 @@ namespace etl { iterator next(position); ++next; - ++next; - - remove_link_after(*position.p_value); - - //if (TLink::OPTION == etl::link_option::CHECKED) - //{ - // position.p_value->TLink::clear(); - //} + if (next != end()) + { + ++next; + remove_link_after(*position.p_value); + } return next; } @@ -579,14 +564,8 @@ namespace etl // One less. --current_size; - p_next = p_first->etl_next; // Remember the next link. - - if (TLink::OPTION == etl::link_option::CHECKED) - { - p_first->TLink::clear(); // Clear the link. - } - - p_first = p_next; // Move to the next link. + p_next = p_first->etl_next; // Remember the next link. + p_first = p_next; // Move to the next link. } if (p_next == nullptr) @@ -659,7 +638,7 @@ namespace etl if (is_trivial_list()) { - return; + return; } while (true) @@ -698,32 +677,32 @@ namespace etl // Decide whether the next link of merge comes from left or right. if (left_size == 0) { - // Left is empty. The link must come from right. - i_link = i_right; + // Left is empty. The link must come from right. + i_link = i_right; ++i_right; --right_size; - } + } else if (right_size == 0 || i_right == end()) { - // Right is empty. The link must come from left. - i_link = i_left; + // Right is empty. The link must come from left. + i_link = i_left; ++i_left; --left_size; - } + } else if (compare(*i_left, *i_right)) { - // First link of left is lower or same. The link must come from left. - i_link = i_left; + // First link of left is lower or same. The link must come from left. + i_link = i_left; ++i_left; --left_size; - } + } else { - // First link of right is lower. The link must come from right. - i_link = i_right; + // First link of right is lower. The link must come from right. + i_link = i_right; ++i_right; --right_size; - } + } // Add the next link to the merged head. if (i_head == before_begin()) @@ -814,14 +793,7 @@ namespace etl //************************************************************************* size_t size() const { - if (COUNT_OPTION == etl::count_option::SLOW_COUNT) - { - return std::distance(cbegin(), cend()); - } - else - { - return current_size.get_count(); - } + return current_size; } //************************************************************************* @@ -835,14 +807,10 @@ namespace etl if (!other.empty()) { link_type& first = other.get_head(); - other.initialise(); - if (COUNT_OPTION == etl::count_option::FAST_COUNT) + if (&other != this) { - if (&other != this) - { - current_size += other.size(); - } + current_size += other.size(); } link_type& before = *position.p_value; @@ -857,6 +825,8 @@ namespace etl } etl::link(last, after); + + other.initialise(); } } } @@ -871,13 +841,10 @@ namespace etl etl::unlink(*isource.p_value); etl::link_splice(before, *isource.p_value); - if (COUNT_OPTION == etl::count_option::FAST_COUNT) + if (&other != this) { - if (&other != this) - { - ++current_size; - --other.current_size; - } + ++current_size; + --other.current_size; } } @@ -888,14 +855,11 @@ namespace etl { if (!other.empty()) { - if (COUNT_OPTION == etl::count_option::FAST_COUNT) + if (&other != this) { - if (&other != this) - { - size_t n = std::distance(begin_, end_) - 1; - current_size += n; - other.current_size -= n; - } + size_t n = std::distance(begin_, end_) - 1; + current_size += n; + other.current_size -= n; } link_type* first = begin_.p_value; @@ -979,10 +943,7 @@ namespace etl } } - if (COUNT_OPTION == etl::count_option::FAST_COUNT) - { - current_size += other.size(); - } + current_size += other.size(); other.initialise(); } @@ -992,7 +953,7 @@ namespace etl link_type start_link; ///< The link that acts as the intrusive_forward_list start. - counter_type current_size; ///< Counts the number of elements in the list. + size_t current_size; ///< Counts the number of elements in the list. //************************************************************************* /// Is the intrusive_forward_list a trivial length? @@ -1017,7 +978,9 @@ namespace etl //************************************************************************* void remove_link_after(link_type& link) { - if (link.etl_next != nullptr) + link_type* p_next = link.etl_next; + + if (p_next != nullptr) { etl::unlink_after(link); --current_size; diff --git a/src/intrusive_links.h b/src/intrusive_links.h index 823a6dc2..35a8e345 100644 --- a/src/intrusive_links.h +++ b/src/intrusive_links.h @@ -55,25 +55,6 @@ SOFTWARE. namespace etl { - namespace link_option - { - enum - { - DEFAULT, - AUTO, - CHECKED - }; - } - - namespace count_option - { - enum - { - SLOW_COUNT, - FAST_COUNT - }; - } - //*************************************************************************** /// Link exception. //*************************************************************************** @@ -100,25 +81,17 @@ namespace etl } }; - namespace __private_intrusive_links__ + //*************************************************************************** + /// A forward link. + //*************************************************************************** + template + struct forward_link { - //*************************************************************************** - /// A forward link base. - //*************************************************************************** - template - struct forward_link_base - { enum { ID = ID_, - OPTION = OPTION_ }; - forward_link_base() - { - clear(); - } - void clear() { etl_next = nullptr; @@ -129,48 +102,12 @@ namespace etl return etl_next != nullptr; } - TLink* etl_next; - }; - } - - //*************************************************************************** - /// A forward link. - //*************************************************************************** - template - struct forward_link - : public __private_intrusive_links__::forward_link_base, ID_, OPTION_> - { - }; - - //****************************************************************** - // There is no valid specialisation for auto link - //****************************************************************** - template - struct forward_link; - - //****************************************************************** - // Specialisation for checked unlink option. - // An error will be generated if the links are valid when the object - // is destroyed. - //****************************************************************** - template - struct forward_link - : public __private_intrusive_links__::forward_link_base, ID_, etl::link_option::CHECKED> - { - forward_link() - { - this->clear(); - } - - ~forward_link() - { - assert(this->etl_next == nullptr); - } + forward_link* etl_next; }; // Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink& lhs, TLink& rhs) { lhs.etl_next = &rhs; @@ -178,7 +115,7 @@ namespace etl // Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink& lhs, TLink& rhs) { rhs.etl_next = lhs.etl_next; @@ -187,7 +124,7 @@ namespace etl // Pointer, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink* lhs, TLink* rhs) { if (lhs != nullptr) @@ -198,7 +135,7 @@ namespace etl // Pointer, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink* lhs, TLink* rhs) { if (lhs != nullptr) @@ -214,7 +151,7 @@ namespace etl // Reference, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink& lhs, TLink* rhs) { lhs.etl_next = rhs; @@ -222,7 +159,7 @@ namespace etl // Reference, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink& lhs, TLink* rhs) { if (rhs != nullptr) @@ -235,7 +172,7 @@ namespace etl // Pointer, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink* lhs, TLink& rhs) { if (lhs != nullptr) @@ -246,7 +183,7 @@ namespace etl // Pointer, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink* lhs, TLink& rhs) { if (lhs != nullptr) @@ -258,7 +195,7 @@ namespace etl // Reference, Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink& lhs, TLink& first, TLink& last) { last.etl_next = lhs.etl_next; @@ -267,7 +204,7 @@ namespace etl // Pointer, Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink* lhs, TLink& first, TLink& last) { if (lhs != nullptr) @@ -283,55 +220,35 @@ namespace etl // Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type unlink_after(TLink& node) { if (node.etl_next != nullptr) { TLink* unlinked_node = node.etl_next; node.etl_next = unlinked_node->etl_next; - - if ((int(TLink::OPTION) == etl::link_option::AUTO) || - (int(TLink::OPTION) == etl::link_option::CHECKED)) - { - unlinked_node->clear(); - } } } // Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type unlink_after(TLink& before, TLink& last) { before.etl_next = last.etl_next; - - if ((int(TLink::OPTION) == etl::link_option::AUTO) || - (int(TLink::OPTION) == etl::link_option::CHECKED)) - { - last.clear(); - } } - namespace __private_intrusive_links__ + //*************************************************************************** + /// A bidirectional link. + //*************************************************************************** + template + struct bidirectional_link { - //*************************************************************************** - /// A bidirectional link base. - //*************************************************************************** - template - struct bidirectional_link_base - { enum { - ID = ID_, - OPTION = OPTION_ + ID = ID_, }; - bidirectional_link_base() - { - clear(); - } - void clear() { etl_previous = nullptr; @@ -348,13 +265,11 @@ namespace etl std::swap(etl_previous, etl_next); } - TLink* etl_previous; - TLink* etl_next; + bidirectional_link* etl_previous; + bidirectional_link* etl_next; - protected: - - void base_unlink() - { + void unlink() + { // Connect the previous link with the next. if (etl_previous != nullptr) { @@ -366,78 +281,12 @@ namespace etl { etl_next->etl_previous = etl_previous; } - } - }; - } - - //*************************************************************************** - /// A bidirectional link. - //*************************************************************************** - template - struct bidirectional_link - : public __private_intrusive_links__::bidirectional_link_base, ID_, OPTION_> - { - void unlink() - { - this->base_unlink(); - } - }; - - //****************************************************************** - // Specialisation for auto unlinked option. - // When this link is destroyed it will automatically unlink itself. - //****************************************************************** - template - struct bidirectional_link - : public __private_intrusive_links__::bidirectional_link_base, ID_, etl::link_option::AUTO> - { - bidirectional_link() - { - this->clear(); - } - - ~bidirectional_link() - { - this->base_unlink(); - } - - void unlink() - { - this->base_unlink(); - this->clear(); - } - }; - - //****************************************************************** - // Specialisation for checked unlink option. - // An error will be generated if the links are valid when the object - // is destroyed. - //****************************************************************** - template - struct bidirectional_link - : public __private_intrusive_links__::bidirectional_link_base, ID_, etl::link_option::CHECKED> - { - bidirectional_link() - { - this->clear(); - } - - ~bidirectional_link() - { - assert(this->etl_previous == nullptr); - assert(this->etl_next == nullptr); - } - - void unlink() - { - this->base_unlink(); - this->clear(); } }; // Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink& lhs, TLink& rhs) { lhs.etl_next = &rhs; @@ -446,7 +295,7 @@ namespace etl // Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink& lhs, TLink& rhs) { rhs.etl_next = lhs.etl_next; @@ -462,7 +311,7 @@ namespace etl // Pointer, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink* lhs, TLink* rhs) { if (lhs != nullptr) @@ -478,7 +327,7 @@ namespace etl // Pointer, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink* lhs, TLink* rhs) { if (rhs != nullptr) @@ -504,7 +353,7 @@ namespace etl // Reference, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink& lhs, TLink* rhs) { lhs.etl_next = rhs; @@ -517,7 +366,7 @@ namespace etl // Reference, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink& lhs, TLink* rhs) { if (rhs != nullptr) @@ -536,7 +385,7 @@ namespace etl // Pointer, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link(TLink* lhs, TLink& rhs) { if (lhs != nullptr) @@ -549,7 +398,7 @@ namespace etl // Pointer, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink* lhs, TLink& rhs) { if (lhs != nullptr) @@ -572,7 +421,7 @@ namespace etl // Reference, Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink& lhs, TLink& first, TLink& last) { last.etl_next = lhs.etl_next; @@ -588,7 +437,7 @@ namespace etl // Pointer, Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_splice(TLink* lhs, TLink& first, TLink& last) { if (lhs != nullptr) @@ -615,7 +464,7 @@ namespace etl // Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type unlink(TLink& node) { node.unlink(); @@ -623,7 +472,7 @@ namespace etl // Reference Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type unlink(TLink& first, TLink& last) { if (&first == &last) @@ -641,34 +490,20 @@ namespace etl { first.etl_previous->etl_next = last.etl_next; } - - if ((TLink::OPTION == etl::link_option::AUTO) || - (int(TLink::OPTION) == etl::link_option::CHECKED)) - { - first.etl_previous = nullptr; - last.etl_next = nullptr; - } } } - namespace __private_intrusive_links__ + //*************************************************************************** + /// A binary tree link. + //*************************************************************************** + template + struct tree_link { - //*************************************************************************** - /// A tree link base. - //*************************************************************************** - template - struct tree_link_base - { enum { - ID = ID_, - OPTION = OPTION_ + ID = ID_, }; - tree_link_base() - { - clear(); - } void clear() { etl_parent = nullptr; @@ -681,52 +516,14 @@ namespace etl return (etl_parent != nullptr) || (etl_left != nullptr) || (etl_right != nullptr); } - TLink* etl_parent; - TLink* etl_left; - TLink* etl_right; - }; - } - - //*************************************************************************** - /// A tree link. - //*************************************************************************** - template - struct tree_link - : public __private_intrusive_links__::tree_link_base, ID_, OPTION_> - { - }; - - //****************************************************************** - // There is no valid specialisation for auto link - //****************************************************************** - template - struct tree_link; - - //****************************************************************** - // Specialisation for checked unlink option. - // An error will be generated if the links are valid when the object - // is destroyed. - //****************************************************************** - template - struct tree_link - : public __private_intrusive_links__::tree_link_base, ID_, etl::link_option::CHECKED> - { - tree_link() - { - this->clear(); - } - - ~tree_link() - { - assert(this->etl_parent == nullptr); - assert(this->etl_left == nullptr); - assert(this->etl_right == nullptr); - } + tree_link* etl_parent; + tree_link* etl_left; + tree_link* etl_right; }; // Reference, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_left(TLink& parent, TLink& leaf) { parent.etl_left = &leaf; @@ -734,7 +531,7 @@ namespace etl } template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_right(TLink& parent, TLink& leaf) { parent.etl_right = &leaf; @@ -743,7 +540,7 @@ namespace etl // Pointer, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_left(TLink* parent, TLink* leaf) { if (parent != nullptr) @@ -758,7 +555,7 @@ namespace etl } template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_right(TLink* parent, TLink* leaf) { if (parent != nullptr) @@ -774,7 +571,7 @@ namespace etl // Reference, Pointer template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_left(TLink& parent, TLink* leaf) { parent.etl_left = leaf; @@ -786,7 +583,7 @@ namespace etl } template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_right(TLink& parent, TLink* leaf) { parent.etl_right = leaf; @@ -799,7 +596,7 @@ namespace etl // Pointer, Reference template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_left(TLink* parent, TLink& leaf) { if (parent != nullptr) @@ -811,7 +608,7 @@ namespace etl } template - typename etl::enable_if >::value, void>::type + typename etl::enable_if >::value, void>::type link_right(TLink* parent, TLink& leaf) { if (parent != nullptr) @@ -821,6 +618,175 @@ namespace etl leaf.etl_parent = parent; } + + // Reference, Reference + template + typename etl::enable_if >::value, void>::type + link_rotate_left(TLink& parent, TLink& leaf) + { + parent.etl_right = leaf.etl_left; + + if (parent.etl_right != nullptr) + { + parent.etl_right->etl_parent = &parent; + } + + leaf.etl_parent = parent.etl_parent; + parent.etl_parent = &leaf; + leaf.etl_left = &parent; + } + + template + typename etl::enable_if >::value, void>::type + link_rotate_right(TLink& parent, TLink& leaf) + { + parent.etl_left = leaf.etl_right; + + if (parent.etl_left != nullptr) + { + parent.etl_left->etl_parent = &parent; + } + + leaf.etl_parent = parent.etl_parent; + parent.etl_parent = &leaf; + leaf.etl_right = &parent; + } + + // Pointer, Pointer + template + typename etl::enable_if >::value, void>::type + link_rotate_left(TLink* parent, TLink* leaf) + { + if ((parent != nullptr) && (leaf != nullptr)) + { + link_rotate_left(*parent, *leaf); + } + } + + template + typename etl::enable_if >::value, void>::type + link_rotate_right(TLink* parent, TLink* leaf) + { + if ((parent != nullptr) && (leaf != nullptr)) + { + link_rotate_right(*parent, *leaf); + } + } + + // Reference, Pointer + template + typename etl::enable_if >::value, void>::type + link_rotate_left(TLink& parent, TLink* leaf) + { + if (leaf != nullptr) + { + link_rotate_left(parent, *leaf); + } + } + + template + typename etl::enable_if >::value, void>::type + link_rotate_right(TLink& parent, TLink* leaf) + { + if (leaf != nullptr) + { + link_rotate_right(parent, *leaf); + } + } + + // Pointer, Reference + template + typename etl::enable_if >::value, void>::type + link_rotate_left(TLink* parent, TLink& leaf) + { + if (parent != nullptr) + { + link_rotate_left(*parent, leaf); + } + } + + template + typename etl::enable_if >::value, void>::type + link_rotate_right(TLink* parent, TLink& leaf) + { + if (parent != nullptr) + { + link_rotate_right(*parent, leaf); + } + } + + // Reference, Reference + /// Automatically detects whether a left or right rotate is expected. + template + typename etl::enable_if >::value, void>::type + link_rotate(TLink& parent, TLink& leaf) + { + if (parent.etl_left == &leaf) + { + etl::link_rotate_right(parent, leaf); + } + else + { + etl::link_rotate_left(parent, leaf); + } + } + + // Pointer, Pointer + /// Automatically detects whether a left or right rotate is expected. + template + typename etl::enable_if >::value, void>::type + link_rotate(TLink* parent, TLink* leaf) + { + if ((parent != nullptr) && (leaf != nullptr)) + { + if (parent->etl_left == leaf) + { + etl::link_rotate_right(*parent, *leaf); + } + else + { + etl::link_rotate_left(*parent, *leaf); + } + } + } + + // Reference, Pointer + /// Automatically detects whether a left or right rotate is expected. + template + typename etl::enable_if >::value, void>::type + link_rotate(TLink& parent, TLink* leaf) + { + if (leaf != nullptr) + { + if (parent.etl_left == leaf) + { + etl::link_rotate_right(parent, *leaf); + } + else + { + etl::link_rotate_left(parent, *leaf); + } + } + } + + // Pointer, Reference + /// Automatically detects whether a left or right rotate is expected. + template + typename etl::enable_if >::value, void>::type + link_rotate(TLink* parent, TLink& leaf) + { + if (parent != nullptr) + { + if (parent->etl_left == &leaf) + { + etl::link_rotate_right(*parent, leaf); + } + else + { + etl::link_rotate_left(*parent, leaf); + } + } + } } #undef ETL_FILE diff --git a/src/intrusive_list.h b/src/intrusive_list.h index 2da75417..981a8d80 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -122,13 +122,6 @@ namespace etl { public: - enum - { - // The count option is based on the type of link. - COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || - (TLink::OPTION == etl::link_option::CHECKED)) ? etl::count_option::SLOW_COUNT : etl::count_option::FAST_COUNT - }; - typedef intrusive_list list_type; // Node typedef. @@ -342,7 +335,7 @@ namespace etl const value_type* p_value; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Constructor. @@ -422,11 +415,6 @@ namespace etl //************************************************************************* void clear() { - if (TLink::OPTION == etl::link_option::CHECKED) - { - erase(begin(), end()); - } - initialise(); } @@ -470,7 +458,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(intrusive_list_iterator_exception)); #endif @@ -492,7 +480,7 @@ namespace etl //************************************************************************* /// Pushes a value to the front of the intrusive_list. //************************************************************************* - void push_front(value_type& value) + void push_front(link_type& value) { insert_link(terminal_link, value); } @@ -596,27 +584,7 @@ namespace etl // Join the ends. etl::link(p_first->etl_previous, p_last); - if (COUNT_OPTION == etl::count_option::FAST_COUNT) - { - current_size -= std::distance(first, last); - } - - if ((TLink::OPTION == etl::link_option::AUTO) || - (TLink::OPTION == etl::link_option::CHECKED)) - { - // Clear the ones in between. - link_type* p_next; - - while (p_first != p_last) - { - // One less. - --current_size; - - p_next = p_first->etl_next; // Remember the next link. - p_first->TLink::clear(); // Clear the link. - p_first = p_next; // Move to the next link. - } - } + current_size -= std::distance(first, last); if (p_last == &terminal_link) { @@ -833,14 +801,7 @@ namespace etl //************************************************************************* size_t size() const { - if (COUNT_OPTION == etl::count_option::SLOW_COUNT) - { - return std::distance(cbegin(), cend()); - } - else - { - return current_size.get_count(); - } + return current_size; } //************************************************************************* @@ -856,12 +817,9 @@ namespace etl link_type& first = *other.get_head(); link_type& last = *other.get_tail(); - if (COUNT_OPTION == etl::count_option::FAST_COUNT) + if (&other != this) { - if (&other != this) - { - current_size += other.size(); - } + current_size += other.size(); } link_type& after = *position.p_value; @@ -885,13 +843,10 @@ namespace etl etl::unlink(*isource.p_value); etl::link_splice(before, *isource.p_value); - if (COUNT_OPTION == etl::count_option::FAST_COUNT) + if (&other != this) { - if (&other != this) - { - ++current_size; - --other.current_size; - } + ++current_size; + --other.current_size; } } @@ -902,14 +857,11 @@ namespace etl { if (!other.empty()) { - if (COUNT_OPTION == etl::count_option::FAST_COUNT) + if (&other != this) { - if (&other != this) - { - size_t n = std::distance(begin_, end_); - current_size += n; - other.current_size -= n; - } + size_t n = std::distance(begin_, end_); + current_size += n; + other.current_size -= n; } link_type& first = *begin_.p_value; @@ -978,11 +930,7 @@ namespace etl etl::link_splice(*get_tail(), *other_begin, *other_end->link_type::etl_previous); } - - if (COUNT_OPTION == etl::count_option::FAST_COUNT) - { - current_size += other.size(); - } + current_size += other.size(); other.initialise(); } @@ -993,7 +941,7 @@ namespace etl /// The link that acts as the intrusive_list start & end. link_type terminal_link; - counter_type current_size; ///< Counts the number of elements in the list. + size_t current_size; ///< Counts the number of elements in the list. //************************************************************************* /// Is the intrusive_list a trivial length? diff --git a/src/intrusive_queue.h b/src/intrusive_queue.h index 69a530d9..efd77e41 100644 --- a/src/intrusive_queue.h +++ b/src/intrusive_queue.h @@ -31,8 +31,6 @@ SOFTWARE. #ifndef __ETL_INTRUSIVE_QUEUE__ #define __ETL_INTRUSIVE_QUEUE__ -#error In Development. Do not use. - #include #include "type_traits.h" @@ -95,20 +93,13 @@ namespace etl typedef const value_type& const_reference; typedef size_t size_type; - enum - { - // The count option is based on the type of link. - COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || (TLink::OPTION == etl::link_option::CHECKED)) ? - etl::count_option::SLOW_COUNT : - etl::count_option::FAST_COUNT - }; - //************************************************************************* /// Constructor //************************************************************************* intrusive_queue() : p_front(nullptr), - p_back(nullptr) + p_back(nullptr), + current_size(0) { } @@ -158,15 +149,17 @@ namespace etl //************************************************************************* void push(link_type& value) { + value.clear(); + if (p_back != nullptr) { - etl::link(p_front, value); + etl::link(p_back, value); } else - { + { p_front = &value; } - + p_back = &value; ++current_size; @@ -182,13 +175,13 @@ namespace etl ETL_ASSERT(!empty(), ETL_ERROR(intrusive_queue_empty)); #endif link_type* p_next = p_front->etl_next; - p_front->clear(); + p_front = p_next; // Now empty? if (p_front == nullptr) { - p_back == nullptr; + p_back = nullptr; } --current_size; @@ -203,6 +196,7 @@ namespace etl { pop(); } + current_size = 0; } @@ -211,7 +205,7 @@ namespace etl //************************************************************************* bool empty() const { - return p_front == nullptr; + return current_size == 0; } //************************************************************************* @@ -219,27 +213,7 @@ namespace etl //************************************************************************* size_t size() const { - if (COUNT_OPTION == etl::count_option::SLOW_COUNT) - { - size_t count = 0; - - if (p_front != nullptr) - { - link_type* p_link = p_front; - - while (p_link != nullptr) - { - ++count; - p_link = p_link->etl_next; - } - } - - return count; - } - else - { - return current_size.get_count(); - } + return current_size; } private: @@ -251,7 +225,7 @@ namespace etl link_type* p_front; // The current front of the queue. link_type* p_back; // The current back of the queue. - etl::counter_type current_size; ///< Counts the number of elements in the list. + size_t current_size; ///< Counts the number of elements in the list. }; } diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h index 787f2dba..ffa61e72 100644 --- a/src/intrusive_stack.h +++ b/src/intrusive_stack.h @@ -93,19 +93,12 @@ namespace etl typedef const value_type& const_reference; typedef size_t size_type; - enum - { - // The count option is based on the type of link. - COUNT_OPTION = ((TLink::OPTION == etl::link_option::AUTO) || (TLink::OPTION == etl::link_option::CHECKED)) ? - etl::count_option::SLOW_COUNT : - etl::count_option::FAST_COUNT - }; - //************************************************************************* /// Constructor //************************************************************************* intrusive_stack() - : p_top(nullptr) + : p_top(nullptr), + current_size(0) { } @@ -134,6 +127,8 @@ namespace etl //************************************************************************* void push(link_type& value) { + value.clear(); + if (p_top != nullptr) { etl::link(value, p_top); @@ -154,7 +149,6 @@ namespace etl ETL_ASSERT(!empty(), ETL_ERROR(intrusive_stack_empty)); #endif link_type* p_next = p_top->etl_next; - p_top->clear(); p_top = p_next; --current_size; } @@ -168,6 +162,7 @@ namespace etl { pop(); } + current_size = 0; } @@ -176,7 +171,7 @@ namespace etl //************************************************************************* bool empty() const { - return p_top == nullptr; + return current_size == 0; } //************************************************************************* @@ -184,27 +179,7 @@ namespace etl //************************************************************************* size_t size() const { - if (COUNT_OPTION == etl::count_option::SLOW_COUNT) - { - size_t count = 0; - - if (p_top != nullptr) - { - link_type* p_link = p_top; - - while (p_link != nullptr) - { - ++count; - p_link = p_link->etl_next; - } - } - - return count; - } - else - { - return current_size.get_count(); - } + return current_size; } private: @@ -215,7 +190,7 @@ namespace etl link_type* p_top; // The current top of the stack. - etl::counter_type current_size; ///< Counts the number of elements in the list. + size_t current_size; ///< Counts the number of elements in the list. }; } From 4b9e9cd651231a713a03212d75a2c684d8b3b036 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:52:31 +0000 Subject: [PATCH 061/168] Fixed GCC warnings --- src/imultimap.h | 4 ++-- src/imultiset.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/imultimap.h b/src/imultimap.h index f88fd25b..5291177c 100644 --- a/src/imultimap.h +++ b/src/imultimap.h @@ -675,7 +675,7 @@ namespace etl ///\param position The position that would precede the value to insert. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const value_type& value) + iterator insert(iterator /*position*/, const value_type& value) { // Ignore position provided and just do a normal insert return insert(value); @@ -687,7 +687,7 @@ namespace etl ///\param position The position that would precede the value to insert. ///\param value The value to insert. //********************************************************************* - iterator insert(const_iterator position, const value_type& value) + iterator insert(const_iterator /*position*/, const value_type& value) { // Ignore position provided and just do a normal insert return insert(value); diff --git a/src/imultiset.h b/src/imultiset.h index 9f36182c..c0c96840 100644 --- a/src/imultiset.h +++ b/src/imultiset.h @@ -656,7 +656,7 @@ namespace etl ///\param position The position that would precede the value to insert. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const value_type& value) + iterator insert(iterator /*position*/, const value_type& value) { // Ignore position provided and just do a normal insert return insert(value); @@ -668,7 +668,7 @@ namespace etl ///\param position The position that would precede the value to insert. ///\param value The value to insert. //********************************************************************* - iterator insert(const_iterator position, const value_type& value) + iterator insert(const_iterator /*position*/, const value_type& value) { // Ignore position provided and just do a normal insert return insert(value); From 0906d2927896fb4734fa1d217bb92655bbd8d89e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:52:50 +0000 Subject: [PATCH 062/168] Modified debug #defines --- src/iflat_map.h | 2 +- src/iflat_multimap.h | 2 +- src/iflat_multiset.h | 2 +- src/iflat_set.h | 2 +- src/iforward_list.h | 6 +++--- src/ilist.h | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/iflat_map.h b/src/iflat_map.h index 399897f2..1e50ea1c 100644 --- a/src/iflat_map.h +++ b/src/iflat_map.h @@ -271,7 +271,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_map_full)); #endif diff --git a/src/iflat_multimap.h b/src/iflat_multimap.h index e5fa864e..ed4e75ed 100644 --- a/src/iflat_multimap.h +++ b/src/iflat_multimap.h @@ -222,7 +222,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_multimap_full)); #endif diff --git a/src/iflat_multiset.h b/src/iflat_multiset.h index 135511c0..e06995a4 100644 --- a/src/iflat_multiset.h +++ b/src/iflat_multiset.h @@ -198,7 +198,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_multiset_full)); #endif diff --git a/src/iflat_set.h b/src/iflat_set.h index 55ca571a..be975c69 100644 --- a/src/iflat_set.h +++ b/src/iflat_set.h @@ -198,7 +198,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_set_full)); #endif diff --git a/src/iforward_list.h b/src/iforward_list.h index b663ad8e..e4a7dfb5 100644 --- a/src/iforward_list.h +++ b/src/iforward_list.h @@ -354,7 +354,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(forward_list_iterator)); #endif @@ -512,7 +512,7 @@ namespace etl template void insert_after(iterator position, TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT((count + current_size) <= MAX_SIZE, ETL_ERROR(forward_list_full)); #endif @@ -609,7 +609,7 @@ namespace etl return; // Can't more to before yourself! } -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) // Check that we are not doing an illegal move! for (const_iterator item = first_before; item != last; ++item) { diff --git a/src/ilist.h b/src/ilist.h index 50795bf2..514ffc7a 100644 --- a/src/ilist.h +++ b/src/ilist.h @@ -452,7 +452,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(list_iterator)); ETL_ASSERT(size_t(count) <= MAX_SIZE, ETL_ERROR(list_full)); @@ -475,7 +475,7 @@ namespace etl //************************************************************************* void assign(size_t n, parameter_t value) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(list_full)); #endif @@ -1062,7 +1062,7 @@ namespace etl return; // Can't more to before yourself! } -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) // Check that we are not doing an illegal move! for (const_iterator item = first; item != last; ++item) { From 6e5ef7b2300fa6942d2686e80797a2ddd8836586 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:53:06 +0000 Subject: [PATCH 063/168] Fixed GCC warnings --- src/ideque.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ideque.h b/src/ideque.h index 6c235183..9afcc3bb 100644 --- a/src/ideque.h +++ b/src/ideque.h @@ -295,7 +295,7 @@ namespace etl //*************************************************** const_iterator& operator ++() { - index = (index == p_deque->BUFFER_SIZE - 1) ? 0 : index + 1; + index = (static_cast(index) == p_deque->BUFFER_SIZE - 1) ? 0 : index + 1; return *this; } @@ -331,7 +331,7 @@ namespace etl if (offset > 0) { index -= offset; - index = (index < 0) ? index + p_deque->BUFFER_SIZE : index; + index = (index < 0) ? static_cast(index) + p_deque->BUFFER_SIZE : index; } else if (offset < 0) { From 388f1c2d436f67fe928603bd38bd7b91bac4ed95 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:53:52 +0000 Subject: [PATCH 064/168] Fixed GCC warnings --- src/container.h | 2 +- src/fixed_iterator.h | 8 ++++---- src/private/set_base.h | 18 +++++++++--------- src/private/string_base.h | 5 ++++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/container.h b/src/container.h index d03cddc4..1cf87391 100644 --- a/src/container.h +++ b/src/container.h @@ -277,7 +277,7 @@ namespace etl ///\ingroup container ///************************************************************************** template - size_t size(TValue(&data)[ARRAY_SIZE]) + size_t size(TValue(&)[ARRAY_SIZE]) { return ARRAY_SIZE; } diff --git a/src/fixed_iterator.h b/src/fixed_iterator.h index 1b9d1370..8357f30a 100644 --- a/src/fixed_iterator.h +++ b/src/fixed_iterator.h @@ -137,7 +137,7 @@ namespace etl //*************************************************************************** /// += operator. //*************************************************************************** - fixed_iterator& operator +=(typename std::iterator_traits::difference_type offset) + fixed_iterator& operator +=(typename std::iterator_traits::difference_type /*offset*/) { return *this; } @@ -145,7 +145,7 @@ namespace etl //*************************************************************************** /// -= operator. //*************************************************************************** - fixed_iterator& operator -=(typename std::iterator_traits::difference_type offset) + fixed_iterator& operator -=(typename std::iterator_traits::difference_type /*offset*/) { return *this; } @@ -179,7 +179,7 @@ namespace etl //***************************************************************************** template etl::fixed_iterator& operator +(etl::fixed_iterator& lhs, - typename std::iterator_traits::difference_type rhs) + typename std::iterator_traits::difference_type /*rhs*/) { return lhs; } @@ -189,7 +189,7 @@ etl::fixed_iterator& operator +(etl::fixed_iterator& lhs, //***************************************************************************** template etl::fixed_iterator& operator -(etl::fixed_iterator& lhs, - typename std::iterator_traits::difference_type rhs) + typename std::iterator_traits::difference_type /*rhs*/) { return lhs; } diff --git a/src/private/set_base.h b/src/private/set_base.h index b0b85b45..a4eab8c2 100644 --- a/src/private/set_base.h +++ b/src/private/set_base.h @@ -260,12 +260,12 @@ namespace etl while (weight_node) { // Keep going until we reach a terminal node (dir == kNeither) - if (kNeither != weight_node->dir) + if (uint_least8_t(kNeither) != weight_node->dir) { // Does this insert balance the previous weight factor value? if (weight_node->weight == 1 - weight_node->dir) { - weight_node->weight = kNeither; + weight_node->weight = uint_least8_t(kNeither); } else { @@ -283,14 +283,14 @@ namespace etl } // while(weight_node) // Step 2: Update weight for critical_node or rotate tree to balance node - if (kNeither == critical_node->weight) + if (uint_least8_t(kNeither) == critical_node->weight) { critical_node->weight = critical_node->dir; } // If direction is different than weight, then it will now be balanced else if (critical_node->dir != critical_node->weight) { - critical_node->weight = kNeither; + critical_node->weight = uint_least8_t(kNeither); } // Rotate is required to balance the tree at the critical node else @@ -368,11 +368,11 @@ namespace etl // New root now becomes parent of current position new_root->children[1 - dir] = position; // Clear weight factor from current position - position->weight = kNeither; + position->weight = uint_least8_t(kNeither); // Newly detached right now becomes current position position = new_root; // Clear weight factor from new root - position->weight = kNeither; + position->weight = uint_least8_t(kNeither); } //************************************************************************* @@ -395,7 +395,7 @@ namespace etl // Capture new root (either E or D depending on dir) Node* new_root = position->children[dir]->children[1 - dir]; // Set weight factor for B or C based on F or G existing and being a different than dir - position->children[dir]->weight = third != kNeither && third != dir ? dir : kNeither; + position->children[dir]->weight = third != uint_least8_t(kNeither) && third != dir ? dir : uint_least8_t(kNeither); // Detach new root from its tree (replace with new roots child) position->children[dir]->children[1 - dir] = @@ -403,7 +403,7 @@ namespace etl // Attach current left tree to new root new_root->children[dir] = position->children[dir]; // Set weight factor for A based on F or G - position->weight = third != kNeither && third == dir ? 1 - dir : kNeither; + position->weight = third != uint_least8_t(kNeither) && third == dir ? 1 - dir : uint_least8_t(kNeither); // Move new root's right tree to current roots left tree position->children[dir] = new_root->children[1 - dir]; @@ -412,7 +412,7 @@ namespace etl // Replace current position with new root position = new_root; // Clear weight factor for new current position - position->weight = kNeither; + position->weight = uint_least8_t(kNeither); } diff --git a/src/private/string_base.h b/src/private/string_base.h index 7807448f..98f15131 100644 --- a/src/private/string_base.h +++ b/src/private/string_base.h @@ -116,7 +116,10 @@ namespace etl typedef size_t size_type; - static const size_t npos = etl::integral_limits::max; + enum + { + npos = etl::integral_limits::max + }; //************************************************************************* /// Gets the current size of the string. From 3c5f8260c2730eac04bde8d875967a6631a34580 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:54:01 +0000 Subject: [PATCH 065/168] Modified debug #defines --- src/ibasic_string.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ibasic_string.h b/src/ibasic_string.h index 85bd6d9c..a6f3616d 100644 --- a/src/ibasic_string.h +++ b/src/ibasic_string.h @@ -400,7 +400,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(string_iterator)); #endif @@ -893,7 +893,7 @@ namespace etl //********************************************************************* size_t find(const_pointer s, size_t pos = 0) const { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) if ((pos + etl::strlen(s)) > size()) { return npos; @@ -920,7 +920,7 @@ namespace etl //********************************************************************* size_t find(const_pointer s, size_t pos, size_t n) const { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) if ((pos + etl::strlen(s) - n) > size()) { return npos; From 3845ad41d400c4bec0af1a323b1ee7c6832b3603 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:54:33 +0000 Subject: [PATCH 066/168] Modified debug #defines --- src/private/pvoidvector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/private/pvoidvector.h b/src/private/pvoidvector.h index 010b47c0..f44b4bed 100644 --- a/src/private/pvoidvector.h +++ b/src/private/pvoidvector.h @@ -325,7 +325,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#ifdef _DEBUG +#if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(static_cast(count) <= MAX_SIZE, ETL_ERROR(vector_full)); #endif From 7634b5639b80770b69dedf86460ff79c1bb36ab4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:54:58 +0000 Subject: [PATCH 067/168] Added as_const tests --- test/test_utility.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/test_utility.cpp b/test/test_utility.cpp index fad3bc26..046b12dd 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -30,6 +30,22 @@ SOFTWARE. #include "../src/utility.h" +namespace +{ + bool nonConstCalled; + bool constCalled; + + void TestText(std::string&) + { + nonConstCalled = true; + } + + void TestText(const std::string&) + { + constCalled = true; + } +} + namespace { SUITE(test_utility) @@ -57,5 +73,27 @@ namespace CHECK_EQUAL(2, b); CHECK_EQUAL(1, c); } + + //========================================================================= + TEST(test_as_const) + { + std::string text = "Hello World!"; + + nonConstCalled = false; + constCalled = false; + + TestText(text); + + CHECK(nonConstCalled); + CHECK(!constCalled); + + nonConstCalled = false; + constCalled = false; + + TestText(etl::as_const(text)); + + CHECK(!nonConstCalled); + CHECK(constCalled); + } }; } From 511c5b88a9c6d1d1196516c43592b92796bdd7e9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:56:05 +0000 Subject: [PATCH 068/168] Changed "string.h" header to "cstring.h" --- test/test_string_char.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index a715f42c..712a9efc 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -32,7 +32,7 @@ SOFTWARE. #include #include -#include "../src/string.h" +#include "../src/cstring.h" #undef min @@ -969,8 +969,8 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0); - text.append(append, 0); + compare_text.append(insert_text, 0, std::string::npos); + text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2067,7 +2067,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(etl::string<50>::npos, position2); etl::string<50> pin(STR("pin")); position2 = haystack.find(pin); From 5cab8418339843c125109a68764552f781b50adf Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:56:26 +0000 Subject: [PATCH 069/168] Added tests for new classes --- test/test_smallest.cpp | 149 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 13 deletions(-) diff --git a/test/test_smallest.cpp b/test/test_smallest.cpp index 26beb42c..232119b3 100644 --- a/test/test_smallest.cpp +++ b/test/test_smallest.cpp @@ -79,44 +79,167 @@ namespace } //************************************************************************* - TEST(test_smallest_size_for_bits) + TEST(test_smallest_uint_for_bits) { bool type; - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; CHECK(type); - type = std::is_same::type>::value; + type = std::is_same::type>::value; + CHECK(type); + } + + //************************************************************************* + TEST(test_smallest_int_for_bits) + { + bool type; + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + } + + //************************************************************************* + TEST(test_smallest_uint_for_value) + { + bool type; + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + } + + //************************************************************************* + TEST(test_smallest_int_for_value) + { + bool type; + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; + CHECK(type); + + type = std::is_same::type>::value; CHECK(type); } }; From b038e375cd2a8578eb766b7ae5ab7ce506976a09 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:56:53 +0000 Subject: [PATCH 070/168] Fixed GCC warnings --- test/test_priority_queue.cpp | 4 ++-- test/test_string_u16.cpp | 4 ++-- test/test_string_u32.cpp | 4 ++-- test/test_string_wchar_t.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_priority_queue.cpp b/test/test_priority_queue.cpp index a911fa1f..f6ca449f 100644 --- a/test/test_priority_queue.cpp +++ b/test/test_priority_queue.cpp @@ -97,7 +97,7 @@ namespace priority_queue.push(2); priority_queue.push(3); - CHECK_EQUAL(3, priority_queue.size()); + CHECK_EQUAL(3U, priority_queue.size()); } //************************************************************************* @@ -108,7 +108,7 @@ namespace priority_queue.push(1); priority_queue.push(2); priority_queue.clear(); - CHECK_EQUAL(0, priority_queue.size()); + CHECK_EQUAL(0U, priority_queue.size()); } //************************************************************************* diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 07bed379..0fc03b28 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -969,8 +969,8 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0); - text.append(append, 0); + compare_text.append(insert_text, 0, std::u16string::npos); + text.append(append, 0, etl::iu16string::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index abd21bfc..366ee2aa 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -969,8 +969,8 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0); - text.append(append, 0); + compare_text.append(insert_text, 0, std::u32string::npos); + text.append(append, 0, etl::iu32string::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index bd32385b..e60ab97b 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -969,8 +969,8 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0); - text.append(append, 0); + compare_text.append(insert_text, 0, std::wstring::npos); + text.append(append, 0, etl::iwstring::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); From dd60c3aa7c539ac856a50965bb73c1538ccd6447 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:57:04 +0000 Subject: [PATCH 071/168] Fixed GCC warnings --- test/test_unordered_map.cpp | 6 +++--- test/test_unordered_multimap.cpp | 10 +++++----- test/test_unordered_multiset.cpp | 10 +++++----- test/test_unordered_set.cpp | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 3d19f4f5..9f33b8d7 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -431,7 +431,7 @@ namespace size_t count = data.erase(K5); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); DataNDC::iterator idata = data.find(K5); CHECK(idata == data.end()); @@ -511,10 +511,10 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); size_t count = data.count(K5); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); count = data.count(K12); - CHECK_EQUAL(0, count); + CHECK_EQUAL(0U, count); } //************************************************************************* diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index d5ca8aa6..fe595ad4 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -369,14 +369,14 @@ namespace size_t count = data.erase(K10); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); DataNDC::iterator idata = data.find(K10); CHECK(idata == data.end()); count = data.erase(K11); - CHECK_EQUAL(3, count); + CHECK_EQUAL(3U, count); idata = data.find(K11); CHECK(idata == data.end()); @@ -456,13 +456,13 @@ namespace DataNDC data(equal_data.begin(), equal_data.end()); size_t count = data.count(K10); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); count = data.count(K11); - CHECK_EQUAL(3, count); + CHECK_EQUAL(3U, count); count = data.count(K1); - CHECK_EQUAL(0, count); + CHECK_EQUAL(0U, count); } //************************************************************************* diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 0edf7a86..1800db01 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -294,14 +294,14 @@ namespace size_t count = data.erase(N0); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); DataNDC::iterator idata = data.find(N0); CHECK(idata == data.end()); count = data.erase(N1); - CHECK_EQUAL(3, count); + CHECK_EQUAL(3U, count); idata = data.find(N1); CHECK(idata == data.end()); @@ -386,13 +386,13 @@ namespace DataNDC data(equal_data.begin(), equal_data.end()); size_t count = data.count(N0); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); count = data.count(N1); - CHECK_EQUAL(3, count); + CHECK_EQUAL(3U, count); count = data.count(N10); - CHECK_EQUAL(0, count); + CHECK_EQUAL(0U, count); } //************************************************************************* diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 1436c177..919a06f7 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -281,7 +281,7 @@ namespace size_t count = data.erase(N5); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); DataNDC::iterator idata = data.find(N5); CHECK(idata == data.end()); @@ -366,10 +366,10 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); size_t count = data.count(N5); - CHECK_EQUAL(1, count); + CHECK_EQUAL(1U, count); count = data.count(N12); - CHECK_EQUAL(0, count); + CHECK_EQUAL(0U, count); } //************************************************************************* From 62d03d7e104ea143c29c8331e2ec107f89943cf6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:57:47 +0000 Subject: [PATCH 072/168] Changed tests for wchar_t. --- test/test_type_traits.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 207fc468..db654ad6 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -425,7 +425,7 @@ namespace CHECK((std::is_same::type, std::make_signed::type>::value)); CHECK((std::is_same::type, std::make_signed::type>::value)); CHECK((std::is_same::type, std::make_signed::type>::value)); - CHECK((std::is_same::type, std::make_signed::type>::value)); + CHECK(std::is_signed::type>::value && (sizeof(wchar_t) == sizeof(etl::make_signed::type))); CHECK((std::is_same::type, std::make_signed::type>::value)); CHECK((std::is_same::type, std::make_signed::type>::value)); CHECK((std::is_same::type, std::make_signed::type>::value)); @@ -450,7 +450,7 @@ namespace CHECK((std::is_same::type, std::make_unsigned::type>::value)); CHECK((std::is_same::type, std::make_unsigned::type>::value)); CHECK((std::is_same::type, std::make_unsigned::type>::value)); - CHECK((std::is_same::type, std::make_unsigned::type>::value)); + CHECK(std::is_unsigned::type>::value && (sizeof(wchar_t) == sizeof(etl::make_unsigned::type))); CHECK((std::is_same::type, std::make_unsigned::type>::value)); CHECK((std::is_same::type, std::make_unsigned::type>::value)); CHECK((std::is_same::type, std::make_unsigned::type>::value)); From 1aa2592691863b9b89185ca9253403f81cff11fb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:57:57 +0000 Subject: [PATCH 073/168] Fixed GCC warnings --- test/test_type_def.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_type_def.cpp b/test/test_type_def.cpp index c921293a..9d851909 100644 --- a/test/test_type_def.cpp +++ b/test/test_type_def.cpp @@ -116,7 +116,7 @@ namespace CHECK_EQUAL(i %= 23, t %= 23); t = type_t(0x1234); - CHECK_EQUAL(0x1234, t); + CHECK_EQUAL(0x1234U, t); } //========================================================================= From fbf7eaf085ba8df97b901090f073a94d52098757 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 12:58:09 +0000 Subject: [PATCH 074/168] Fixed GCC warnings --- test/test_pool.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_pool.cpp b/test/test_pool.cpp index afbbbff2..165c110e 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -36,6 +36,11 @@ SOFTWARE. #include "../src/pool.h" +#if defined(ETL_COMPILER_GCC) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif + typedef TestDataDC Test_Data; typedef TestDataNDC Test_Data2; @@ -145,7 +150,7 @@ namespace TEST(test_available) { etl::pool pool; - CHECK_EQUAL(4, pool.available()); + CHECK_EQUAL(4U, pool.available()); Test_Data* p; @@ -385,3 +390,7 @@ namespace } }; } + +#if defined(ETL_COMPILER_GCC) + #pragma GCC diagnostic pop +#endif From 0fb7a0e458547fc2d22d1174caf048532f69bc41 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:11:29 +0000 Subject: [PATCH 075/168] Fixed GCC warnings --- test/test_list.cpp | 4 +- test/test_maths.cpp | 120 ++++++++++++++++++++--------------------- test/test_observer.cpp | 12 ++--- test/test_optional.cpp | 2 +- 4 files changed, 69 insertions(+), 69 deletions(-) diff --git a/test/test_list.cpp b/test/test_list.cpp index 217e5ddc..77ca4200 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -270,7 +270,7 @@ namespace DataNDC data(sorted_data.begin(), sorted_data.end()); data.clear(); - CHECK_EQUAL(data.size(), 0); + CHECK_EQUAL(0U, data.size()); } //************************************************************************* @@ -678,7 +678,7 @@ namespace // Check that it is still in a valid state. data.push_back(ItemNDC("1")); CHECK(!data.empty()); - CHECK_EQUAL(1, data.size()); + CHECK_EQUAL(1U, data.size()); } //************************************************************************* diff --git a/test/test_maths.cpp b/test/test_maths.cpp index 2a4ac523..47f98fc3 100644 --- a/test/test_maths.cpp +++ b/test/test_maths.cpp @@ -281,71 +281,71 @@ namespace //************************************************************************* TEST(test_fibbonacci) { - CHECK_EQUAL(0, (size_t)etl::fibonacci<0>::value); - CHECK_EQUAL(1, (size_t)etl::fibonacci<1>::value); - CHECK_EQUAL(1, (size_t)etl::fibonacci<2>::value); - CHECK_EQUAL(2, (size_t)etl::fibonacci<3>::value); - CHECK_EQUAL(3, (size_t)etl::fibonacci<4>::value); - CHECK_EQUAL(5, (size_t)etl::fibonacci<5>::value); - CHECK_EQUAL(8, (size_t)etl::fibonacci<6>::value); - CHECK_EQUAL(13, (size_t)etl::fibonacci<7>::value); - CHECK_EQUAL(21, (size_t)etl::fibonacci<8>::value); - CHECK_EQUAL(34, (size_t)etl::fibonacci<9>::value); - CHECK_EQUAL(55, (size_t)etl::fibonacci<10>::value); - CHECK_EQUAL(89, (size_t)etl::fibonacci<11>::value); - CHECK_EQUAL(144, (size_t)etl::fibonacci<12>::value); - CHECK_EQUAL(233, (size_t)etl::fibonacci<13>::value); - CHECK_EQUAL(377, (size_t)etl::fibonacci<14>::value); - CHECK_EQUAL(610, (size_t)etl::fibonacci<15>::value); - CHECK_EQUAL(987, (size_t)etl::fibonacci<16>::value); - CHECK_EQUAL(1597, (size_t)etl::fibonacci<17>::value); - CHECK_EQUAL(2584, (size_t)etl::fibonacci<18>::value); - CHECK_EQUAL(4181, (size_t)etl::fibonacci<19>::value); - CHECK_EQUAL(6765, (size_t)etl::fibonacci<20>::value); - CHECK_EQUAL(10946, (size_t)etl::fibonacci<21>::value); - CHECK_EQUAL(17711, (size_t)etl::fibonacci<22>::value); - CHECK_EQUAL(28657, (size_t)etl::fibonacci<23>::value); - CHECK_EQUAL(46368, (size_t)etl::fibonacci<24>::value); - CHECK_EQUAL(75025, (size_t)etl::fibonacci<25>::value); - CHECK_EQUAL(121393, (size_t)etl::fibonacci<26>::value); - CHECK_EQUAL(196418, (size_t)etl::fibonacci<27>::value); - CHECK_EQUAL(317811, (size_t)etl::fibonacci<28>::value); - CHECK_EQUAL(514229, (size_t)etl::fibonacci<29>::value); - CHECK_EQUAL(832040, (size_t)etl::fibonacci<30>::value); - CHECK_EQUAL(1346269, (size_t)etl::fibonacci<31>::value); - CHECK_EQUAL(2178309, (size_t)etl::fibonacci<32>::value); - CHECK_EQUAL(3524578, (size_t)etl::fibonacci<33>::value); - CHECK_EQUAL(5702887, (size_t)etl::fibonacci<34>::value); - CHECK_EQUAL(9227465, (size_t)etl::fibonacci<35>::value); - CHECK_EQUAL(14930352, (size_t)etl::fibonacci<36>::value); - CHECK_EQUAL(24157817, (size_t)etl::fibonacci<37>::value); - CHECK_EQUAL(39088169, (size_t)etl::fibonacci<38>::value); - CHECK_EQUAL(63245986, (size_t)etl::fibonacci<39>::value); - CHECK_EQUAL(102334155, (size_t)etl::fibonacci<40>::value); - CHECK_EQUAL(165580141, (size_t)etl::fibonacci<41>::value); - CHECK_EQUAL(267914296, (size_t)etl::fibonacci<42>::value); - CHECK_EQUAL(433494437, (size_t)etl::fibonacci<43>::value); - CHECK_EQUAL(701408733, (size_t)etl::fibonacci<44>::value); - CHECK_EQUAL(1134903170, (size_t)etl::fibonacci<45>::value); - CHECK_EQUAL(1836311903, (size_t)etl::fibonacci<46>::value); + CHECK_EQUAL(0U, (size_t)etl::fibonacci<0>::value); + CHECK_EQUAL(1U, (size_t)etl::fibonacci<1>::value); + CHECK_EQUAL(1U, (size_t)etl::fibonacci<2>::value); + CHECK_EQUAL(2U, (size_t)etl::fibonacci<3>::value); + CHECK_EQUAL(3U, (size_t)etl::fibonacci<4>::value); + CHECK_EQUAL(5U, (size_t)etl::fibonacci<5>::value); + CHECK_EQUAL(8U, (size_t)etl::fibonacci<6>::value); + CHECK_EQUAL(13U, (size_t)etl::fibonacci<7>::value); + CHECK_EQUAL(21U, (size_t)etl::fibonacci<8>::value); + CHECK_EQUAL(34U, (size_t)etl::fibonacci<9>::value); + CHECK_EQUAL(55U, (size_t)etl::fibonacci<10>::value); + CHECK_EQUAL(89U, (size_t)etl::fibonacci<11>::value); + CHECK_EQUAL(144U, (size_t)etl::fibonacci<12>::value); + CHECK_EQUAL(233U, (size_t)etl::fibonacci<13>::value); + CHECK_EQUAL(377U, (size_t)etl::fibonacci<14>::value); + CHECK_EQUAL(610U, (size_t)etl::fibonacci<15>::value); + CHECK_EQUAL(987U, (size_t)etl::fibonacci<16>::value); + CHECK_EQUAL(1597U, (size_t)etl::fibonacci<17>::value); + CHECK_EQUAL(2584U, (size_t)etl::fibonacci<18>::value); + CHECK_EQUAL(4181U, (size_t)etl::fibonacci<19>::value); + CHECK_EQUAL(6765U, (size_t)etl::fibonacci<20>::value); + CHECK_EQUAL(10946U, (size_t)etl::fibonacci<21>::value); + CHECK_EQUAL(17711U, (size_t)etl::fibonacci<22>::value); + CHECK_EQUAL(28657U, (size_t)etl::fibonacci<23>::value); + CHECK_EQUAL(46368U, (size_t)etl::fibonacci<24>::value); + CHECK_EQUAL(75025U, (size_t)etl::fibonacci<25>::value); + CHECK_EQUAL(121393U, (size_t)etl::fibonacci<26>::value); + CHECK_EQUAL(196418U, (size_t)etl::fibonacci<27>::value); + CHECK_EQUAL(317811U, (size_t)etl::fibonacci<28>::value); + CHECK_EQUAL(514229U, (size_t)etl::fibonacci<29>::value); + CHECK_EQUAL(832040U, (size_t)etl::fibonacci<30>::value); + CHECK_EQUAL(1346269U, (size_t)etl::fibonacci<31>::value); + CHECK_EQUAL(2178309U, (size_t)etl::fibonacci<32>::value); + CHECK_EQUAL(3524578U, (size_t)etl::fibonacci<33>::value); + CHECK_EQUAL(5702887U, (size_t)etl::fibonacci<34>::value); + CHECK_EQUAL(9227465U, (size_t)etl::fibonacci<35>::value); + CHECK_EQUAL(14930352U, (size_t)etl::fibonacci<36>::value); + CHECK_EQUAL(24157817U, (size_t)etl::fibonacci<37>::value); + CHECK_EQUAL(39088169U, (size_t)etl::fibonacci<38>::value); + CHECK_EQUAL(63245986U, (size_t)etl::fibonacci<39>::value); + CHECK_EQUAL(102334155U, (size_t)etl::fibonacci<40>::value); + CHECK_EQUAL(165580141U, (size_t)etl::fibonacci<41>::value); + CHECK_EQUAL(267914296U, (size_t)etl::fibonacci<42>::value); + CHECK_EQUAL(433494437U, (size_t)etl::fibonacci<43>::value); + CHECK_EQUAL(701408733U, (size_t)etl::fibonacci<44>::value); + CHECK_EQUAL(1134903170U, (size_t)etl::fibonacci<45>::value); + CHECK_EQUAL(1836311903U, (size_t)etl::fibonacci<46>::value); CHECK_EQUAL(2971215073U, (size_t)etl::fibonacci<47>::value); } TEST(test_factorial) { - CHECK_EQUAL(1, (size_t)etl::factorial<0>::value); - CHECK_EQUAL(1, (size_t)etl::factorial<1>::value); - CHECK_EQUAL(2, (size_t)etl::factorial<2>::value); - CHECK_EQUAL(6, (size_t)etl::factorial<3>::value); - CHECK_EQUAL(24, (size_t)etl::factorial<4>::value); - CHECK_EQUAL(120, (size_t)etl::factorial<5>::value); - CHECK_EQUAL(720, (size_t)etl::factorial<6>::value); - CHECK_EQUAL(5040, (size_t)etl::factorial<7>::value); - CHECK_EQUAL(40320, (size_t)etl::factorial<8>::value); - CHECK_EQUAL(362880, (size_t)etl::factorial<9>::value); - CHECK_EQUAL(3628800, (size_t)etl::factorial<10>::value); - CHECK_EQUAL(39916800, (size_t)etl::factorial<11>::value); - CHECK_EQUAL(479001600, (size_t)etl::factorial<12>::value); + CHECK_EQUAL(1U, (size_t)etl::factorial<0>::value); + CHECK_EQUAL(1U, (size_t)etl::factorial<1>::value); + CHECK_EQUAL(2U, (size_t)etl::factorial<2>::value); + CHECK_EQUAL(6U, (size_t)etl::factorial<3>::value); + CHECK_EQUAL(24U, (size_t)etl::factorial<4>::value); + CHECK_EQUAL(120U, (size_t)etl::factorial<5>::value); + CHECK_EQUAL(720U, (size_t)etl::factorial<6>::value); + CHECK_EQUAL(5040U, (size_t)etl::factorial<7>::value); + CHECK_EQUAL(40320U, (size_t)etl::factorial<8>::value); + CHECK_EQUAL(362880U, (size_t)etl::factorial<9>::value); + CHECK_EQUAL(3628800U, (size_t)etl::factorial<10>::value); + CHECK_EQUAL(39916800U, (size_t)etl::factorial<11>::value); + CHECK_EQUAL(479001600U, (size_t)etl::factorial<12>::value); } }; } diff --git a/test/test_observer.cpp b/test/test_observer.cpp index a59e2a56..1c6853ad 100644 --- a/test/test_observer.cpp +++ b/test/test_observer.cpp @@ -125,7 +125,7 @@ public: //******************************************* // Notification1 is passed by value. //******************************************* - void notification(Notification1 data1) + void notification(Notification1 /*data1*/) { ++data1_count; } @@ -133,7 +133,7 @@ public: //******************************************* // Notification2 is passed by reference. //******************************************* - void notification(Notification2& data2) + void notification(Notification2& /*data2*/) { ++data2_count; } @@ -141,7 +141,7 @@ public: //******************************************* // Notification3 is passed by const reference. //******************************************* - void notification(const Notification3& data3) + void notification(const Notification3& /*data3*/) { ++data3_count; } @@ -170,7 +170,7 @@ public: //******************************************* // Notification1 is passed by value. //******************************************* - void notification(Notification1 data1) + void notification(Notification1 /*data1*/) { ++data1_count; } @@ -178,7 +178,7 @@ public: //******************************************* // Notification2 is passed by reference. //******************************************* - void notification(Notification2& data2) + void notification(Notification2& /*data2*/) { ++data2_count; } @@ -186,7 +186,7 @@ public: //******************************************* // Notification3 is passed by const reference. //******************************************* - void notification(const Notification3& data3) + void notification(const Notification3& /*data3*/) { ++data3_count; } diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 222698c5..47b821e2 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -184,7 +184,7 @@ namespace CHECK(bool(container)); container.value().resize(5, Data("1")); - CHECK_EQUAL(5, container.value().size()); + CHECK_EQUAL(5U, container.value().size()); CHECK_EQUAL(Data("1"), container.value()[0]); CHECK_EQUAL(Data("1"), container.value()[1]); From d4a1c8a3808800d8d85d198e8c98fdeb24cbe30a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:12:09 +0000 Subject: [PATCH 076/168] Changed Jenkins template class to individual 32 & 64 bit versions. --- test/test_jenkins.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/test_jenkins.cpp b/test/test_jenkins.cpp index 3bef5bf2..47b59b39 100644 --- a/test/test_jenkins.cpp +++ b/test/test_jenkins.cpp @@ -85,7 +85,7 @@ namespace { std::string data("123456789"); - uint32_t hash = etl::jenkins(data.begin(), data.end()); + uint32_t hash = etl::jenkins32(data.begin(), data.end()); uint32_t compare = jenkins32(data.begin(), data.end()); CHECK_EQUAL(compare, hash); @@ -96,7 +96,7 @@ namespace { std::string data("123456789"); - etl::jenkins jenkins_32_calculator; + etl::jenkins32 jenkins_32_calculator; for (size_t i = 0; i < data.size(); ++i) { @@ -114,7 +114,7 @@ namespace { std::string data("123456789"); - etl::jenkins jenkins_32_calculator; + etl::jenkins32 jenkins_32_calculator; jenkins_32_calculator.add(data.begin(), data.end()); @@ -132,9 +132,9 @@ namespace std::vector data2 = { 0x04030201, 0x08070605 }; std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - uint32_t hash1 = etl::jenkins(data1.begin(), data1.end()); - uint32_t hash2 = etl::jenkins((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); - uint32_t hash3 = etl::jenkins(data3.rbegin(), data3.rend()); + uint32_t hash1 = etl::jenkins32(data1.begin(), data1.end()); + uint32_t hash2 = etl::jenkins32((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); + uint32_t hash3 = etl::jenkins32(data3.rbegin(), data3.rend()); CHECK_EQUAL(hash1, hash2); CHECK_EQUAL(hash1, hash3); @@ -146,7 +146,7 @@ namespace CHECK_EQUAL(compare2, hash2); uint64_t compare3 = jenkins32(data3.rbegin(), data3.rend()); - CHECK_EQUAL(compare2, hash3); + CHECK_EQUAL(compare3, hash3); } //************************************************************************* @@ -154,9 +154,10 @@ namespace { std::string data("123456789"); - etl::jenkins j32; + etl::jenkins32 j32; j32.add(data.begin(), data.end()); - uint32_t hash = j32; + + j32.value(); CHECK_THROW(j32.add(0), etl::hash_finalised); } @@ -166,7 +167,7 @@ namespace { std::string data("123456789"); - uint64_t hash = etl::jenkins(data.begin(), data.end()); + uint64_t hash = etl::jenkins64(data.begin(), data.end()); uint64_t compare = jenkins64(data.begin(), data.end()); CHECK_EQUAL(compare, hash); @@ -177,7 +178,7 @@ namespace { std::string data("123456789"); - etl::jenkins jenkins_64_calculator; + etl::jenkins64 jenkins_64_calculator; for (size_t i = 0; i < data.size(); ++i) { @@ -195,7 +196,7 @@ namespace { std::string data("123456789"); - etl::jenkins jenkins_64_calculator; + etl::jenkins64 jenkins_64_calculator; jenkins_64_calculator.add(data.begin(), data.end()); @@ -213,9 +214,9 @@ namespace std::vector data2 = { 0x04030201, 0x08070605 }; std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - uint64_t hash1 = etl::jenkins(data1.begin(), data1.end()); - uint64_t hash2 = etl::jenkins((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); - uint64_t hash3 = etl::jenkins(data3.rbegin(), data3.rend()); + uint64_t hash1 = etl::jenkins64(data1.begin(), data1.end()); + uint64_t hash2 = etl::jenkins64((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); + uint64_t hash3 = etl::jenkins64(data3.rbegin(), data3.rend()); CHECK_EQUAL(hash1, hash2); CHECK_EQUAL(hash1, hash3); @@ -226,7 +227,7 @@ namespace CHECK_EQUAL(compare2, hash2); uint64_t compare3 = jenkins64(data3.rbegin(), data3.rend()); - CHECK_EQUAL(compare2, hash3); + CHECK_EQUAL(compare3, hash3); } }; } From b4f0855410132d39eaa7c28fa4a4ec5aa2c7d7a2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:12:22 +0000 Subject: [PATCH 077/168] Fixed GCC warnings --- test/test_io_port.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/test_io_port.cpp b/test/test_io_port.cpp index 62487683..656ce1a3 100644 --- a/test/test_io_port.cpp +++ b/test/test_io_port.cpp @@ -32,7 +32,12 @@ SOFTWARE. #include -#pragma warning(disable:4101) // Unused variable. +#if defined(ETL_COMPILER_GCC) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-variable" +#else + #pragma warning(disable:4101) // Unused variable. +#endif template struct serial_port @@ -113,3 +118,7 @@ namespace } }; } + +#if defined(ETL_COMPILER_GCC) + #pragma GCC diagnostic pop +#endif From 093b29a48c99f87b8df0fca3534794d48ce50fe7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:12:37 +0000 Subject: [PATCH 078/168] Removed support for auto and checked links. --- test/test_intrusive_forward_list.cpp | 278 +++-- test/test_intrusive_links.cpp | 1514 ++++++++++++++------------ test/test_intrusive_list.cpp | 102 +- test/test_intrusive_stack.cpp | 72 +- 4 files changed, 1003 insertions(+), 963 deletions(-) diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 46ce13b7..4c962b37 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -45,8 +45,8 @@ typedef TestDataNDC ItemNDC; namespace { - typedef etl::forward_link<0, etl::link_option::CHECKED> FirstLink; - typedef etl::forward_link<1> SecondLink; + typedef etl::forward_link<0> FirstLink; + typedef etl::bidirectional_link<1> SecondLink; //*************************************************************************** class ItemDCNode : public FirstLink, public SecondLink @@ -259,12 +259,6 @@ namespace ////************************************************************************* TEST_FIXTURE(SetupFixture, test_two_lists_different) { - std::list compare0; - std::list compare1; - - DataNDC0 data0; - DataNDC1 data1; - ItemNDCNode node0("0"); ItemNDCNode node1("1"); ItemNDCNode node2("2"); @@ -274,43 +268,51 @@ namespace ItemNDCNode node6("6"); ItemNDCNode node7("7"); - compare0.push_front(node0); - compare0.push_front(node1); - compare0.push_front(node2); - compare0.push_front(node4); - compare0.push_front(node6); - compare0.push_front(node7); - - data0.push_front(node0); - data0.push_front(node1); - data0.push_front(node2); - data0.push_front(node4); - data0.push_front(node6); - data0.push_front(node7); + { + std::list compare0; + std::list compare1; - are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data0.size()); - CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + DataNDC0 data0; + DataNDC1 data1; - compare1.push_front(node0); - compare1.push_front(node1); - compare1.push_front(node3); - compare1.push_front(node4); - compare1.push_front(node5); - compare1.push_front(node7); + compare0.push_front(node0); + compare0.push_front(node1); + compare0.push_front(node2); + compare0.push_front(node4); + compare0.push_front(node6); + compare0.push_front(node7); - data1.push_front(node0); - data1.push_front(node1); - data1.push_front(node3); - data1.push_front(node4); - data1.push_front(node5); - data1.push_front(node7); + compare1.push_front(node0); + compare1.push_front(node1); + compare1.push_front(node3); + compare1.push_front(node4); + compare1.push_front(node5); + compare1.push_front(node7); - are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data1.size()); - CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node4); + data0.push_front(node6); + data0.push_front(node7); + + are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); + CHECK(are_equal); + CHECK_EQUAL(6U, data0.size()); + CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + + data1.push_front(node0); + data1.push_front(node1); + data1.push_front(node3); + data1.push_front(node4); + data1.push_front(node5); + data1.push_front(node7); + + are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); + CHECK(are_equal); + CHECK_EQUAL(6U, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + } } //************************************************************************* @@ -336,13 +338,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); offset = 0; @@ -352,22 +354,18 @@ namespace i_compare_data = compare_data.begin(); std::advance(i_compare_data, offset); - std::forward_list temp(data0.begin(), data0.end()); - data0.insert_after(i_data, INSERT_VALUE2); compare_data.insert_after(i_compare_data, INSERT_VALUE2); - temp.assign(data0.begin(), data0.end()); - are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -389,7 +387,7 @@ namespace are_equal = std::equal(data1.begin(), data1.end(), test1.begin()); CHECK(are_equal); CHECK_EQUAL(test1.size(), data1.size()); - CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(test1.size(), size_t(std::distance(data1.begin(), data1.end()))); compare.assign(test1.begin(), test1.end()); data0.assign(test1.begin(), test1.end()); @@ -411,15 +409,12 @@ namespace are_equal = std::equal(data1.begin(), data1.end(), test1.begin()); CHECK(are_equal); CHECK_EQUAL(test1.size(), data1.size()); - CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(test1.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_front) { - std::list compare_data; - DataNDC0 data0; - ItemNDCNode node1("1"); ItemNDCNode node2("2"); ItemNDCNode node3("3"); @@ -427,32 +422,34 @@ namespace ItemNDCNode node5("5"); ItemNDCNode node6("6"); - compare_data.push_front(node1); - compare_data.push_front(node2); - compare_data.push_front(node3); - compare_data.push_front(node4); - compare_data.push_front(node5); - compare_data.push_front(node6); + { + std::list compare_data; + DataNDC0 data0; - CHECK_NO_THROW(data0.push_front(node1)); - CHECK_NO_THROW(data0.push_front(node2)); - CHECK_NO_THROW(data0.push_front(node3)); - CHECK_NO_THROW(data0.push_front(node4)); - CHECK_NO_THROW(data0.push_front(node5)); - CHECK_NO_THROW(data0.push_front(node6)); + compare_data.push_front(node1); + compare_data.push_front(node2); + compare_data.push_front(node3); + compare_data.push_front(node4); + compare_data.push_front(node5); + compare_data.push_front(node6); - are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); - CHECK(are_equal); - CHECK_EQUAL(6, data0.size()); - CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + CHECK_NO_THROW(data0.push_front(node1)); + CHECK_NO_THROW(data0.push_front(node2)); + CHECK_NO_THROW(data0.push_front(node3)); + CHECK_NO_THROW(data0.push_front(node4)); + CHECK_NO_THROW(data0.push_front(node5)); + CHECK_NO_THROW(data0.push_front(node6)); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + CHECK(are_equal); + CHECK_EQUAL(6U, data0.size()); + CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_front_pop_front) { - DataNDC0 data0; - DataNDC1 data1; - ItemNDCNode node1("1"); ItemNDCNode node2("2"); ItemNDCNode node3("3"); @@ -460,43 +457,48 @@ namespace ItemNDCNode node5("5"); ItemNDCNode node6("6"); - data0.push_front(node1); - data0.push_front(node2); - data0.push_front(node3); - data0.push_front(node4); - data0.push_front(node5); - data0.push_front(node6); + { + DataNDC0 data0; + DataNDC1 data1; - data1.push_front(node1); - data1.push_front(node2); - data1.push_front(node3); - data1.push_front(node4); - data1.push_front(node5); - data1.push_front(node6); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + data0.push_front(node6); - CHECK_EQUAL(6, data0.size()); - CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); - CHECK(!data0.empty()); + data1.push_front(node1); + data1.push_front(node2); + data1.push_front(node3); + data1.push_front(node4); + data1.push_front(node5); + data1.push_front(node6); - data0.pop_front(); - data0.pop_front(); - data0.pop_front(); - data0.pop_front(); - data0.pop_front(); + CHECK_EQUAL(6U, data0.size()); + CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); + CHECK(!data0.empty()); - CHECK_EQUAL(1, data0.size()); - CHECK_EQUAL(1, std::distance(data0.begin(), data0.end())); - CHECK(!data0.empty()); + data0.pop_front(); + data0.pop_front(); + data0.pop_front(); + data0.pop_front(); + data0.pop_front(); - data0.pop_front(); + CHECK_EQUAL(1U, data0.size()); + CHECK_EQUAL(1, std::distance(data0.begin(), data0.end())); + CHECK(!data0.empty()); - CHECK_EQUAL(0, data0.size()); - CHECK_EQUAL(0, std::distance(data0.begin(), data0.end())); - CHECK(data0.empty()); + data0.pop_front(); - CHECK_EQUAL(6, data1.size()); - CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); - CHECK(!data1.empty()); + CHECK_EQUAL(0U, data0.size()); + CHECK_EQUAL(0, std::distance(data0.begin(), data0.end())); + CHECK(data0.empty()); + + CHECK_EQUAL(6U, data1.size()); + CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); + CHECK(!data1.empty()); + } } //************************************************************************* @@ -526,13 +528,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); are_equal = *i_data == *i_compare_data; CHECK(are_equal); @@ -547,13 +549,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); are_equal = *i_data == *i_compare_data; CHECK(are_equal); @@ -586,13 +588,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -616,13 +618,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -655,13 +657,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), unique_data.begin()); CHECK(are_equal); CHECK_EQUAL(unique_data.size(), data0.size()); - CHECK_EQUAL(unique_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(unique_data.size(), size_t(std::distance(data0.begin(), data0.end()))); // data1 should not have changed. are_equal = std::equal(data1.begin(), data1.end(), non_unique_data.begin()); CHECK(are_equal); CHECK_EQUAL(non_unique_data.size(), data1.size()); - CHECK_EQUAL(non_unique_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(non_unique_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -677,13 +679,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -699,13 +701,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -776,8 +778,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } //************************************************************************* @@ -790,18 +792,14 @@ namespace DataNDC0::iterator idata_destination = data0.begin(); std::advance(idata_destination, 3); - std::forward_list compare0(data0.begin(), data0.end()); - - std::forward_list::iterator icompare_destination = compare0.begin(); - std::advance(icompare_destination, 3); + std::forward_list compare0(sorted_data2.begin(), sorted_data2.end()); data0.splice_after(idata_destination, data0); - compare0.splice_after(icompare_destination, compare0); are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); } //************************************************************************* @@ -839,8 +837,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } //************************************************************************* @@ -859,7 +857,7 @@ namespace DataNDC0::iterator idata_end = data0.begin(); std::advance(idata_end, 7); - std::forward_list compare0(data0.begin(), data0.end()); + std::forward_list compare0(sorted_data2.begin(), sorted_data2.end()); std::forward_list::iterator icompare_destination = compare0.begin(); std::advance(icompare_destination, 2); @@ -872,11 +870,11 @@ namespace data0.splice_after(idata_destination, data0, idata_begin, idata_end); compare0.splice_after(icompare_destination, compare0, icompare_begin, icompare_end); - + are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); } //************************************************************************* @@ -896,8 +894,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } //************************************************************************* @@ -917,8 +915,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare2.begin(), compare2.end()), data2.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare2.begin(), compare2.end())), data2.size()); } //************************************************************************* @@ -938,8 +936,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare3.begin(), compare3.end()), data3.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare3.begin(), compare3.end())), data3.size()); } //************************************************************************* @@ -959,8 +957,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare4.begin(), compare4.end()), data4.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare4.begin(), compare4.end())), data4.size()); } //************************************************************************* @@ -986,8 +984,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(std::distance(compare0.begin(), compare0.end()), data0.size()); - CHECK_EQUAL(std::distance(compare1.begin(), compare1.end()), data1.size()); + CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); + CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } }; } diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index 9351497b..299df532 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -38,11 +38,10 @@ namespace //******************************************************* // Forward //******************************************************* - typedef etl::forward_link<0> FirstFLink; - typedef etl::forward_link<1> SecondFLink; - typedef etl::forward_link<2, etl::link_option::CHECKED> ThirdFLinkChecked; + typedef etl::forward_link<0> FLink0; + typedef etl::forward_link<1> FLink1; - struct FData : public FirstFLink, public SecondFLink, public ThirdFLinkChecked + struct FData : public FLink0, public FLink1 { FData(int value) : value(value) @@ -55,12 +54,10 @@ namespace //******************************************************* // Bidirectional //******************************************************* - typedef etl::bidirectional_link<0, etl::link_option::AUTO> FirstBLinkAuto; - typedef etl::bidirectional_link<0, etl::link_option::CHECKED> FirstBLinkChecked; - typedef etl::bidirectional_link<0> FirstBLink; - typedef etl::bidirectional_link<1> SecondBLink; + typedef etl::bidirectional_link<0> BLink0; + typedef etl::bidirectional_link<1> BLink1; - struct BData : public FirstBLink, public SecondBLink + struct BData : public BLink0, public BLink1 { BData(int value) : value(value) @@ -70,34 +67,14 @@ namespace int value; }; - struct BDataAuto : public FirstBLinkAuto, public SecondBLink - { - BDataAuto(int value) - : value(value) - { - } - - int value; - }; - - struct BDataChecked : public FirstBLinkChecked - { - BDataChecked(int value) - : value(value) - { - } - - int value; - }; - //******************************************************* // Tree //******************************************************* - typedef etl::tree_link<0> FirstTLink; - typedef etl::tree_link<1> SecondTLink; - typedef etl::tree_link<2> ThirdTLink; + typedef etl::tree_link<0> TLink0; + typedef etl::tree_link<1> TLink1; + typedef etl::tree_link<2> TLink2; - struct TData : public FirstTLink, public SecondTLink + struct TData : public TLink0, public TLink1 { TData(int value) : value(value) @@ -110,7 +87,7 @@ namespace //******************************************************* // Mixed //******************************************************* - struct MData : public FirstFLink, public SecondBLink, public ThirdTLink + struct MData : public FLink0, public BLink1, public TLink2 { MData(int value) : value(value) @@ -121,7 +98,7 @@ namespace }; SUITE(test_forward_list) - { + { //************************************************************************* TEST(test_link_forward_link) { @@ -130,54 +107,54 @@ namespace FData data2(2); FData data3(3); - data0.FirstFLink::clear(); - etl::link(data0, data1); - CHECK(data0.FirstFLink::etl_next == &data1); + data0.FLink0::clear(); + etl::link(data0, data1); + CHECK(data0.FLink0::etl_next == &data1); - data0.FirstFLink::clear(); - etl::link(&data0, data1); - CHECK(data0.FirstFLink::etl_next == &data1); + data0.FLink0::clear(); + etl::link(&data0, data1); + CHECK(data0.FLink0::etl_next == &data1); - data0.FirstFLink::clear(); - etl::link(data0, &data1); - CHECK(data0.FirstFLink::etl_next == &data1); + data0.FLink0::clear(); + etl::link(data0, &data1); + CHECK(data0.FLink0::etl_next == &data1); - data0.FirstFLink::clear(); - etl::link(&data0, &data1); - CHECK(data0.FirstFLink::etl_next == &data1); + data0.FLink0::clear(); + etl::link(&data0, &data1); + CHECK(data0.FLink0::etl_next == &data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); - CHECK(data1.FirstFLink::etl_next == &data2); - CHECK(data2.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == nullptr); - CHECK(data3.SecondFLink::etl_next == &data2); - CHECK(data2.SecondFLink::etl_next == &data1); - CHECK(data1.SecondFLink::etl_next == &data0); - CHECK(data0.SecondFLink::etl_next == nullptr); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == nullptr); FData* pdata; - pdata = static_cast(data0.FirstFLink::etl_next); + pdata = static_cast(data0.FLink0::etl_next); CHECK_EQUAL(1, pdata->value); - pdata = static_cast(pdata->FirstFLink::etl_next); + pdata = static_cast(pdata->FLink0::etl_next); CHECK_EQUAL(2, pdata->value); - pdata = static_cast(pdata->FirstFLink::etl_next); + pdata = static_cast(pdata->FLink0::etl_next); CHECK_EQUAL(3, pdata->value); - pdata = static_cast(data3.SecondFLink::etl_next); + pdata = static_cast(data3.FLink1::etl_next); CHECK_EQUAL(2, pdata->value); - pdata = static_cast(pdata->SecondFLink::etl_next); + pdata = static_cast(pdata->FLink1::etl_next); CHECK_EQUAL(1, pdata->value); - pdata = static_cast(pdata->SecondFLink::etl_next); + pdata = static_cast(pdata->FLink1::etl_next); CHECK_EQUAL(0, pdata->value); } @@ -189,35 +166,35 @@ namespace FData data2(2); FData data3(3); - data0.FirstFLink::clear(); - etl::link_splice(data0, data1); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == nullptr); + data0.FLink0::clear(); + etl::link_splice(data0, data1); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == nullptr); - data0.FirstFLink::clear(); - etl::link_splice(data0, &data1); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == nullptr); + data0.FLink0::clear(); + etl::link_splice(data0, &data1); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == nullptr); - data0.FirstFLink::clear(); - etl::link_splice(&data0, data1); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == nullptr); + data0.FLink0::clear(); + etl::link_splice(&data0, data1); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == nullptr); - data0.FirstFLink::clear(); - etl::link_splice(&data0, &data1); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == nullptr); + data0.FLink0::clear(); + etl::link_splice(&data0, &data1); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == nullptr); - data0.FirstFLink::clear(); - etl::link_splice(data0, data3); - etl::link_splice(data0, data1); - etl::link_splice(data1, data2); + data0.FLink0::clear(); + etl::link_splice(data0, data3); + etl::link_splice(data0, data1); + etl::link_splice(data1, data2); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data2); - CHECK(data2.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == nullptr); } //************************************************************************* @@ -233,65 +210,65 @@ namespace FData data7(7); // First range. - data0.FirstFLink::clear(); - etl::link_splice(data0, data1); - etl::link_splice(data1, data6); - etl::link_splice(data6, data7); + data0.FLink0::clear(); + etl::link_splice(data0, data1); + etl::link_splice(data1, data6); + etl::link_splice(data6, data7); // Second range. - data2.FirstFLink::clear(); - etl::link_splice(data2, data3); - etl::link_splice(data3, data4); - etl::link_splice(data4, data5); + data2.FLink0::clear(); + etl::link_splice(data2, data3); + etl::link_splice(data3, data4); + etl::link_splice(data4, data5); - etl::link_splice(data1, data2, data5); + etl::link_splice(data1, data2, data5); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data2); - CHECK(data2.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == &data4); - CHECK(data4.FirstFLink::etl_next == &data5); - CHECK(data5.FirstFLink::etl_next == &data6); - CHECK(data6.FirstFLink::etl_next == &data7); - CHECK(data7.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == nullptr); // Do it again with a pointer. // First range. - data0.FirstFLink::clear(); - etl::link_splice(data0, data1); - etl::link_splice(data1, data6); - etl::link_splice(data6, data7); + data0.FLink0::clear(); + etl::link_splice(data0, data1); + etl::link_splice(data1, data6); + etl::link_splice(data6, data7); // Second range. - data2.FirstFLink::clear(); - etl::link_splice(data2, data3); - etl::link_splice(data3, data4); - etl::link_splice(data4, data5); + data2.FLink0::clear(); + etl::link_splice(data2, data3); + etl::link_splice(data3, data4); + etl::link_splice(data4, data5); - etl::link_splice(&data1, data2, data5); + etl::link_splice(&data1, data2, data5); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data2); - CHECK(data2.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == &data4); - CHECK(data4.FirstFLink::etl_next == &data5); - CHECK(data5.FirstFLink::etl_next == &data6); - CHECK(data6.FirstFLink::etl_next == &data7); - CHECK(data7.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == nullptr); // Do it again with a nullptr pointer. // Second range. - data2.FirstFLink::clear(); - etl::link_splice(data2, data3); - etl::link_splice(data3, data4); - etl::link_splice(data4, data5); + data2.FLink0::clear(); + etl::link_splice(data2, data3); + etl::link_splice(data3, data4); + etl::link_splice(data4, data5); - etl::link_splice(nullptr, data2, data5); + etl::link_splice(nullptr, data2, data5); - CHECK(data2.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == &data4); - CHECK(data4.FirstFLink::etl_next == &data5); - CHECK(data5.FirstFLink::etl_next == nullptr); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == nullptr); } @@ -303,63 +280,51 @@ namespace FData data2(2); FData data3(3); - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + etl::link(data0, data1); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); - etl::unlink_after(data1); - data2.FirstFLink::clear(); + etl::unlink_after(data1); + data2.FLink0::clear(); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data3); - CHECK(data2.FirstFLink::etl_next == nullptr); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data3); + CHECK(data2.FLink0::etl_next == nullptr); + CHECK(data3.FLink0::etl_next == nullptr); - CHECK(data3.SecondFLink::etl_next == &data2); - CHECK(data2.SecondFLink::etl_next == &data1); - CHECK(data1.SecondFLink::etl_next == &data0); - CHECK(data0.SecondFLink::etl_next == nullptr); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == nullptr); - etl::unlink_after(data2); - data1.SecondFLink::clear(); + etl::unlink_after(data2); + data1.FLink1::clear(); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == nullptr); - CHECK(data3.SecondFLink::etl_next == &data2); - CHECK(data2.SecondFLink::etl_next == &data0); - CHECK(data1.SecondFLink::etl_next == nullptr); - CHECK(data0.SecondFLink::etl_next == nullptr); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data0); + CHECK(data1.FLink1::etl_next == nullptr); + CHECK(data0.FLink1::etl_next == nullptr); - etl::unlink_after(data3); - etl::unlink_after(data0); + etl::unlink_after(data3); + etl::unlink_after(data0); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == nullptr); - CHECK(data3.SecondFLink::etl_next == &data2); - CHECK(data2.SecondFLink::etl_next == &data0); - CHECK(data0.SecondFLink::etl_next == nullptr); - - // Check auto link. - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); - - etl::unlink_after(data1); - - CHECK(data0.ThirdFLinkChecked::etl_next == &data1); - CHECK(data1.ThirdFLinkChecked::etl_next == &data3); - CHECK(data3.ThirdFLinkChecked::etl_next == nullptr); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == nullptr); } //************************************************************************* @@ -370,29 +335,29 @@ namespace FData data2(2); FData data3(3); - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + etl::link(data0, data1); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); - etl::unlink_after(data0, data2); - data1.FirstFLink::clear(); - data2.FirstFLink::clear(); + etl::unlink_after(data0, data2); + data1.FLink0::clear(); + data2.FLink0::clear(); - CHECK(data0.FirstFLink::etl_next == &data3); - CHECK(data1.FirstFLink::etl_next == nullptr); - CHECK(data2.FirstFLink::etl_next == nullptr); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data3); + CHECK(data1.FLink0::etl_next == nullptr); + CHECK(data2.FLink0::etl_next == nullptr); + CHECK(data3.FLink0::etl_next == nullptr); - CHECK(data3.SecondFLink::etl_next == &data2); - CHECK(data2.SecondFLink::etl_next == &data1); - CHECK(data1.SecondFLink::etl_next == &data0); - CHECK(data0.SecondFLink::etl_next == nullptr); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == nullptr); } //************************************************************************* @@ -400,134 +365,131 @@ namespace { FData data0(0); - etl::link(data0, data0); + etl::link(data0, data0); - CHECK(data0.FirstFLink::etl_next == &data0); + CHECK(data0.FLink0::etl_next == &data0); - etl::unlink_after(data0); + etl::unlink_after(data0); - CHECK(data0.FirstFLink::etl_next == &data0); + CHECK(data0.FLink0::etl_next == &data0); } //************************************************************************* TEST(test_link_bidirectional_link) { - // FirstBLinkAuto is auto-unlink, SecondBLink is not. + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); - BDataAuto* data0 = new BDataAuto(0); - BDataAuto* data1 = new BDataAuto(1); - BDataAuto* data2 = new BDataAuto(2); - BDataAuto* data3 = new BDataAuto(3); + etl::link(nullptr, data0); - etl::link(nullptr, data0); + data1.BLink0::clear(); + etl::link(data0, data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); - data1->FirstBLinkAuto::clear(); - etl::link(*data0, *data1); - CHECK(data0->FirstBLinkAuto::etl_next == data1); - CHECK(data1->FirstBLinkAuto::etl_previous == data0); - - data1->FirstBLinkAuto::clear(); - etl::link(*data0, data1); - CHECK(data0->FirstBLinkAuto::etl_next == data1); - CHECK(data1->FirstBLinkAuto::etl_previous == data0); + data1.BLink0::clear(); + etl::link(data0, data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); - data1->FirstBLinkAuto::clear(); - etl::link(data0, *data1); - CHECK(data0->FirstBLinkAuto::etl_next == data1); - CHECK(data1->FirstBLinkAuto::etl_previous == data0); + data1.BLink0::clear(); + etl::link(data0, data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); - data1->FirstBLinkAuto::clear(); - etl::link(data0, data1); - CHECK(data0->FirstBLinkAuto::etl_next == data1); - CHECK(data1->FirstBLinkAuto::etl_previous == data0); + data1.BLink0::clear(); + etl::link(data0, data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - CHECK(data0->FirstBLinkAuto::etl_previous == nullptr); - CHECK(data1->FirstBLinkAuto::etl_previous == data0); - CHECK(data1->FirstBLinkAuto::etl_next == data2); - CHECK(data2->FirstBLinkAuto::etl_previous == data1); - CHECK(data2->FirstBLinkAuto::etl_next == data3); - CHECK(data3->FirstBLinkAuto::etl_previous == data2); - CHECK(data3->FirstBLinkAuto::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == nullptr); - etl::link(nullptr, data3); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(nullptr, data3); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); - CHECK(data3->SecondBLink::etl_previous == nullptr); - CHECK(data3->SecondBLink::etl_next == data2); - CHECK(data2->SecondBLink::etl_previous == data3); - CHECK(data2->SecondBLink::etl_next == data1); - CHECK(data1->SecondBLink::etl_previous == data2); - CHECK(data1->SecondBLink::etl_next == data0); - CHECK(data0->SecondBLink::etl_previous == data1); - CHECK(data0->SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); - BDataAuto* pdataauto; BData* pdata; - pdataauto = static_cast(data0->FirstBLinkAuto::etl_next); - CHECK_EQUAL(1, pdataauto->value); - pdataauto = static_cast(pdataauto->FirstBLinkAuto::etl_next); - CHECK_EQUAL(2, pdataauto->value); - pdataauto = static_cast(pdataauto->FirstBLinkAuto::etl_next); - CHECK_EQUAL(3, pdataauto->value); - - pdataauto = static_cast(data3->FirstBLinkAuto::etl_previous); - CHECK_EQUAL(2, pdataauto->value); - pdataauto = static_cast(pdataauto->FirstBLinkAuto::etl_previous); - CHECK_EQUAL(1, pdataauto->value); - pdataauto = static_cast(pdataauto->FirstBLinkAuto::etl_previous); - CHECK_EQUAL(0, pdataauto->value); - - pdata = static_cast(data3->SecondBLink::etl_next); - CHECK_EQUAL(2, pdata->value); - pdata = static_cast(pdata->SecondBLink::etl_next); + pdata = static_cast(data0.BLink0::etl_next); CHECK_EQUAL(1, pdata->value); - pdata = static_cast(pdata->SecondBLink::etl_next); - CHECK_EQUAL(0, pdata->value); - - pdata = static_cast(data0->SecondBLink::etl_previous); - CHECK_EQUAL(1, pdata->value); - pdata = static_cast(pdata->SecondBLink::etl_previous); + pdata = static_cast(pdata->BLink0::etl_next); CHECK_EQUAL(2, pdata->value); - pdata = static_cast(pdata->SecondBLink::etl_previous); + pdata = static_cast(pdata->BLink0::etl_next); CHECK_EQUAL(3, pdata->value); - delete data1; - CHECK(data0->FirstBLinkAuto::etl_next == data2); - CHECK(data2->FirstBLinkAuto::etl_previous == data0); + pdata = static_cast(data3.BLink0::etl_previous); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_previous); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_previous); + CHECK_EQUAL(0, pdata->value); - CHECK(data3->SecondBLink::etl_previous == nullptr); - CHECK(data3->SecondBLink::etl_next == data2); - CHECK(data2->SecondBLink::etl_previous == data3); - CHECK(data2->SecondBLink::etl_next != nullptr); - CHECK(data0->SecondBLink::etl_previous != nullptr); - CHECK(data0->SecondBLink::etl_next == nullptr); + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); - delete data0; - CHECK(data2->FirstBLinkAuto::etl_next == data3); - CHECK(data2->FirstBLinkAuto::etl_previous == nullptr); - CHECK(data3->FirstBLinkAuto::etl_previous == data2); - - CHECK(data3->SecondBLink::etl_previous == nullptr); - CHECK(data3->SecondBLink::etl_next == data2); - CHECK(data2->SecondBLink::etl_previous == data3); - CHECK(data2->SecondBLink::etl_next != nullptr); + pdata = static_cast(data0.BLink1::etl_previous); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_previous); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_previous); + CHECK_EQUAL(3, pdata->value); - delete data3; - CHECK(data2->FirstBLinkAuto::etl_next == nullptr); - CHECK(data2->FirstBLinkAuto::etl_previous == nullptr); + data1.BLink0::unlink(); + CHECK(data0.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data0); - CHECK(data2->SecondBLink::etl_next != nullptr); - CHECK(data2->SecondBLink::etl_previous != nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next != nullptr); + CHECK(data0.BLink1::etl_previous != nullptr); + CHECK(data0.BLink1::etl_next == nullptr); - delete data2; + data0.BLink0::unlink(); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data2.BLink0::etl_previous == nullptr); + CHECK(data3.BLink0::etl_previous == &data2); + + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next != nullptr); + + data3.BLink0::unlink(); + CHECK(data2.BLink0::etl_next == nullptr); + CHECK(data2.BLink0::etl_previous == nullptr); + + CHECK(data2.BLink1::etl_next != nullptr); + CHECK(data2.BLink1::etl_previous != nullptr); + + data2.BLink0::unlink(); } //************************************************************************* @@ -538,52 +500,52 @@ namespace BData data2(2); BData data3(3); - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); - etl::link_splice(data0, data1); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == nullptr); + etl::link_splice(data0, data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == nullptr); - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); - etl::link_splice(data0, &data1); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == nullptr); + etl::link_splice(data0, &data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == nullptr); - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); - etl::link_splice(&data0, data1); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == nullptr); + etl::link_splice(&data0, data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == nullptr); - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); - etl::link_splice(&data0, &data1); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == nullptr); + etl::link_splice(&data0, &data1); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == nullptr); - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); - etl::link_splice(data0, data3); - etl::link_splice(data0, data1); - etl::link_splice(data1, data2); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); + etl::link_splice(data0, data3); + etl::link_splice(data0, data1); + etl::link_splice(data1, data2); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == &data2); - CHECK(data2.FirstBLink::etl_previous == &data1); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == nullptr); } //************************************************************************* @@ -599,110 +561,90 @@ namespace BData data7(7); // Build the first range. - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); - etl::link_splice(data0, data1); - etl::link_splice(data1, data6); - etl::link_splice(data6, data7); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); + etl::link_splice(data0, data1); + etl::link_splice(data1, data6); + etl::link_splice(data6, data7); // Build the second range. - data2.FirstBLink::clear(); - etl::link_splice(nullptr, data2); - etl::link_splice(data2, data3); - etl::link_splice(data3, data4); - etl::link_splice(data4, data5); + data2.BLink0::clear(); + etl::link_splice(nullptr, data2); + etl::link_splice(data2, data3); + etl::link_splice(data3, data4); + etl::link_splice(data4, data5); - etl::link_splice(data1, data2, data5); - - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == &data2); - CHECK(data2.FirstBLink::etl_previous == &data1); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == &data4); - CHECK(data4.FirstBLink::etl_previous == &data3); - CHECK(data4.FirstBLink::etl_next == &data5); - CHECK(data5.FirstBLink::etl_previous == &data4); - CHECK(data5.FirstBLink::etl_next == &data6); - CHECK(data6.FirstBLink::etl_previous == &data5); - CHECK(data6.FirstBLink::etl_next == &data7); - CHECK(data7.FirstBLink::etl_previous == &data6); - CHECK(data7.FirstBLink::etl_next == nullptr); + etl::link_splice(data1, data2, data5); + + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_previous == &data5); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_previous == &data6); + CHECK(data7.BLink0::etl_next == nullptr); // Do it again with a pointer parameter. // Build the first range. - data0.FirstBLink::clear(); - etl::link_splice(nullptr, data0); - etl::link_splice(data0, data1); - etl::link_splice(data1, data6); - etl::link_splice(data6, data7); + data0.BLink0::clear(); + etl::link_splice(nullptr, data0); + etl::link_splice(data0, data1); + etl::link_splice(data1, data6); + etl::link_splice(data6, data7); // Build the second range. - data2.FirstBLink::clear(); - etl::link_splice(nullptr, data2); - etl::link_splice(data2, data3); - etl::link_splice(data3, data4); - etl::link_splice(data4, data5); + data2.BLink0::clear(); + etl::link_splice(nullptr, data2); + etl::link_splice(data2, data3); + etl::link_splice(data3, data4); + etl::link_splice(data4, data5); - etl::link_splice(&data1, data2, data5); + etl::link_splice(&data1, data2, data5); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == &data1); - CHECK(data1.FirstBLink::etl_previous == &data0); - CHECK(data1.FirstBLink::etl_next == &data2); - CHECK(data2.FirstBLink::etl_previous == &data1); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == &data4); - CHECK(data4.FirstBLink::etl_previous == &data3); - CHECK(data4.FirstBLink::etl_next == &data5); - CHECK(data5.FirstBLink::etl_previous == &data4); - CHECK(data5.FirstBLink::etl_next == &data6); - CHECK(data6.FirstBLink::etl_previous == &data5); - CHECK(data6.FirstBLink::etl_next == &data7); - CHECK(data7.FirstBLink::etl_previous == &data6); - CHECK(data7.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_previous == &data5); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_previous == &data6); + CHECK(data7.BLink0::etl_next == nullptr); // Do it again with a nullptr parameter. // Build the range. - data2.FirstBLink::clear(); - etl::link_splice(nullptr, data2); - etl::link_splice(data2, data3); - etl::link_splice(data3, data4); - etl::link_splice(data4, data5); + data2.BLink0::clear(); + etl::link_splice(nullptr, data2); + etl::link_splice(data2, data3); + etl::link_splice(data3, data4); + etl::link_splice(data4, data5); - etl::link_splice(nullptr, data2, data5); + etl::link_splice(nullptr, data2, data5); - CHECK(data2.FirstBLink::etl_previous == nullptr); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == &data4); - CHECK(data4.FirstBLink::etl_previous == &data3); - CHECK(data4.FirstBLink::etl_next == &data5); - CHECK(data5.FirstBLink::etl_previous == &data4); - CHECK(data5.FirstBLink::etl_next == nullptr); - } - - //************************************************************************* - TEST(test_link_bidirectional_link_checked) - { - // FirstBLinkAuto is auto-unlink - - BDataChecked* data0 = new BDataChecked(0); - BDataChecked* data1 = new BDataChecked(1); - BDataChecked* data2 = new BDataChecked(2); - BDataChecked* data3 = new BDataChecked(3); - - etl::link(nullptr, data0); - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); - - data2->FirstBLinkChecked::clear(); - CHECK_NO_THROW(delete data2); + CHECK(data2.BLink0::etl_previous == nullptr); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == nullptr); } //************************************************************************* @@ -713,101 +655,101 @@ namespace BData data2(2); BData data3(3); - etl::link(nullptr, data0); - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + etl::link(nullptr, data0); + etl::link(data0, data1); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - etl::link(nullptr, data3); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(nullptr, data3); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); - etl::unlink(data1); - data1.FirstBLink::clear(); + etl::unlink(data1); + data1.BLink0::clear(); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == &data2); - CHECK(data1.FirstBLink::etl_previous == nullptr); - CHECK(data1.FirstBLink::etl_next == nullptr); - CHECK(data2.FirstBLink::etl_previous == &data0); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == &data2); + CHECK(data1.BLink0::etl_previous == nullptr); + CHECK(data1.BLink0::etl_next == nullptr); + CHECK(data2.BLink0::etl_previous == &data0); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == nullptr); - CHECK(data3.SecondBLink::etl_previous == nullptr); - CHECK(data3.SecondBLink::etl_next == &data2); - CHECK(data2.SecondBLink::etl_previous == &data3); - CHECK(data2.SecondBLink::etl_next == &data1); - CHECK(data1.SecondBLink::etl_previous == &data2); - CHECK(data1.SecondBLink::etl_next == &data0); - CHECK(data0.SecondBLink::etl_previous == &data1); - CHECK(data0.SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); - etl::unlink(data2); - data2.SecondBLink::clear(); + etl::unlink(data2); + data2.BLink1::clear(); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == &data2); - CHECK(data1.FirstBLink::etl_previous == nullptr); - CHECK(data1.FirstBLink::etl_next == nullptr); - CHECK(data2.FirstBLink::etl_previous == &data0); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == &data2); + CHECK(data1.BLink0::etl_previous == nullptr); + CHECK(data1.BLink0::etl_next == nullptr); + CHECK(data2.BLink0::etl_previous == &data0); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == nullptr); - CHECK(data3.SecondBLink::etl_previous == nullptr); - CHECK(data3.SecondBLink::etl_next == &data1); - CHECK(data2.SecondBLink::etl_previous == nullptr); - CHECK(data2.SecondBLink::etl_next == nullptr); - CHECK(data1.SecondBLink::etl_previous == &data3); - CHECK(data1.SecondBLink::etl_next == &data0); - CHECK(data0.SecondBLink::etl_previous == &data1); - CHECK(data0.SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data1); + CHECK(data2.BLink1::etl_previous == nullptr); + CHECK(data2.BLink1::etl_next == nullptr); + CHECK(data1.BLink1::etl_previous == &data3); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); - etl::unlink(data0); - data0.FirstBLink::clear(); + etl::unlink(data0); + data0.BLink0::clear(); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == nullptr); - CHECK(data1.FirstBLink::etl_previous == nullptr); - CHECK(data1.FirstBLink::etl_next == nullptr); - CHECK(data2.FirstBLink::etl_previous == nullptr); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == nullptr); + CHECK(data1.BLink0::etl_previous == nullptr); + CHECK(data1.BLink0::etl_next == nullptr); + CHECK(data2.BLink0::etl_previous == nullptr); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == nullptr); - CHECK(data3.SecondBLink::etl_previous == nullptr); - CHECK(data3.SecondBLink::etl_next == &data1); - CHECK(data2.SecondBLink::etl_previous == nullptr); - CHECK(data2.SecondBLink::etl_next == nullptr); - CHECK(data1.SecondBLink::etl_previous == &data3); - CHECK(data1.SecondBLink::etl_next == &data0); - CHECK(data0.SecondBLink::etl_previous == &data1); - CHECK(data0.SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data1); + CHECK(data2.BLink1::etl_previous == nullptr); + CHECK(data2.BLink1::etl_next == nullptr); + CHECK(data1.BLink1::etl_previous == &data3); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); - etl::unlink(data3); - data3.SecondBLink::clear(); + etl::unlink(data3); + data3.BLink1::clear(); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == nullptr); - CHECK(data1.FirstBLink::etl_previous == nullptr); - CHECK(data1.FirstBLink::etl_next == nullptr); - CHECK(data2.FirstBLink::etl_previous == nullptr); - CHECK(data2.FirstBLink::etl_next == &data3); - CHECK(data3.FirstBLink::etl_previous == &data2); - CHECK(data3.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == nullptr); + CHECK(data1.BLink0::etl_previous == nullptr); + CHECK(data1.BLink0::etl_next == nullptr); + CHECK(data2.BLink0::etl_previous == nullptr); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == nullptr); - CHECK(data3.SecondBLink::etl_previous == nullptr); - CHECK(data3.SecondBLink::etl_next == nullptr); - CHECK(data2.SecondBLink::etl_previous == nullptr); - CHECK(data2.SecondBLink::etl_next == nullptr); - CHECK(data1.SecondBLink::etl_previous == nullptr); - CHECK(data1.SecondBLink::etl_next == &data0); - CHECK(data0.SecondBLink::etl_previous == &data1); - CHECK(data0.SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == nullptr); + CHECK(data2.BLink1::etl_previous == nullptr); + CHECK(data2.BLink1::etl_next == nullptr); + CHECK(data1.BLink1::etl_previous == nullptr); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); } //************************************************************************* @@ -818,55 +760,55 @@ namespace BData data2(2); BData data3(3); - etl::link(nullptr, data0); - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + etl::link(nullptr, data0); + etl::link(data0, data1); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); - etl::link(nullptr, data3); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(nullptr, data3); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); - etl::unlink(data1, data2); - data1.FirstBLink::clear(); - data2.FirstBLink::clear(); + etl::unlink(data1, data2); + data1.BLink0::clear(); + data2.BLink0::clear(); - CHECK(data0.FirstBLink::etl_previous == nullptr); - CHECK(data0.FirstBLink::etl_next == &data3); - CHECK(data1.FirstBLink::etl_previous == nullptr); - CHECK(data1.FirstBLink::etl_next == nullptr); - CHECK(data2.FirstBLink::etl_previous == nullptr); - CHECK(data2.FirstBLink::etl_next == nullptr); - CHECK(data3.FirstBLink::etl_previous == &data0); - CHECK(data3.FirstBLink::etl_next == nullptr); + CHECK(data0.BLink0::etl_previous == nullptr); + CHECK(data0.BLink0::etl_next == &data3); + CHECK(data1.BLink0::etl_previous == nullptr); + CHECK(data1.BLink0::etl_next == nullptr); + CHECK(data2.BLink0::etl_previous == nullptr); + CHECK(data2.BLink0::etl_next == nullptr); + CHECK(data3.BLink0::etl_previous == &data0); + CHECK(data3.BLink0::etl_next == nullptr); - CHECK(data3.SecondBLink::etl_previous == nullptr); - CHECK(data3.SecondBLink::etl_next == &data2); - CHECK(data2.SecondBLink::etl_previous == &data3); - CHECK(data2.SecondBLink::etl_next == &data1); - CHECK(data1.SecondBLink::etl_previous == &data2); - CHECK(data1.SecondBLink::etl_next == &data0); - CHECK(data0.SecondBLink::etl_previous == &data1); - CHECK(data0.SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); } - + //************************************************************************* TEST(test_self_link_bidirectional_link) { BData data0(0); - etl::link(data0, data0); + etl::link(data0, data0); - CHECK(data0.FirstBLink::etl_previous == &data0); - CHECK(data0.FirstBLink::etl_next == &data0); + CHECK(data0.BLink0::etl_previous == &data0); + CHECK(data0.BLink0::etl_next == &data0); - etl::unlink(data0); + etl::unlink(data0); - CHECK(data0.FirstBLink::etl_previous == &data0); - CHECK(data0.FirstBLink::etl_next == &data0); + CHECK(data0.BLink0::etl_previous == &data0); + CHECK(data0.BLink0::etl_next == &data0); } //************************************************************************* @@ -881,114 +823,114 @@ namespace TData data6(6); // First link - data0.FirstTLink::clear(); - etl::link_left(data0, data1); - etl::link_right(data0, data2); - CHECK(data0.FirstTLink::etl_left == &data1); - CHECK(data0.FirstTLink::etl_right == &data2); - CHECK(data1.FirstTLink::etl_parent == &data0); - CHECK(data2.FirstTLink::etl_parent == &data0); + data0.TLink0::clear(); + etl::link_left(data0, data1); + etl::link_right(data0, data2); + CHECK(data0.TLink0::etl_left == &data1); + CHECK(data0.TLink0::etl_right == &data2); + CHECK(data1.TLink0::etl_parent == &data0); + CHECK(data2.TLink0::etl_parent == &data0); - data0.FirstTLink::clear(); - etl::link_left(&data0, data1); - etl::link_right(&data0, data2); - CHECK(data0.FirstTLink::etl_left == &data1); - CHECK(data0.FirstTLink::etl_right == &data2); - CHECK(data1.FirstTLink::etl_parent == &data0); - CHECK(data2.FirstTLink::etl_parent == &data0); + data0.TLink0::clear(); + etl::link_left(&data0, data1); + etl::link_right(&data0, data2); + CHECK(data0.TLink0::etl_left == &data1); + CHECK(data0.TLink0::etl_right == &data2); + CHECK(data1.TLink0::etl_parent == &data0); + CHECK(data2.TLink0::etl_parent == &data0); - data0.FirstTLink::clear(); - etl::link_left(data0, &data1); - etl::link_right(data0, &data2); - CHECK(data0.FirstTLink::etl_left == &data1); - CHECK(data0.FirstTLink::etl_right == &data2); - CHECK(data1.FirstTLink::etl_parent == &data0); - CHECK(data2.FirstTLink::etl_parent == &data0); + data0.TLink0::clear(); + etl::link_left(data0, &data1); + etl::link_right(data0, &data2); + CHECK(data0.TLink0::etl_left == &data1); + CHECK(data0.TLink0::etl_right == &data2); + CHECK(data1.TLink0::etl_parent == &data0); + CHECK(data2.TLink0::etl_parent == &data0); - data0.FirstTLink::clear(); - etl::link_left(&data0, &data1); - etl::link_right(&data0, &data2); + data0.TLink0::clear(); + etl::link_left(&data0, &data1); + etl::link_right(&data0, &data2); - etl::link_left(data1, data3); - etl::link_right(data1, data4); - etl::link_left(data3, nullptr); - etl::link_right(data3, nullptr); - etl::link_left(data4, nullptr); - etl::link_right(data4, nullptr); + etl::link_left(data1, data3); + etl::link_right(data1, data4); + etl::link_left(data3, nullptr); + etl::link_right(data3, nullptr); + etl::link_left(data4, nullptr); + etl::link_right(data4, nullptr); - etl::link_left(data2, data5); - etl::link_right(data2, data6); - etl::link_left(data5, nullptr); - etl::link_right(data5, nullptr); - etl::link_left(data6, nullptr); - etl::link_right(data6, nullptr); + etl::link_left(data2, data5); + etl::link_right(data2, data6); + etl::link_left(data5, nullptr); + etl::link_right(data5, nullptr); + etl::link_left(data6, nullptr); + etl::link_right(data6, nullptr); // Second link - data0.SecondTLink::clear(); - etl::link_left(&data6, &data4); - etl::link_right(&data6, &data5); + data0.TLink1::clear(); + etl::link_left(&data6, &data4); + etl::link_right(&data6, &data5); - etl::link_left(data4, data0); - etl::link_right(data4, data1); - etl::link_left(data0, nullptr); - etl::link_right(data0, nullptr); - etl::link_left(data1, nullptr); - etl::link_right(data1, nullptr); + etl::link_left(data4, data0); + etl::link_right(data4, data1); + etl::link_left(data0, nullptr); + etl::link_right(data0, nullptr); + etl::link_left(data1, nullptr); + etl::link_right(data1, nullptr); - etl::link_left(data5, data2); - etl::link_right(data5, data3); - etl::link_left(data2, nullptr); - etl::link_right(data2, nullptr); - etl::link_left(data3, nullptr); - etl::link_right(data3, nullptr); + etl::link_left(data5, data2); + etl::link_right(data5, data3); + etl::link_left(data2, nullptr); + etl::link_right(data2, nullptr); + etl::link_left(data3, nullptr); + etl::link_right(data3, nullptr); // Check first - CHECK(data0.FirstTLink::etl_left == &data1); - CHECK(data0.FirstTLink::etl_right == &data2); - CHECK(data1.FirstTLink::etl_parent == &data0); - CHECK(data2.FirstTLink::etl_parent == &data0); + CHECK(data0.TLink0::etl_left == &data1); + CHECK(data0.TLink0::etl_right == &data2); + CHECK(data1.TLink0::etl_parent == &data0); + CHECK(data2.TLink0::etl_parent == &data0); - CHECK(data1.FirstTLink::etl_left == &data3); - CHECK(data1.FirstTLink::etl_right == &data4); - CHECK(data3.FirstTLink::etl_parent == &data1); - CHECK(data3.FirstTLink::etl_left == nullptr); - CHECK(data3.FirstTLink::etl_right == nullptr); - CHECK(data4.FirstTLink::etl_parent == &data1); - CHECK(data4.FirstTLink::etl_left == nullptr); - CHECK(data4.FirstTLink::etl_right == nullptr); + CHECK(data1.TLink0::etl_left == &data3); + CHECK(data1.TLink0::etl_right == &data4); + CHECK(data3.TLink0::etl_parent == &data1); + CHECK(data3.TLink0::etl_left == nullptr); + CHECK(data3.TLink0::etl_right == nullptr); + CHECK(data4.TLink0::etl_parent == &data1); + CHECK(data4.TLink0::etl_left == nullptr); + CHECK(data4.TLink0::etl_right == nullptr); - CHECK(data2.FirstTLink::etl_left == &data5); - CHECK(data2.FirstTLink::etl_right == &data6); - CHECK(data5.FirstTLink::etl_parent == &data2); - CHECK(data5.FirstTLink::etl_left == nullptr); - CHECK(data5.FirstTLink::etl_right == nullptr); - CHECK(data6.FirstTLink::etl_parent == &data2); - CHECK(data6.FirstTLink::etl_left == nullptr); - CHECK(data6.FirstTLink::etl_right == nullptr); + CHECK(data2.TLink0::etl_left == &data5); + CHECK(data2.TLink0::etl_right == &data6); + CHECK(data5.TLink0::etl_parent == &data2); + CHECK(data5.TLink0::etl_left == nullptr); + CHECK(data5.TLink0::etl_right == nullptr); + CHECK(data6.TLink0::etl_parent == &data2); + CHECK(data6.TLink0::etl_left == nullptr); + CHECK(data6.TLink0::etl_right == nullptr); // Check second - CHECK(data6.SecondTLink::etl_left == &data4); - CHECK(data6.SecondTLink::etl_right == &data5); - CHECK(data4.SecondTLink::etl_parent == &data6); - CHECK(data5.SecondTLink::etl_parent == &data6); - - CHECK(data4.SecondTLink::etl_left == &data0); - CHECK(data4.SecondTLink::etl_right == &data1); - CHECK(data0.SecondTLink::etl_parent == &data4); - CHECK(data0.SecondTLink::etl_left == nullptr); - CHECK(data0.SecondTLink::etl_right == nullptr); - CHECK(data1.SecondTLink::etl_parent == &data4); - CHECK(data1.SecondTLink::etl_left == nullptr); - CHECK(data1.SecondTLink::etl_right == nullptr); + CHECK(data6.TLink1::etl_left == &data4); + CHECK(data6.TLink1::etl_right == &data5); + CHECK(data4.TLink1::etl_parent == &data6); + CHECK(data5.TLink1::etl_parent == &data6); - CHECK(data5.SecondTLink::etl_left == &data2); - CHECK(data5.SecondTLink::etl_right == &data3); - CHECK(data2.SecondTLink::etl_parent == &data5); - CHECK(data2.SecondTLink::etl_left == nullptr); - CHECK(data2.SecondTLink::etl_right == nullptr); - CHECK(data3.SecondTLink::etl_parent == &data5); - CHECK(data3.SecondTLink::etl_left == nullptr); - CHECK(data3.SecondTLink::etl_right == nullptr); + CHECK(data4.TLink1::etl_left == &data0); + CHECK(data4.TLink1::etl_right == &data1); + CHECK(data0.TLink1::etl_parent == &data4); + CHECK(data0.TLink1::etl_left == nullptr); + CHECK(data0.TLink1::etl_right == nullptr); + CHECK(data1.TLink1::etl_parent == &data4); + CHECK(data1.TLink1::etl_left == nullptr); + CHECK(data1.TLink1::etl_right == nullptr); + + CHECK(data5.TLink1::etl_left == &data2); + CHECK(data5.TLink1::etl_right == &data3); + CHECK(data2.TLink1::etl_parent == &data5); + CHECK(data2.TLink1::etl_left == nullptr); + CHECK(data2.TLink1::etl_right == nullptr); + CHECK(data3.TLink1::etl_parent == &data5); + CHECK(data3.TLink1::etl_left == nullptr); + CHECK(data3.TLink1::etl_right == nullptr); } //************************************************************************* @@ -996,51 +938,51 @@ namespace { // Forward link FData fdata(0); - - fdata.FirstFLink::clear(); - fdata.SecondFLink::clear(); - CHECK(!fdata.FirstFLink::is_linked()); - CHECK(!fdata.SecondFLink::is_linked()); - etl::link(fdata, fdata); - CHECK(fdata.FirstFLink::is_linked()); - CHECK(!fdata.SecondFLink::is_linked()); + fdata.FLink0::clear(); + fdata.FLink1::clear(); + CHECK(!fdata.FLink0::is_linked()); + CHECK(!fdata.FLink1::is_linked()); - etl::link(fdata, fdata); - CHECK(fdata.FirstFLink::is_linked()); - CHECK(fdata.SecondFLink::is_linked()); + etl::link(fdata, fdata); + CHECK(fdata.FLink0::is_linked()); + CHECK(!fdata.FLink1::is_linked()); + + etl::link(fdata, fdata); + CHECK(fdata.FLink0::is_linked()); + CHECK(fdata.FLink1::is_linked()); // Bidirectional link BData bdata(0); - bdata.FirstBLink::clear(); - bdata.SecondBLink::clear(); - CHECK(!bdata.FirstBLink::is_linked()); - CHECK(!bdata.SecondBLink::is_linked()); + bdata.BLink0::clear(); + bdata.BLink1::clear(); + CHECK(!bdata.BLink0::is_linked()); + CHECK(!bdata.BLink1::is_linked()); - etl::link(bdata, bdata); - CHECK(bdata.FirstBLink::is_linked()); - CHECK(!bdata.SecondBLink::is_linked()); + etl::link(bdata, bdata); + CHECK(bdata.BLink0::is_linked()); + CHECK(!bdata.BLink1::is_linked()); - etl::link(bdata, bdata); - CHECK(bdata.FirstBLink::is_linked()); - CHECK(bdata.SecondBLink::is_linked()); + etl::link(bdata, bdata); + CHECK(bdata.BLink0::is_linked()); + CHECK(bdata.BLink1::is_linked()); // Tree link TData tdata(0); - tdata.FirstTLink::clear(); - tdata.SecondTLink::clear(); - CHECK(!tdata.FirstTLink::is_linked()); - CHECK(!tdata.SecondTLink::is_linked()); + tdata.TLink0::clear(); + tdata.TLink1::clear(); + CHECK(!tdata.TLink0::is_linked()); + CHECK(!tdata.TLink1::is_linked()); - etl::link_left(tdata, tdata); - CHECK(tdata.FirstTLink::is_linked()); - CHECK(!tdata.SecondTLink::is_linked()); + etl::link_left(tdata, tdata); + CHECK(tdata.TLink0::is_linked()); + CHECK(!tdata.TLink1::is_linked()); - etl::link_right(tdata, tdata); - CHECK(tdata.FirstTLink::is_linked()); - CHECK(tdata.SecondTLink::is_linked()); + etl::link_right(tdata, tdata); + CHECK(tdata.TLink0::is_linked()); + CHECK(tdata.TLink1::is_linked()); } //************************************************************************* @@ -1055,72 +997,198 @@ namespace MData data6(6); // Forward - data0.FirstFLink::clear(); - etl::link(data0, data1); - etl::link(data1, data2); - etl::link(data2, data3); - etl::link(data3, nullptr); + data0.FLink0::clear(); + etl::link(data0, data1); + etl::link(data1, data2); + etl::link(data2, data3); + etl::link(data3, nullptr); // Bidirectional - etl::link(nullptr, data3); - etl::link(data3, data2); - etl::link(data2, data1); - etl::link(data1, data0); - etl::link(data0, nullptr); + etl::link(nullptr, data3); + etl::link(data3, data2); + etl::link(data2, data1); + etl::link(data1, data0); + etl::link(data0, nullptr); // Tree - data0.ThirdTLink::clear(); - etl::link_left(data0, data1); - etl::link_right(data0, data2); - etl::link_left(data1, data3); - etl::link_right(data1, data4); - etl::link_left(data3, nullptr); - etl::link_right(data3, nullptr); - etl::link_left(data4, nullptr); - etl::link_right(data4, nullptr); - etl::link_left(data2, data5); - etl::link_right(data2, data6); - etl::link_left(data5, nullptr); - etl::link_right(data5, nullptr); - etl::link_left(data6, nullptr); - etl::link_right(data6, nullptr); + data0.TLink2::clear(); + etl::link_left(data0, data1); + etl::link_right(data0, data2); + etl::link_left(data1, data3); + etl::link_right(data1, data4); + etl::link_left(data3, nullptr); + etl::link_right(data3, nullptr); + etl::link_left(data4, nullptr); + etl::link_right(data4, nullptr); + etl::link_left(data2, data5); + etl::link_right(data2, data6); + etl::link_left(data5, nullptr); + etl::link_right(data5, nullptr); + etl::link_left(data6, nullptr); + etl::link_right(data6, nullptr); - CHECK(data0.FirstFLink::etl_next == &data1); - CHECK(data1.FirstFLink::etl_next == &data2); - CHECK(data2.FirstFLink::etl_next == &data3); - CHECK(data3.FirstFLink::etl_next == nullptr); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == nullptr); - CHECK(data3.SecondBLink::etl_previous == nullptr); - CHECK(data3.SecondBLink::etl_next == &data2); - CHECK(data2.SecondBLink::etl_previous == &data3); - CHECK(data2.SecondBLink::etl_next == &data1); - CHECK(data1.SecondBLink::etl_previous == &data2); - CHECK(data1.SecondBLink::etl_next == &data0); - CHECK(data0.SecondBLink::etl_previous == &data1); - CHECK(data0.SecondBLink::etl_next == nullptr); + CHECK(data3.BLink1::etl_previous == nullptr); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == nullptr); - CHECK(data0.ThirdTLink::etl_left == &data1); - CHECK(data0.ThirdTLink::etl_right == &data2); - CHECK(data1.ThirdTLink::etl_parent == &data0); - CHECK(data2.ThirdTLink::etl_parent == &data0); + CHECK(data0.TLink2::etl_left == &data1); + CHECK(data0.TLink2::etl_right == &data2); + CHECK(data1.TLink2::etl_parent == &data0); + CHECK(data2.TLink2::etl_parent == &data0); - CHECK(data1.ThirdTLink::etl_left == &data3); - CHECK(data1.ThirdTLink::etl_right == &data4); - CHECK(data3.ThirdTLink::etl_parent == &data1); - CHECK(data3.ThirdTLink::etl_left == nullptr); - CHECK(data3.ThirdTLink::etl_right == nullptr); - CHECK(data4.ThirdTLink::etl_parent == &data1); - CHECK(data4.ThirdTLink::etl_left == nullptr); - CHECK(data4.ThirdTLink::etl_right == nullptr); + CHECK(data1.TLink2::etl_left == &data3); + CHECK(data1.TLink2::etl_right == &data4); + CHECK(data3.TLink2::etl_parent == &data1); + CHECK(data3.TLink2::etl_left == nullptr); + CHECK(data3.TLink2::etl_right == nullptr); + CHECK(data4.TLink2::etl_parent == &data1); + CHECK(data4.TLink2::etl_left == nullptr); + CHECK(data4.TLink2::etl_right == nullptr); - CHECK(data2.ThirdTLink::etl_left == &data5); - CHECK(data2.ThirdTLink::etl_right == &data6); - CHECK(data5.ThirdTLink::etl_parent == &data2); - CHECK(data5.ThirdTLink::etl_left == nullptr); - CHECK(data5.ThirdTLink::etl_right == nullptr); - CHECK(data6.ThirdTLink::etl_parent == &data2); - CHECK(data6.ThirdTLink::etl_left == nullptr); - CHECK(data6.ThirdTLink::etl_right == nullptr); + CHECK(data2.TLink2::etl_left == &data5); + CHECK(data2.TLink2::etl_right == &data6); + CHECK(data5.TLink2::etl_parent == &data2); + CHECK(data5.TLink2::etl_left == nullptr); + CHECK(data5.TLink2::etl_right == nullptr); + CHECK(data6.TLink2::etl_parent == &data2); + CHECK(data6.TLink2::etl_left == nullptr); + CHECK(data6.TLink2::etl_right == nullptr); + } + + //************************************************************************* + TEST(test_tree_link_rotate_left) + { + TLink0 r; + TLink0 a; + TLink0 b; + TLink0 c; + TLink0 d; + TLink0 e; + + r.clear(); + c.clear(); + d.clear(); + e.clear(); + etl::link_left(r, b); + etl::link_right(b, a); + etl::link_left(b, d); + etl::link_right(a, c); + etl::link_left(a, e); + + etl::link_rotate_left(b, a); + + CHECK(a.etl_parent == &r); + CHECK(b.etl_parent == &a); + CHECK(e.etl_parent == &b); + CHECK(d.etl_parent == &b); + CHECK(c.etl_parent == &a); + CHECK(a.etl_left == &b); + CHECK(a.etl_right == &c); + CHECK(b.etl_left == &d); + CHECK(b.etl_right == &e); + } + + //************************************************************************* + TEST(test_tree_link_rotate_left_nullptr) + { + TLink0 r; + TLink0 a; + TLink0 b; + TLink0 c; + TLink0 d; + + r.clear(); + a.clear(); + c.clear(); + d.clear(); + etl::link_left(r, b); + etl::link_right(b, a); + etl::link_left(b, d); + etl::link_right(a, c); + + etl::link_rotate_left(b, a); + + CHECK(a.etl_parent == &r); + CHECK(b.etl_parent == &a); + CHECK(d.etl_parent == &b); + CHECK(c.etl_parent == &a); + CHECK(a.etl_left == &b); + CHECK(a.etl_right == &c); + CHECK(b.etl_left == &d); + CHECK(b.etl_right == nullptr); + } + + //************************************************************************* + TEST(test_tree_link_rotate_right) + { + TLink0 r; + TLink0 a; + TLink0 b; + TLink0 c; + TLink0 d; + TLink0 e; + + r.clear(); + c.clear(); + d.clear(); + e.clear(); + etl::link_left(r, a); + etl::link_left(a, b); + etl::link_left(b, d); + etl::link_right(a, c); + etl::link_right(b, e); + + etl::link_rotate_right(a, b); + + CHECK(b.etl_parent == &r); + CHECK(d.etl_parent == &b); + CHECK(a.etl_parent == &b); + CHECK(e.etl_parent == &a); + CHECK(c.etl_parent == &a); + CHECK(b.etl_left == &d); + CHECK(b.etl_right == &a); + CHECK(a.etl_left == &e); + CHECK(a.etl_right == &c); + } + + //************************************************************************* + TEST(test_tree_link_rotate_right_nullptr) + { + TLink0 r; + TLink0 a; + TLink0 b; + TLink0 c; + TLink0 d; + + r.clear(); + b.clear(); + c.clear(); + d.clear(); + etl::link_left(r, a); + etl::link_left(a, b); + etl::link_left(b, d); + etl::link_right(a, c); + + etl::link_rotate_right(a, b); + + CHECK(b.etl_parent == &r); + CHECK(d.etl_parent == &b); + CHECK(a.etl_parent == &b); + CHECK(c.etl_parent == &a); + CHECK(b.etl_left == &d); + CHECK(b.etl_right == &a); + CHECK(a.etl_left == nullptr); + CHECK(a.etl_right == &c); } }; } diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index d7c16ff8..34b3ca54 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -84,25 +84,25 @@ namespace }; //*************************************************************************** - bool operator ==(const ItemDCNode& lhs, const ItemDCNode& rhs) - { - return lhs.data == rhs.data; - } +// bool operator ==(const ItemDCNode& lhs, const ItemDCNode& rhs) +// { +// return lhs.data == rhs.data; +// } bool operator ==(const ItemNDCNode& lhs, const ItemNDCNode& rhs) { return lhs.data == rhs.data; } - bool operator !=(const ItemDCNode& lhs, const ItemDCNode& rhs) - { - return lhs.data != rhs.data; - } +// bool operator !=(const ItemDCNode& lhs, const ItemDCNode& rhs) +// { +// return lhs.data != rhs.data; +// } - bool operator !=(const ItemNDCNode& lhs, const ItemNDCNode& rhs) - { - return lhs.data != rhs.data; - } +// bool operator !=(const ItemNDCNode& lhs, const ItemNDCNode& rhs) +// { +// return lhs.data != rhs.data; +// } std::ostream& operator << (std::ostream& os, const ItemNDCNode& node) { @@ -136,10 +136,10 @@ namespace typedef std::vector InitialDataNDC; } -namespace -{ +namespace +{ SUITE(test_intrusive_list) - { + { InitialDataNDC unsorted_data; InitialDataNDC sorted_data; InitialDataNDC sorted_data2; @@ -151,7 +151,7 @@ namespace InitialDataNDC merge_data2; InitialDataNDC merge_data3; InitialDataNDC merge_data4; - + //************************************************************************* struct SetupFixture { @@ -200,11 +200,11 @@ namespace DataNDC0 data0; CHECK(data0.begin() == data0.end()); - + DataNDC0::const_iterator begin = data0.begin(); DataNDC0::const_iterator end = data0.end(); CHECK(begin == end); - + CHECK(data0.cbegin() == data0.cend()); } @@ -224,7 +224,7 @@ namespace TEST_FIXTURE(SetupFixture, test_const_iterator) { bool are_equal; - + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); are_equal = std::equal(data0.cbegin(), data0.cend(), sorted_data.begin()); @@ -282,7 +282,7 @@ namespace std::list compare0; std::list compare1; - + DataNDC0 data0; DataNDC1 data1; @@ -301,7 +301,7 @@ namespace compare0.push_front(node4); compare0.push_front(node6); compare0.push_front(node7); - + data0.push_front(node0); data0.push_front(node1); data0.push_front(node2); @@ -311,7 +311,7 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(6, data0.size()); + CHECK_EQUAL(6U, data0.size()); CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); compare1.push_front(node0); @@ -330,7 +330,7 @@ namespace are_equal = std::equal(data1.begin(), data1.end(), compare1.begin()); CHECK(are_equal); - CHECK_EQUAL(6, data1.size()); + CHECK_EQUAL(6U, data1.size()); CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); } @@ -360,12 +360,12 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); offset = 0; @@ -385,12 +385,12 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -414,7 +414,7 @@ namespace are_equal = std::equal(data1.begin(), data1.end(), test1.begin()); CHECK(are_equal); CHECK_EQUAL(test1.size(), data1.size()); - CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(test1.size(), size_t(std::distance(data1.begin(), data1.end()))); compare.assign(test1.begin(), test1.end()); data0.assign(test1.begin(), test1.end()); @@ -437,7 +437,7 @@ namespace are_equal = std::equal(data1.begin(), data1.end(), test1.begin()); CHECK(are_equal); CHECK_EQUAL(test1.size(), data1.size()); - CHECK_EQUAL(test1.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(test1.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -471,7 +471,7 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); - CHECK_EQUAL(6, data0.size()); + CHECK_EQUAL(6U, data0.size()); CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); } @@ -502,7 +502,7 @@ namespace data1.push_front(node5); data1.push_front(node6); - CHECK_EQUAL(6, data0.size()); + CHECK_EQUAL(6U, data0.size()); CHECK_EQUAL(6, std::distance(data0.begin(), data0.end())); CHECK(!data0.empty()); @@ -512,17 +512,17 @@ namespace data0.pop_front(); data0.pop_front(); - CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(1U, data0.size()); CHECK_EQUAL(1, std::distance(data0.begin(), data0.end())); CHECK(!data0.empty()); data0.pop_front(); - CHECK_EQUAL(0, data0.size()); + CHECK_EQUAL(0U, data0.size()); CHECK_EQUAL(0, std::distance(data0.begin(), data0.end())); CHECK(data0.empty()); - CHECK_EQUAL(6, data1.size()); + CHECK_EQUAL(6U, data1.size()); CHECK_EQUAL(6, std::distance(data1.begin(), data1.end())); CHECK(!data1.empty()); } @@ -557,12 +557,12 @@ namespace CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); are_equal = *i_data == *i_compare_data; CHECK(are_equal); @@ -578,12 +578,12 @@ namespace CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); are_equal = *i_data == *i_compare_data; CHECK(are_equal); @@ -619,12 +619,12 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -651,12 +651,12 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -691,13 +691,13 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), unique_data.begin()); CHECK(are_equal); CHECK_EQUAL(unique_data.size(), data0.size()); - CHECK_EQUAL(unique_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(unique_data.size(), size_t(std::distance(data0.begin(), data0.end()))); // data1 should not have changed. are_equal = std::equal(data1.begin(), data1.end(), non_unique_data.begin()); CHECK(are_equal); CHECK_EQUAL(non_unique_data.size(), data1.size()); - CHECK_EQUAL(non_unique_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(non_unique_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -717,12 +717,12 @@ namespace CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -742,12 +742,12 @@ namespace CHECK(are_equal); CHECK_EQUAL(compare_data.size(), data0.size()); - CHECK_EQUAL(compare_data.size(), std::distance(data0.begin(), data0.end())); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); CHECK(are_equal); CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), std::distance(data1.begin(), data1.end())); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } //************************************************************************* @@ -899,13 +899,9 @@ namespace DataNDC0::iterator idata_destination = data0.begin(); std::advance(idata_destination, 3); - std::list compare0(data0.begin(), data0.end()); - - std::list::iterator icompare_destination = compare0.begin(); - std::advance(icompare_destination, 3); + std::list compare0(sorted_data2.begin(), sorted_data2.end()); data0.splice(idata_destination, data0); - compare0.splice(icompare_destination, compare0); are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); diff --git a/test/test_intrusive_stack.cpp b/test/test_intrusive_stack.cpp index cec894da..da4da4ba 100644 --- a/test/test_intrusive_stack.cpp +++ b/test/test_intrusive_stack.cpp @@ -35,19 +35,10 @@ SOFTWARE. namespace { - enum - { - DEFAULT, - AUTO, - CHECKED - }; + typedef etl::forward_link<0> link0; + typedef etl::bidirectional_link<1> link1; - etl::forward_link link; - - typedef etl::forward_link default_link; - typedef etl::forward_link checked_link; - - struct Data : public default_link, public checked_link + struct Data : public link0, public link1 { Data(int i) : i(i) @@ -79,25 +70,25 @@ namespace //************************************************************************* TEST(test_constructor) { - etl::intrusive_stack stackD; - etl::intrusive_stack stackC; + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; CHECK(stackD.empty()); CHECK(stackC.empty()); - CHECK_EQUAL(0, stackD.size()); - CHECK_EQUAL(0, stackC.size()); + CHECK_EQUAL(0U, stackD.size()); + CHECK_EQUAL(0U, stackC.size()); } //************************************************************************* TEST(test_empty) { - etl::intrusive_stack stackD; - etl::intrusive_stack stackC; - Data data1(1); Data data2(2); + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + CHECK(stackD.empty()); CHECK(stackC.empty()); @@ -106,21 +97,18 @@ namespace CHECK(!stackD.empty()); CHECK(!stackC.empty()); - - data1.checked_link::clear(); - data2.checked_link::clear(); } //************************************************************************* TEST(test_size) { - etl::intrusive_stack stackD; - etl::intrusive_stack stackC; - Data data1(1); Data data2(2); Data data3(3); + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + stackD.push(data1); stackD.push(data2); stackD.push(data3); @@ -130,21 +118,18 @@ namespace CHECK_EQUAL(3U, stackD.size()); CHECK_EQUAL(2U, stackC.size()); - - data1.checked_link::clear(); - data2.checked_link::clear(); } //************************************************************************* TEST(test_clear) { - etl::intrusive_stack stackD; - etl::intrusive_stack stackC; - Data data1(1); Data data2(2); Data data3(3); + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + stackD.push(data1); stackD.push(data2); stackD.push(data3); @@ -162,13 +147,13 @@ namespace //************************************************************************* TEST(test_push) { - etl::intrusive_stack stackD; - etl::intrusive_stack stackC; - Data data1(1); Data data2(2); Data data3(3); + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + stackD.push(data1); CHECK_EQUAL(stackD.top(), data1); @@ -183,22 +168,18 @@ namespace stackC.push(data2); CHECK_EQUAL(stackC.top(), data2); - - data1.checked_link::clear(); - data2.checked_link::clear(); } - //************************************************************************* TEST(test_pop) { - etl::intrusive_stack stackD; - etl::intrusive_stack stackC; - Data data1(1); Data data2(2); Data data3(3); + etl::intrusive_stack stackD; + etl::intrusive_stack stackC; + stackD.push(data1); stackD.push(data2); stackD.push(data3); @@ -219,21 +200,18 @@ namespace CHECK_EQUAL(stackC.top(), data1); stackC.pop(); CHECK(stackC.empty()); - - data1.checked_link::clear(); - data2.checked_link::clear(); } //************************************************************************* TEST(test_top_const) { - etl::intrusive_stack stackD; - const etl::intrusive_stack& stackDR = stackD; - Data data1(1); Data data2(2); Data data3(3); + etl::intrusive_stack stackD; + const etl::intrusive_stack& stackDR = stackD; + stackD.push(data1); stackD.push(data2); stackD.push(data3); From 4036d5db3cf4634ccd7052f7fdf4829a86c8da53 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:15:47 +0000 Subject: [PATCH 079/168] Removed redundant include --- src/intrusive_forward_list.h | 1 - src/intrusive_list.h | 1 - src/intrusive_queue.h | 1 - src/intrusive_stack.h | 1 - 4 files changed, 4 deletions(-) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 8acd26ed..43f07e05 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -48,7 +48,6 @@ SOFTWARE. #include "error_handler.h" #include "intrusive_links.h" #include "algorithm.h" -#include "private/counter_type.h" #undef ETL_FILE #define ETL_FILE "20" diff --git a/src/intrusive_list.h b/src/intrusive_list.h index 981a8d80..298c0ab3 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -49,7 +49,6 @@ SOFTWARE. #include "intrusive_links.h" #include "static_assert.h" #include "algorithm.h" -#include "private/counter_type.h" #undef ETL_FILE #define ETL_FILE "21" diff --git a/src/intrusive_queue.h b/src/intrusive_queue.h index efd77e41..e48111b9 100644 --- a/src/intrusive_queue.h +++ b/src/intrusive_queue.h @@ -36,7 +36,6 @@ SOFTWARE. #include "type_traits.h" #include "error_handler.h" #include "intrusive_links.h" -#include "private/counter_type.h" #define ETL_FILE "29" diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h index ffa61e72..cb358609 100644 --- a/src/intrusive_stack.h +++ b/src/intrusive_stack.h @@ -36,7 +36,6 @@ SOFTWARE. #include "type_traits.h" #include "error_handler.h" #include "intrusive_links.h" -#include "private/counter_type.h" #define ETL_FILE "28" From 37f4dac47d1833dcde68da920bafa588ede1a4f3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:17:45 +0000 Subject: [PATCH 080/168] Restored commented out tests --- test/test_instance_count.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/test_instance_count.cpp b/test/test_instance_count.cpp index 885963bc..5be67615 100644 --- a/test/test_instance_count.cpp +++ b/test/test_instance_count.cpp @@ -47,25 +47,25 @@ namespace struct Test2 : public etl::instance_count {}; - CHECK_EQUAL(0, Test1::get_instance_count()); - CHECK_EQUAL(0, Test2::get_instance_count()); + CHECK_EQUAL(0U, Test1::get_instance_count()); + CHECK_EQUAL(0U, Test2::get_instance_count()); - //Test1 test1a; - //CHECK_EQUAL(1, Test1::get_instance_count()); - //CHECK_EQUAL(0, Test2::get_instance_count()); + Test1 test1a; + CHECK_EQUAL(1U, Test1::get_instance_count()); + CHECK_EQUAL(0U, Test2::get_instance_count()); - //Test1 test1b; - //Test2 test2a; - //CHECK_EQUAL(2, Test1::get_instance_count()); - //CHECK_EQUAL(1, Test2::get_instance_count()); + Test1 test1b; + Test2 test2a; + CHECK_EQUAL(2U, Test1::get_instance_count()); + CHECK_EQUAL(1U, Test2::get_instance_count()); - //Test2* ptest2b = new Test2; - //CHECK_EQUAL(2, Test1::get_instance_count()); - //CHECK_EQUAL(2, Test2::get_instance_count()); + Test2* ptest2b = new Test2; + CHECK_EQUAL(2U, Test1::get_instance_count()); + CHECK_EQUAL(2U, Test2::get_instance_count()); - //delete ptest2b; - //CHECK_EQUAL(2, Test1::get_instance_count()); - //CHECK_EQUAL(1, Test2::get_instance_count()); + delete ptest2b; + CHECK_EQUAL(2U, Test1::get_instance_count()); + CHECK_EQUAL(1U, Test2::get_instance_count()); } }; -} \ No newline at end of file +} From 9e9fa45f1342d40d43e1ed11acec2b617af1f0e2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:18:05 +0000 Subject: [PATCH 081/168] Fixed GCC warnings --- test/test_fnv_1.cpp | 24 ++++++++++++------------ test/test_forward_list.cpp | 4 ++-- test/test_hash.cpp | 36 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/test_fnv_1.cpp b/test/test_fnv_1.cpp index 33b6ed67..8f8d4ccf 100644 --- a/test/test_fnv_1.cpp +++ b/test/test_fnv_1.cpp @@ -46,7 +46,7 @@ namespace uint32_t hash = etl::fnv_1_32(data.begin(), data.end()); - CHECK_EQUAL(0x24148816, hash); + CHECK_EQUAL(0x24148816U, hash); } //************************************************************************* @@ -63,7 +63,7 @@ namespace uint32_t hash = fnv_1_32_calculator.value(); - CHECK_EQUAL(0x24148816, hash); + CHECK_EQUAL(0x24148816U, hash); } //************************************************************************* @@ -77,7 +77,7 @@ namespace uint32_t hash = fnv_1_32_calculator.value(); - CHECK_EQUAL(0x24148816, hash); + CHECK_EQUAL(0x24148816U, hash); } //************************************************************************* @@ -102,7 +102,7 @@ namespace uint32_t hash = etl::fnv_1a_32(data.begin(), data.end()); - CHECK_EQUAL(0xBB86B11C, hash); + CHECK_EQUAL(0xBB86B11CU, hash); } //************************************************************************* @@ -119,7 +119,7 @@ namespace uint32_t hash = fnv_1a_32_calculator.value(); - CHECK_EQUAL(0xBB86B11C, hash); + CHECK_EQUAL(0xBB86B11CU, hash); } //************************************************************************* @@ -133,7 +133,7 @@ namespace uint32_t hash = fnv_1a_32_calculator.value(); - CHECK_EQUAL(0xBB86B11C, hash); + CHECK_EQUAL(0xBB86B11CU, hash); } //************************************************************************* @@ -158,7 +158,7 @@ namespace uint64_t hash = etl::fnv_1_64(data.begin(), data.end()); - CHECK_EQUAL(0xA72FFC362BF916D6, hash); + CHECK_EQUAL(0xA72FFC362BF916D6U, hash); } //************************************************************************* @@ -175,7 +175,7 @@ namespace uint64_t hash = fnv_1_64_calculator; - CHECK_EQUAL(0xA72FFC362BF916D6, hash); + CHECK_EQUAL(0xA72FFC362BF916D6U, hash); } //************************************************************************* @@ -189,7 +189,7 @@ namespace uint64_t hash = fnv_1_64_calculator.value(); - CHECK_EQUAL(0xA72FFC362BF916D6, hash); + CHECK_EQUAL(0xA72FFC362BF916D6U, hash); } //************************************************************************* @@ -214,7 +214,7 @@ namespace uint64_t hash = etl::fnv_1a_64(data.begin(), data.end()); - CHECK_EQUAL(0x06D5573923C6CDFC, hash); + CHECK_EQUAL(0x06D5573923C6CDFCU, hash); } //************************************************************************* @@ -231,7 +231,7 @@ namespace uint64_t hash = fnv_1a_64_calculator; - CHECK_EQUAL(0x06D5573923C6CDFC, hash); + CHECK_EQUAL(0x06D5573923C6CDFCU, hash); } //************************************************************************* @@ -245,7 +245,7 @@ namespace uint64_t hash = fnv_1a_64_calculator.value(); - CHECK_EQUAL(0x06D5573923C6CDFC, hash); + CHECK_EQUAL(0x06D5573923C6CDFCU, hash); } //************************************************************************* diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 45d35805..44911f72 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -423,7 +423,7 @@ namespace CHECK_NO_THROW(data.push_front(ItemNDC("5"))); CHECK_NO_THROW(data.push_front(ItemNDC("6"))); - CHECK_EQUAL(6, data.size()); + CHECK_EQUAL(6U, data.size()); CHECK_EQUAL(6, std::distance(data.begin(), data.end())); are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -457,7 +457,7 @@ namespace CHECK_NO_THROW(data.push_front()); data.front() = ItemNDC("6"); - CHECK_EQUAL(6, data.size()); + CHECK_EQUAL(6U, data.size()); CHECK_EQUAL(6, std::distance(data.begin(), data.end())); are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); diff --git a/test/test_hash.cpp b/test/test_hash.cpp index 53e50d70..d8e42e6b 100644 --- a/test/test_hash.cpp +++ b/test/test_hash.cpp @@ -43,10 +43,10 @@ namespace TEST(test_hash_bool) { size_t hash = etl::hash()(false); - CHECK_EQUAL(0, hash); + CHECK_EQUAL(0U, hash); hash = etl::hash()(true); - CHECK_EQUAL(1, hash); + CHECK_EQUAL(1U, hash); } //************************************************************************* @@ -54,7 +54,7 @@ namespace { size_t hash = etl::hash()((char)(0x5A)); - CHECK_EQUAL(0x5A, hash); + CHECK_EQUAL(0x5AU, hash); } //************************************************************************* @@ -62,7 +62,7 @@ namespace { size_t hash = etl::hash()((signed char)(0x5A)); - CHECK_EQUAL(0x5A, hash); + CHECK_EQUAL(0x5AU, hash); } //************************************************************************* @@ -70,7 +70,7 @@ namespace { size_t hash = etl::hash()((unsigned char)(0x5A)); - CHECK_EQUAL(0x5A, hash); + CHECK_EQUAL(0x5AU, hash); } //************************************************************************* @@ -78,7 +78,7 @@ namespace { size_t hash = etl::hash()((short)(0x5AA5)); - CHECK_EQUAL(0x5AA5, hash); + CHECK_EQUAL(0x5AA5U, hash); } //************************************************************************* @@ -86,7 +86,7 @@ namespace { size_t hash = etl::hash()((unsigned short)(0x5AA5)); - CHECK_EQUAL(0x5AA5, hash); + CHECK_EQUAL(0x5AA5U, hash); } //************************************************************************* @@ -94,7 +94,7 @@ namespace { size_t hash = etl::hash()((int)(0x5AA555AA)); - CHECK_EQUAL(0x5AA555AA, hash); + CHECK_EQUAL(0x5AA555AAU, hash); } //************************************************************************* @@ -102,7 +102,7 @@ namespace { size_t hash = etl::hash()((unsigned int)(0x5AA555AA)); - CHECK_EQUAL(0x5AA555AA, hash); + CHECK_EQUAL(0x5AA555AAU, hash); } //************************************************************************* @@ -110,7 +110,7 @@ namespace { size_t hash = etl::hash()((long)(0x5AA555AA)); - CHECK_EQUAL(0x5AA555AA, hash); + CHECK_EQUAL(0x5AA555AAU, hash); } //************************************************************************* @@ -118,7 +118,7 @@ namespace { size_t hash = etl::hash()((unsigned long)(0x5AA555AA)); - CHECK_EQUAL(0x5AA555AA, hash); + CHECK_EQUAL(0x5AA555AAU, hash); } //************************************************************************* @@ -127,9 +127,9 @@ namespace size_t hash = etl::hash()((long long)(0x5AA555AA3CC333CC)); if (sizeof(size_t) == sizeof(long long)) - CHECK_EQUAL(0x5AA555AA3CC333CC, hash); + CHECK_EQUAL(0x5AA555AA3CC333CCU, hash); else - CHECK_EQUAL(0xEC6A8D69, hash); + CHECK_EQUAL(0xEC6A8D69U, hash); } //************************************************************************* @@ -138,9 +138,9 @@ namespace size_t hash = etl::hash()((unsigned long long)(0x5AA555AA3CC333CC)); if (sizeof(size_t) == sizeof(unsigned long long)) - CHECK_EQUAL(0x5AA555AA3CC333CC, hash); + CHECK_EQUAL(0x5AA555AA3CC333CCU, hash); else - CHECK_EQUAL(0xEC6A8D69, hash); + CHECK_EQUAL(0xEC6A8D69U, hash); } //************************************************************************* @@ -148,7 +148,7 @@ namespace { size_t hash = etl::hash()((float)(1.2345)); - CHECK_EQUAL(0X3F9E0419, hash); + CHECK_EQUAL(0X3F9E0419U, hash); } //************************************************************************* @@ -157,9 +157,9 @@ namespace size_t hash = etl::hash()((double)(1.2345)); if (sizeof(size_t) == sizeof(double)) - CHECK_EQUAL(0X3FF3C083126E978D, hash); + CHECK_EQUAL(0X3FF3C083126E978DU, hash); else - CHECK_EQUAL(0x86FBF224, hash); + CHECK_EQUAL(0x86FBF224U, hash); } //************************************************************************* From a27ac63149208806a75ce3f62232c03e1012677d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:18:26 +0000 Subject: [PATCH 082/168] Removed redundant code --- test/test_exception.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/test_exception.cpp b/test/test_exception.cpp index 9d1854cc..c99816b4 100644 --- a/test/test_exception.cpp +++ b/test/test_exception.cpp @@ -40,10 +40,6 @@ namespace { etl::exception e("An exception", "Some file", 123); - std::string what(e.what()); - std::string file(e.file_name()); - int line(e.line_number()); - CHECK_EQUAL(std::string("An exception"), std::string(e.what())); CHECK_EQUAL(std::string("Some file"), std::string(e.file_name())); CHECK_EQUAL(123, e.line_number()); @@ -60,14 +56,10 @@ namespace } catch (etl::exception& c) { - std::string what(c.what()); - std::string file(c.file_name()); - int line(c.line_number()); - CHECK_EQUAL(std::string("An exception"), std::string(c.what())); CHECK_EQUAL(std::string("Some file"), std::string(c.file_name())); CHECK_EQUAL(123, c.line_number()); } } }; -} \ No newline at end of file +} From 0179e7123d0db759b5a008d511f5bb7d718ba94c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:19:37 +0000 Subject: [PATCH 083/168] Changed string length calls. --- test/test_bloom_filter.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/test_bloom_filter.cpp b/test/test_bloom_filter.cpp index 46341f12..eed634bb 100644 --- a/test/test_bloom_filter.cpp +++ b/test/test_bloom_filter.cpp @@ -28,8 +28,8 @@ SOFTWARE. #include -#include #include +#include #include "../src/bloom_filter.h" @@ -38,13 +38,15 @@ SOFTWARE. #include "../src/crc16_ccitt.h" #include "../src/crc32.h" +#include "../src/char_traits.h" + struct hash1_t { typedef const char* argument_type; size_t operator ()(argument_type text) const { - return etl::fnv_1a_32(text, text + strlen(text)); + return etl::fnv_1a_32(text, text + etl::char_traits::length(text)); } }; @@ -54,7 +56,7 @@ struct hash2_t size_t operator ()(argument_type text) const { - return etl::crc32(text, text + strlen(text)); + return etl::crc32(text, text + etl::char_traits::length(text)); } }; @@ -64,7 +66,7 @@ struct hash3_t size_t operator ()(argument_type text) const { - return etl::crc16(text, text + strlen(text)) | (etl::crc16_ccitt(text, text + strlen(text)) << 16); + return etl::crc16(text, text + etl::char_traits::length(text)) | (etl::crc16_ccitt(text, text + etl::char_traits::length(text)) << 16); } }; @@ -106,7 +108,7 @@ namespace CHECK(!any_exist); size_t usage = bloom.usage(); - CHECK(usage >= 0); + CHECK(usage > 0); CHECK(usage < 100); size_t count = bloom.count(); @@ -145,7 +147,6 @@ namespace CHECK(!any_exist); size_t usage = bloom.usage(); - CHECK(usage >= 0); CHECK(usage < 100); size_t count = bloom.count(); @@ -184,7 +185,6 @@ namespace CHECK(!any_exist); size_t usage = bloom.usage(); - CHECK(usage >= 0); CHECK(usage < 100); size_t count = bloom.count(); From 912cb40d0cf57b27e9197edd609d020e5b98b265 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:20:27 +0000 Subject: [PATCH 084/168] Fixed GCC warnings Removed redundant code --- test/test_bitset.cpp | 52 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/test/test_bitset.cpp b/test/test_bitset.cpp index a0ce46a4..6a863299 100644 --- a/test/test_bitset.cpp +++ b/test/test_bitset.cpp @@ -432,6 +432,8 @@ namespace bool bc = ~compare[3]; bool bd = ~data[3]; + CHECK_EQUAL(bc, bd); + for (size_t i = 0; i < data.size(); ++i) { CHECK_EQUAL(compare.test(i), data.test(i)); @@ -593,7 +595,7 @@ namespace etl::bitset<60> data2(0x23456789); etl::bitset<60> data3(0x12345678 & 0x23456789); - etl::bitset<60>& rdata = data2 &= data1; + data2 &= data1; CHECK(data2 == data3); } @@ -616,7 +618,7 @@ namespace etl::bitset<60> data2(0x23456789); etl::bitset<60> data3(0x12345678 | 0x23456789); - etl::bitset<60>& rdata = data2 |= data1; + data2 |= data1; CHECK(data2 == data3); } @@ -639,7 +641,7 @@ namespace etl::bitset<60> data2(0x23456789); etl::bitset<60> data3(0x12345678 ^ 0x23456789); - etl::bitset<60>& rdata = data2 ^= data1; + data2 ^= data1; CHECK(data2 == data3); } @@ -723,32 +725,32 @@ namespace etl::bitset<6> data; data.set("000000"); - CHECK_EQUAL(0, data.find_first(false)); + CHECK_EQUAL(0U, data.find_first(false)); CHECK_EQUAL(etl::ibitset::npos, data.find_first(true)); data.set("111111"); CHECK_EQUAL(etl::ibitset::npos, data.find_first(false)); - CHECK_EQUAL(0, data.find_first(true)); + CHECK_EQUAL(0U, data.find_first(true)); data.set("000001"); - CHECK_EQUAL(1, data.find_first(false)); - CHECK_EQUAL(0, data.find_first(true)); + CHECK_EQUAL(1U, data.find_first(false)); + CHECK_EQUAL(0U, data.find_first(true)); data.set("100000"); - CHECK_EQUAL(0, data.find_first(false)); - CHECK_EQUAL(5, data.find_first(true)); + CHECK_EQUAL(0U, data.find_first(false)); + CHECK_EQUAL(5U, data.find_first(true)); data.set("100001"); - CHECK_EQUAL(1, data.find_first(false)); - CHECK_EQUAL(0, data.find_first(true)); + CHECK_EQUAL(1U, data.find_first(false)); + CHECK_EQUAL(0U, data.find_first(true)); data.set("001110"); - CHECK_EQUAL(0, data.find_first(false)); - CHECK_EQUAL(1, data.find_first(true)); + CHECK_EQUAL(0U, data.find_first(false)); + CHECK_EQUAL(1U, data.find_first(true)); data.set("110001"); - CHECK_EQUAL(1, data.find_first(false)); - CHECK_EQUAL(0, data.find_first(true)); + CHECK_EQUAL(1U, data.find_first(false)); + CHECK_EQUAL(0U, data.find_first(true)); } //************************************************************************* @@ -757,24 +759,24 @@ namespace etl::bitset<6> data; data.set("000000"); - CHECK_EQUAL(0, data.find_next(false, 0)); - CHECK_EQUAL(1, data.find_next(false, 1)); + CHECK_EQUAL(0U, data.find_next(false, 0)); + CHECK_EQUAL(1U, data.find_next(false, 1)); CHECK_EQUAL(etl::ibitset::npos, data.find_next(true, 2)); data.set("111111"); - CHECK_EQUAL(0, data.find_next(true, 0)); - CHECK_EQUAL(1, data.find_next(true, 1)); + CHECK_EQUAL(0U, data.find_next(true, 0)); + CHECK_EQUAL(1U, data.find_next(true, 1)); CHECK_EQUAL(etl::ibitset::npos, data.find_next(false, 2)); data.set("001110"); - CHECK_EQUAL(0, data.find_next(false, 0)); - CHECK_EQUAL(1, data.find_next(true, 0)); - CHECK_EQUAL(4, data.find_next(false, 1)); + CHECK_EQUAL(0U, data.find_next(false, 0)); + CHECK_EQUAL(1U, data.find_next(true, 0)); + CHECK_EQUAL(4U, data.find_next(false, 1)); data.set("110001"); - CHECK_EQUAL(0, data.find_next(true, 0)); - CHECK_EQUAL(1, data.find_next(false, 0)); - CHECK_EQUAL(4, data.find_next(true, 1)); + CHECK_EQUAL(0U, data.find_next(true, 0)); + CHECK_EQUAL(1U, data.find_next(false, 0)); + CHECK_EQUAL(4U, data.find_next(true, 1)); } From ff9cfa724bf8dbe4b391a9c027106bc9de1c92de Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:20:40 +0000 Subject: [PATCH 085/168] Fixed GCC warnings --- test/test_alignment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_alignment.cpp b/test/test_alignment.cpp index ed90a952..f3b28b42 100644 --- a/test/test_alignment.cpp +++ b/test/test_alignment.cpp @@ -36,7 +36,7 @@ SOFTWARE. #include #include -void f(int a) +void f(int) { } From 36a018019b9ca3dd44146db8731b1a4b62466710 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:20:58 +0000 Subject: [PATCH 086/168] Tabs to spaces --- test/data.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data.h b/test/data.h index c256cc4f..bc5db259 100644 --- a/test/data.h +++ b/test/data.h @@ -40,7 +40,7 @@ class TestDataDC public: TestDataDC() - : value(T()) + : value(T()) { } @@ -90,7 +90,7 @@ class TestDataNDC public: TestDataNDC() - : value(T()) + : value(T()) {} TestDataNDC(const T& value) From 5f3e05b8fc147d78b3ef779b29ddb47a8b56f6ed Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:21:20 +0000 Subject: [PATCH 087/168] Updated project files --- test/codeblocks/ETL.cbp | 30 +- test/codeblocks/ETL.depend | 2616 +++++++++++++++++++++++++++---- test/codeblocks/ETL.layout | 672 ++++---- test/vs2015/etl.vcxproj | 18 +- test/vs2015/etl.vcxproj.filters | 18 +- 5 files changed, 2771 insertions(+), 583 deletions(-) diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 7f58fb61..d8bab481 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -19,6 +19,9 @@ + + + @@ -84,6 +87,8 @@ + + @@ -100,6 +105,7 @@ + @@ -114,6 +120,7 @@ + @@ -132,8 +139,10 @@ + + @@ -172,6 +181,8 @@ + + @@ -183,6 +194,7 @@ + @@ -202,6 +214,7 @@ + @@ -215,14 +228,19 @@ + + + + + @@ -239,6 +257,7 @@ + @@ -259,6 +278,8 @@ + + @@ -278,13 +299,20 @@ + + + + + + + diff --git a/test/codeblocks/ETL.depend b/test/codeblocks/ETL.depend index 22211a47..e5a50fcf 100644 --- a/test/codeblocks/ETL.depend +++ b/test/codeblocks/ETL.depend @@ -2,7 +2,7 @@ 1424729709 source:u:\users\john\documents\programming\github\etl\crc16.cpp -1427746630 +1481841066 1424729709 source:u:\users\john\documents\programming\github\etl\crc16_ccitt.cpp @@ -19,12 +19,12 @@ 1424729709 source:u:\users\john\documents\programming\github\etl\test\main.cpp -1414173716 +/UnitTest++.h> +1452692153 +/UnitTest++.h> 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\unittest++.h "UnitTestPP.h" -1414845610 P.h" +1447740690 P.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\unittestpp.h "Config.h" @@ -34,7 +34,7 @@ "TimeConstraint.h" "ReportAssert.h" -1414845610 ert.h" +1447740690 ert.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\config.h @@ -48,7 +48,7 @@ "MemoryOutStream.h" "Posix/SignalTranslator.h" -1414845610 nalTranslator.h" +1447740690 nalTranslator.h" 1416833496 u:\users\john\documents\programming\github\unittest-cpp\unittest++\testsuite.h @@ -69,7 +69,7 @@ 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\testdetails.h "HelperMacros.h" -1414845610 ros.h" +1447740690 ros.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\helpermacros.h "Config.h" @@ -88,7 +88,7 @@ "HelperMacros.h" -1427741862 > +1482076051 > 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\currenttest.h "HelperMacros.h" @@ -112,26 +112,26 @@ "CurrentTest.h" "ReportAssertImpl.h" -1414927690 ertImpl.h" +1447740690 ertImpl.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\checks.h "Config.h" "TestResults.h" "MemoryOutStream.h" -1414845610 Stream.h" +1447740690 Stream.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\testrunner.h "Test.h" "TestList.h" "CurrentTest.h" -1414845610 st.h" +1447740690 st.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\test.h "TestDetails.h" -1414845610 ls.h" +1447740690 ls.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\testlist.h "HelperMacros.h" @@ -145,18 +145,18 @@ "Posix/TimeHelpers.h" "Win32/TimeHelpers.h" -1414845610 eHelpers.h" +1447740690 eHelpers.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\posix\timehelpers.h -1414845610 h> +1447740690 h> 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\win32\timehelpers.h "../Config.h" "../HelperMacros.h" -1414845610 Macros.h" +1447740690 Macros.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassert.h "HelperMacros.h" @@ -169,7 +169,7 @@ "../integral_limits.h" -1424729709 al_limits.h" +1452516033 al_limits.h" 1424729709 u:\users\john\documents\programming\github\etl\array.h @@ -182,9 +182,9 @@ "static_assert.h" "error_handler.h" -1424729709 dler.h" +1482748240 dler.h" -1427741862 .h" +1481309504 .h" 1424729709 u:\users\john\documents\programming\github\etl\exception.h @@ -193,7 +193,7 @@ "../container.h" -1414586788 ner.h" +1452516033 ner.h" 1424729709 u:\users\john\documents\programming\github\etl\container.h @@ -213,7 +213,7 @@ "../crc64_ecma.h" "../endian.h" -1414929413 ecma.h" +1452701006 ecma.h" 1424729709 u:\users\john\documents\programming\github\etl\crc8_ccitt.h @@ -261,7 +261,7 @@ "../cyclic_value.h" -1415139747 _value.h" +1452516033 _value.h" 1424729709 u:\users\john\documents\programming\github\etl\cyclic_value.h @@ -307,7 +307,7 @@ "nullptr.h" -1424729709 " +1481841437 " 1424729709 u:\users\john\documents\programming\github\etl\nullptr.h @@ -320,7 +320,7 @@ "../enum_type.h" -1414345217 ype.h" +1452516033 ype.h" 1424729709 u:\users\john\documents\programming\github\etl\enum_type.h @@ -329,13 +329,13 @@ "../exception.h" -1424729709 ion.h" +1452516033 ion.h" 1424729709 source:u:\users\john\documents\programming\github\etl\test\test_function.cpp "../function.h" -1414347748 on.h" +1452516033 on.h" 1424729709 u:\users\john\documents\programming\github\etl\function.h @@ -344,12 +344,12 @@ "../largest.h" -1424729709 ts> +1452516033 ts> 1424729709 u:\users\john\documents\programming\github\etl\largest.h "type_traits.h" -1424729709 ts.h" +1482075058 ts.h" 1424729709 source:u:\users\john\documents\programming\github\etl\test\test_list.cpp @@ -383,7 +383,7 @@ -1415009648 +/ReportAssertImpl.h> +1452516033 +/ReportAssertImpl.h> 1424729709 u:\users\john\documents\programming\github\etl\list.h @@ -452,7 +452,7 @@ "../observer.h" -1415136649 er.h" +1452696227 er.h" 1424729709 u:\users\john\documents\programming\github\etl\observer.h @@ -492,7 +492,7 @@ "../queue.h" -1424729709 h" +1482098369 h" 1427740329 u:\users\john\documents\programming\github\etl\queue.h @@ -557,14 +557,14 @@ "../visitor.h" -1414764632 r.h" +1452516033 r.h" 1424729709 u:\users\john\documents\programming\github\etl\visitor.h 1414849210 source:u:\users\john\documents\programming\github\unittest-cpp\unittest++\assertexception.cpp "AssertException.h" -1414845610 eption.h" +1447740690 eption.h" 1414849210 source:u:\users\john\documents\programming\github\unittest-cpp\unittest++\checks.cpp "Checks.h" @@ -577,7 +577,7 @@ 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\compositetestreporter.h "TestReporter.h" -1414845610 ter.h" +1482076051 ter.h" 1414849210 u:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporter.h "HelperMacros.h" @@ -879,7 +879,7 @@ 1414845610 source:/mnt/hgfs/W7 My Documents/Programming/GitHub/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp "SignalTranslator.h" -1414845610 nslator.h" +1447740690 nslator.h" 1414845610 source:/mnt/hgfs/W7 My Documents/Programming/GitHub/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp "TimeHelpers.h" @@ -1099,7 +1099,7 @@ "integral_limits.h" -1427740329 limits.h" +1482653105 limits.h" 1424729709 source:u:\users\john\documents\programming\github\etl\test\test_forward_list.cpp @@ -1129,7 +1129,7 @@ "type_traits.h" "parameter_type.h" -1427740329 _type.h" +1479511690 _type.h" 1424729709 u:\users\john\documents\programming\github\etl\forward_list_base.h @@ -1152,7 +1152,7 @@ "type_traits.h" "static_assert.h" -1427740329 sert.h" +1481309477 sert.h" 1424729709 u:\users\john\documents\programming\github\etl\parameter_type.h "type_traits.h" @@ -1175,7 +1175,7 @@ "../fibonacci.h" "../factorial.h" -1424729709 ial.h" +1452700712 ial.h" 1427741862 source:u:\users\john\documents\programming\github\etl\test\test_pool.cpp @@ -1409,7 +1409,7 @@ "../fixed_iterator.h" -1424729709 iterator.h" +1452516033 iterator.h" 1424729709 u:\users\john\documents\programming\github\etl\fixed_iterator.h @@ -1445,7 +1445,7 @@ "data.h" "../flat_map.h" -1424729709 ap.h" +1452516120 ap.h" 1427740329 u:\users\john\documents\programming\github\etl\flat_map.h @@ -1484,7 +1484,7 @@ "data.h" "../flat_set.h" -1424729709 et.h" +1452516033 et.h" 1427740329 u:\users\john\documents\programming\github\etl\flat_set.h @@ -2621,80 +2621,80 @@ 1424726109 /mnt/hgfs/Programming/GitHub/etl/visitor.h -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\assertexception.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\assertexception.cpp "AssertException.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\assertexception.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\assertexception.h "Config.h" "HelperMacros.h" -1457468069 d:\users\john\documents\programming\github\unittest-cpp\unittest++\config.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\config.h -1457468069 d:\users\john\documents\programming\github\unittest-cpp\unittest++\helpermacros.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\helpermacros.h "Config.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\checks.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\checks.cpp "Checks.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\checks.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\checks.h "Config.h" "TestResults.h" "MemoryOutStream.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testresults.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testresults.h "HelperMacros.h" -1417970069 d:\users\john\documents\programming\github\unittest-cpp\unittest++\memoryoutstream.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\memoryoutstream.h "Config.h" "HelperMacros.h" -1417970061 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\compositetestreporter.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\compositetestreporter.cpp "CompositeTestReporter.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\compositetestreporter.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\compositetestreporter.h "TestReporter.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporter.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporter.h "HelperMacros.h" -1417970067 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\currenttest.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\currenttest.cpp "CurrentTest.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\currenttest.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\currenttest.h "HelperMacros.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestreporter.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestreporter.cpp "Config.h" "DeferredTestReporter.h" "TestDetails.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestreporter.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestreporter.h "Config.h" "TestReporter.h" "DeferredTestResult.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestresult.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestresult.h "Config.h" "HelperMacros.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testdetails.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testdetails.h "HelperMacros.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestresult.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\deferredtestresult.cpp "Config.h" "DeferredTestResult.h" -1457468069 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\memoryoutstream.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\memoryoutstream.cpp "MemoryOutStream.h" @@ -2702,7 +2702,7 @@ 1417875047 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\posix\signaltranslator.cpp "SignalTranslator.h" -1417871449 d:\users\john\documents\programming\github\unittest-cpp\unittest++\posix\signaltranslator.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\posix\signaltranslator.h @@ -2710,10 +2710,10 @@ "TimeHelpers.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\posix\timehelpers.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\posix\timehelpers.h -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassert.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassert.cpp "ReportAssert.h" "ReportAssertImpl.h" "AssertException.h" @@ -2722,15 +2722,15 @@ "TestDetails.h" "ReportAssertImpl.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassert.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassert.h "HelperMacros.h" -1457468069 d:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassertimpl.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\reportassertimpl.h "Config.h" "HelperMacros.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\test.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\test.cpp "Config.h" "Test.h" "TestList.h" @@ -2740,51 +2740,52 @@ "ExecuteTest.h" "Posix/SignalTranslator.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\test.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\test.h "TestDetails.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testlist.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testlist.h "HelperMacros.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\executetest.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\executetest.h "Config.h" "ExceptionMacros.h" "TestDetails.h" "TestResults.h" "MemoryOutStream.h" "AssertException.h" + "RequiredCheckException.h" "CurrentTest.h" "ReportAssertImpl.h" "Posix/SignalTranslator.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\exceptionmacros.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\exceptionmacros.h "Config.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testdetails.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testdetails.cpp "TestDetails.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testlist.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testlist.cpp "TestList.h" "Test.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporter.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporter.cpp "TestReporter.h" -1457465178 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporterstdout.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporterstdout.cpp "TestReporterStdout.h" "TestDetails.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporterstdout.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testreporterstdout.h "TestReporter.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testresults.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testresults.cpp "TestResults.h" "TestReporter.h" "TestDetails.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testrunner.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\testrunner.cpp "TestRunner.h" "TestResults.h" "TestReporter.h" @@ -2793,38 +2794,39 @@ "MemoryOutStream.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testrunner.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testrunner.h "Test.h" "TestList.h" "CurrentTest.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\timehelpers.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\timehelpers.h "Config.h" "Posix/TimeHelpers.h" "Win32/TimeHelpers.h" -1456667834 d:\users\john\documents\programming\github\unittest-cpp\unittest++\win32\timehelpers.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\win32\timehelpers.h "../Config.h" "../HelperMacros.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\timeconstraint.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\timeconstraint.cpp "TimeConstraint.h" "TestResults.h" "MemoryOutStream.h" "CurrentTest.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\timeconstraint.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\timeconstraint.h "TimeHelpers.h" "HelperMacros.h" + "TestDetails.h" -1414845610 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\xmltestreporter.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\xmltestreporter.cpp "Config.h" "XmlTestReporter.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\xmltestreporter.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\xmltestreporter.h "Config.h" "DeferredTestReporter.h" @@ -2862,21 +2864,22 @@ 1450265856 d:\users\john\documents\programming\github\etl\nullptr.h -1450264056 source:d:\users\john\documents\programming\github\etl\test\main.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\main.cpp -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\unittest++.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\unittest++.h "UnitTestPP.h" -1414845610 d:\users\john\documents\programming\github\unittest-cpp\unittest++\unittestpp.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\unittestpp.h "Config.h" "TestMacros.h" "CheckMacros.h" + "RequireMacros.h" "TestRunner.h" "TimeConstraint.h" "ReportAssert.h" -1416829904 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testmacros.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testmacros.h "Config.h" "TestSuite.h" "ExceptionMacros.h" @@ -2886,19 +2889,20 @@ "MemoryOutStream.h" "Posix/SignalTranslator.h" -1416829896 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testsuite.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\testsuite.h -1414927690 d:\users\john\documents\programming\github\unittest-cpp\unittest++\checkmacros.h +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\checkmacros.h "HelperMacros.h" "ExceptionMacros.h" "Checks.h" "AssertException.h" + "RequiredCheckException.h" "MemoryOutStream.h" "TestDetails.h" "CurrentTest.h" "ReportAssertImpl.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_algorithm.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_algorithm.cpp "../src/algorithm.h" "../src/container.h" @@ -2923,7 +2927,7 @@ -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_alignment.cpp +1482624126 source:d:\users\john\documents\programming\github\etl\test\test_alignment.cpp "../src/alignment.h" "../src/type_traits.h" @@ -2939,7 +2943,7 @@ 1450265856 d:\users\john\documents\programming\github\etl\static_assert.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_array.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_array.cpp "../src/array.h" @@ -2947,6 +2951,8 @@ "../src/integral_limits.h" +1479511692 tegral_limits.h" + 1450265856 d:\users\john\documents\programming\github\etl\array.h @@ -2966,7 +2972,7 @@ "type_traits.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_binary.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_binary.cpp @@ -3029,22 +3035,27 @@ "exception.h" "error_handler.h" -1457468093 source:d:\users\john\documents\programming\github\etl\test\test_bitset.cpp +1482623861 source:d:\users\john\documents\programming\github\etl\test\test_bitset.cpp "../src/bitset.h" -1457378733 source:d:\users\john\documents\programming\github\etl\test\test_bloom_filter.cpp +1482623861 tset.h" + +1482612858 source:d:\users\john\documents\programming\github\etl\test\test_bloom_filter.cpp - + "../src/bloom_filter.h" "../src/fnv_1.h" "../src/crc16.h" "../src/crc16_ccitt.h" "../src/crc32.h" + "../src/char_traits.h" + +1482612858 ar_traits.h" 1450265856 d:\users\john\documents\programming\github\etl\bloom_filter.h "parameter_type.h" @@ -3073,7 +3084,7 @@ "static_assert.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_checksum.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_checksum.cpp @@ -3082,18 +3093,22 @@ "../src/checksum.h" "../src/endian.h" +1479511692 dian.h" + 1450265856 d:\users\john\documents\programming\github\etl\checksum.h "static_assert.h" "type_traits.h" "ihash.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_container.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_container.cpp "../src/container.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_crc.cpp +1479511691 ntainer.h" + +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_crc.cpp @@ -3106,6 +3121,8 @@ "../src/crc32.h" "../src/crc64_ecma.h" +1479511691 c64_ecma.h" + 1450265856 d:\users\john\documents\programming\github\etl\crc8_ccitt.h "static_assert.h" @@ -3121,17 +3138,19 @@ "static_assert.h" "type_traits.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_cyclic_value.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_cyclic_value.cpp "../src/cyclic_value.h" +1479511691 clic_value.h" + 1452794793 d:\users\john\documents\programming\github\etl\cyclic_value.h "static_assert.h" "exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_deque.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_deque.cpp "ExtraCheckMacros.h" "../src/deque.h" @@ -3142,7 +3161,7 @@ -1421962897 d:\users\john\documents\programming\github\etl\test\extracheckmacros.h +1479511691 d:\users\john\documents\programming\github\etl\test\extracheckmacros.h @@ -3175,20 +3194,22 @@ "exception.h" -1456432601 d:\users\john\documents\programming\github\etl\test\data.h +1482185150 d:\users\john\documents\programming\github\etl\test\data.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_endian.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_endian.cpp "../src/endian.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_enum_type.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_enum_type.cpp "../src/enum_type.h" -1457468158 source:d:\users\john\documents\programming\github\etl\test\test_error_handler.cpp +1479511691 um_type.h" + +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_error_handler.cpp @@ -3196,12 +3217,14 @@ "../src/error_handler.h" "../src/exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_exception.cpp +1482625380 ception.h" + +1482625380 source:d:\users\john\documents\programming\github\etl\test\test_exception.cpp "../src/exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_flat_map.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_flat_map.cpp @@ -3213,6 +3236,8 @@ "data.h" "../src/flat_map.h" +1479511691 at_map.h" + 1452796556 d:\users\john\documents\programming\github\etl\flat_map.h @@ -3263,7 +3288,7 @@ "alignment.h" "array.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_flat_set.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_flat_set.cpp @@ -3275,6 +3300,8 @@ "data.h" "../src/flat_set.h" +1479511691 at_set.h" + 1452796556 d:\users\john\documents\programming\github\etl\flat_set.h @@ -3300,7 +3327,7 @@ "ivector.h" "error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_fnv_1.cpp +1482623723 source:d:\users\john\documents\programming\github\etl\test\test_fnv_1.cpp @@ -3308,7 +3335,9 @@ "../src/fnv_1.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_forward_list.cpp +1482623723 v_1.h" + +1482625680 source:d:\users\john\documents\programming\github\etl\test\test_forward_list.cpp "ExtraCheckMacros.h" "data.h" @@ -3359,11 +3388,13 @@ "exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_function.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_function.cpp "../src/function.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_functional.cpp +1479511692 nction.h" + +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_functional.cpp "../src/functional.h" @@ -3372,7 +3403,7 @@ 1450265856 d:\users\john\documents\programming\github\etl\functional.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_hash.cpp +1482624624 source:d:\users\john\documents\programming\github\etl\test\test_hash.cpp @@ -3380,12 +3411,14 @@ "../src/hash.h" +1482624624 sh.h" + 1450265856 d:\users\john\documents\programming\github\etl\hash.h "fnv_1.h" "type_traits.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_instance_count.cpp +1482624916 source:d:\users\john\documents\programming\github\etl\test\test_instance_count.cpp "../src/instance_count.h" @@ -3394,14 +3427,14 @@ 1450265856 d:\users\john\documents\programming\github\etl\instance_count.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_integral_limits.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_integral_limits.cpp "../src/integral_limits.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_io_port.cpp +1482750186 source:d:\users\john\documents\programming\github\etl\test\test_io_port.cpp "../src/io_port.h" @@ -3411,7 +3444,7 @@ "nullptr.h" "parameter_type.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_largest.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_largest.cpp "../src/largest.h" @@ -3419,7 +3452,7 @@ 1450265856 d:\users\john\documents\programming\github\etl\largest.h "type_traits.h" -1457468249 source:d:\users\john\documents\programming\github\etl\test\test_list.cpp +1482625302 source:d:\users\john\documents\programming\github\etl\test\test_list.cpp "ExtraCheckMacros.h" "../src/list.h" @@ -3450,20 +3483,22 @@ "exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_maths.cpp +1482692728 source:d:\users\john\documents\programming\github\etl\test\test_maths.cpp "../src/log.h" "../src/power.h" "../src/fibonacci.h" "../src/factorial.h" +1482692728 ctorial.h" + 1450265856 d:\users\john\documents\programming\github\etl\fibonacci.h 1450265856 d:\users\john\documents\programming\github\etl\factorial.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_numeric.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_numeric.cpp "../src/numeric.h" @@ -3471,21 +3506,25 @@ 1450265856 d:\users\john\documents\programming\github\etl\numeric.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_observer.cpp +1482624916 source:d:\users\john\documents\programming\github\etl\test\test_observer.cpp "../src/observer.h" +1482624916 server.h" + 1450959449 d:\users\john\documents\programming\github\etl\observer.h "vector.h" "exception.h" "error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_queue.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_queue.cpp "../src/queue.h" +1479511692 eue.h" + 1450265856 d:\users\john\documents\programming\github\etl\queue.h @@ -3505,17 +3544,19 @@ "exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_smallest.cpp +1482654345 source:d:\users\john\documents\programming\github\etl\test\test_smallest.cpp "../src/smallest.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_stack.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_stack.cpp "data.h" "../src/stack.h" +1479511692 ack.h" + 1450265856 d:\users\john\documents\programming\github\etl\stack.h @@ -3536,29 +3577,35 @@ "exception.h" -1457027610 source:d:\users\john\documents\programming\github\etl\test\test_vector.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_vector.cpp "../src/vector.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_visitor.cpp +1479511692 ctor.h" + +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_visitor.cpp "../src/visitor.h" +1479511692 sitor.h" + 1450265856 d:\users\john\documents\programming\github\etl\visitor.h -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_fixed_iterator.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_fixed_iterator.cpp "../src/fixed_iterator.h" +1479511691 xed_iterator.h" + 1450265856 d:\users\john\documents\programming\github\etl\fixed_iterator.h -1457468069 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\win32\timehelpers.cpp +1482076051 source:d:\users\john\documents\programming\github\unittest-cpp\unittest++\win32\timehelpers.cpp "TimeHelpers.h" @@ -3567,6 +3614,8 @@ "../exception.h" "../error_handler.h" +1482614484 handler.h" + 1450265856 d:\users\john\documents\programming\github\etl\private\flat_map_base.h "../exception.h" @@ -3600,7 +3649,7 @@ "../exception.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_map.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_map.cpp @@ -3611,6 +3660,8 @@ "../src/map.h" +1479511692 p.h" + 1452337350 d:\users\john\documents\programming\github\etl\map.h @@ -3635,7 +3686,7 @@ "../exception.h" "../error_handler.h" -1457464314 source:d:\users\john\documents\programming\github\etl\test\test_optional.cpp +1482624916 source:d:\users\john\documents\programming\github\etl\test\test_optional.cpp @@ -3649,7 +3700,7 @@ "exception.h" "error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_pool.cpp +1482750186 source:d:\users\john\documents\programming\github\etl\test\test_pool.cpp "ExtraCheckMacros.h" "data.h" @@ -3657,12 +3708,14 @@ "../src/pool.h" +1482750186 ol.h" + 1450265856 d:\users\john\documents\programming\github\etl\private\queue_base.h "../exception.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_set.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_set.cpp @@ -3673,6 +3726,8 @@ "../src/set.h" +1479511692 t.h" + 1452337350 d:\users\john\documents\programming\github\etl\set.h @@ -3702,12 +3757,12 @@ "../exception.h" "../error_handler.h" -1457463236 source:d:\users\john\documents\programming\github\etl\test\test_type_traits.cpp +1482768991 source:d:\users\john\documents\programming\github\etl\test\test_type_traits.cpp "../src/type_traits.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_variant.cpp +1481841066 source:d:\users\john\documents\programming\github\etl\test\test_variant.cpp "ExtraCheckMacros.h" "../src/variant.h" @@ -4784,7 +4839,7 @@ 1452516033 /home/jwellbelove/Programming/etl/visitor.h -1457468232 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_forward_list.cpp +1482799048 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_forward_list.cpp "ExtraCheckMacros.h" "data.h" @@ -4805,48 +4860,55 @@ "type_traits.h" "intrusive_forward_list_link.h" +1453405528 _forward_list_link.h" + 1453324561 d:\users\john\documents\programming\github\etl\intrusive_forward_list_link.h "error_handler.h" "array.h" -1456669289 source:d:\users\john\documents\programming\github\etl\src\crc16.cpp +1479511689 source:d:\users\john\documents\programming\github\etl\src\crc16.cpp -1456669289 source:d:\users\john\documents\programming\github\etl\src\crc16_ccitt.cpp +1479511689 source:d:\users\john\documents\programming\github\etl\src\crc16_ccitt.cpp -1456669289 source:d:\users\john\documents\programming\github\etl\src\crc16_kermit.cpp +1479511689 source:d:\users\john\documents\programming\github\etl\src\crc16_kermit.cpp -1456669289 source:d:\users\john\documents\programming\github\etl\src\crc32.cpp +1479511689 source:d:\users\john\documents\programming\github\etl\src\crc32.cpp -1456669289 source:d:\users\john\documents\programming\github\etl\src\crc64_ecma.cpp +1479511689 source:d:\users\john\documents\programming\github\etl\src\crc64_ecma.cpp -1456669289 source:d:\users\john\documents\programming\github\etl\src\crc8_ccitt.cpp +1481309487 source:d:\users\john\documents\programming\github\etl\src\crc8_ccitt.cpp + "platform.h" + "static_assert.h" -1456669289 source:d:\users\john\documents\programming\github\etl\src\error_handler.cpp +1479511689 source:d:\users\john\documents\programming\github\etl\src\error_handler.cpp "error_handler.h" "nullptr.h" -1456669289 d:\users\john\documents\programming\github\etl\src\error_handler.h +1479511689 d:\users\john\documents\programming\github\etl\src\error_handler.h "exception.h" "function.h" -1456669289 d:\users\john\documents\programming\github\etl\src\exception.h +1481841065 d:\users\john\documents\programming\github\etl\src\exception.h -1456669289 d:\users\john\documents\programming\github\etl\src\function.h +1481841065 d:\users\john\documents\programming\github\etl\src\function.h -1457547753 d:\users\john\documents\programming\github\etl\src\nullptr.h +1481308917 d:\users\john\documents\programming\github\etl\src\nullptr.h "platform.h" + -1456669289 source:d:\users\john\documents\programming\github\etl\src\pearson.cpp +1481841066 source:d:\users\john\documents\programming\github\etl\src\pearson.cpp + "platform.h" + "static_assert.h" -1456669289 d:\users\john\documents\programming\github\etl\src\algorithm.h +1479511689 d:\users\john\documents\programming\github\etl\src\algorithm.h @@ -4854,24 +4916,24 @@ "type_traits.h" -1457559890 d:\users\john\documents\programming\github\etl\src\type_traits.h +1481841066 d:\users\john\documents\programming\github\etl\src\type_traits.h "platform.h" "nullptr.h" -1456669289 d:\users\john\documents\programming\github\etl\src\container.h +1482613987 d:\users\john\documents\programming\github\etl\src\container.h -1456669289 d:\users\john\documents\programming\github\etl\src\alignment.h +1481309570 d:\users\john\documents\programming\github\etl\src\alignment.h "type_traits.h" "static_assert.h" -1457463503 d:\users\john\documents\programming\github\etl\src\static_assert.h +1481841065 d:\users\john\documents\programming\github\etl\src\static_assert.h "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\array.h +1479511689 d:\users\john\documents\programming\github\etl\src\array.h @@ -4882,15 +4944,16 @@ "static_assert.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\parameter_type.h +1479511690 d:\users\john\documents\programming\github\etl\src\parameter_type.h "type_traits.h" -1456669289 d:\users\john\documents\programming\github\etl\src\integral_limits.h +1479511690 d:\users\john\documents\programming\github\etl\src\integral_limits.h "type_traits.h" + "platform.h" -1457027659 d:\users\john\documents\programming\github\etl\src\binary.h +1481309537 d:\users\john\documents\programming\github\etl\src\binary.h "type_traits.h" @@ -4899,19 +4962,20 @@ "log.h" "power.h" "smallest.h" + "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\log.h +1479511690 d:\users\john\documents\programming\github\etl\src\log.h -1456669289 d:\users\john\documents\programming\github\etl\src\power.h +1479511690 d:\users\john\documents\programming\github\etl\src\power.h "log.h" -1456669289 d:\users\john\documents\programming\github\etl\src\smallest.h +1482653105 d:\users\john\documents\programming\github\etl\src\smallest.h "integral_limits.h" -1457463503 d:\users\john\documents\programming\github\etl\src\bitset.h +1479511689 d:\users\john\documents\programming\github\etl\src\bitset.h @@ -4924,7 +4988,7 @@ "ibitset.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\ibitset.h +1481309224 d:\users\john\documents\programming\github\etl\src\ibitset.h @@ -4932,21 +4996,25 @@ "integral_limits.h" "binary.h" "algorithm.h" + "platform.h" -1457463503 d:\users\john\documents\programming\github\etl\src\fnv_1.h +1481841066 d:\users\john\documents\programming\github\etl\src\fnv_1.h "platform.h" "static_assert.h" "type_traits.h" "ihash.h" + "frame_check_sequence.h" -1456669289 d:\users\john\documents\programming\github\etl\src\ihash.h +1481872412 ck_sequence.h" + +1479511690 d:\users\john\documents\programming\github\etl\src\ihash.h "exception.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\bloom_filter.h +1479511689 d:\users\john\documents\programming\github\etl\src\bloom_filter.h "parameter_type.h" "bitset.h" "type_traits.h" @@ -4954,66 +5022,67 @@ "log.h" "power.h" -1457463503 d:\users\john\documents\programming\github\etl\src\crc16.h +1479511689 d:\users\john\documents\programming\github\etl\src\crc16.h "platform.h" "frame_check_sequence.h" -1456669289 d:\users\john\documents\programming\github\etl\src\frame_check_sequence.h +1481841065 d:\users\john\documents\programming\github\etl\src\frame_check_sequence.h + "platform.h" "static_assert.h" "type_traits.h" "binary.h" -1457463503 d:\users\john\documents\programming\github\etl\src\crc16_ccitt.h +1479511689 d:\users\john\documents\programming\github\etl\src\crc16_ccitt.h "platform.h" "frame_check_sequence.h" -1457463503 d:\users\john\documents\programming\github\etl\src\crc32.h +1479511689 d:\users\john\documents\programming\github\etl\src\crc32.h "platform.h" "frame_check_sequence.h" -1456953131 d:\users\john\documents\programming\github\etl\src\checksum.h +1479511689 d:\users\john\documents\programming\github\etl\src\checksum.h "binary.h" "frame_check_sequence.h" -1456669289 d:\users\john\documents\programming\github\etl\src\endian.h +1481309464 d:\users\john\documents\programming\github\etl\src\endian.h "enum_type.h" -1456669289 d:\users\john\documents\programming\github\etl\src\enum_type.h +1479511689 d:\users\john\documents\programming\github\etl\src\enum_type.h -1457463503 d:\users\john\documents\programming\github\etl\src\crc8_ccitt.h +1479511689 d:\users\john\documents\programming\github\etl\src\crc8_ccitt.h "platform.h" "frame_check_sequence.h" -1457463503 d:\users\john\documents\programming\github\etl\src\crc16_kermit.h +1479511689 d:\users\john\documents\programming\github\etl\src\crc16_kermit.h "platform.h" "frame_check_sequence.h" -1457463503 d:\users\john\documents\programming\github\etl\src\crc64_ecma.h +1479511689 d:\users\john\documents\programming\github\etl\src\crc64_ecma.h "platform.h" "frame_check_sequence.h" -1456669289 d:\users\john\documents\programming\github\etl\src\cyclic_value.h +1479511689 d:\users\john\documents\programming\github\etl\src\cyclic_value.h "static_assert.h" "exception.h" -1456669289 d:\users\john\documents\programming\github\etl\src\deque.h +1479511689 d:\users\john\documents\programming\github\etl\src\deque.h @@ -5023,7 +5092,7 @@ "alignment.h" "array.h" -1457468266 d:\users\john\documents\programming\github\etl\src\ideque.h +1482624126 d:\users\john\documents\programming\github\etl\src\ideque.h "algorithm.h" @@ -5032,22 +5101,22 @@ "parameter_type.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\deque_base.h +1479511690 d:\users\john\documents\programming\github\etl\src\private\deque_base.h "../exception.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\fixed_iterator.h +1482624125 d:\users\john\documents\programming\github\etl\src\fixed_iterator.h -1456669289 d:\users\john\documents\programming\github\etl\src\flat_map.h +1479511690 d:\users\john\documents\programming\github\etl\src\flat_map.h "iflat_map.h" "vector.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iflat_map.h +1482748252 d:\users\john\documents\programming\github\etl\src\iflat_map.h @@ -5059,13 +5128,13 @@ "ivector.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\flat_map_base.h +1479511690 d:\users\john\documents\programming\github\etl\src\private\flat_map_base.h "../exception.h" "../ivector.h" "../error_handler.h" -1457595336 d:\users\john\documents\programming\github\etl\src\ivector.h +1482748239 d:\users\john\documents\programming\github\etl\src\ivector.h @@ -5076,13 +5145,16 @@ "type_traits.h" "parameter_type.h" "error_handler.h" + "private/ivectorpointer.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\vector_base.h +1482748239 vectorpointer.h" + +1479511691 d:\users\john\documents\programming\github\etl\src\private\vector_base.h "../exception.h" "../error_handler.h" -1456953131 d:\users\john\documents\programming\github\etl\src\vector.h +1481841065 d:\users\john\documents\programming\github\etl\src\vector.h @@ -5091,14 +5163,14 @@ "alignment.h" "array.h" -1456669289 d:\users\john\documents\programming\github\etl\src\flat_set.h +1479511690 d:\users\john\documents\programming\github\etl\src\flat_set.h "iflat_set.h" "vector.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iflat_set.h +1482748239 d:\users\john\documents\programming\github\etl\src\iflat_set.h @@ -5110,39 +5182,40 @@ "ivector.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\flat_set_base.h +1479511690 d:\users\john\documents\programming\github\etl\src\private\flat_set_base.h "../exception.h" "../ivector.h" "../error_handler.h" -1456953131 d:\users\john\documents\programming\github\etl\src\forward_list.h +1479511690 d:\users\john\documents\programming\github\etl\src\forward_list.h "pool.h" "iforward_list.h" "container.h" -1456669289 d:\users\john\documents\programming\github\etl\src\pool.h +1479511690 d:\users\john\documents\programming\github\etl\src\pool.h "alignment.h" "array.h" "bitset.h" "ipool.h" -1456669289 d:\users\john\documents\programming\github\etl\src\ipool.h +1481841065 d:\users\john\documents\programming\github\etl\src\ipool.h "private/pool_base.h" "nullptr.h" "ibitset.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\pool_base.h +1479511691 d:\users\john\documents\programming\github\etl\src\private\pool_base.h "../exception.h" "../error_handler.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iforward_list.h +1482748239 d:\users\john\documents\programming\github\etl\src\iforward_list.h + "platform.h" @@ -5153,21 +5226,24 @@ "type_traits.h" "parameter_type.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\forward_list_base.h +1479511690 d:\users\john\documents\programming\github\etl\src\private\forward_list_base.h "../exception.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\functional.h +1479511690 d:\users\john\documents\programming\github\etl\src\functional.h -1456669289 d:\users\john\documents\programming\github\etl\src\hash.h +1481841145 d:\users\john\documents\programming\github\etl\src\hash.h + "fnv_1.h" "type_traits.h" + "static_assert.h" -1456669289 d:\users\john\documents\programming\github\etl\src\instance_count.h +1479511690 d:\users\john\documents\programming\github\etl\src\instance_count.h -1456953131 d:\users\john\documents\programming\github\etl\src\intrusive_forward_list.h +1482748239 d:\users\john\documents\programming\github\etl\src\intrusive_forward_list.h + "platform.h" @@ -5178,29 +5254,33 @@ "error_handler.h" "intrusive_links.h" "algorithm.h" + "private/counter_type.h" -1457466644 d:\users\john\documents\programming\github\etl\src\intrusive_links.h +1482354421 ounter_type.h" + +1482357841 d:\users\john\documents\programming\github\etl\src\intrusive_links.h + "nullptr.h" "type_traits.h" "exception.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\io_port.h +1479511690 d:\users\john\documents\programming\github\etl\src\io_port.h "nullptr.h" "parameter_type.h" -1456669289 d:\users\john\documents\programming\github\etl\src\largest.h +1479511690 d:\users\john\documents\programming\github\etl\src\largest.h "type_traits.h" -1456953131 d:\users\john\documents\programming\github\etl\src\list.h +1479511690 d:\users\john\documents\programming\github\etl\src\list.h "ilist.h" "container.h" "pool.h" -1456669289 d:\users\john\documents\programming\github\etl\src\ilist.h +1482748239 d:\users\john\documents\programming\github\etl\src\ilist.h @@ -5210,13 +5290,14 @@ "type_traits.h" "parameter_type.h" "pool.h" + "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\list_base.h +1479511691 d:\users\john\documents\programming\github\etl\src\private\list_base.h "../exception.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\map.h +1479511690 d:\users\john\documents\programming\github\etl\src\map.h @@ -5224,7 +5305,7 @@ "container.h" "pool.h" -1456669289 d:\users\john\documents\programming\github\etl\src\imap.h +1479511690 d:\users\john\documents\programming\github\etl\src\imap.h @@ -5234,33 +5315,34 @@ "type_traits.h" "parameter_type.h" "pool.h" + "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\map_base.h +1481841066 d:\users\john\documents\programming\github\etl\src\private\map_base.h "../exception.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\fibonacci.h +1479511689 d:\users\john\documents\programming\github\etl\src\fibonacci.h -1456669289 d:\users\john\documents\programming\github\etl\src\factorial.h +1479511689 d:\users\john\documents\programming\github\etl\src\factorial.h -1456669289 d:\users\john\documents\programming\github\etl\src\numeric.h +1479511690 d:\users\john\documents\programming\github\etl\src\numeric.h -1456669289 d:\users\john\documents\programming\github\etl\src\observer.h +1479511690 d:\users\john\documents\programming\github\etl\src\observer.h "vector.h" "exception.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\optional.h +1482748239 d:\users\john\documents\programming\github\etl\src\optional.h "alignment.h" "type_traits.h" "exception.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\queue.h +1479511691 d:\users\john\documents\programming\github\etl\src\queue.h "iqueue.h" @@ -5268,19 +5350,19 @@ "alignment.h" "array.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iqueue.h +1481841066 d:\users\john\documents\programming\github\etl\src\iqueue.h "private/queue_base.h" "type_traits.h" "parameter_type.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\queue_base.h +1479511691 d:\users\john\documents\programming\github\etl\src\private\queue_base.h "../exception.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\set.h +1479511691 d:\users\john\documents\programming\github\etl\src\set.h @@ -5288,7 +5370,7 @@ "container.h" "pool.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iset.h +1479511690 d:\users\john\documents\programming\github\etl\src\iset.h @@ -5298,13 +5380,14 @@ "type_traits.h" "parameter_type.h" "pool.h" + "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\set_base.h +1482625676 d:\users\john\documents\programming\github\etl\src\private\set_base.h "../exception.h" "../error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\stack.h +1479511691 d:\users\john\documents\programming\github\etl\src\stack.h @@ -5313,19 +5396,19 @@ "alignment.h" "array.h" -1456669289 d:\users\john\documents\programming\github\etl\src\istack.h +1481841066 d:\users\john\documents\programming\github\etl\src\istack.h "private/stack_base.h" "type_traits.h" "parameter_type.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\stack_base.h +1479511691 d:\users\john\documents\programming\github\etl\src\private\stack_base.h "../exception.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_unordered_map.cpp +1482624915 source:d:\users\john\documents\programming\github\etl\test\test_unordered_map.cpp @@ -5338,7 +5421,9 @@ "data.h" "../src/unordered_map.h" -1456669289 d:\users\john\documents\programming\github\etl\src\unordered_map.h +1482624915 ordered_map.h" + +1479511691 d:\users\john\documents\programming\github\etl\src\unordered_map.h @@ -5349,7 +5434,7 @@ "intrusive_forward_list.h" "hash.h" -1456953131 d:\users\john\documents\programming\github\etl\src\iunordered_map.h +1482748240 d:\users\john\documents\programming\github\etl\src\iunordered_map.h @@ -5366,7 +5451,7 @@ "exception.h" "error_handler.h" -1457463503 d:\users\john\documents\programming\github\etl\src\variant.h +1481841437 d:\users\john\documents\programming\github\etl\src\variant.h "platform.h" "array.h" @@ -5377,20 +5462,23 @@ "static_assert.h" "alignment.h" "error_handler.h" + "largest.h" -1456669289 d:\users\john\documents\programming\github\etl\src\visitor.h +1479511691 d:\users\john\documents\programming\github\etl\src\visitor.h -1457570381 d:\users\john\documents\programming\github\etl\src\platform.h +1482759320 d:\users\john\documents\programming\github\etl\src\platform.h + + -1457463956 source:d:\users\john\documents\programming\github\etl\test\murmurhash3.cpp - "MurmurHash3.h" +1481841065 source:d:\users\john\documents\programming\github\etl\test\murmurhash3.cpp + "murmurhash3.h" -1457464314 d:\users\john\documents\programming\github\etl\test\murmurhash3.h +1479511691 d:\users\john\documents\programming\github\etl\test\murmurhash3.h "../src/platform.h" -1457508036 source:d:\users\john\documents\programming\github\etl\test\test_bsd_checksum.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_bsd_checksum.cpp @@ -5398,7 +5486,9 @@ "../src/checksum.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_flat_multimap.cpp +1479511692 ecksum.h" + +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_flat_multimap.cpp @@ -5410,14 +5500,16 @@ "data.h" "../src/flat_multimap.h" -1456669289 d:\users\john\documents\programming\github\etl\src\flat_multimap.h +1479511691 at_multimap.h" + +1479511690 d:\users\john\documents\programming\github\etl\src\flat_multimap.h "iflat_multimap.h" "vector.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iflat_multimap.h +1482748239 d:\users\john\documents\programming\github\etl\src\iflat_multimap.h @@ -5429,13 +5521,13 @@ "ivector.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\flat_multimap_base.h +1479511690 d:\users\john\documents\programming\github\etl\src\private\flat_multimap_base.h "../exception.h" "../ivector.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_flat_multiset.cpp +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_flat_multiset.cpp @@ -5447,14 +5539,16 @@ "data.h" "../src/flat_multiset.h" -1456669289 d:\users\john\documents\programming\github\etl\src\flat_multiset.h +1479511691 at_multiset.h" + +1479511690 d:\users\john\documents\programming\github\etl\src\flat_multiset.h "iflat_multiset.h" "vector.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iflat_multiset.h +1482748239 d:\users\john\documents\programming\github\etl\src\iflat_multiset.h @@ -5466,19 +5560,21 @@ "ivector.h" "error_handler.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\flat_multiset_base.h +1479511690 d:\users\john\documents\programming\github\etl\src\private\flat_multiset_base.h "../exception.h" "../ivector.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_links.cpp +1482358550 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_links.cpp "ExtraCheckMacros.h" "data.h" "../src/intrusive_links.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_list.cpp +1482358550 trusive_links.h" + +1482840619 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_list.cpp "ExtraCheckMacros.h" "data.h" @@ -5489,7 +5585,8 @@ -1457547716 d:\users\john\documents\programming\github\etl\src\intrusive_list.h +1482748239 d:\users\john\documents\programming\github\etl\src\intrusive_list.h + "platform.h" @@ -5501,8 +5598,9 @@ "intrusive_links.h" "static_assert.h" "algorithm.h" + "private/counter_type.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_jenkins.cpp +1482624277 source:d:\users\john\documents\programming\github\etl\test\test_jenkins.cpp "murmurhash3.h" @@ -5512,7 +5610,7 @@ "../src/jenkins.h" "../src/endian.h" -1457463503 d:\users\john\documents\programming\github\etl\src\jenkins.h +1481872412 d:\users\john\documents\programming\github\etl\src\jenkins.h "platform.h" @@ -5520,8 +5618,9 @@ "type_traits.h" "error_handler.h" "ihash.h" + "frame_check_sequence.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_multimap.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_multimap.cpp @@ -5531,7 +5630,9 @@ "../src/multimap.h" -1456669289 d:\users\john\documents\programming\github\etl\src\multimap.h +1479511692 ltimap.h" + +1479511690 d:\users\john\documents\programming\github\etl\src\multimap.h @@ -5539,7 +5640,7 @@ "container.h" "pool.h" -1457548955 d:\users\john\documents\programming\github\etl\src\imultimap.h +1482098369 d:\users\john\documents\programming\github\etl\src\imultimap.h @@ -5549,13 +5650,14 @@ "type_traits.h" "parameter_type.h" "pool.h" + "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\multimap_base.h +1481309650 d:\users\john\documents\programming\github\etl\src\private\multimap_base.h "../exception.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_multiset.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_multiset.cpp @@ -5565,7 +5667,9 @@ "../src/multiset.h" -1457548976 d:\users\john\documents\programming\github\etl\src\multiset.h +1479511692 ltiset.h" + +1479511690 d:\users\john\documents\programming\github\etl\src\multiset.h @@ -5573,7 +5677,7 @@ "container.h" "pool.h" -1457548988 d:\users\john\documents\programming\github\etl\src\imultiset.h +1482098369 d:\users\john\documents\programming\github\etl\src\imultiset.h @@ -5583,13 +5687,14 @@ "type_traits.h" "parameter_type.h" "pool.h" + "platform.h" -1456669289 d:\users\john\documents\programming\github\etl\src\private\multiset_base.h +1481309628 d:\users\john\documents\programming\github\etl\src\private\multiset_base.h "../exception.h" "../error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_murmur3.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_murmur3.cpp "murmurhash3.h" @@ -5599,14 +5704,14 @@ "../src/murmur3.h" "../src/endian.h" -1457463503 d:\users\john\documents\programming\github\etl\src\murmur3.h +1479511690 d:\users\john\documents\programming\github\etl\src\murmur3.h "platform.h" "ihash.h" "binary.h" "error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_pearson.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_pearson.cpp @@ -5616,7 +5721,7 @@ "../src/pearson.h" "../src/endian.h" -1457549034 d:\users\john\documents\programming\github\etl\src\pearson.h +1481308892 d:\users\john\documents\programming\github\etl\src\pearson.h "platform.h" "static_assert.h" @@ -5626,19 +5731,21 @@ "array.h" "container.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_priority_queue.cpp +1482624474 source:d:\users\john\documents\programming\github\etl\test\test_priority_queue.cpp "../src/priority_queue.h" -1456669289 d:\users\john\documents\programming\github\etl\src\priority_queue.h +1482624474 iority_queue.h" + +1479511690 d:\users\john\documents\programming\github\etl\src\priority_queue.h "ipriority_queue.h" "container.h" "vector.h" -1456669289 d:\users\john\documents\programming\github\etl\src\ipriority_queue.h +1482748239 d:\users\john\documents\programming\github\etl\src\ipriority_queue.h "type_traits.h" @@ -5646,7 +5753,7 @@ "error_handler.h" "exception.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_unordered_multimap.cpp +1482625301 source:d:\users\john\documents\programming\github\etl\test\test_unordered_multimap.cpp @@ -5659,7 +5766,9 @@ "data.h" "../src/unordered_multimap.h" -1456669289 d:\users\john\documents\programming\github\etl\src\unordered_multimap.h +1482625301 ordered_multimap.h" + +1479511691 d:\users\john\documents\programming\github\etl\src\unordered_multimap.h @@ -5670,7 +5779,7 @@ "intrusive_forward_list.h" "hash.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iunordered_multimap.h +1482748240 d:\users\john\documents\programming\github\etl\src\iunordered_multimap.h @@ -5687,7 +5796,7 @@ "exception.h" "error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_unordered_multiset.cpp +1482625301 source:d:\users\john\documents\programming\github\etl\test\test_unordered_multiset.cpp @@ -5701,7 +5810,7 @@ "../src/unordered_multiset.h" "../src/checksum.h" -1456669289 d:\users\john\documents\programming\github\etl\src\unordered_multiset.h +1479511691 d:\users\john\documents\programming\github\etl\src\unordered_multiset.h @@ -5712,7 +5821,7 @@ "intrusive_forward_list.h" "hash.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iunordered_multiset.h +1482748239 d:\users\john\documents\programming\github\etl\src\iunordered_multiset.h @@ -5729,7 +5838,7 @@ "exception.h" "error_handler.h" -1457378530 source:d:\users\john\documents\programming\github\etl\test\test_unordered_set.cpp +1482624916 source:d:\users\john\documents\programming\github\etl\test\test_unordered_set.cpp @@ -5742,7 +5851,7 @@ "../src/unordered_set.h" "../src/checksum.h" -1456669289 d:\users\john\documents\programming\github\etl\src\unordered_set.h +1479511691 d:\users\john\documents\programming\github\etl\src\unordered_set.h @@ -5753,7 +5862,7 @@ "intrusive_forward_list.h" "hash.h" -1456669289 d:\users\john\documents\programming\github\etl\src\iunordered_set.h +1482748240 d:\users\john\documents\programming\github\etl\src\iunordered_set.h @@ -5770,7 +5879,7 @@ "exception.h" "error_handler.h" -1456669289 source:d:\users\john\documents\programming\github\etl\test\test_xor_checksum.cpp +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_xor_checksum.cpp @@ -5778,3 +5887,1970 @@ "../src/checksum.h" +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\requiredcheckexception.h + "Config.h" + "HelperMacros.h" + + +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\requiremacros.h + "RequiredCheckTestReporter.h" + +1482076051 heckTestReporter.h" + +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\requiredchecktestreporter.h + "HelperMacros.h" + "ThrowingTestReporter.h" + +1482076051 estReporter.h" + +1482076051 d:\users\john\documents\programming\github\unittest-cpp\unittest++\throwingtestreporter.h + "TestReporter.h" + +1481309504 d:\users\john\documents\programming\github\etl\src\char_traits.h + + "platform.h" + "stdint.h" + "algorithm.h" + +1481841066 d:\users\john\documents\programming\github\etl\src\private\ivectorpointer.h + "pvoidvector.h" + +1482079098 or.h" + +1482748239 d:\users\john\documents\programming\github\etl\src\private\pvoidvector.h + + + + + "../platform.h" + "../algorithm.h" + "vector_base.h" + "../type_traits.h" + "../error_handler.h" + +1482353821 d:\users\john\documents\programming\github\etl\src\private\counter_type.h + +1482079098 source:d:\users\john\documents\programming\github\etl\src\private\pvoidvector.cpp + "pvoidvector.h" + +1479511691 source:d:\users\john\documents\programming\github\etl\test\test_debounce.cpp + + "../src/debounce.h" + +1479511691 bounce.h" + +1481309477 d:\users\john\documents\programming\github\etl\src\debounce.h + + "static_assert.h" + +1482624916 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_queue.cpp + + "../src/intrusive_queue.h" + "../src/intrusive_links.h" + + +1482354421 d:\users\john\documents\programming\github\etl\src\intrusive_queue.h + + "type_traits.h" + "error_handler.h" + "intrusive_links.h" + "private/counter_type.h" + +1482624474 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_stack.cpp + + "../src/intrusive_stack.h" + "../src/intrusive_links.h" + + +1482354421 d:\users\john\documents\programming\github\etl\src\intrusive_stack.h + + "type_traits.h" + "error_handler.h" + "intrusive_links.h" + "private/counter_type.h" + +1482614415 source:d:\users\john\documents\programming\github\etl\test\test_string_char.cpp + + + + + "../src/cstring.h" + +1482181573 tring.h" + +1482614484 d:\users\john\documents\programming\github\etl\src\cstring.h + "platform.h" + "basic_string.h" + "ibasic_string.h" + "hash.h" + +1479511689 d:\users\john\documents\programming\github\etl\src\basic_string.h + + + + "ibasic_string.h" + "char_traits.h" + "container.h" + "alignment.h" + "array.h" + +1482748239 d:\users\john\documents\programming\github\etl\src\ibasic_string.h + + + + + + "private/string_base.h" + "platform.h" + "algorithm.h" + "type_traits.h" + "error_handler.h" + "algorithm.h" + "char_traits.h" + +1482614484 d:\users\john\documents\programming\github\etl\src\private\string_base.h + + "../platform.h" + "../integral_limits.h" + "../exception.h" + "../error_handler.h" + +1482099557 source:d:\users\john\documents\programming\github\etl\test\test_string_u16.cpp + + + + + "../src/u16string.h" + +1482099557 6string.h" + +1481841066 d:\users\john\documents\programming\github\etl\src\u16string.h + "platform.h" + "basic_string.h" + "hash.h" + +1482099666 source:d:\users\john\documents\programming\github\etl\test\test_string_u32.cpp + + + + + "../src/u32string.h" + +1482099666 2string.h" + +1481841066 d:\users\john\documents\programming\github\etl\src\u32string.h + "platform.h" + "basic_string.h" + "hash.h" + +1482181573 source:d:\users\john\documents\programming\github\etl\test\test_string_wchar_t.cpp + + + + + "../src/wstring.h" + +1481841066 d:\users\john\documents\programming\github\etl\src\wstring.h + "platform.h" + "basic_string.h" + "hash.h" + +1482624916 source:d:\users\john\documents\programming\github\etl\test\test_type_def.cpp + + + "../src/type_def.h" + +1482624916 pe_def.h" + +1481841066 d:\users\john\documents\programming\github\etl\src\type_def.h + +1482074959 source:d:\users\john\documents\programming\github\etl\test\test_utility.cpp + + "../src/utility.h" + +1482074959 ility.h" + +1482075058 d:\users\john\documents\programming\github\etl\src\utility.h + "type_traits.h" + +1479511692 source:d:\users\john\documents\programming\github\etl\test\test_vector_pointer.cpp + + + + + "../src/vector.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/AssertException.cpp + "AssertException.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/AssertException.h + "Config.h" + "HelperMacros.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Config.h + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/HelperMacros.h + "Config.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Checks.cpp + "Checks.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Checks.h + "Config.h" + "TestResults.h" + "MemoryOutStream.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestResults.h + "HelperMacros.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/MemoryOutStream.h + "Config.h" + "HelperMacros.h" + + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/CompositeTestReporter.cpp + "CompositeTestReporter.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/CompositeTestReporter.h + "TestReporter.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestReporter.h + "HelperMacros.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/CurrentTest.cpp + "CurrentTest.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/CurrentTest.h + "HelperMacros.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/DeferredTestReporter.cpp + "Config.h" + "DeferredTestReporter.h" + "TestDetails.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/DeferredTestReporter.h + "Config.h" + "TestReporter.h" + "DeferredTestResult.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/DeferredTestResult.h + "Config.h" + "HelperMacros.h" + + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestDetails.h + "HelperMacros.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/DeferredTestResult.cpp + "Config.h" + "DeferredTestResult.h" + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/MemoryOutStream.cpp + "MemoryOutStream.h" + + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp + "SignalTranslator.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Posix/SignalTranslator.h + + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp + "TimeHelpers.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Posix/TimeHelpers.h + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ReportAssert.cpp + "ReportAssert.h" + "ReportAssertImpl.h" + "AssertException.h" + "CurrentTest.h" + "TestResults.h" + "TestDetails.h" + "ReportAssertImpl.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ReportAssert.h + "HelperMacros.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ReportAssertImpl.h + "Config.h" + "HelperMacros.h" + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/RequiredCheckException.cpp + "RequiredCheckException.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/RequiredCheckException.h + "Config.h" + "HelperMacros.h" + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/RequiredCheckTestReporter.cpp + "RequiredCheckTestReporter.h" + "CurrentTest.h" + "TestResults.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/RequiredCheckTestReporter.h + "HelperMacros.h" + "ThrowingTestReporter.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ThrowingTestReporter.h + "TestReporter.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Test.cpp + "Config.h" + "Test.h" + "TestList.h" + "TestResults.h" + "AssertException.h" + "MemoryOutStream.h" + "ExecuteTest.h" + "Posix/SignalTranslator.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Test.h + "TestDetails.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestList.h + "HelperMacros.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ExecuteTest.h + "Config.h" + "ExceptionMacros.h" + "TestDetails.h" + "TestResults.h" + "MemoryOutStream.h" + "AssertException.h" + "RequiredCheckException.h" + "CurrentTest.h" + "ReportAssertImpl.h" + "Posix/SignalTranslator.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ExceptionMacros.h + "Config.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestDetails.cpp + "TestDetails.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestList.cpp + "TestList.h" + "Test.h" + + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestReporter.cpp + "TestReporter.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestReporterStdout.cpp + "TestReporterStdout.h" + + "TestDetails.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestReporterStdout.h + "TestReporter.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestResults.cpp + "TestResults.h" + "TestReporter.h" + "TestDetails.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestRunner.cpp + "TestRunner.h" + "TestResults.h" + "TestReporter.h" + "TestReporterStdout.h" + "TimeHelpers.h" + "MemoryOutStream.h" + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestRunner.h + "Test.h" + "TestList.h" + "CurrentTest.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TimeHelpers.h + "Config.h" + "Posix/TimeHelpers.h" + "Win32/TimeHelpers.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/Win32/TimeHelpers.h + "../Config.h" + "../HelperMacros.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/ThrowingTestReporter.cpp + "ThrowingTestReporter.h" + "RequiredCheckException.h" + "ReportAssertImpl.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TimeConstraint.cpp + "TimeConstraint.h" + "TestResults.h" + "MemoryOutStream.h" + "CurrentTest.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TimeConstraint.h + "TimeHelpers.h" + "HelperMacros.h" + "TestDetails.h" + +1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/XmlTestReporter.cpp + "Config.h" + "XmlTestReporter.h" + + + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/XmlTestReporter.h + "Config.h" + "DeferredTestReporter.h" + + +1479511689 source:/mnt/hgfs/Programming/GitHub/etl/src/crc16.cpp + + +1479511689 source:/mnt/hgfs/Programming/GitHub/etl/src/crc16_ccitt.cpp + + +1479511689 source:/mnt/hgfs/Programming/GitHub/etl/src/crc16_kermit.cpp + + +1479511689 source:/mnt/hgfs/Programming/GitHub/etl/src/crc32.cpp + + +1479511689 source:/mnt/hgfs/Programming/GitHub/etl/src/crc64_ecma.cpp + + +1481309487 source:/mnt/hgfs/Programming/GitHub/etl/src/crc8_ccitt.cpp + + "platform.h" + "static_assert.h" + +1482759320 /mnt/hgfs/Programming/GitHub/etl/src/platform.h + + + +1481841065 /mnt/hgfs/Programming/GitHub/etl/src/static_assert.h + "platform.h" + +1479511689 source:/mnt/hgfs/Programming/GitHub/etl/src/error_handler.cpp + "error_handler.h" + "nullptr.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/error_handler.h + + "exception.h" + "function.h" + +1481841065 /mnt/hgfs/Programming/GitHub/etl/src/exception.h + +1481841065 /mnt/hgfs/Programming/GitHub/etl/src/function.h + +1481308917 /mnt/hgfs/Programming/GitHub/etl/src/nullptr.h + "platform.h" + + +1481841066 source:/mnt/hgfs/Programming/GitHub/etl/src/pearson.cpp + + "platform.h" + "static_assert.h" + +1482079098 source:/mnt/hgfs/Programming/GitHub/etl/src/private/pvoidvector.cpp + "pvoidvector.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/private/pvoidvector.h + + + + + "../platform.h" + "../algorithm.h" + "vector_base.h" + "../type_traits.h" + "../error_handler.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/algorithm.h + + + + + + "type_traits.h" + +1482922140 /mnt/hgfs/Programming/GitHub/etl/src/type_traits.h + + "platform.h" + "nullptr.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/private/vector_base.h + + "../exception.h" + "../error_handler.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/main.cpp + + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/UnitTest++.h + "UnitTestPP.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/UnitTestPP.h + "Config.h" + "TestMacros.h" + "CheckMacros.h" + "RequireMacros.h" + "TestRunner.h" + "TimeConstraint.h" + "ReportAssert.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestMacros.h + "Config.h" + "TestSuite.h" + "ExceptionMacros.h" + "ExecuteTest.h" + "AssertException.h" + "TestDetails.h" + "MemoryOutStream.h" + "Posix/SignalTranslator.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/TestSuite.h + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/CheckMacros.h + "HelperMacros.h" + "ExceptionMacros.h" + "Checks.h" + "AssertException.h" + "RequiredCheckException.h" + "MemoryOutStream.h" + "TestDetails.h" + "CurrentTest.h" + "ReportAssertImpl.h" + +1482076051 /mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/RequireMacros.h + "RequiredCheckTestReporter.h" + +1481841065 source:/mnt/hgfs/Programming/GitHub/etl/test/murmurhash3.cpp + "murmurhash3.h" + + +1479511691 /mnt/hgfs/Programming/GitHub/etl/test/murmurhash3.h + "../src/platform.h" + + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_algorithm.cpp + + "../src/algorithm.h" + "../src/container.h" + + + + + +1482613987 /mnt/hgfs/Programming/GitHub/etl/src/container.h + + + +1482624126 source:/mnt/hgfs/Programming/GitHub/etl/test/test_alignment.cpp + + "../src/alignment.h" + "../src/type_traits.h" + + + + + +1481309570 /mnt/hgfs/Programming/GitHub/etl/src/alignment.h + + "type_traits.h" + "static_assert.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_array.cpp + + "../src/array.h" + + + + "../src/integral_limits.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/array.h + + + + + "exception.h" + "type_traits.h" + "parameter_type.h" + "static_assert.h" + "error_handler.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/parameter_type.h + "type_traits.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/integral_limits.h + + + "type_traits.h" + "platform.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_binary.cpp + + + + "../src/binary.h" + "../src/bitset.h" + "../src/fnv_1.h" + "../src/integral_limits.h" + +1481309537 /mnt/hgfs/Programming/GitHub/etl/src/binary.h + + + "type_traits.h" + "integral_limits.h" + "static_assert.h" + "log.h" + "power.h" + "smallest.h" + "platform.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/log.h + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/power.h + + "log.h" + +1482653105 /mnt/hgfs/Programming/GitHub/etl/src/smallest.h + + "integral_limits.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/bitset.h + + + + + "platform.h" + "integral_limits.h" + "algorithm.h" + "nullptr.h" + "log.h" + "ibitset.h" + "error_handler.h" + +1481309224 /mnt/hgfs/Programming/GitHub/etl/src/ibitset.h + + + + "exception.h" + "integral_limits.h" + "binary.h" + "algorithm.h" + "platform.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/fnv_1.h + + "platform.h" + "static_assert.h" + "type_traits.h" + "ihash.h" + "frame_check_sequence.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/ihash.h + + + "exception.h" + "error_handler.h" + +1481841065 /mnt/hgfs/Programming/GitHub/etl/src/frame_check_sequence.h + + "platform.h" + "static_assert.h" + "type_traits.h" + "binary.h" + +1482623861 source:/mnt/hgfs/Programming/GitHub/etl/test/test_bitset.cpp + + + + + "../src/bitset.h" + +1482612858 source:/mnt/hgfs/Programming/GitHub/etl/test/test_bloom_filter.cpp + + + + "../src/bloom_filter.h" + "../src/fnv_1.h" + "../src/crc16.h" + "../src/crc16_ccitt.h" + "../src/crc32.h" + "../src/char_traits.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/bloom_filter.h + "parameter_type.h" + "bitset.h" + "type_traits.h" + "binary.h" + "log.h" + "power.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/crc16.h + + + "platform.h" + "frame_check_sequence.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/crc16_ccitt.h + + + "platform.h" + "frame_check_sequence.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/crc32.h + + + "platform.h" + "frame_check_sequence.h" + +1481309504 /mnt/hgfs/Programming/GitHub/etl/src/char_traits.h + + "platform.h" + "stdint.h" + "algorithm.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_bsd_checksum.cpp + + + + + + "../src/checksum.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/checksum.h + + "binary.h" + "frame_check_sequence.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_checksum.cpp + + + + + + "../src/checksum.h" + "../src/endian.h" + +1481309464 /mnt/hgfs/Programming/GitHub/etl/src/endian.h + + "enum_type.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/enum_type.h + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_container.cpp + + "../src/container.h" + + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_crc.cpp + + + + + + "../src/crc8_ccitt.h" + "../src/crc16.h" + "../src/crc16_ccitt.h" + "../src/crc16_kermit.h" + "../src/crc32.h" + "../src/crc64_ecma.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/crc8_ccitt.h + + + "platform.h" + "frame_check_sequence.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/crc16_kermit.h + + + "platform.h" + "frame_check_sequence.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/crc64_ecma.h + + + "platform.h" + "frame_check_sequence.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_cyclic_value.cpp + + "../src/cyclic_value.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/cyclic_value.h + + + "static_assert.h" + "exception.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_debounce.cpp + + "../src/debounce.h" + +1481309477 /mnt/hgfs/Programming/GitHub/etl/src/debounce.h + + "static_assert.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_deque.cpp + + "ExtraCheckMacros.h" + "../src/deque.h" + "data.h" + + + + + + +1479511691 /mnt/hgfs/Programming/GitHub/etl/test/ExtraCheckMacros.h + + + + + + + + + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/deque.h + + + + + "ideque.h" + "container.h" + "alignment.h" + "array.h" + +1482624126 /mnt/hgfs/Programming/GitHub/etl/src/ideque.h + + + "algorithm.h" + "type_traits.h" + "private/deque_base.h" + "parameter_type.h" + "error_handler.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/private/deque_base.h + + "../exception.h" + "../error_handler.h" + +1482185150 /mnt/hgfs/Programming/GitHub/etl/test/data.h + + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_endian.cpp + + + "../src/endian.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_enum_type.cpp + + + "../src/enum_type.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_error_handler.cpp + + + + + "../src/error_handler.h" + "../src/exception.h" + +1482625380 source:/mnt/hgfs/Programming/GitHub/etl/test/test_exception.cpp + + + "../src/exception.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_fixed_iterator.cpp + + + + "../src/fixed_iterator.h" + +1482624125 /mnt/hgfs/Programming/GitHub/etl/src/fixed_iterator.h + + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_flat_map.cpp + + + + + + + + + "data.h" + "../src/flat_map.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/flat_map.h + + + + "iflat_map.h" + "vector.h" + +1482748252 /mnt/hgfs/Programming/GitHub/etl/src/iflat_map.h + + + + + + "private/flat_map_base.h" + "type_traits.h" + "parameter_type.h" + "ivector.h" + "error_handler.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/private/flat_map_base.h + + "../exception.h" + "../ivector.h" + "../error_handler.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/ivector.h + + + + + "platform.h" + "algorithm.h" + "private/vector_base.h" + "type_traits.h" + "parameter_type.h" + "error_handler.h" + "private/ivectorpointer.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/private/ivectorpointer.h + "pvoidvector.h" + +1481841065 /mnt/hgfs/Programming/GitHub/etl/src/vector.h + + + + "ivector.h" + "container.h" + "alignment.h" + "array.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_flat_multimap.cpp + + + + + + + + + "data.h" + "../src/flat_multimap.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/flat_multimap.h + + + + "iflat_multimap.h" + "vector.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/iflat_multimap.h + + + + + + "private/flat_multimap_base.h" + "type_traits.h" + "parameter_type.h" + "ivector.h" + "error_handler.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/private/flat_multimap_base.h + + "../exception.h" + "../ivector.h" + "../error_handler.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_flat_multiset.cpp + + + + + + + + + "data.h" + "../src/flat_multiset.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/flat_multiset.h + + + + "iflat_multiset.h" + "vector.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/iflat_multiset.h + + + + + + "private/flat_multiset_base.h" + "type_traits.h" + "parameter_type.h" + "ivector.h" + "error_handler.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/private/flat_multiset_base.h + + "../exception.h" + "../ivector.h" + "../error_handler.h" + +1479511691 source:/mnt/hgfs/Programming/GitHub/etl/test/test_flat_set.cpp + + + + + + + + + "data.h" + "../src/flat_set.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/flat_set.h + + + + "iflat_set.h" + "vector.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/iflat_set.h + + + + + + "private/flat_set_base.h" + "type_traits.h" + "parameter_type.h" + "ivector.h" + "error_handler.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/private/flat_set_base.h + + "../exception.h" + "../ivector.h" + "../error_handler.h" + +1482623723 source:/mnt/hgfs/Programming/GitHub/etl/test/test_fnv_1.cpp + + + + + + "../src/fnv_1.h" + +1482625680 source:/mnt/hgfs/Programming/GitHub/etl/test/test_forward_list.cpp + + "ExtraCheckMacros.h" + "data.h" + "../src/forward_list.h" + + + + + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/forward_list.h + + "pool.h" + "iforward_list.h" + "container.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/pool.h + "alignment.h" + "array.h" + "bitset.h" + "ipool.h" + + +1481841065 /mnt/hgfs/Programming/GitHub/etl/src/ipool.h + + "private/pool_base.h" + "nullptr.h" + "ibitset.h" + "error_handler.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/private/pool_base.h + + "../exception.h" + "../error_handler.h" + "../error_handler.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/iforward_list.h + "platform.h" + + + + + "pool.h" + "nullptr.h" + "private/forward_list_base.h" + "type_traits.h" + "parameter_type.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/private/forward_list_base.h + + "../exception.h" + "../error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_function.cpp + + "../src/function.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_functional.cpp + + "../src/functional.h" + + + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/functional.h + +1482624624 source:/mnt/hgfs/Programming/GitHub/etl/test/test_hash.cpp + + + + + + "../src/hash.h" + +1481841145 /mnt/hgfs/Programming/GitHub/etl/src/hash.h + + + "fnv_1.h" + "type_traits.h" + "static_assert.h" + +1482624916 source:/mnt/hgfs/Programming/GitHub/etl/test/test_instance_count.cpp + + "../src/instance_count.h" + + + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/instance_count.h + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_integral_limits.cpp + + + + + "../src/integral_limits.h" + +1482799048 source:/mnt/hgfs/Programming/GitHub/etl/test/test_intrusive_forward_list.cpp + + "ExtraCheckMacros.h" + "data.h" + "../src/intrusive_forward_list.h" + + + + + + + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/intrusive_forward_list.h + "platform.h" + + + + + "nullptr.h" + "type_traits.h" + "exception.h" + "error_handler.h" + "intrusive_links.h" + "algorithm.h" + "private/counter_type.h" + +1482357841 /mnt/hgfs/Programming/GitHub/etl/src/intrusive_links.h + + + "nullptr.h" + "type_traits.h" + "exception.h" + "error_handler.h" + +1482353821 /mnt/hgfs/Programming/GitHub/etl/src/private/counter_type.h + +1482358550 source:/mnt/hgfs/Programming/GitHub/etl/test/test_intrusive_links.cpp + + "ExtraCheckMacros.h" + "data.h" + "../src/intrusive_links.h" + +1482840779 source:/mnt/hgfs/Programming/GitHub/etl/test/test_intrusive_list.cpp + + "ExtraCheckMacros.h" + "data.h" + "../src/intrusive_list.h" + + + + + + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/intrusive_list.h + "platform.h" + + + + + "nullptr.h" + "type_traits.h" + "exception.h" + "error_handler.h" + "intrusive_links.h" + "static_assert.h" + "algorithm.h" + "private/counter_type.h" + +1482624916 source:/mnt/hgfs/Programming/GitHub/etl/test/test_intrusive_queue.cpp + + "../src/intrusive_queue.h" + "../src/intrusive_links.h" + + +1482354421 /mnt/hgfs/Programming/GitHub/etl/src/intrusive_queue.h + + "type_traits.h" + "error_handler.h" + "intrusive_links.h" + "private/counter_type.h" + +1482624474 source:/mnt/hgfs/Programming/GitHub/etl/test/test_intrusive_stack.cpp + + "../src/intrusive_stack.h" + "../src/intrusive_links.h" + + +1482354421 /mnt/hgfs/Programming/GitHub/etl/src/intrusive_stack.h + + "type_traits.h" + "error_handler.h" + "intrusive_links.h" + "private/counter_type.h" + +1482750186 source:/mnt/hgfs/Programming/GitHub/etl/test/test_io_port.cpp + + "../src/io_port.h" + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/io_port.h + + "nullptr.h" + "parameter_type.h" + +1482624277 source:/mnt/hgfs/Programming/GitHub/etl/test/test_jenkins.cpp + + "murmurhash3.h" + + + + + "../src/jenkins.h" + "../src/endian.h" + +1481872412 /mnt/hgfs/Programming/GitHub/etl/src/jenkins.h + + + "platform.h" + "static_assert.h" + "type_traits.h" + "error_handler.h" + "ihash.h" + "frame_check_sequence.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_largest.cpp + + "../src/largest.h" + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/largest.h + "type_traits.h" + +1482625302 source:/mnt/hgfs/Programming/GitHub/etl/test/test_list.cpp + + "ExtraCheckMacros.h" + "../src/list.h" + "data.h" + + + + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/list.h + + "ilist.h" + "container.h" + "pool.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/ilist.h + + + + + "nullptr.h" + "private/list_base.h" + "type_traits.h" + "parameter_type.h" + "pool.h" + "platform.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/private/list_base.h + + "../exception.h" + "../error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_map.cpp + + + + + + + + + "../src/map.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/map.h + + + + "imap.h" + "container.h" + "pool.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/imap.h + + + + + "nullptr.h" + "private/map_base.h" + "type_traits.h" + "parameter_type.h" + "pool.h" + "platform.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/private/map_base.h + + "../exception.h" + "../error_handler.h" + +1482692728 source:/mnt/hgfs/Programming/GitHub/etl/test/test_maths.cpp + + "../src/log.h" + "../src/power.h" + "../src/fibonacci.h" + "../src/factorial.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/fibonacci.h + + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/factorial.h + + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_multimap.cpp + + + + + + + + "../src/multimap.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/multimap.h + + + + "imultimap.h" + "container.h" + "pool.h" + +1482098369 /mnt/hgfs/Programming/GitHub/etl/src/imultimap.h + + + + + "nullptr.h" + "private/multimap_base.h" + "type_traits.h" + "parameter_type.h" + "pool.h" + "platform.h" + +1481309650 /mnt/hgfs/Programming/GitHub/etl/src/private/multimap_base.h + + "../exception.h" + "../error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_multiset.cpp + + + + + + + + "../src/multiset.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/multiset.h + + + + "imultiset.h" + "container.h" + "pool.h" + +1482098369 /mnt/hgfs/Programming/GitHub/etl/src/imultiset.h + + + + + "nullptr.h" + "private/multiset_base.h" + "type_traits.h" + "parameter_type.h" + "pool.h" + "platform.h" + +1481309628 /mnt/hgfs/Programming/GitHub/etl/src/private/multiset_base.h + + "../exception.h" + "../error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_murmur3.cpp + + "murmurhash3.h" + + + + + "../src/murmur3.h" + "../src/endian.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/murmur3.h + + "platform.h" + "ihash.h" + "binary.h" + "error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_numeric.cpp + + "../src/numeric.h" + + + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/numeric.h + +1482624916 source:/mnt/hgfs/Programming/GitHub/etl/test/test_observer.cpp + + "../src/observer.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/observer.h + + "vector.h" + "exception.h" + "error_handler.h" + +1482624916 source:/mnt/hgfs/Programming/GitHub/etl/test/test_optional.cpp + + + + "../src/optional.h" + "../src/vector.h" + "data.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/optional.h + "alignment.h" + "type_traits.h" + "exception.h" + "error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_pearson.cpp + + + + + + + "../src/pearson.h" + "../src/endian.h" + +1481308892 /mnt/hgfs/Programming/GitHub/etl/src/pearson.h + + "platform.h" + "static_assert.h" + "type_traits.h" + "endian.h" + "ihash.h" + "array.h" + "container.h" + +1482750186 source:/mnt/hgfs/Programming/GitHub/etl/test/test_pool.cpp + + "ExtraCheckMacros.h" + "data.h" + + + "../src/pool.h" + +1482624474 source:/mnt/hgfs/Programming/GitHub/etl/test/test_priority_queue.cpp + + + "../src/priority_queue.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/priority_queue.h + + + "ipriority_queue.h" + "container.h" + "vector.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/ipriority_queue.h + + + "type_traits.h" + "parameter_type.h" + "error_handler.h" + "exception.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_queue.cpp + + + "../src/queue.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/queue.h + + + "iqueue.h" + "container.h" + "alignment.h" + "array.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/iqueue.h + + "private/queue_base.h" + "type_traits.h" + "parameter_type.h" + "error_handler.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/private/queue_base.h + + "../exception.h" + "../error_handler.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_set.cpp + + + + + + + + + "../src/set.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/set.h + + + + "iset.h" + "container.h" + "pool.h" + +1479511690 /mnt/hgfs/Programming/GitHub/etl/src/iset.h + + + + + "nullptr.h" + "private/set_base.h" + "type_traits.h" + "parameter_type.h" + "pool.h" + "platform.h" + +1482625676 /mnt/hgfs/Programming/GitHub/etl/src/private/set_base.h + + "../exception.h" + "../error_handler.h" + +1482654345 source:/mnt/hgfs/Programming/GitHub/etl/test/test_smallest.cpp + + "../src/smallest.h" + + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_stack.cpp + + + "data.h" + "../src/stack.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/stack.h + + + + "istack.h" + "container.h" + "alignment.h" + "array.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/istack.h + + "private/stack_base.h" + "type_traits.h" + "parameter_type.h" + "error_handler.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/private/stack_base.h + + "../exception.h" + "../error_handler.h" + +1482614415 source:/mnt/hgfs/Programming/GitHub/etl/test/test_string_char.cpp + + + + + "../src/cstring.h" + +1482614484 /mnt/hgfs/Programming/GitHub/etl/src/cstring.h + "platform.h" + "basic_string.h" + "ibasic_string.h" + "hash.h" + +1479511689 /mnt/hgfs/Programming/GitHub/etl/src/basic_string.h + + + + "ibasic_string.h" + "char_traits.h" + "container.h" + "alignment.h" + "array.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/ibasic_string.h + + + + + + "private/string_base.h" + "platform.h" + "algorithm.h" + "type_traits.h" + "error_handler.h" + "algorithm.h" + "char_traits.h" + +1482614484 /mnt/hgfs/Programming/GitHub/etl/src/private/string_base.h + + "../platform.h" + "../integral_limits.h" + "../exception.h" + "../error_handler.h" + +1482099557 source:/mnt/hgfs/Programming/GitHub/etl/test/test_string_u16.cpp + + + + + "../src/u16string.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/u16string.h + "platform.h" + "basic_string.h" + "hash.h" + +1482099666 source:/mnt/hgfs/Programming/GitHub/etl/test/test_string_u32.cpp + + + + + "../src/u32string.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/u32string.h + "platform.h" + "basic_string.h" + "hash.h" + +1482181573 source:/mnt/hgfs/Programming/GitHub/etl/test/test_string_wchar_t.cpp + + + + + "../src/wstring.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/wstring.h + "platform.h" + "basic_string.h" + "hash.h" + +1482624916 source:/mnt/hgfs/Programming/GitHub/etl/test/test_type_def.cpp + + + "../src/type_def.h" + +1481841066 /mnt/hgfs/Programming/GitHub/etl/src/type_def.h + +1482624915 source:/mnt/hgfs/Programming/GitHub/etl/test/test_unordered_map.cpp + + + + + + + + + + "data.h" + "../src/unordered_map.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/unordered_map.h + + + + "iunordered_map.h" + "container.h" + "pool.h" + "vector.h" + "intrusive_forward_list.h" + "hash.h" + +1482748240 /mnt/hgfs/Programming/GitHub/etl/src/iunordered_map.h + + + + + + "type_traits.h" + "parameter_type.h" + "hash.h" + "nullptr.h" + "ipool.h" + "ivector.h" + "error_handler.h" + "intrusive_forward_list.h" + "exception.h" + "error_handler.h" + +1482625301 source:/mnt/hgfs/Programming/GitHub/etl/test/test_unordered_multimap.cpp + + + + + + + + + + "data.h" + "../src/unordered_multimap.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/unordered_multimap.h + + + + "iunordered_multimap.h" + "container.h" + "pool.h" + "vector.h" + "intrusive_forward_list.h" + "hash.h" + +1482748240 /mnt/hgfs/Programming/GitHub/etl/src/iunordered_multimap.h + + + + + + "type_traits.h" + "parameter_type.h" + "hash.h" + "nullptr.h" + "ipool.h" + "ivector.h" + "error_handler.h" + "intrusive_forward_list.h" + "exception.h" + "error_handler.h" + +1482625301 source:/mnt/hgfs/Programming/GitHub/etl/test/test_unordered_multiset.cpp + + + + + + + + + + "data.h" + "../src/unordered_multiset.h" + "../src/checksum.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/unordered_multiset.h + + + + "iunordered_multiset.h" + "container.h" + "pool.h" + "vector.h" + "intrusive_forward_list.h" + "hash.h" + +1482748239 /mnt/hgfs/Programming/GitHub/etl/src/iunordered_multiset.h + + + + + + "type_traits.h" + "parameter_type.h" + "hash.h" + "nullptr.h" + "ipool.h" + "ivector.h" + "error_handler.h" + "intrusive_forward_list.h" + "exception.h" + "error_handler.h" + +1482624916 source:/mnt/hgfs/Programming/GitHub/etl/test/test_unordered_set.cpp + + + + + + + + + "data.h" + "../src/unordered_set.h" + "../src/checksum.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/unordered_set.h + + + + "iunordered_set.h" + "container.h" + "pool.h" + "vector.h" + "intrusive_forward_list.h" + "hash.h" + +1482748240 /mnt/hgfs/Programming/GitHub/etl/src/iunordered_set.h + + + + + + "type_traits.h" + "parameter_type.h" + "hash.h" + "nullptr.h" + "ipool.h" + "ivector.h" + "error_handler.h" + "intrusive_forward_list.h" + "exception.h" + "error_handler.h" + +1482074959 source:/mnt/hgfs/Programming/GitHub/etl/test/test_utility.cpp + + "../src/utility.h" + +1482075058 /mnt/hgfs/Programming/GitHub/etl/src/utility.h + "type_traits.h" + +1481841066 source:/mnt/hgfs/Programming/GitHub/etl/test/test_variant.cpp + + "ExtraCheckMacros.h" + "../src/variant.h" + + + + +1481841437 /mnt/hgfs/Programming/GitHub/etl/src/variant.h + + "platform.h" + "array.h" + "largest.h" + "exception.h" + "type_traits.h" + "integral_limits.h" + "static_assert.h" + "alignment.h" + "error_handler.h" + "largest.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_vector.cpp + + + + + "../src/vector.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_vector_pointer.cpp + + + + + "../src/vector.h" + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_visitor.cpp + + "../src/visitor.h" + +1479511691 /mnt/hgfs/Programming/GitHub/etl/src/visitor.h + +1479511692 source:/mnt/hgfs/Programming/GitHub/etl/test/test_xor_checksum.cpp + + + + + + "../src/checksum.h" + +1482922480 source:/mnt/hgfs/Programming/GitHub/etl/test/test_type_traits.cpp + + "../src/type_traits.h" + + + diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index 8fa3ea47..199dbeca 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -1,355 +1,419 @@ - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index c671e270..69d2a083 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -169,6 +169,7 @@ + @@ -208,6 +209,7 @@ + @@ -271,7 +273,6 @@ - @@ -281,6 +282,7 @@ + @@ -358,15 +360,20 @@ - true + false - true + false - true + false + + + false + + + false - @@ -403,6 +410,7 @@ + diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index 244fdd50..d74a3301 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -498,9 +498,6 @@ ETL\Containers - - ETL\Containers - ETL\Containers @@ -522,6 +519,15 @@ ETL\Containers + + ETL\Utilities + + + ETL\Containers + + + ETL\Containers + @@ -812,6 +818,12 @@ Source Files + + Source Files + + + Source Files + From 77ecb120dc916afe8eaa3694210d5af77ba1c7fe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:21:54 +0000 Subject: [PATCH 088/168] Deleted files --- src/private/counter_type.h | 139 ------------------------- src/string.h | 203 ------------------------------------- 2 files changed, 342 deletions(-) delete mode 100644 src/private/counter_type.h delete mode 100644 src/string.h diff --git a/src/private/counter_type.h b/src/private/counter_type.h deleted file mode 100644 index df94fbe8..00000000 --- a/src/private/counter_type.h +++ /dev/null @@ -1,139 +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. -******************************************************************************/ - -#ifndef __ETL_COUNTER_TYPE__ -#define __ETL_COUNTER_TYPE__ - -#include - -#include "../intrusive_links.h" - -namespace etl -{ - //************************************************************************* - /// Counter type based on intrusive link count option. - //************************************************************************* - template - class counter_type - { - }; - - //************************************************************************* - /// Slow type. - //************************************************************************* - template <> - class counter_type - { - public: - - counter_type& operator ++() - { - return *this; - } - - counter_type& operator --() - { - return *this; - } - - counter_type& operator =(size_t new_count) - { - return *this; - } - - counter_type& operator +=(size_t diff) - { - return *this; - } - - counter_type& operator -=(size_t diff) - { - return *this; - } - - size_t get_count() const - { - return 0; - } - }; - - //************************************************************************* - /// Fast type. - //************************************************************************* - template <> - class counter_type - { - public: - - counter_type() - : count(0) - { - } - - counter_type& operator ++() - { - ++count; - return *this; - } - - counter_type& operator --() - { - --count; - return *this; - } - - counter_type& operator =(size_t new_count) - { - count = new_count; - return *this; - } - - counter_type& operator +=(size_t diff) - { - count += diff; - return *this; - } - - counter_type& operator -=(size_t diff) - { - count -= diff; - return *this; - } - - size_t get_count() const - { - return count; - } - - size_t count; - }; -} - -#endif diff --git a/src/string.h b/src/string.h deleted file mode 100644 index 26f1fbdf..00000000 --- a/src/string.h +++ /dev/null @@ -1,203 +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. -******************************************************************************/ - -#ifndef __ETL_STRING__ -#define __ETL_STRING__ - -#include "platform.h" -#include "basic_string.h" -#include "hash.h" - -#if defined(ETL_COMPILER_MICROSOFT) - #undef min -#endif - -namespace etl -{ - typedef ibasic_string istring; - - //*************************************************************************** - /// A string implementation that uses a fixed size buffer. - ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. - ///\ingroup string - //*************************************************************************** - template - class string : public istring - { - public: - - typedef istring::value_type value_type; - - static const size_t MAX_SIZE = MAX_SIZE_; - - //************************************************************************* - /// Constructor. - //************************************************************************* - string() - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - istring::initialise(); - } - - //************************************************************************* - /// Copy constructor. - ///\param other The other string. - //************************************************************************* - string(const etl::string& other) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - istring::initialise(); - istring::assign(other.begin(), other.end()); - } - - //************************************************************************* - /// From other string, position, length. - ///\param other The other string. - ///\param position The position of the first character. - ///\param length The number of characters. Default = npos. - //************************************************************************* - string(const etl::string& other, size_t position, size_t length = npos) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - - // Set the length to the exact amount. - length = (length > MAX_SIZE_) ? MAX_SIZE_ : length; - - istring::initialise(); - istring::assign(other.begin() + position, other.begin() + position + length); - } - - //************************************************************************* - /// Constructor, from null terminated text. - ///\param text The initial text of the string. - //************************************************************************* - string(const value_type* text) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - istring::initialise(); - istring::assign(text, text + etl::char_traits::length(text)); - } - - //************************************************************************* - /// Constructor, from null terminated text and count. - ///\param text The initial text of the string. - ///\param count The number of characters to copy. - //************************************************************************* - string(const value_type* text, size_t count) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - istring::initialise(); - istring::assign(text, text + count); - } - - //************************************************************************* - /// Constructor, from initial size and value. - ///\param initialSize The initial size of the string. - ///\param value The value to fill the string with. - //************************************************************************* - string(size_t count, value_type c) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - istring::initialise(); - istring::resize(count, c); - } - - //************************************************************************* - /// Constructor, from an iterator range. - ///\tparam TIterator The iterator type. - ///\param first The iterator to the first element. - ///\param last The iterator to the last element + 1. - //************************************************************************* - template - string(TIterator first, TIterator last) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - istring::assign(first, last); - } - - //************************************************************************* - /// Returns a sub-string. - ///\param position The position of the first character. Default = 0. - ///\param length The number of characters. Default = npos. - //************************************************************************* - etl::string substr(size_t position = 0, size_t length = npos) const - { - etl::string new_string; - - if (position != size()) - { - ETL_ASSERT(position < size(), ETL_ERROR(string_out_of_bounds)); - - length = std::min(length, size() - position); - - new_string.assign(buffer + position, buffer + position + length); - } - - return new_string; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const string& rhs) - { - if (&rhs != this) - { - istring::assign(rhs.cbegin(), rhs.cend()); - } - - return *this; - } - - private: - - value_type buffer[MAX_SIZE + 1]; - }; - - //************************************************************************* - /// Hash function. - //************************************************************************* - template <> - struct hash - { - size_t operator()(const etl::istring& text) const - { - return etl::__private_hash__::generic_hash<>(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); - } - }; -} - -#if defined(ETL_COMPILER_MICROSOFT) - #define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#endif From bc18cfa49647f236ea441171fc4d5c87bb0cfa30 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:22:37 +0000 Subject: [PATCH 089/168] Tests for intrusive_queue --- test/test_intrusive_queue.cpp | 259 ++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 test/test_intrusive_queue.cpp diff --git a/test/test_intrusive_queue.cpp b/test/test_intrusive_queue.cpp new file mode 100644 index 00000000..a0f660e2 --- /dev/null +++ b/test/test_intrusive_queue.cpp @@ -0,0 +1,259 @@ +/****************************************************************************** +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 "../src/intrusive_queue.h" +#include "../src/intrusive_links.h" + +#include + +namespace +{ + typedef etl::forward_link<0> link0; + typedef etl::bidirectional_link<1> link1; + + struct Data : public link0, public link1 + { + Data(int i) + : i(i) + { + + } + + int i; + }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return lhs.i == rhs.i; + } + + std::ostream& operator << (std::ostream& os, const Data& data) + { + os << data.i; + return os; + } + + std::vector data = + { + Data(1), Data(2), Data(3), Data(4), Data(5), Data(6), Data(7), Data(8) + }; + + SUITE(test_intrusive_queue) + { + //************************************************************************* + TEST(test_constructor) + { + etl::intrusive_queue queueD; + etl::intrusive_queue queueC; + + CHECK(queueD.empty()); + CHECK(queueC.empty()); + + CHECK_EQUAL(0U, queueD.size()); + CHECK_EQUAL(0U, queueC.size()); + } + + //************************************************************************* + TEST(test_empty) + { + etl::intrusive_queue queueD; + etl::intrusive_queue queueC; + + Data data1(1); + Data data2(2); + + CHECK(queueD.empty()); + CHECK(queueC.empty()); + + queueD.push(data1); + queueC.push(data2); + + CHECK(!queueD.empty()); + CHECK(!queueC.empty()); + } + + //************************************************************************* + TEST(test_size) + { + Data data1(1); + Data data2(2); + Data data3(3); + + etl::intrusive_queue queueD; + etl::intrusive_queue queueC; + + queueD.push(data1); + queueD.push(data2); + queueD.push(data3); + + queueC.push(data1); + queueC.push(data2); + + CHECK_EQUAL(3U, queueD.size()); + CHECK_EQUAL(2U, queueC.size()); + } + + //************************************************************************* + TEST(test_clear) + { + Data data1(1); + Data data2(2); + Data data3(3); + + etl::intrusive_queue queueD; + etl::intrusive_queue queueC; + + queueD.push(data1); + queueD.push(data2); + queueD.push(data3); + + queueC.push(data1); + queueC.push(data2); + + queueD.clear(); + queueC.clear(); + + CHECK(queueD.empty()); + CHECK(queueC.empty()); + } + + //************************************************************************* + TEST(test_push) + { + Data data1(1); + Data data2(2); + Data data3(3); + + etl::intrusive_queue queueD; + etl::intrusive_queue queueC; + + queueD.push(data1); + CHECK_EQUAL(queueD.front(), data1); + CHECK_EQUAL(queueD.back(), data1); + + queueD.push(data2); + CHECK_EQUAL(queueD.front(), data1); + CHECK_EQUAL(queueD.back(), data2); + + queueD.push(data3); + CHECK_EQUAL(queueD.front(), data1); + CHECK_EQUAL(queueD.back(), data3); + + queueC.push(data1); + CHECK_EQUAL(queueC.front(), data1); + CHECK_EQUAL(queueC.back(), data1); + + queueC.push(data2); + CHECK_EQUAL(queueC.front(), data1); + CHECK_EQUAL(queueC.back(), data2); + } + + + //************************************************************************* + TEST(test_pop) + { + Data data1(1); + Data data2(2); + Data data3(3); + + etl::intrusive_queue queueD; + etl::intrusive_queue queueC; + + queueD.push(data1); + queueD.push(data2); + queueD.push(data3); + + queueC.push(data1); + queueC.push(data2); + + CHECK_EQUAL(queueD.front(), data1); + CHECK_EQUAL(queueD.back(), data3); + queueD.pop(); + CHECK_EQUAL(queueD.front(), data2); + CHECK_EQUAL(queueD.back(), data3); + queueD.pop(); + CHECK_EQUAL(queueD.front(), data3); + CHECK_EQUAL(queueD.back(), data3); + queueD.pop(); + CHECK(queueD.empty()); + + CHECK_EQUAL(queueC.front(), data1); + CHECK_EQUAL(queueC.back(), data2); + queueC.pop(); + CHECK_EQUAL(queueC.front(), data2); + CHECK_EQUAL(queueC.back(), data2); + queueC.pop(); + CHECK(queueC.empty()); + } + + //************************************************************************* + TEST(test_front_const) + { + Data data1(1); + Data data2(2); + Data data3(3); + + etl::intrusive_queue queueD; + const etl::intrusive_queue& queueDR = queueD; + + queueD.push(data1); + queueD.push(data2); + queueD.push(data3); + + CHECK_EQUAL(queueD.front(), queueDR.front()); + queueD.pop(); + CHECK_EQUAL(queueD.front(), queueDR.front()); + queueD.pop(); + CHECK_EQUAL(queueD.front(), queueDR.front()); + } + + //************************************************************************* + TEST(test_back_const) + { + + Data data1(1); + Data data2(2); + Data data3(3); + + etl::intrusive_queue queueD; + const etl::intrusive_queue& queueDR = queueD; + + queueD.push(data1); + queueD.push(data2); + queueD.push(data3); + + CHECK_EQUAL(queueD.back(), queueDR.back()); + queueD.pop(); + CHECK_EQUAL(queueD.back(), queueDR.back()); + queueD.pop(); + CHECK_EQUAL(queueD.back(), queueDR.back()); + } + }; +} From d38cde25a692267796aa117d2eda7ee6dbfd6118 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:33:30 +0000 Subject: [PATCH 090/168] Replaces string.h --- src/cstring.h | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 src/cstring.h diff --git a/src/cstring.h b/src/cstring.h new file mode 100644 index 00000000..61f08f64 --- /dev/null +++ b/src/cstring.h @@ -0,0 +1,204 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_STRING__ +#define __ETL_STRING__ + +#include "platform.h" +#include "basic_string.h" +#include "ibasic_string.h" +#include "hash.h" + +#if defined(ETL_COMPILER_MICROSOFT) + #undef min +#endif + +namespace etl +{ + typedef etl::ibasic_string istring; + + //*************************************************************************** + /// A string implementation that uses a fixed size buffer. + ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. + ///\ingroup string + //*************************************************************************** + template + class string : public istring + { + public: + + typedef istring::value_type value_type; + + static const size_t MAX_SIZE = MAX_SIZE_; + + //************************************************************************* + /// Constructor. + //************************************************************************* + string() + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + istring::initialise(); + } + + //************************************************************************* + /// Copy constructor. + ///\param other The other string. + //************************************************************************* + string(const etl::string& other) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + istring::initialise(); + istring::assign(other.begin(), other.end()); + } + + //************************************************************************* + /// From other string, position, length. + ///\param other The other string. + ///\param position The position of the first character. + ///\param length The number of characters. Default = npos. + //************************************************************************* + string(const etl::string& other, size_t position, size_t length = npos) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); + + // Set the length to the exact amount. + length = (length > MAX_SIZE_) ? MAX_SIZE_ : length; + + istring::initialise(); + istring::assign(other.begin() + position, other.begin() + position + length); + } + + //************************************************************************* + /// Constructor, from null terminated text. + ///\param text The initial text of the string. + //************************************************************************* + string(const value_type* text) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + istring::initialise(); + istring::assign(text, text + etl::char_traits::length(text)); + } + + //************************************************************************* + /// Constructor, from null terminated text and count. + ///\param text The initial text of the string. + ///\param count The number of characters to copy. + //************************************************************************* + string(const value_type* text, size_t count) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + istring::initialise(); + istring::assign(text, text + count); + } + + //************************************************************************* + /// Constructor, from initial size and value. + ///\param initialSize The initial size of the string. + ///\param value The value to fill the string with. + //************************************************************************* + string(size_t count, value_type c) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + istring::initialise(); + istring::resize(count, c); + } + + //************************************************************************* + /// Constructor, from an iterator range. + ///\tparam TIterator The iterator type. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //************************************************************************* + template + string(TIterator first, TIterator last) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + istring::assign(first, last); + } + + //************************************************************************* + /// Returns a sub-string. + ///\param position The position of the first character. Default = 0. + ///\param length The number of characters. Default = npos. + //************************************************************************* + etl::string substr(size_t position = 0, size_t length = npos) const + { + etl::string new_string; + + if (position != this->size()) + { + ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds)); + + length = std::min(length, this->size() - position); + + new_string.assign(buffer + position, buffer + position + length); + } + + return new_string; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const string& rhs) + { + if (&rhs != this) + { + istring::assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + + private: + + value_type buffer[MAX_SIZE + 1]; + }; + + //************************************************************************* + /// Hash function. + //************************************************************************* + template <> + struct hash + { + size_t operator()(const etl::istring& text) const + { + return etl::__private_hash__::generic_hash<>(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); + } + }; +} + +#if defined(ETL_COMPILER_MICROSOFT) + #define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#endif From e7293655291d96a2b8b39762de2d7979f187df42 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:34:04 +0000 Subject: [PATCH 091/168] Support for vectors of pointers. --- src/private/pvoidvector.cpp | 107 ++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/private/pvoidvector.cpp diff --git a/src/private/pvoidvector.cpp b/src/private/pvoidvector.cpp new file mode 100644 index 00000000..6b74805d --- /dev/null +++ b/src/private/pvoidvector.cpp @@ -0,0 +1,107 @@ +///\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 "pvoidvector.h" + +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); + } +} + From 782fc9983ec6e9437930e944c38efee741e6be5d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 13:36:06 +0000 Subject: [PATCH 092/168] Support for vectors of pointers. --- src/ivectorpointer.h | 531 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 531 insertions(+) create mode 100644 src/ivectorpointer.h diff --git a/src/ivectorpointer.h b/src/ivectorpointer.h new file mode 100644 index 00000000..594af73a --- /dev/null +++ b/src/ivectorpointer.h @@ -0,0 +1,531 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_IVECTOR_POINTER__ +#define __ETL_IVECTOR_POINTER__ + +#ifndef __ETL_IN_IVECTOR_H__ +#error This header is a private element of etl::ivector +#endif + +namespace etl +{ + //*************************************************************************** + /// The base class for specifically sized vectors. + /// Can be used as a reference type for all vectors containing a specific pointer type. + ///\ingroup vector + //*************************************************************************** + template ::value, void>::type*/> + class ivector : public ivector + { + private: + + // Stops warning messages about unused template parameter. + //const bool not_void_ptr = typedef etl::is_same::value; + + public: + + typedef T* value_type; + typedef T*& reference; + typedef const T* const & const_reference; + typedef T** pointer; + typedef const T* const * const_pointer; + typedef T** iterator; + typedef const T* const * const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef size_t size_type; + typedef typename std::iterator_traits::difference_type difference_type; + + protected: + + typedef value_type parameter_t; + + private: + + typedef ivector base_t; + + public: + + //********************************************************************* + /// Returns an iterator to the beginning of the vector. + ///\return An iterator to the beginning of the vector. + //********************************************************************* + iterator begin() + { + return iterator(base_t::begin()); + } + + //********************************************************************* + /// 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(base_t::begin()); + } + + //********************************************************************* + /// Returns an iterator to the end of the vector. + ///\return An iterator to the end of the vector. + //********************************************************************* + iterator end() + { + return iterator(base_t::end()); + } + + //********************************************************************* + /// 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(base_t::end()); + } + + //********************************************************************* + /// 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(base_t::cbegin()); + } + + //********************************************************************* + /// 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(base_t::cend()); + } + + //********************************************************************* + /// 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(iterator(base_t::end())); + } + + //********************************************************************* + /// 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(const_iterator(base_t::end())); + } + + //********************************************************************* + /// 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(iterator(base_t::begin())); + } + + //********************************************************************* + /// 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(const_iterator(base_t::begin())); + } + + //********************************************************************* + /// 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(const_iterator(base_t::cend())); + } + + //********************************************************************* + /// 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(const_iterator(base_t::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) + { + base_t::resize(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) + { + base_t::resize(new_size, value); + } + + //********************************************************************* + /// 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(base_t::operator[](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(base_t::operator[](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) + { + return reference(base_t::at(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 + { + return const_reference(base_t::at(i)); + } + + //********************************************************************* + /// Returns a reference to the first element. + ///\return A reference to the first element. + //********************************************************************* + reference front() + { + return reference(base_t::front()); + } + + //********************************************************************* + /// Returns a const reference to the first element. + ///\return A const reference to the first element. + //********************************************************************* + const_reference front() const + { + return const_reference(base_t::front()); + } + + //********************************************************************* + /// Returns a reference to the last element. + ///\return A reference to the last element. + //********************************************************************* + reference back() + { + return reference(base_t::back()); + } + + //********************************************************************* + /// Returns a const reference to the last element. + ///\return A const reference to the last element. + //********************************************************************* + const_reference back() const + { + return const_reference(base_t::back()); + } + + //********************************************************************* + /// Returns a pointer to the beginning of the vector data. + ///\return A pointer to the beginning of the vector data. + //********************************************************************* + pointer data() + { + return pointer(base_t::data()); + } + + //********************************************************************* + /// 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(base_t::data()); + } + + //********************************************************************* + /// Assigns values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + /// If asserts or exceptions are enabled, emits vector_iterator if the iterators are reversed. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //********************************************************************* + template + void assign(TIterator first, TIterator last) + { + base_t::initialise(); + + while (first != last) + { + p_buffer[current_size++] = (void*)*first++; + } + } + + //********************************************************************* + /// 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, parameter_t value) + { + base_t::assign(n, value); + } + + //************************************************************************* + /// Clears the vector. + //************************************************************************* + void clear() + { + base_t::clear(); + } + + //************************************************************************* + /// Increases the size of the vector by one, but does not initialise the new element. + /// If asserts or exceptions are enabled, throws a vector_full if the vector is already full. + //************************************************************************* + void push_back() + { + base_t::push_back(); + } + + //********************************************************************* + /// 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(parameter_t value) + { + base_t::push_back(value); + } + + //************************************************************************* + /// Removes an element from the end of the vector. + /// Does nothing if the vector is empty. + //************************************************************************* + void pop_back() + { + base_t::pop_back(); + } + + //********************************************************************* + /// 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, parameter_t value) + { + return iterator(base_t::insert(base_t::iterator(position), value)); + } + + //********************************************************************* + /// 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, parameter_t value) + { + base_t::insert(base_t::iterator(position), n, value); + } + + //********************************************************************* + /// Inserts a range of 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 first The first element to add. + ///\param last The last + 1 element to add. + //********************************************************************* + template + void insert(iterator position, TIterator first, TIterator last) + { + base_t::insert(base_t::iterator(position), first, 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) + { + return iterator(base_t::erase(base_t::iterator(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. + //********************************************************************* + iterator erase(iterator first, iterator last) + { + return iterator(base_t::erase(base_t::iterator(first), base_t::iterator(last))); + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + ivector& operator = (const ivector& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + + protected: + + //********************************************************************* + /// Constructor. + //********************************************************************* + ivector(void** p_buffer, size_t MAX_SIZE) + : ivector(p_buffer, MAX_SIZE) + { + } + }; + + //*************************************************************************** + /// 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 + //*************************************************************************** + template + bool operator ==(const etl::ivector& lhs, const etl::ivector& 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 + //*************************************************************************** + template + bool operator !=(const etl::ivector& lhs, const etl::ivector& 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 + //*************************************************************************** + template + bool operator <(const etl::ivector& lhs, const etl::ivector& 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 + //*************************************************************************** + template + bool operator >(const etl::ivector& lhs, const etl::ivector& 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 lexigraphically less than or equal to the second, otherwise false + ///\ingroup vector + //*************************************************************************** + template + bool operator <=(const etl::ivector& lhs, const etl::ivector& 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 lexigraphically greater than or equal to the second, otherwise false + ///\ingroup vector + //*************************************************************************** + template + bool operator >=(const etl::ivector& lhs, const etl::ivector& rhs) + { + return !(lhs < rhs); + } +} + +#endif From 0112c572352f0241d629551917117a42ea2a2cd8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 28 Dec 2016 14:10:30 +0000 Subject: [PATCH 093/168] Updated to version 9.0.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index a29ea47a..fbd7fbf0 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=8.2.0 +version=9.0.0 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. From 6c4a29b498d27ecaec3adf5b4d3801998b1f89e0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 30 Dec 2016 11:56:08 +0000 Subject: [PATCH 094/168] Fixed bug in erase() --- src/iunordered_map.h | 11 +++++++++++ src/iunordered_multimap.h | 11 +++++++++++ src/iunordered_multiset.h | 11 +++++++++++ src/iunordered_set.h | 11 +++++++++++ test/test_unordered_map.cpp | 9 +++++++++ test/test_unordered_multimap.cpp | 9 +++++++++ test/test_unordered_multiset.cpp | 9 +++++++++ test/test_unordered_set.cpp | 9 +++++++++ 8 files changed, 80 insertions(+) diff --git a/src/iunordered_map.h b/src/iunordered_map.h index 2c1ff1bb..bfd5ef6c 100644 --- a/src/iunordered_map.h +++ b/src/iunordered_map.h @@ -872,6 +872,7 @@ namespace etl if (icurrent != bucket.end()) { bucket.erase_after(iprevious); + pnodepool->release(*icurrent); count = 1; } @@ -899,6 +900,7 @@ namespace etl } bucket.erase_after(iprevious); + pnodepool->release(*icurrent); return inext; } @@ -940,8 +942,17 @@ namespace etl } // Erase the range. + local_iterator irelease = iprevious; + ++irelease; + ibucket->erase_after(iprevious, iend); + while (irelease != iend) + { + pnodepool->release(*irelease); + ++irelease; + } + // At the end of this bucket? if (iend == ibucket->end()) { diff --git a/src/iunordered_multimap.h b/src/iunordered_multimap.h index 6b62924a..6f369585 100644 --- a/src/iunordered_multimap.h +++ b/src/iunordered_multimap.h @@ -758,6 +758,7 @@ namespace etl if (icurrent->key_value_pair.first == key) { bucket.erase_after(iprevious); + pnodepool->release(*icurrent); ++count; icurrent = iprevious; } @@ -793,6 +794,7 @@ namespace etl } bucket.erase_after(iprevious); + pnodepool->release(*icurrent); return inext; } @@ -834,8 +836,17 @@ namespace etl } // Erase the range. + local_iterator irelease = iprevious; + ++irelease; + ibucket->erase_after(iprevious, iend); + while (irelease != iend) + { + pnodepool->release(*irelease); + ++irelease; + } + // At the end of this bucket? if (iend == ibucket->end()) { diff --git a/src/iunordered_multiset.h b/src/iunordered_multiset.h index 29a75fc3..994c1e9d 100644 --- a/src/iunordered_multiset.h +++ b/src/iunordered_multiset.h @@ -750,6 +750,7 @@ namespace etl if (icurrent->key == key) { bucket.erase_after(iprevious); + pnodepool->release(*icurrent); ++count; icurrent = iprevious; } @@ -785,6 +786,7 @@ namespace etl } bucket.erase_after(iprevious); + pnodepool->release(*icurrent); return inext; } @@ -826,8 +828,17 @@ namespace etl } // Erase the range. + local_iterator irelease = iprevious; + ++irelease; + ibucket->erase_after(iprevious, iend); + while (irelease != iend) + { + pnodepool->release(*irelease); + ++irelease; + } + // At the end of this bucket? if (iend == ibucket->end()) { diff --git a/src/iunordered_set.h b/src/iunordered_set.h index af6c90c8..d47ef3c6 100644 --- a/src/iunordered_set.h +++ b/src/iunordered_set.h @@ -758,6 +758,7 @@ namespace etl if (icurrent != bucket.end()) { bucket.erase_after(iprevious); + pnodepool->release(*icurrent); count = 1; } @@ -785,6 +786,7 @@ namespace etl } bucket.erase_after(iprevious); + pnodepool->release(*icurrent); return inext; } @@ -826,8 +828,17 @@ namespace etl } // Erase the range. + local_iterator irelease = iprevious; + ++irelease; + ibucket->erase_after(iprevious, iend); + while (irelease != iend) + { + pnodepool->release(*irelease); + ++irelease; + } + // At the end of this bucket? if (iend == ibucket->end()) { diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 9f33b8d7..22ffa1ee 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -435,6 +435,10 @@ namespace DataNDC::iterator idata = data.find(K5); CHECK(idata == data.end()); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); } //************************************************************************* @@ -462,6 +466,11 @@ namespace DataNDC::iterator idata_end = data.find(K8); idata = data.erase(idata, idata_end); // Erase K5, K6, K7 + + CHECK_EQUAL(initial_data.size() - 3, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(idata == data.find(K8)); idata = data.find(K0); diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index fe595ad4..97d570c9 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -396,6 +396,10 @@ namespace CHECK(idata == data.end()); CHECK(inext == iafter); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); } //************************************************************************* @@ -407,6 +411,11 @@ namespace DataNDC::iterator idata_end = data.find(K8); idata = data.erase(idata, idata_end); // Erase K5, K6, K7 + + CHECK_EQUAL(initial_data.size() - 3, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(idata == data.find(K8)); idata = data.find(K0); diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 1800db01..c39a06df 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -321,6 +321,10 @@ namespace CHECK(idata == data.end()); CHECK(inext == iafter); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); } //************************************************************************* @@ -336,6 +340,11 @@ namespace test.assign(data.begin(), data.end()); idata = data.erase(idata, idata_end); // Erase N5, N6, N7 + + CHECK_EQUAL(initial_data.size() - 3, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(idata == data.find(N8)); test.assign(data.begin(), data.end()); diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 919a06f7..ac152d8f 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -301,6 +301,10 @@ namespace CHECK(idata == data.end()); CHECK(inext == iafter); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); } //************************************************************************* @@ -316,6 +320,11 @@ namespace test.assign(data.begin(), data.end()); idata = data.erase(idata, idata_end); // Erase N5, N6, N7 + + CHECK_EQUAL(initial_data.size() - 3, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(idata == data.find(N8)); test.assign(data.begin(), data.end()); From 0f05e7d4be67a2b277c71562adbb70545c40b71e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 30 Dec 2016 11:57:00 +0000 Subject: [PATCH 095/168] Improved erase_after --- src/intrusive_forward_list.h | 39 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 43f07e05..85f67169 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -527,7 +527,6 @@ namespace etl //************************************************************************* /// Erases the value at the specified position. - /// Clears the link after erasing if CHECKED. //************************************************************************* iterator erase_after(iterator position) { @@ -544,36 +543,32 @@ namespace etl //************************************************************************* /// Erases a range of elements. - /// Clears the links after erasing if CHECKED. //************************************************************************* iterator erase_after(iterator first, iterator last) { - link_type* p_first = first.p_value; - link_type* p_last = last.p_value; - link_type* p_next = p_first->etl_next; - - // Join the ends. - etl::link(p_first, p_last); - - p_first = p_next; - - // Erase the ones in between. - while (p_first != p_last) + if (first != last) { - // One less. - --current_size; + current_size -= std::distance(first, last) - 1; - p_next = p_first->etl_next; // Remember the next link. - p_first = p_next; // Move to the next link. - } + link_type* p_first = first.p_value; + link_type* p_last = last.p_value; + link_type* p_next = p_first->etl_next; - if (p_next == nullptr) - { - return end(); + // Join the ends. + etl::link(p_first, p_last); + + if (p_next == nullptr) + { + return end(); + } + else + { + return last; + } } else { - return iterator(*static_cast(p_last)); + return last; } } From 695e16a8e447efe10f6a59b67f240ac718f57088 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 31 Dec 2016 10:06:40 +0000 Subject: [PATCH 096/168] Experimental reimplementation of etl::pool --- src/iforward_list.h | 94 ++++--- src/intrusive_forward_list.h | 9 +- src/ipool.h | 452 +++++++------------------------- src/pool.h | 15 +- src/private/pool_base.h | 8 +- test/test_pool.cpp | 214 +++++++-------- test/vs2015/etl.vcxproj | 1 + test/vs2015/etl.vcxproj.filters | 3 + 8 files changed, 272 insertions(+), 524 deletions(-) diff --git a/src/iforward_list.h b/src/iforward_list.h index e4a7dfb5..c2d2b275 100644 --- a/src/iforward_list.h +++ b/src/iforward_list.h @@ -256,7 +256,7 @@ namespace etl const Node* p_node; }; - typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::iterator_traits::difference_type difference_type; //************************************************************************* /// Gets the beginning of the forward_list. @@ -348,7 +348,7 @@ namespace etl //************************************************************************* /// Assigns a range of values to the forward_list. - /// If asserts or exceptions are enabled throws etl::forward_list_full if the forward_list does not have enough free space. + /// If asserts or exceptions are enabled throws etl::forward_list_full if the forward_list does not have enough free space. /// If ETL_THROW_EXCEPTIONS & _DEBUG are defined throws forward_list_iterator if the iterators are reversed. //************************************************************************* template @@ -532,10 +532,15 @@ namespace etl iterator erase_after(iterator position) { iterator next(position); - ++next; - ++next; - - remove_node_after(*position.p_node); + if (next != end()) + { + ++next; + if (next != end()) + { + ++next; + remove_node_after(*position.p_node); + } + } return next; } @@ -545,33 +550,40 @@ namespace etl //************************************************************************* iterator erase_after(iterator first, iterator last) { - Node* p_first = first.p_node; - Node* p_last = last.p_node; - Node* p_next = p_first->next; - - // Join the ends. - join(p_first, p_last); - - p_first = p_next; - - // Erase the ones in between. - while (p_first != p_last) + if (first != end() && (first != last)) { - // One less. - --current_size; + Node* p_first = first.p_node; + Node* p_last = last.p_node; + Node* p_next = p_first->next; - p_next = p_first->next; // Remember the next node. - destroy_data_node(static_cast(*p_first)); // Destroy the pool object. - p_first = p_next; // Move to the next node. - } + // Join the ends. + join(p_first, p_last); - if (p_next == nullptr) - { - return end(); + p_first = p_next; + + // Erase the ones in between. + while (p_first != p_last) + { + // One less. + --current_size; + + p_next = p_first->next; // Remember the next node. + destroy_data_node(static_cast(*p_first)); // Destroy the pool object. + p_first = p_next; // Move to the next node. + } + + if (p_next == nullptr) + { + return end(); + } + else + { + return iterator(*p_last); + } } else { - return iterator(*p_last); + return end(); } } @@ -580,7 +592,7 @@ namespace etl //************************************************************************* void move_after(const_iterator from_before, const_iterator to_before) { - if (from_before == to_before) // Can't more to after yourself! + if (from_before == to_before) // Can't move to after yourself! { return; } @@ -707,7 +719,7 @@ namespace etl if (is_trivial_list()) { - return; + return; } while (true) @@ -746,32 +758,32 @@ namespace etl // Decide whether the next node of merge comes from left or right. if (left_size == 0) { - // Left is empty. The node must come from right. - p_node = p_right; + // Left is empty. The node must come from right. + p_node = p_right; ++p_right; --right_size; - } + } else if (right_size == 0 || p_right == end()) { - // Right is empty. The node must come from left. - p_node = p_left; + // Right is empty. The node must come from left. + p_node = p_left; ++p_left; --left_size; - } + } else if (compare(*p_left, *p_right)) { - // First node of left is lower or same. The node must come from left. - p_node = p_left; + // First node of left is lower or same. The node must come from left. + p_node = p_left; ++p_left; --left_size; - } + } else { - // First node of right is lower. The node must come from right. - p_node = p_right; + // First node of right is lower. The node must come from right. + p_node = p_right; ++p_right; --right_size; - } + } // Add the next node to the merged head. if (p_head == before_begin()) diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 85f67169..1ed9fcaa 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -531,11 +531,14 @@ namespace etl iterator erase_after(iterator position) { iterator next(position); - ++next; if (next != end()) { ++next; - remove_link_after(*position.p_value); + if (next != end()) + { + ++next; + remove_link_after(*position.p_value); + } } return next; @@ -546,7 +549,7 @@ namespace etl //************************************************************************* iterator erase_after(iterator first, iterator last) { - if (first != last) + if (first != end() && (first != last)) { current_size -= std::distance(first, last) - 1; diff --git a/src/ipool.h b/src/ipool.h index ad3c16d1..7f30650b 100644 --- a/src/ipool.h +++ b/src/ipool.h @@ -28,6 +28,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ +//***************************************************************************** +// The algorithm for this implementation is based on this paper. +// +// Fast Efficient Fixed-Size Memory Pool +// https://www.thinkmind.org/index.php?view=article&articleid=computation_tools_2012_1_10_80006 +// +// Ben Kenwright +// School of Computer Science +// Newcastle University +// Newcastle, United Kingdom, +// b.kenwright@ncl.ac.uk +//***************************************************************************** + #ifndef __ETL_IPOOL__ #define __ETL_IPOOL__ #define __ETL_IN_IPOOL_H__ @@ -36,7 +49,7 @@ SOFTWARE. #include "private/pool_base.h" #include "nullptr.h" -#include "ibitset.h" +//#include "ibitset.h" #include "error_handler.h" namespace etl @@ -44,7 +57,7 @@ namespace etl //*************************************************************************** ///\ingroup pool //*************************************************************************** - template + template class ipool : public pool_base { public: @@ -56,307 +69,45 @@ namespace etl typedef const T& const_reference; typedef size_t size_type; - //************************************************************************* - /// iterator - //************************************************************************* - class iterator : public std::iterator - { - public: - - friend class ipool; - friend class const_iterator; - - //******************************* - iterator() - : index(0), - p_buffer(nullptr), - p_in_use_flags(nullptr) - { - } - - //******************************* - iterator(const iterator& other) - : index(other.index), - p_buffer(other.p_buffer), - p_in_use_flags(other.p_in_use_flags) - { - } - - //******************************* - iterator& operator ++() - { - index = p_in_use_flags->find_next(true, index + 1); - return *this; - } - - //******************************* - iterator operator ++(int) - { - iterator temp(*this); - index = p_in_use_flags->find_next(true, index + 1); - return temp; - } - - //******************************* - iterator operator =(const iterator& other) - { - index = other.index; - p_buffer = other.p_buffer; - p_in_use_flags = other.p_in_use_flags; - return *this; - } - - //******************************* - const_reference operator *() const - { - return p_buffer[index]; - } - - //******************************* - const_pointer operator ->() const - { - return &p_buffer[index]; - } - - //******************************* - friend bool operator == (const iterator& lhs, const iterator& rhs) - { - return (lhs.p_buffer == rhs.p_buffer) && (lhs.index == rhs.index); - } - - //******************************* - friend bool operator != (const iterator& lhs, const iterator& rhs) - { - return !(lhs == rhs); - } - - private: - - //******************************* - iterator(size_t index, - pointer p_buffer, - const ibitset* p_in_use_flags) - : index(index), - p_buffer(p_buffer), - p_in_use_flags(p_in_use_flags) - { - } - - size_t index; - pointer p_buffer; - const ibitset* p_in_use_flags; - }; - - - //************************************************************************* - /// const_iterator - //************************************************************************* - class const_iterator : public std::iterator - { - public: - - friend class ipool; - - //******************************* - const_iterator() - : index(0), - p_buffer(nullptr), - p_in_use_flags(nullptr) - { - } - - //******************************* - const_iterator(const const_iterator& other) - : index(other.index), - p_buffer(other.p_buffer), - p_in_use_flags(other.p_in_use_flags) - { - } - - //******************************* - const_iterator(const typename ipool::iterator& other) - : index(other.index), - p_buffer(other.p_buffer), - p_in_use_flags(other.p_in_use_flags) - { - } - - //******************************* - const_iterator& operator ++() - { - index = p_in_use_flags->find_next(true, index + 1); - return *this; - } - - //******************************* - const_iterator operator ++(int) - { - const_iterator temp(*this); - index = p_in_use_flags->find_next(true, index + 1); - return temp; - } - - //******************************* - const_iterator operator =(const const_iterator& other) - { - index = other.index; - p_buffer = other.p_buffer; - p_in_use_flags = other.p_in_use_flags; - return *this; - } - - //******************************* - const_reference operator *() const - { - return p_buffer[index]; - } - - //******************************* - const_pointer operator ->() const - { - return &p_buffer[index]; - } - - //******************************* - friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) - { - return (lhs.p_buffer == rhs.p_buffer) && (lhs.index == rhs.index); - } - - //******************************* - friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) - { - return !(lhs == rhs); - } - - private: - - //******************************* - const_iterator(size_t index, - const_pointer p_buffer, - const ibitset* p_in_use_flags) - : index(index), - p_buffer(p_buffer), - p_in_use_flags(p_in_use_flags) - { - } - - size_t index; - const_pointer p_buffer; - const ibitset* p_in_use_flags; - }; - - //************************************************************************* - /// Get an iterator to the first allocated item in the pool. - //************************************************************************* - iterator begin() - { - size_t index = in_use_flags.find_first(true); - - if (index != ibitset::npos) - { - return iterator(index, p_buffer, &in_use_flags); - } - else - { - return end(); - } - } - - //************************************************************************* - /// Get a const iterator to the first allocated item in the pool. - //************************************************************************* - const_iterator begin() const - { - size_t index = in_use_flags.find_first(true); - - if (index != ibitset::npos) - { - return const_iterator(index, p_buffer, &in_use_flags); - } - else - { - return end(); - } - } - - //************************************************************************* - /// Get a const iterator to the first allocated item in the pool. - //************************************************************************* - const_iterator cbegin() const - { - return begin(); - } - - //************************************************************************* - /// Get an iterator to the end of the pool. - //************************************************************************* - iterator end() - { - return iterator(ibitset::npos, p_buffer, &in_use_flags); - } - - //************************************************************************* - /// Get a const iterator to the end of the pool. - //************************************************************************* - const_iterator end() const - { - return const_iterator(ibitset::npos, p_buffer, &in_use_flags); - } - - //************************************************************************* - /// Get a const iterator to the end of the pool. - //************************************************************************* - const_iterator cend() const - { - return end(); - } - //************************************************************************* /// Allocate an object from the pool. /// Uses the default constructor. /// 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. - /// \note The state of the object returned is undefined. //************************************************************************* T* allocate() { -#if defined(_DEBUG) || defined(DEBUG) - ETL_ASSERT(items_allocated < MAX_SIZE && !in_use_flags.test(next_free), ETL_ERROR(pool_no_allocation)); -#else - ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation)); -#endif - - T* result = new(&p_buffer[next_free]) T(); - - in_use_flags.set(next_free); - next_free = in_use_flags.find_first(false); - ++items_allocated; - - return result; + return allocate(T()); } //************************************************************************* /// Allocate an object from the pool from an initial value. /// 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. - /// \note The state of the object returned is undefined. //************************************************************************* T* allocate(const T& initial) { -#if defined(_DEBUG) || defined(DEBUG) - ETL_ASSERT(items_allocated < MAX_SIZE && !in_use_flags.test(next_free), ETL_ERROR(pool_no_allocation)); -#else ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation)); -#endif - T* result = new(&p_buffer[next_free]) T(initial); + T* p_value = nullptr; - in_use_flags.set(next_free); - next_free = in_use_flags.find_first(false); - ++items_allocated; + if (available() > 0) + { + p_value = new(&p_next->value) T(initial); + p_next->index = -p_next->index; + ++items_allocated; - return result; + if (available() != 0) + { + p_next = AddressFromIndex(p_next->index); + } + else + { + p_next = nullptr; + } + } + + return p_value; } //************************************************************************* @@ -381,19 +132,24 @@ namespace etl // Does it belong to me? ETL_ASSERT(is_in_pool(p_object), ETL_ERROR(pool_object_not_in_pool)); - // Where is it in the buffer? - typename std::iterator_traits::difference_type distance = p_object - p_buffer; - size_t index = static_cast(distance); + // Get the pointer to the element by adjusting for the index. + uintptr_t p = (uintptr_t)p_object - offsetof(Element, value); - // Check that it hasn't already been released. - if (in_use_flags.test(index)) + Element* p_element = reinterpret_cast(p); + + if (p_next != nullptr) { - // Destroy the object and mark as available. - p_object->~T(); - in_use_flags.reset(index); - --items_allocated; - next_free = index; + p_element->index = -IndexFromAddress(p_next); } + else + { + p_element->index = -TIndex(MAX_SIZE); + } + + p_object->~T(); + + p_next = p_element; + --items_allocated; } //************************************************************************* @@ -401,18 +157,19 @@ namespace etl //************************************************************************* void release_all() { - const_iterator i_object = begin(); - - while (i_object != end()) + for (size_t i = 0; i < MAX_SIZE; ++i) { - i_object->~T(); - ++i_object; + if (p_buffer[i].index > 0) + { + p_buffer[i].value.~T(); + } + + p_buffer[i].index = -int32_t(i + 1); } - in_use_flags.reset(); items_allocated = 0; - next_free = 0; - } + p_next = p_buffer; + } //************************************************************************* /// Check to see if the object belongs to the pool. @@ -432,77 +189,37 @@ namespace etl bool is_in_pool(const T* p_object) const { // Does this object belong to this pool? - typename std::iterator_traits::difference_type distance = p_object - p_buffer; + // Get the pointer to the element by adjusting for the index. + uintptr_t p = (uintptr_t)p_object - sizeof(TIndex); - // Within the range of the buffer? - return ((distance >= 0) && (distance < static_cast::difference_type>(MAX_SIZE))); + Element* p_element = reinterpret_cast(p); + + // Within the range of the buffer? + intptr_t distance = p_element - p_buffer; + return ((distance >= 0) && (distance < static_cast(MAX_SIZE))); } - //************************************************************************* - /// Gets the iterator to the object. - /// If the object is not in the pool then end() is returned. - /// \param object A const reference to the object to be checked. - /// \return An iterator to the object or end(). - //************************************************************************* - iterator get_iterator(T& object) - { - if (is_in_pool(object)) - { - iterator i_object = begin(); - - while (i_object != end()) - { - // Same one? - if (&object == &*i_object) - { - return i_object; - } - - ++i_object; - } - } - - return end(); - } - - //************************************************************************* - /// Gets the const_iterator to the object. - /// If the object is not in the pool then end() is returned. - /// \param object A const reference to the object to be checked. - /// \return An const_iterator to the object or end(). - //************************************************************************* - const_iterator get_iterator(const T& object) const - { - if (is_in_pool(object)) - { - const_iterator i_object = begin(); - - while (i_object != end()) - { - // Same one? - if (&object == &*i_object) - { - return i_object; - } - - ++i_object; - } - } - - return end(); - } - - protected: + struct Element + { + TIndex index; + T value; + }; + //************************************************************************* /// Constructor //************************************************************************* - ipool(T* p_buffer, ibitset& in_use_flags, size_t size) + ipool(Element* p_buffer, size_t size) : pool_base(size), p_buffer(p_buffer), - in_use_flags(in_use_flags) + p_next(p_buffer) + { + for (int32_t i = 0; i < MAX_SIZE; ++i) + { + p_buffer[i].index = -(i + 1); + } } //************************************************************************* @@ -515,12 +232,23 @@ namespace etl private: + Element* AddressFromIndex(TIndex i) const + { + i = (i < 0) ? -i : i; + return &p_buffer[i]; + } + + TIndex IndexFromAddress(const Element* p_element) const + { + return TIndex(p_element - p_buffer); + } + // Disable copy construction and assignment. ipool(const ipool&); ipool& operator =(const ipool&); - T* p_buffer; - ibitset& in_use_flags; + Element* p_buffer; + Element* p_next; }; } diff --git a/src/pool.h b/src/pool.h index eb98e2ec..5d669fc3 100644 --- a/src/pool.h +++ b/src/pool.h @@ -50,8 +50,8 @@ namespace etl /// A templated pool implementation that uses a fixed size pool. ///\ingroup pool //************************************************************************* - template - class pool : public ipool + template + class pool : public ipool { public: @@ -61,7 +61,7 @@ namespace etl /// Constructor //************************************************************************* pool() - : ipool(reinterpret_cast(&buffer[0]), in_use, SIZE) + : ipool(reinterpret_cast(&buffer[0]), SIZE) { } @@ -70,16 +70,15 @@ namespace etl //************************************************************************* ~pool() { - ipool::release_all(); + ipool::release_all(); } private: - ///< The memory for the pool of objects. - typename etl::aligned_storage::value>::type buffer[SIZE]; + typedef typename ipool::Element Element; - ///< The set of flags that indicate which items are free in the pool. - bitset in_use; + ///< The memory for the pool of objects. + typename etl::aligned_storage::value>::type buffer[SIZE]; // Should not be copied. pool(const pool&); diff --git a/src/private/pool_base.h b/src/private/pool_base.h index 7a358166..020a2aad 100644 --- a/src/private/pool_base.h +++ b/src/private/pool_base.h @@ -143,13 +143,15 @@ namespace etl pool_base(size_t max_size) : next_free(0), items_allocated(0), + items_initialised(0), MAX_SIZE(max_size) { } - size_t next_free; ///< The next free slot in the block. - size_t items_allocated; ///< The number of items allocated. - const size_t MAX_SIZE; ///< The maximum number of objects that can be allocated. + size_t next_free; ///< The next free slot in the block. + size_t items_allocated; ///< The number of items allocated. + size_t items_initialised; ///< The number of items that have been initialised with an index; + const size_t MAX_SIZE; ///< The maximum number of objects that can be allocated. }; } diff --git a/test/test_pool.cpp b/test/test_pool.cpp index 165c110e..836823e6 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -53,10 +53,10 @@ namespace { etl::pool pool; - Test_Data* p1; - Test_Data* p2; - Test_Data* p3; - Test_Data* p4; + Test_Data* p1 = nullptr; + Test_Data* p2 = nullptr; + Test_Data* p3 = nullptr; + Test_Data* p4 = nullptr; CHECK_NO_THROW(p1 = pool.allocate()); CHECK_NO_THROW(p2 = pool.allocate()); @@ -237,156 +237,156 @@ namespace //************************************************************************* TEST(test_begin_empty) { - etl::pool pool; + //etl::pool pool; - etl::pool::iterator it = pool.begin(); - CHECK(it == pool.end()); + //etl::pool::iterator it = pool.begin(); + //CHECK(it == pool.end()); - etl::pool::const_iterator cit = pool.begin(); - CHECK(cit == pool.end()); + //etl::pool::const_iterator cit = pool.begin(); + //CHECK(cit == pool.end()); - cit = pool.cbegin(); - CHECK(cit == pool.end()); + //cit = pool.cbegin(); + //CHECK(cit == pool.end()); } //************************************************************************* TEST(test_iterator) { - etl::pool pool; + //etl::pool pool; - std::set compare = { Test_Data2("0"), Test_Data2("2"), Test_Data2("4"), Test_Data2("6"), Test_Data2("8") }; - std::set test; - std::vector objects; + //std::set compare = { Test_Data2("0"), Test_Data2("2"), Test_Data2("4"), Test_Data2("6"), Test_Data2("8") }; + //std::set test; + //std::vector objects; - // Build the set of objects. - objects.push_back(pool.allocate(Test_Data2("9"))); - objects.push_back(pool.allocate(Test_Data2("7"))); - objects.push_back(pool.allocate(Test_Data2("8"))); - objects.push_back(pool.allocate(Test_Data2("6"))); - objects.push_back(pool.allocate(Test_Data2("5"))); - objects.push_back(pool.allocate(Test_Data2("3"))); - objects.push_back(pool.allocate(Test_Data2("4"))); - objects.push_back(pool.allocate(Test_Data2("2"))); - objects.push_back(pool.allocate(Test_Data2("0"))); - objects.push_back(pool.allocate(Test_Data2("1"))); + //// Build the set of objects. + //objects.push_back(pool.allocate(Test_Data2("9"))); + //objects.push_back(pool.allocate(Test_Data2("7"))); + //objects.push_back(pool.allocate(Test_Data2("8"))); + //objects.push_back(pool.allocate(Test_Data2("6"))); + //objects.push_back(pool.allocate(Test_Data2("5"))); + //objects.push_back(pool.allocate(Test_Data2("3"))); + //objects.push_back(pool.allocate(Test_Data2("4"))); + //objects.push_back(pool.allocate(Test_Data2("2"))); + //objects.push_back(pool.allocate(Test_Data2("0"))); + //objects.push_back(pool.allocate(Test_Data2("1"))); - // Release "1", "3", "5", "7", "9". - pool.release(objects[0]); - pool.release(objects[1]); - pool.release(objects[4]); - pool.release(objects[5]); - pool.release(objects[9]); + //// Release "1", "3", "5", "7", "9". + //pool.release(objects[0]); + //pool.release(objects[1]); + //pool.release(objects[4]); + //pool.release(objects[5]); + //pool.release(objects[9]); - // Fill the test set with what we get from the iterator. - etl::pool::iterator i_pool = pool.begin(); + //// Fill the test set with what we get from the iterator. + //etl::pool::iterator i_pool = pool.begin(); - while (i_pool != pool.end()) - { - test.insert(*i_pool); - ++i_pool; - } + //while (i_pool != pool.end()) + //{ + // test.insert(*i_pool); + // ++i_pool; + //} - // Compare the results. - std::set::iterator i_compare = compare.begin(); - std::set::iterator i_test = test.begin(); + //// Compare the results. + //std::set::iterator i_compare = compare.begin(); + //std::set::iterator i_test = test.begin(); - CHECK_EQUAL(compare.size(), test.size()); + //CHECK_EQUAL(compare.size(), test.size()); - while ((i_compare != compare.end()) && (i_test != test.end())) - { - CHECK_EQUAL(*i_compare++, *i_test++); - } + //while ((i_compare != compare.end()) && (i_test != test.end())) + //{ + // CHECK_EQUAL(*i_compare++, *i_test++); + //} } //************************************************************************* TEST(test_const_iterator) { - etl::pool pool; + //etl::pool pool; - std::set compare = { Test_Data2("0"), Test_Data2("2"), Test_Data2("4"), Test_Data2("6"), Test_Data2("8") }; - std::set test; - std::vector objects; + //std::set compare = { Test_Data2("0"), Test_Data2("2"), Test_Data2("4"), Test_Data2("6"), Test_Data2("8") }; + //std::set test; + //std::vector objects; - // Build the set of objects. - objects.push_back(pool.allocate(Test_Data2("9"))); - objects.push_back(pool.allocate(Test_Data2("7"))); - objects.push_back(pool.allocate(Test_Data2("8"))); - objects.push_back(pool.allocate(Test_Data2("6"))); - objects.push_back(pool.allocate(Test_Data2("5"))); - objects.push_back(pool.allocate(Test_Data2("3"))); - objects.push_back(pool.allocate(Test_Data2("4"))); - objects.push_back(pool.allocate(Test_Data2("2"))); - objects.push_back(pool.allocate(Test_Data2("0"))); - objects.push_back(pool.allocate(Test_Data2("1"))); + //// Build the set of objects. + //objects.push_back(pool.allocate(Test_Data2("9"))); + //objects.push_back(pool.allocate(Test_Data2("7"))); + //objects.push_back(pool.allocate(Test_Data2("8"))); + //objects.push_back(pool.allocate(Test_Data2("6"))); + //objects.push_back(pool.allocate(Test_Data2("5"))); + //objects.push_back(pool.allocate(Test_Data2("3"))); + //objects.push_back(pool.allocate(Test_Data2("4"))); + //objects.push_back(pool.allocate(Test_Data2("2"))); + //objects.push_back(pool.allocate(Test_Data2("0"))); + //objects.push_back(pool.allocate(Test_Data2("1"))); - // Release "1", "3", "5", "7", "9". - pool.release(objects[0]); - pool.release(objects[1]); - pool.release(objects[4]); - pool.release(objects[5]); - pool.release(objects[9]); + //// Release "1", "3", "5", "7", "9". + //pool.release(objects[0]); + //pool.release(objects[1]); + //pool.release(objects[4]); + //pool.release(objects[5]); + //pool.release(objects[9]); - // Fill the test set with what we get from the iterator. - etl::pool::const_iterator i_pool = pool.begin(); + //// Fill the test set with what we get from the iterator. + //etl::pool::const_iterator i_pool = pool.begin(); - while (i_pool != pool.end()) - { - test.insert(*i_pool); - ++i_pool; - } + //while (i_pool != pool.end()) + //{ + // test.insert(*i_pool); + // ++i_pool; + //} - // Compare the results. - std::set::const_iterator i_compare = compare.begin(); - std::set::const_iterator i_test = test.begin(); + //// Compare the results. + //std::set::const_iterator i_compare = compare.begin(); + //std::set::const_iterator i_test = test.begin(); - CHECK_EQUAL(compare.size(), test.size()); + //CHECK_EQUAL(compare.size(), test.size()); - while ((i_compare != compare.end()) && (i_test != test.end())) - { - CHECK_EQUAL(*i_compare++, *i_test++); - } + //while ((i_compare != compare.end()) && (i_test != test.end())) + //{ + // CHECK_EQUAL(*i_compare++, *i_test++); + //} } //************************************************************************* TEST(test_get_iterator) { - typedef etl::pool Pool; + //typedef etl::pool Pool; - Pool pool; - Test_Data not_in_pool; + //Pool pool; + //Test_Data not_in_pool; - Test_Data* p1 = pool.allocate(); - Test_Data* p2 = pool.allocate(); + //Test_Data* p1 = pool.allocate(); + //Test_Data* p2 = pool.allocate(); - Pool::iterator i_data = pool.get_iterator(*p1); - Pool::iterator i_data2 = pool.get_iterator(*p2); - Pool::iterator i_ndata = pool.get_iterator(not_in_pool); + //Pool::iterator i_data = pool.get_iterator(*p1); + //Pool::iterator i_data2 = pool.get_iterator(*p2); + //Pool::iterator i_ndata = pool.get_iterator(not_in_pool); - CHECK(p1 == &*i_data); - CHECK(p2 != &*i_data); - CHECK(p2 == &*i_data2); - CHECK(pool.end() == i_ndata); + //CHECK(p1 == &*i_data); + //CHECK(p2 != &*i_data); + //CHECK(p2 == &*i_data2); + //CHECK(pool.end() == i_ndata); } //************************************************************************* TEST(test_get_iterator_const) { - typedef etl::pool Pool; + //typedef etl::pool Pool; - Pool pool; - const Test_Data not_in_pool; + //Pool pool; + //const Test_Data not_in_pool; - const Test_Data* p1 = pool.allocate(); - const Test_Data* p2 = pool.allocate(); + //const Test_Data* p1 = pool.allocate(); + //const Test_Data* p2 = pool.allocate(); - Pool::const_iterator i_data = pool.get_iterator(*p1); - Pool::const_iterator i_data2 = pool.get_iterator(*p2); - Pool::const_iterator i_ndata = pool.get_iterator(not_in_pool); + //Pool::const_iterator i_data = pool.get_iterator(*p1); + //Pool::const_iterator i_data2 = pool.get_iterator(*p2); + //Pool::const_iterator i_ndata = pool.get_iterator(not_in_pool); - CHECK(p1 == &*i_data); - CHECK(p2 != &*i_data); - CHECK(p2 == &*i_data2); - CHECK(pool.end() == i_ndata); + //CHECK(p1 == &*i_data); + //CHECK(p2 != &*i_data); + //CHECK(p2 == &*i_data2); + //CHECK(pool.end() == i_ndata); } }; } diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index 69d2a083..cde6fd79 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -222,6 +222,7 @@ + diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index d74a3301..6a2486b7 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -528,6 +528,9 @@ ETL\Containers + + ETL\Containers + From a371b27c2a611e41bfbd328bb5dd31062f25f477 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 31 Dec 2016 10:07:14 +0000 Subject: [PATCH 097/168] Performance tests for unordered map. --- .../unordered_map/unordered_map.sln | 28 +++ .../unordered_map/unordered_map/ReadMe.txt | 40 +++++ .../unordered_map/unordered_map/stdafx.cpp | 8 + .../unordered_map/unordered_map/stdafx.h | 15 ++ .../unordered_map/unordered_map/targetver.h | 8 + .../unordered_map/unordered_map.cpp | 82 +++++++++ .../unordered_map/unordered_map.vcxproj | 164 ++++++++++++++++++ .../unordered_map.vcxproj.filters | 42 +++++ 8 files changed, 387 insertions(+) create mode 100644 test/Performance/unordered_map/unordered_map.sln create mode 100644 test/Performance/unordered_map/unordered_map/ReadMe.txt create mode 100644 test/Performance/unordered_map/unordered_map/stdafx.cpp create mode 100644 test/Performance/unordered_map/unordered_map/stdafx.h create mode 100644 test/Performance/unordered_map/unordered_map/targetver.h create mode 100644 test/Performance/unordered_map/unordered_map/unordered_map.cpp create mode 100644 test/Performance/unordered_map/unordered_map/unordered_map.vcxproj create mode 100644 test/Performance/unordered_map/unordered_map/unordered_map.vcxproj.filters diff --git a/test/Performance/unordered_map/unordered_map.sln b/test/Performance/unordered_map/unordered_map.sln new file mode 100644 index 00000000..b7f0b842 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unordered_map", "unordered_map\unordered_map.vcxproj", "{AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x64.ActiveCfg = Debug|x64 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x64.Build.0 = Debug|x64 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x86.ActiveCfg = Debug|Win32 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Debug|x86.Build.0 = Debug|Win32 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x64.ActiveCfg = Release|x64 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x64.Build.0 = Release|x64 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x86.ActiveCfg = Release|Win32 + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test/Performance/unordered_map/unordered_map/ReadMe.txt b/test/Performance/unordered_map/unordered_map/ReadMe.txt new file mode 100644 index 00000000..bc20f9d5 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : unordered_map Project Overview +======================================================================== + +AppWizard has created this unordered_map application for you. + +This file contains a summary of what you will find in each of the files that +make up your unordered_map application. + + +unordered_map.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +unordered_map.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +unordered_map.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named unordered_map.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/test/Performance/unordered_map/unordered_map/stdafx.cpp b/test/Performance/unordered_map/unordered_map/stdafx.cpp new file mode 100644 index 00000000..291c2903 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// unordered_map.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/test/Performance/unordered_map/unordered_map/stdafx.h b/test/Performance/unordered_map/unordered_map/stdafx.h new file mode 100644 index 00000000..b005a839 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/test/Performance/unordered_map/unordered_map/targetver.h b/test/Performance/unordered_map/unordered_map/targetver.h new file mode 100644 index 00000000..87c0086d --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/test/Performance/unordered_map/unordered_map/unordered_map.cpp b/test/Performance/unordered_map/unordered_map/unordered_map.cpp new file mode 100644 index 00000000..3c996e63 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/unordered_map.cpp @@ -0,0 +1,82 @@ +// unordered_map.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" +#include +#include + +#include +#include "../../../../src/unordered_map.h" + +LARGE_INTEGER frequency; +LARGE_INTEGER begin; + +void StartTimer() +{ + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&begin); + + frequency.QuadPart /= 1000; +} + +uint64_t StopTimer() +{ + LARGE_INTEGER end; + + QueryPerformanceCounter(&end); + + return (end.QuadPart - begin.QuadPart) / frequency.QuadPart; +} + +const size_t TESTSIZE = 10000000; +const size_t TESTINTERATIONS = 16; + +typedef std::unordered_map Stdmap; +typedef etl::unordered_map Etlmap; + +Stdmap stdmap; +Etlmap etlmap; + +int main() +{ + StartTimer(); + + for (size_t i = 0; i < TESTINTERATIONS; ++i) + { + for (size_t j = 0; j < TESTSIZE; ++j) + { + std::pair ok = stdmap.insert(std::make_pair(uint64_t(j), uint16_t(j))); + } + + for (size_t j = 0; j < TESTSIZE; ++j) + { + stdmap.erase(j); + } + } + + uint64_t time; + + time = StopTimer(); + std::cout << "STD Time = " << time << "ms\n"; + + StartTimer(); + + for (size_t i = 0; i < TESTINTERATIONS; ++i) + { + for (size_t j = 0; j < TESTSIZE; ++j) + { + std::pair ok = etlmap.insert(std::make_pair(uint64_t(j), uint16_t(j))); + } + + for (size_t j = 0; j < TESTSIZE; ++j) + { + etlmap.erase(j); + } + } + + time = StopTimer(); + std::cout << "ETL Time = " << time << "ms\n"; + + return 0; +} + diff --git a/test/Performance/unordered_map/unordered_map/unordered_map.vcxproj b/test/Performance/unordered_map/unordered_map/unordered_map.vcxproj new file mode 100644 index 00000000..a400bbf4 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/unordered_map.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {AA7F5179-0617-49EC-B6AC-8D71A64D8DC6} + Win32Proj + unordered_map + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../../../../src;%(AdditionalIncludeDirectories) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ..\..\..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + true + true + true + true + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Performance/unordered_map/unordered_map/unordered_map.vcxproj.filters b/test/Performance/unordered_map/unordered_map/unordered_map.vcxproj.filters new file mode 100644 index 00000000..66f299a8 --- /dev/null +++ b/test/Performance/unordered_map/unordered_map/unordered_map.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file From c24d007d5c613542c796b32573eb695dfb5f03a8 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 4 Jan 2017 11:23:16 +0000 Subject: [PATCH 098/168] Added find first set/clear bit functions. --- src/binary.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/binary.h b/src/binary.h index fb99de13..a86b92b6 100644 --- a/src/binary.h +++ b/src/binary.h @@ -71,6 +71,12 @@ namespace etl template const typename max_value_for_nbits_helper::value_type max_value_for_nbits_helper::value; + + static const uint_least8_t bit_position_lookup[32] = + { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 + }; } /// Definition for non-zero NBITS. @@ -564,6 +570,39 @@ namespace etl return signed_value; } + //*************************************************************************** + /// Find the position of the first set bit. + /// Starts from LSB. + //*************************************************************************** + uint_least8_t find_first_set_bit(uint32_t value) + { + return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; + } + + //*************************************************************************** + /// Find the position of the first clear bit. + /// Starts from LSB. + //*************************************************************************** + uint_least8_t find_first_clear_bit(uint32_t value) + { + value ~= value; + return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; + } + + //*************************************************************************** + /// Find the position of the first bit that is clear or set. + /// Starts from LSB. + //*************************************************************************** + uint_least8_t find_first_bit(bool state, uint32_t value) + { + if (!state) + { + value ~= value; + } + + return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; + } + //*************************************************************************** /// 8 bit binary constants. //*************************************************************************** From 4bde024c03ae5109b1377ccd92981bc1360a724f Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 4 Jan 2017 15:51:11 +0000 Subject: [PATCH 099/168] Added find first set/clear bit functions. --- src/binary.h | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/binary.h b/src/binary.h index a86b92b6..73f9df2d 100644 --- a/src/binary.h +++ b/src/binary.h @@ -570,20 +570,39 @@ namespace etl return signed_value; } + //*************************************************************************** + /// Find the value of the first set bit. + /// Starts from LSB. + //*************************************************************************** + uint32_t first_set_bit(uint32_t value) + { + return (uint32_t)(value & -value); + } + //*************************************************************************** /// Find the position of the first set bit. /// Starts from LSB. //*************************************************************************** - uint_least8_t find_first_set_bit(uint32_t value) + uint_least8_t first_set_bit_position(uint32_t value) { - return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; + return __private_binary__::bit_position_lookup[(first_set_bit(value) * 0x077CB531U) >> 27]; + } + + //*************************************************************************** + /// Find the value of the first clear bit. + /// Starts from LSB. + //*************************************************************************** + uint32_t first_clear_bit(uint32_t value) + { + value = ~value; + return (uint32_t)(value & -value); } //*************************************************************************** /// Find the position of the first clear bit. /// Starts from LSB. //*************************************************************************** - uint_least8_t find_first_clear_bit(uint32_t value) + uint_least8_t first_clear_bit_position(uint32_t value) { value ~= value; return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; @@ -593,7 +612,21 @@ namespace etl /// Find the position of the first bit that is clear or set. /// Starts from LSB. //*************************************************************************** - uint_least8_t find_first_bit(bool state, uint32_t value) + uint_least8_t first_bit(bool state, uint32_t value) + { + if (!state) + { + value ~= value; + } + + return (uint32_t)(value & -value); + } + + //*************************************************************************** + /// Find the position of the first bit that is clear or set. + /// Starts from LSB. + //*************************************************************************** + uint_least8_t first_bit_position(bool state, uint32_t value) { if (!state) { From 5e77c55573cc64896d02f960cb198c2afcf3d4d6 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 4 Jan 2017 16:33:44 +0000 Subject: [PATCH 100/168] Better versions --- src/binary.h | 90 +++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/src/binary.h b/src/binary.h index 73f9df2d..91f64a51 100644 --- a/src/binary.h +++ b/src/binary.h @@ -71,12 +71,6 @@ namespace etl template const typename max_value_for_nbits_helper::value_type max_value_for_nbits_helper::value; - - static const uint_least8_t bit_position_lookup[32] = - { - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, - 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 - }; } /// Definition for non-zero NBITS. @@ -571,69 +565,85 @@ namespace etl } //*************************************************************************** - /// Find the value of the first set bit. - /// Starts from LSB. + /// Count trailing zeros. + /// Uses a binary search. //*************************************************************************** - uint32_t first_set_bit(uint32_t value) + template + typename etl::enable_if::type, uint32_t>::value, uint_least8_t>::type + count_trailing_zeros(uint32_t value) { - return (uint32_t)(value & -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; + } } //*************************************************************************** /// Find the position of the first set bit. /// Starts from LSB. //*************************************************************************** - uint_least8_t first_set_bit_position(uint32_t value) + template + uint_least8_t first_set_bit_position(T value) { - return __private_binary__::bit_position_lookup[(first_set_bit(value) * 0x077CB531U) >> 27]; - } - - //*************************************************************************** - /// Find the value of the first clear bit. - /// Starts from LSB. - //*************************************************************************** - uint32_t first_clear_bit(uint32_t value) - { - value = ~value; - return (uint32_t)(value & -value); + return count_trailing_zeros(value); } //*************************************************************************** /// Find the position of the first clear bit. /// Starts from LSB. //*************************************************************************** - uint_least8_t first_clear_bit_position(uint32_t value) + template + uint_least8_t first_clear_bit_position(T value) { value ~= value; - return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; + return count_trailing_zeros(value); } //*************************************************************************** /// Find the position of the first bit that is clear or set. /// Starts from LSB. //*************************************************************************** - uint_least8_t first_bit(bool state, uint32_t value) + template + uint_least8_t first_bit_position(bool state, T value) { if (!state) { value ~= value; } - return (uint32_t)(value & -value); - } - - //*************************************************************************** - /// Find the position of the first bit that is clear or set. - /// Starts from LSB. - //*************************************************************************** - uint_least8_t first_bit_position(bool state, uint32_t value) - { - if (!state) - { - value ~= value; - } - - return __private_binary__::bit_position_lookup[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; + return count_trailing_zeros(value); } //*************************************************************************** From 5c0ea58c81c7747d151c9cad8e4551124657af84 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 4 Jan 2017 17:33:05 +0000 Subject: [PATCH 101/168] Missing return --- src/binary.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/binary.h b/src/binary.h index 91f64a51..653dd9be 100644 --- a/src/binary.h +++ b/src/binary.h @@ -608,6 +608,8 @@ namespace etl count -= value & 0x1; } + + return count; } //*************************************************************************** From 09fda198ecb1c4d2acbd3af01c7679602dfcd1e7 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 4 Jan 2017 17:51:36 +0000 Subject: [PATCH 102/168] Added 8, 16 & 64 bit versions of count_trailing_zeros --- src/binary.h | 144 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 135 insertions(+), 9 deletions(-) diff --git a/src/binary.h b/src/binary.h index 653dd9be..c1243140 100644 --- a/src/binary.h +++ b/src/binary.h @@ -564,13 +564,12 @@ namespace etl return signed_value; } +#if ETL_8BIT_SUPPORT //*************************************************************************** - /// Count trailing zeros. + /// Count trailing zeros. bit. /// Uses a binary search. //*************************************************************************** - template - typename etl::enable_if::type, uint32_t>::value, uint_least8_t>::type - count_trailing_zeros(uint32_t value) + uint_least8_t count_trailing_zeros(uint8_t value) { uint_least8_t count; @@ -582,19 +581,146 @@ namespace etl { count = 1; - if ((value & 0xffff) == 0) + if ((value & 0xF) == 0) { - value >>= 16; - count += 16; + value >>= 4; + count += 4; } - if ((value & 0xff) == 0) + 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) + 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; From 0d86ea39c9516f7dd940aa06eef4d39718d1d539 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 17 Jan 2017 12:21:41 +0000 Subject: [PATCH 103/168] Initial implementation of a random number generator class. --- src/random.cpp | 139 +++++++++++++++++++++++++++++++++++++++++++++++++ src/random.h | 32 ++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 src/random.cpp create mode 100644 src/random.h diff --git a/src/random.cpp b/src/random.cpp new file mode 100644 index 00000000..fbe1ba15 --- /dev/null +++ b/src/random.cpp @@ -0,0 +1,139 @@ +///\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 "random.h" + +namespace +{ + enum + { + W = 32 + N = 624, + M = 397, + R = 31, + A = 0x9908B0DF, + F = 1812433253, + U = 11, + S = 7, + B = 0x9D2C5680, + T = 15, + C = 0xEFC60000, + L = 18, + + MASK_LOWER = (1ull << R) - 1, + MASK_UPPER = (1ull << R) + }; +} + +namespace etl +{ + //*************************************************************************** + /// Default constructor. + //*************************************************************************** + random::random() + { + // An attempt to come up with a reasonable non-zero seed. + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); + initialise(seed); + } + + //*************************************************************************** + /// Constructor with seed value. + //*************************************************************************** + random::random(uint32_t seed) + { + initialise(seed); + } + + //*************************************************************************** + /// Get the next random number. + //*************************************************************************** + uint32_t random::get() const + { + uint32_t n; + uint16_t i = index; + + if (index >= N) + { + twist(); + i = index; + } + + n = mt[i]; + index = i + 1; + + n ^= (mt[i] >> U); + n ^= (n << S) & B; + n ^= (n << T) & C; + n ^= (n >> L); + + return n; + } + + //*************************************************************************** + /// Initialises the sequence with a new seed value. + //*************************************************************************** + void random::initialize(uint32_t seed) + { + uint32_t i; + + mt[0] = seed; + + for (i = 1; i < N; i++) + { + mt[i] = (F * (mt[i - 1] ^ (mt[i - 1] >> (W - 2))) + i); + } + + index = N; + } + + //*************************************************************************** + /// Creates the next iteration. + //*************************************************************************** + void random::twist() + { + for (uint32_t i = 0; i < N; i++ ) + { + uint32_t x = (mt[i] & MASK_UPPER) + (mt[(i + 1) % N] & MASK_LOWER); + + uint32_t xA = x >> 1; + + if (x & 0x01) + { + xA ^= A; + } + + mt[i] = mt[(i + M) % N] ^ xA; + } + + index = 0; + } +} \ No newline at end of file diff --git a/src/random.h b/src/random.h new file mode 100644 index 00000000..c6ba60e4 --- /dev/null +++ b/src/random.h @@ -0,0 +1,32 @@ + +#ifndef __ETL_RANDOM_INCLUDED_ +#define __ETL_RANDOM_INCLUDED_ + +#include + +namespace etl +{ + //*************************************************************************** + /// A 32 bit Mersenne Twister random number generator. + /// Based on C/C++ code on Wikipedia. + /// https://en.wikipedia.org/wiki/Mersenne_Twister#C.2FC.2B.2B_implementation + //*************************************************************************** + class random + { + public: + + random(); + random(uint32_t seed); + void initialise(uint32_t seed); + uint32_t get() const; + + private: + + void twist(); + + uint32_t mt[N]; + uint16_t index; + }; +} + +#endif \ No newline at end of file From 525bdef6911b92a9ab93c8ae648d38074434d98d Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 17 Jan 2017 12:24:53 +0000 Subject: [PATCH 104/168] Added license and comments. --- src/random.cpp | 6 +++++- src/random.h | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index fbe1ba15..5b7eca34 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -56,10 +56,12 @@ namespace etl { //*************************************************************************** /// Default constructor. + /// Attempts to come up with a reasonable non-zero seed. //*************************************************************************** random::random() { - // An attempt to come up with a reasonable non-zero seed. + // An attempt to come up with a reasonable non-zero seed, + // based on the address of the instance. uintptr_t n = reinterpret_cast(this); uint32_t seed = static_cast(n); initialise(seed); @@ -67,6 +69,7 @@ namespace etl //*************************************************************************** /// Constructor with seed value. + ///\param seed The new seed value. //*************************************************************************** random::random(uint32_t seed) { @@ -100,6 +103,7 @@ namespace etl //*************************************************************************** /// Initialises the sequence with a new seed value. + ///\param seed The new seed value. //*************************************************************************** void random::initialize(uint32_t seed) { diff --git a/src/random.h b/src/random.h index c6ba60e4..e8ba5423 100644 --- a/src/random.h +++ b/src/random.h @@ -1,6 +1,35 @@ +///\file -#ifndef __ETL_RANDOM_INCLUDED_ -#define __ETL_RANDOM_INCLUDED_ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +http://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef __ETL_RANDOM__ +#define __ETL_RANDOM__ #include From 5640bfc35ce1ad7252b998b1505815df99573eb1 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 17 Jan 2017 14:47:10 +0000 Subject: [PATCH 105/168] Changed algorithm to 128bit xorshift. --- src/random.cpp | 91 ++++++++++---------------------------------------- src/random.h | 9 ++--- 2 files changed, 20 insertions(+), 80 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index 5b7eca34..051bde79 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -30,28 +30,6 @@ SOFTWARE. #include "random.h" -namespace -{ - enum - { - W = 32 - N = 624, - M = 397, - R = 31, - A = 0x9908B0DF, - F = 1812433253, - U = 11, - S = 7, - B = 0x9D2C5680, - T = 15, - C = 0xEFC60000, - L = 18, - - MASK_LOWER = (1ull << R) - 1, - MASK_UPPER = (1ull << R) - }; -} - namespace etl { //*************************************************************************** @@ -60,7 +38,7 @@ namespace etl //*************************************************************************** random::random() { - // An attempt to come up with a reasonable non-zero seed, + // An attempt to come up with a reasonable non-zero seed, // based on the address of the instance. uintptr_t n = reinterpret_cast(this); uint32_t seed = static_cast(n); @@ -76,68 +54,33 @@ namespace etl initialise(seed); } - //*************************************************************************** - /// Get the next random number. - //*************************************************************************** - uint32_t random::get() const - { - uint32_t n; - uint16_t i = index; - - if (index >= N) - { - twist(); - i = index; - } - - n = mt[i]; - index = i + 1; - - n ^= (mt[i] >> U); - n ^= (n << S) & B; - n ^= (n << T) & C; - n ^= (n >> L); - - return n; - } - //*************************************************************************** /// Initialises the sequence with a new seed value. ///\param seed The new seed value. //*************************************************************************** void random::initialize(uint32_t seed) { - uint32_t i; - - mt[0] = seed; - - for (i = 1; i < N; i++) - { - mt[i] = (F * (mt[i - 1] ^ (mt[i - 1] >> (W - 2))) + i); - } - - index = N; + state[0] = seed; + state[1] = seed + 3; + state[2] = seed + 5; + state[3] = seed + 7; } //*************************************************************************** - /// Creates the next iteration. + /// Get the next random number. //*************************************************************************** - void random::twist() + uint32_t random::operator()() constant { - for (uint32_t i = 0; i < N; i++ ) - { - uint32_t x = (mt[i] & MASK_UPPER) + (mt[(i + 1) % N] & MASK_LOWER); + 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; - uint32_t xA = x >> 1; - - if (x & 0x01) - { - xA ^= A; - } - - mt[i] = mt[(i + M) % N] ^ xA; - } - - index = 0; + return n; } } \ No newline at end of file diff --git a/src/random.h b/src/random.h index e8ba5423..cead31df 100644 --- a/src/random.h +++ b/src/random.h @@ -47,14 +47,11 @@ namespace etl random(); random(uint32_t seed); void initialise(uint32_t seed); - uint32_t get() const; + uint32_t operator()() const; - private: + private: - void twist(); - - uint32_t mt[N]; - uint16_t index; + uint32_t state[4]; }; } From d3c9cd3b1696e8ef1557cc450c3ccd2d802e85a1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 17 Jan 2017 23:03:23 +0000 Subject: [PATCH 106/168] Fixed syntax errors --- src/random.cpp | 22 +++++++++++----------- src/random.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index 051bde79..7fc49e6e 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -40,8 +40,8 @@ namespace etl { // An attempt to come up with a reasonable non-zero seed, // based on the address of the instance. - uintptr_t n = reinterpret_cast(this); - uint32_t seed = static_cast(n); + uintptr_t n = reinterpret_cast(this); + uint32_t seed = static_cast(n); initialise(seed); } @@ -58,7 +58,7 @@ namespace etl /// Initialises the sequence with a new seed value. ///\param seed The new seed value. //*************************************************************************** - void random::initialize(uint32_t seed) + void random::initialise(uint32_t seed) { state[0] = seed; state[1] = seed + 3; @@ -69,17 +69,17 @@ namespace etl //*************************************************************************** /// Get the next random number. //*************************************************************************** - uint32_t random::operator()() constant + uint32_t random::operator()() { - uint32_t n = state[3]; - n ^= n << 11; - n ^= n >> 8; - state[3] = state[2]; + 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; + n ^= state[0]; + n ^= state[0] >> 19; + state[0] = n; return n; } diff --git a/src/random.h b/src/random.h index cead31df..be900735 100644 --- a/src/random.h +++ b/src/random.h @@ -47,7 +47,7 @@ namespace etl random(); random(uint32_t seed); void initialise(uint32_t seed); - uint32_t operator()() const; + uint32_t operator()(); private: From 9848bba4d9285d83fa8c4caaa176965be76dae95 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 18 Jan 2017 12:49:49 +0000 Subject: [PATCH 107/168] Removed Jenkins 64bit hash. --- src/jenkins.h | 81 +++---------------------- test/test_jenkins.cpp | 137 ++++++++---------------------------------- 2 files changed, 31 insertions(+), 187 deletions(-) diff --git a/src/jenkins.h b/src/jenkins.h index b5e50833..c9daa4e5 100644 --- a/src/jenkins.h +++ b/src/jenkins.h @@ -45,16 +45,16 @@ SOFTWARE. #pragma diag_suppress 1300 #endif -///\defgroup jenkins Jenkins 32 & 64 bit hash calculations +///\defgroup jenkins Jenkins 32 hash calculation ///\ingroup maths namespace etl { //*************************************************************************** - /// Jenkins32 policy. + /// Jenkins policy. /// Calculates 32 bit Jenkins hash. //*************************************************************************** - struct jenkins32_policy + struct jenkins_policy { typedef uint32_t value_type; @@ -89,56 +89,17 @@ namespace etl bool is_finalised; }; - //*************************************************************************** - /// Jenkins64 policy. - /// Calculates 32 bit Jenkins hash. - //*************************************************************************** - struct jenkins64_policy - { - typedef uint64_t value_type; - - inline uint64_t initial() - { - is_finalised = false; - - return 0; - } - - inline uint64_t add(value_type hash, uint8_t value) const - { - ETL_ASSERT(!is_finalised, ETL_ERROR(hash_finalised)); - - hash += value; - hash += (hash << 10); - hash ^= (hash >> 6); - - return hash; - } - - inline uint64_t final(value_type hash) - { - hash += (hash << 3); - hash ^= (hash >> 11); - hash += (hash << 15); - is_finalised = true; - - return hash; - } - - bool is_finalised; - }; - //************************************************************************* - /// Jenkins32 + /// jenkins //************************************************************************* - class jenkins32 : public etl::frame_check_sequence + class jenkins : public etl::frame_check_sequence { public: //************************************************************************* /// Default constructor. //************************************************************************* - jenkins32() + jenkins() { this->reset(); } @@ -149,35 +110,7 @@ namespace etl /// \param end End of the range. //************************************************************************* template - jenkins32(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; - - //************************************************************************* - /// Jenkins64 - //************************************************************************* - class jenkins64 : public etl::frame_check_sequence - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - jenkins64() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - jenkins64(TIterator begin, const TIterator end) + jenkins(TIterator begin, const TIterator end) { this->reset(); this->add(begin, end); diff --git a/test/test_jenkins.cpp b/test/test_jenkins.cpp index 47b59b39..9f609f73 100644 --- a/test/test_jenkins.cpp +++ b/test/test_jenkins.cpp @@ -28,8 +28,6 @@ SOFTWARE. #include -#include "murmurhash3.h" // The 'C' reference implementation. - #include #include #include @@ -39,7 +37,7 @@ SOFTWARE. #include "../src/endian.h" template -uint32_t jenkins32(TIterator begin, TIterator end) +uint32_t jenkins(TIterator begin, TIterator end) { uint32_t hash = 0; @@ -57,178 +55,91 @@ uint32_t jenkins32(TIterator begin, TIterator end) return hash; } -template -uint64_t jenkins64(TIterator begin, TIterator end) -{ - uint64_t hash = 0; - - while (begin != end) - { - hash += *begin++; - hash += (hash << 10); - hash ^= (hash >> 6); - } - - hash += (hash << 3); - hash ^= (hash >> 11); - hash += (hash << 15); - - return hash; -} - namespace -{ +{ SUITE(test_jenkins) { //************************************************************************* - TEST(test_jenkins_32_constructor) + TEST(test_jenkins_constructor) { std::string data("123456789"); - uint32_t hash = etl::jenkins32(data.begin(), data.end()); - uint32_t compare = jenkins32(data.begin(), data.end()); + uint32_t hash = etl::jenkins(data.begin(), data.end()); + uint32_t compare = jenkins(data.begin(), data.end()); CHECK_EQUAL(compare, hash); } //************************************************************************* - TEST(test_jenkins_32_add_values) + TEST(test_jenkins_add_values) { std::string data("123456789"); - etl::jenkins32 jenkins_32_calculator; + etl::jenkins jenkins_calculator; for (size_t i = 0; i < data.size(); ++i) { - jenkins_32_calculator.add(data[i]); + jenkins_calculator.add(data[i]); } - uint32_t hash = jenkins_32_calculator; - uint32_t compare = jenkins32(data.begin(), data.end()); + uint32_t hash = jenkins_calculator; + uint32_t compare = jenkins(data.begin(), data.end()); CHECK_EQUAL(compare, hash); } //************************************************************************* - TEST(test_jenkins_32_add_range) + TEST(test_jenkins_add_range) { std::string data("123456789"); - etl::jenkins32 jenkins_32_calculator; + etl::jenkins jenkins_calculator; - jenkins_32_calculator.add(data.begin(), data.end()); + jenkins_calculator.add(data.begin(), data.end()); - uint32_t hash = jenkins_32_calculator.value(); + uint32_t hash = jenkins_calculator.value(); - uint32_t compare = jenkins32(data.begin(), data.end()); + uint32_t compare = jenkins(data.begin(), data.end()); CHECK_EQUAL(compare, hash); } //************************************************************************* - TEST(test_jenkins_32_add_range_endian) + TEST(test_jenkins_add_range_endian) { std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; std::vector data2 = { 0x04030201, 0x08070605 }; std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - uint32_t hash1 = etl::jenkins32(data1.begin(), data1.end()); - uint32_t hash2 = etl::jenkins32((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); - uint32_t hash3 = etl::jenkins32(data3.rbegin(), data3.rend()); + uint32_t hash1 = etl::jenkins(data1.begin(), data1.end()); + uint32_t hash2 = etl::jenkins((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); + uint32_t hash3 = etl::jenkins(data3.rbegin(), data3.rend()); CHECK_EQUAL(hash1, hash2); CHECK_EQUAL(hash1, hash3); - uint64_t compare1 = jenkins32(data1.begin(), data1.end()); + uint64_t compare1 = jenkins(data1.begin(), data1.end()); CHECK_EQUAL(compare1, hash1); - uint64_t compare2 = jenkins32((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); + uint64_t compare2 = jenkins((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); CHECK_EQUAL(compare2, hash2); - uint64_t compare3 = jenkins32(data3.rbegin(), data3.rend()); + uint64_t compare3 = jenkins(data3.rbegin(), data3.rend()); CHECK_EQUAL(compare3, hash3); } //************************************************************************* - TEST(test_jenkins_32_finalised_exception) + TEST(test_jenkins_finalised_exception) { std::string data("123456789"); - etl::jenkins32 j32; + etl::jenkins j32; j32.add(data.begin(), data.end()); j32.value(); CHECK_THROW(j32.add(0), etl::hash_finalised); } - - //************************************************************************* - TEST(test_jenkins_64_constructor) - { - std::string data("123456789"); - - uint64_t hash = etl::jenkins64(data.begin(), data.end()); - uint64_t compare = jenkins64(data.begin(), data.end()); - - CHECK_EQUAL(compare, hash); - } - - //************************************************************************* - TEST(test_jenkins_64_add_values) - { - std::string data("123456789"); - - etl::jenkins64 jenkins_64_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - jenkins_64_calculator.add(data[i]); - } - - uint64_t hash = jenkins_64_calculator; - uint64_t compare = jenkins64(data.begin(), data.end()); - - CHECK_EQUAL(compare, hash); - } - - //************************************************************************* - TEST(test_jenkins_64_add_range) - { - std::string data("123456789"); - - etl::jenkins64 jenkins_64_calculator; - - jenkins_64_calculator.add(data.begin(), data.end()); - - uint64_t hash = jenkins_64_calculator.value(); - - uint64_t compare = jenkins64(data.begin(), data.end()); - - CHECK_EQUAL(compare, hash); - } - - //************************************************************************* - TEST(test_jenkins_64_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint64_t hash1 = etl::jenkins64(data1.begin(), data1.end()); - uint64_t hash2 = etl::jenkins64((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); - uint64_t hash3 = etl::jenkins64(data3.rbegin(), data3.rend()); - CHECK_EQUAL(hash1, hash2); - CHECK_EQUAL(hash1, hash3); - - uint64_t compare1 = jenkins64(data1.begin(), data1.end()); - CHECK_EQUAL(compare1, hash1); - - uint64_t compare2 = jenkins64((uint8_t*)&data2[0], (uint8_t*)&data2[0] + (data2.size() * sizeof(uint32_t))); - CHECK_EQUAL(compare2, hash2); - - uint64_t compare3 = jenkins64(data3.rbegin(), data3.rend()); - CHECK_EQUAL(compare3, hash3); - } }; } From 6dcd00a0a7da3a029f3653a3890b182e624a26ce Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 20 Jan 2017 15:27:42 +0000 Subject: [PATCH 108/168] Made conversion operator explicit. const and non-const get() functions return a reference. --- src/type_def.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/type_def.h b/src/type_def.h index 66d6156e..ce1435c3 100644 --- a/src/type_def.h +++ b/src/type_def.h @@ -41,7 +41,7 @@ namespace etl ///\code /// // Short form. /// ETL_TYPEDEF(int, mytype); - /// + /// /// // Long form. /// class mytype_t_tag; /// typedef etl::type_def mytype_t_tag; @@ -74,7 +74,7 @@ namespace etl } //********************************************************************* - operator TValue() const + explicit operator TValue() const { return value; } @@ -243,7 +243,13 @@ namespace etl } //********************************************************************* - TValue get() const + TValue& get() + { + return value; + } + + //********************************************************************* + const TValue& get() const { return value; } From 3ffe0b50b10832e8c8847ac55c64c5269347153d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 21 Jan 2017 10:40:57 +0000 Subject: [PATCH 109/168] Fixed find/replace editing error. --- src/platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform.h b/src/platform.h index cfbb4eed..0616594c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -72,8 +72,8 @@ SOFTWARE. defined(ETL_COMPILER_TI_MSP430) || \ defined(ETL_COMPILER_IAR) || \ (defined(ETL_COMPILER_GCC) && (__cplusplus < 201103L)) - #define ETL_ETL_NO_NULLPTR_SUPPORT - #define ETL_ETL_NO_LARGE_CHAR_SUPPORT + #define ETL_NO_NULLPTR_SUPPORT + #define ETL_NO_LARGE_CHAR_SUPPORT #endif // Check to see if the compiler supports static_assert. From bf7567c6d8b60878f5b4f38d6d90cfb90c5f49fa Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 21 Jan 2017 10:42:02 +0000 Subject: [PATCH 110/168] Fixed find/replace editing error. --- src/platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform.h b/src/platform.h index cfbb4eed..0616594c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -72,8 +72,8 @@ SOFTWARE. defined(ETL_COMPILER_TI_MSP430) || \ defined(ETL_COMPILER_IAR) || \ (defined(ETL_COMPILER_GCC) && (__cplusplus < 201103L)) - #define ETL_ETL_NO_NULLPTR_SUPPORT - #define ETL_ETL_NO_LARGE_CHAR_SUPPORT + #define ETL_NO_NULLPTR_SUPPORT + #define ETL_NO_LARGE_CHAR_SUPPORT #endif // Check to see if the compiler supports static_assert. From e45994eb49cf9b4f37db47d84efb5aeacae72eb6 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 23 Jan 2017 14:17:36 +0000 Subject: [PATCH 111/168] Initial experimental implementation of user_type --- src/user_type.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/user_type.h diff --git a/src/user_type.h b/src/user_type.h new file mode 100644 index 00000000..06d20c96 --- /dev/null +++ b/src/user_type.h @@ -0,0 +1,132 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_USER_TYPE__ +#define __ETL_USER_TYPE__ + +///\defgroup user_type user_type +/// Smart enumerations.
+/// A method of declaring a user type that also contains a set of constants, +/// but are not constrained to just those values. +/// This contrasts with 'enum_type', where the values are expected to only contain +/// those defined as constants. +/// Declaring the enumeration. +///\code +/// DECLARE_USER_TYPE(CompassDirection, int) +/// USER_TYPE(North, 0) +/// USER_TYPE(South, 180) +/// USER_TYPE(East, 90) +/// USER_TYPE(West, 270) +/// END_USER_TYPE +///\endcode +/// Using the enumeration. +///\code +/// CompassDirection direction; // Default construction. +/// +/// direction = CompassDirection::North; // Assignment from an enumeration constant; +/// +/// int value = int(direction); // Explicit conversion to 'int'. +/// int value = direction.get(); +/// +/// const int& value = direction.get(); // Bind to internal value. +/// +/// direction = CompassDirection(value); // Explicit conversion from 'int'. +/// +/// direction = CompassDirection(3); // Explicit conversion from a value. +/// +/// ++direction; // Manipulate the value; +/// direction -= 20; +/// +/// direction = value; // Implicit conversion from 'int'. **** Compilation error **** +/// +/// std::cout << "Direction = " << direction.c_str(); // Prints "Direction = North" +///\endcode +/// If a conversion to a string is not required then the 'ENUM_TYPE' declaration may be omitted. +/// In that case the c_str() function will return a "?". This will also be the case for any +/// enumeration value that does not have an ENUM_TYPE entry. +///\ingroup utilities + +//***************************************************************************** +// The declaration of the structure. +//***************************************************************************** +#define DECLARE_USER_TYPE(TypeName, ValueType) \ + struct TypeName \ + { \ + enum enum_type \ + { \ + +//***************************************************************************** +// The predefined constants. +//***************************************************************************** +#define USER_TYPE(enum_name, value) \ + enum_name = value, + +//***************************************************************************** +// The final section of the structure. +//***************************************************************************** +#define END_USER_TYPE \ + }; \ + + typedef ValueType value_type; \ + TypeName() {} \ + TypeName(const TypeName &other) : value(other.value) {} \ + TypeName(enum_type value) : value(value) {} \ + TypeName& operator=(const TypeName &other) {value = other.value; return *this;} \ + explicit TypeName(value_type value) : value(static_cast(value)) {} \ + explicit operator value_type() const {return static_cast(value);} \ + value_type& get() {return static_cast(value);} \ + const value_type& get() const {return static_cast(value);} \ + TypeName& operator ++() { ++value; return *this; } \ + TypeName operator ++(int) { TypeName temp(*this); TypeName::operator ++(); return temp; } \ + TypeName& operator --() { --value; return *this; } + TypeName operator --(int) { TypeName temp(*this); TypeName::operator --(); return temp; } \ + TypeName& operator +=(value_type rhs) { value += rhs; return *this; } \ + TypeName& operator +=(const TypeName& rhs) { value += rhs.value; return *this; } \ + TypeName& operator -=(value_type rhs) { value -= rhs; return *this; } \ + TypeName& operator -=(const TypeName& rhs) { value -= rhs.value; return *this; } \ + TypeName& operator *=(value_type rhs) { value *= rhs; return *this; } \ + TypeName& operator *=(const TypeName& rhs) { value *= rhs.value; return *this; } \ + TypeName& operator /=(value_type rhs) { value /= rhs; return *this; } \ + TypeName& operator /=(const TypeName& rhs) { value /= rhs.value; return *this; } \ + TypeName& operator %=(value_type rhs) { value %= rhs; return *this; } \ + TypeName& operator %=(const TypeName& rhs) { value %= rhs.value; return *this; } \ + TypeName& operator &=(value_type rhs) { value &= rhs; return *this; } \ + TypeName& operator &=(const TypeName& rhs) { value &= rhs.value; return *this; } \ + TypeName& operator |=(value_type rhs) { value |= rhs; return *this; } \ + TypeName& operator |=(const TypeName& rhs) { value |= rhs.value; return *this; } \ + TypeName& operator ^=(value_type rhs) { value ^= rhs; return *this; } \ + TypeName& operator ^=(const TypeName& rhs) { value ^= rhs.value; return *this; } \ + TypeName& operator <<=(value_type rhs) { value <<= rhs; return *this; } \ + TypeName& operator >>=(value_type rhs) { value >>= rhs; return *this; } \ +private: \ + value_type value; \ +}; + +#endif From 28f1fb56bb99d68d9d1fdc7362433cf919cb0cac Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 24 Jan 2017 15:18:21 +0000 Subject: [PATCH 112/168] Updated after tests --- src/user_type.h | 93 +++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/src/user_type.h b/src/user_type.h index 06d20c96..b9a39995 100644 --- a/src/user_type.h +++ b/src/user_type.h @@ -39,12 +39,12 @@ SOFTWARE. /// those defined as constants. /// Declaring the enumeration. ///\code -/// DECLARE_USER_TYPE(CompassDirection, int) -/// USER_TYPE(North, 0) -/// USER_TYPE(South, 180) -/// USER_TYPE(East, 90) -/// USER_TYPE(West, 270) -/// END_USER_TYPE +/// ETL_DECLARE_USER_TYPE(CompassDirection, int) +/// ETL_USER_TYPE(North, 0) +/// ETL_USER_TYPE(South, 180) +/// ETL_USER_TYPE(East, 90) +/// ETL_USER_TYPE(West, 270) +/// ETL_END_USER_TYPE(CompassDirection) ///\endcode /// Using the enumeration. ///\code @@ -55,78 +55,71 @@ SOFTWARE. /// int value = int(direction); // Explicit conversion to 'int'. /// int value = direction.get(); /// -/// const int& value = direction.get(); // Bind to internal value. +/// int& value = direction.get(); // Bind to internal value. +/// const int& value = direction.get(); /// /// direction = CompassDirection(value); // Explicit conversion from 'int'. /// /// direction = CompassDirection(3); // Explicit conversion from a value. /// /// ++direction; // Manipulate the value; -/// direction -= 20; +/// direction -= CompassDirection(20); /// /// direction = value; // Implicit conversion from 'int'. **** Compilation error **** /// -/// std::cout << "Direction = " << direction.c_str(); // Prints "Direction = North" ///\endcode -/// If a conversion to a string is not required then the 'ENUM_TYPE' declaration may be omitted. -/// In that case the c_str() function will return a "?". This will also be the case for any -/// enumeration value that does not have an ENUM_TYPE entry. ///\ingroup utilities //***************************************************************************** // The declaration of the structure. //***************************************************************************** -#define DECLARE_USER_TYPE(TypeName, ValueType) \ +#define ETL_DECLARE_USER_TYPE(TypeName, ValueType) \ struct TypeName \ { \ + typedef ValueType value_type; \ + TypeName() {} \ + TypeName(const TypeName &other) : value(other.value) {} \ + TypeName& operator=(const TypeName &other) { value = other.value; return *this; } \ + explicit TypeName(ValueType value) : value(value) {} \ + explicit operator ValueType() const { return value; } \ + ValueType& get() { return value; } \ + const ValueType& get() const { return value; } \ + TypeName& operator ++() { ++value; return *this; } \ + TypeName operator ++(int) { TypeName temp(*this); TypeName::operator ++(); return temp; } \ + TypeName& operator --() { --value; return *this; } \ + TypeName operator --(int) { TypeName temp(*this); TypeName::operator --(); return temp; } \ + TypeName& operator +=(const TypeName& rhs) { value += rhs.value; return *this; } \ + TypeName& operator -=(const TypeName& rhs) { value -= rhs.value; return *this; } \ + TypeName& operator *=(const TypeName& rhs) { value *= rhs.value; return *this; } \ + TypeName& operator /=(const TypeName& rhs) { value /= rhs.value; return *this; } \ + TypeName& operator %=(const TypeName& rhs) { value %= rhs.value; return *this; } \ + TypeName& operator &=(const TypeName& rhs) { value &= rhs.value; return *this; } \ + TypeName& operator &=(ValueType mask) { value &= mask; return *this; } \ + TypeName& operator |=(const TypeName& rhs) { value |= rhs.value; return *this; } \ + TypeName& operator |=(ValueType mask) { value &= mask; return *this; } \ + TypeName& operator ^=(const TypeName& rhs) { value ^= rhs.value; return *this; } \ + TypeName& operator ^=(ValueType mask) { value ^= mask; return *this; } \ + TypeName& operator <<=(ValueType distance) { value <<= distance; return *this; } \ + TypeName& operator >>=(ValueType distance) { value >>= distance; return *this; } \ + private: \ + ValueType value; \ + public: \ enum enum_type \ - { \ + { //***************************************************************************** // The predefined constants. //***************************************************************************** -#define USER_TYPE(enum_name, value) \ +#define ETL_USER_TYPE(enum_name, value) \ enum_name = value, //***************************************************************************** // The final section of the structure. //***************************************************************************** -#define END_USER_TYPE \ +#define ETL_END_USER_TYPE(TypeName) \ }; \ + TypeName(enum_type value) : value(static_cast(value)) {} \ + }; - typedef ValueType value_type; \ - TypeName() {} \ - TypeName(const TypeName &other) : value(other.value) {} \ - TypeName(enum_type value) : value(value) {} \ - TypeName& operator=(const TypeName &other) {value = other.value; return *this;} \ - explicit TypeName(value_type value) : value(static_cast(value)) {} \ - explicit operator value_type() const {return static_cast(value);} \ - value_type& get() {return static_cast(value);} \ - const value_type& get() const {return static_cast(value);} \ - TypeName& operator ++() { ++value; return *this; } \ - TypeName operator ++(int) { TypeName temp(*this); TypeName::operator ++(); return temp; } \ - TypeName& operator --() { --value; return *this; } - TypeName operator --(int) { TypeName temp(*this); TypeName::operator --(); return temp; } \ - TypeName& operator +=(value_type rhs) { value += rhs; return *this; } \ - TypeName& operator +=(const TypeName& rhs) { value += rhs.value; return *this; } \ - TypeName& operator -=(value_type rhs) { value -= rhs; return *this; } \ - TypeName& operator -=(const TypeName& rhs) { value -= rhs.value; return *this; } \ - TypeName& operator *=(value_type rhs) { value *= rhs; return *this; } \ - TypeName& operator *=(const TypeName& rhs) { value *= rhs.value; return *this; } \ - TypeName& operator /=(value_type rhs) { value /= rhs; return *this; } \ - TypeName& operator /=(const TypeName& rhs) { value /= rhs.value; return *this; } \ - TypeName& operator %=(value_type rhs) { value %= rhs; return *this; } \ - TypeName& operator %=(const TypeName& rhs) { value %= rhs.value; return *this; } \ - TypeName& operator &=(value_type rhs) { value &= rhs; return *this; } \ - TypeName& operator &=(const TypeName& rhs) { value &= rhs.value; return *this; } \ - TypeName& operator |=(value_type rhs) { value |= rhs; return *this; } \ - TypeName& operator |=(const TypeName& rhs) { value |= rhs.value; return *this; } \ - TypeName& operator ^=(value_type rhs) { value ^= rhs; return *this; } \ - TypeName& operator ^=(const TypeName& rhs) { value ^= rhs.value; return *this; } \ - TypeName& operator <<=(value_type rhs) { value <<= rhs; return *this; } \ - TypeName& operator >>=(value_type rhs) { value >>= rhs; return *this; } \ -private: \ - value_type value; \ -}; #endif From 64860d86f1494b784e158548a80b5715744630e3 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 24 Jan 2017 15:21:39 +0000 Subject: [PATCH 113/168] Added ETL_ prefixes --- src/enum_type.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/enum_type.h b/src/enum_type.h index 971e8044..ca0c9f55 100644 --- a/src/enum_type.h +++ b/src/enum_type.h @@ -48,12 +48,12 @@ SOFTWARE. /// West = 270 /// }; /// -/// DECLARE_ENUM_TYPE(CompassDirection, int) -/// ENUM_TYPE(North, "North") -/// ENUM_TYPE(South, "South") -/// ENUM_TYPE(East, "East") -/// ENUM_TYPE(West, "West") -/// END_ENUM_TYPE +/// ETL_DECLARE_ENUM_TYPE(CompassDirection, int) +/// ETL_ENUM_TYPE(North, "North") +/// ETL_ENUM_TYPE(South, "South") +/// ETL_ENUM_TYPE(East, "East") +/// ETL_ENUM_TYPE(West, "West") +/// ETL_END_ENUM_TYPE /// }; ///\endcode /// Using the enumeration. @@ -80,7 +80,7 @@ SOFTWARE. //***************************************************************************** // The declaration of the member functions and the first section of the 'c_str' function. //***************************************************************************** -#define DECLARE_ENUM_TYPE(TypeName, ValueType) \ +#define ETL_DECLARE_ENUM_TYPE(TypeName, ValueType) \ typedef ValueType value_type; \ TypeName() {} \ TypeName(const TypeName &other) : value(other.value) {} \ @@ -98,14 +98,14 @@ SOFTWARE. //***************************************************************************** // A case in the 'c_str' function's switch statement. //***************************************************************************** -#define ENUM_TYPE(value, name) \ +#define ETL_ENUM_TYPE(value, name) \ case value: \ return name; \ //***************************************************************************** // The final section of the 'c_str' function and the value declaration. //***************************************************************************** -#define END_ENUM_TYPE \ +#define ETL_END_ENUM_TYPE \ default: \ return "?"; \ } \ From 0ba97b9416404f7fa40331c2425d0e04f7d5f775 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 26 Jan 2017 08:52:01 +0000 Subject: [PATCH 114/168] Fixed compile error in 'first_clear_bit_position' --- src/binary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/binary.h b/src/binary.h index c1243140..9ca9cfce 100644 --- a/src/binary.h +++ b/src/binary.h @@ -755,7 +755,7 @@ namespace etl template uint_least8_t first_clear_bit_position(T value) { - value ~= value; + value = ~value; return count_trailing_zeros(value); } @@ -768,7 +768,7 @@ namespace etl { if (!state) { - value ~= value; + value = ~value; } return count_trailing_zeros(value); From 2e8f09d721b57a0d1c66f6a5babdbd210d7284de Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 26 Jan 2017 09:15:16 +0000 Subject: [PATCH 115/168] Updates for volatile support. --- src/user_type.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/user_type.h b/src/user_type.h index b9a39995..482efeeb 100644 --- a/src/user_type.h +++ b/src/user_type.h @@ -76,6 +76,7 @@ SOFTWARE. #define ETL_DECLARE_USER_TYPE(TypeName, ValueType) \ struct TypeName \ { \ + /* Non-volatile definitions.*/ \ typedef ValueType value_type; \ TypeName() {} \ TypeName(const TypeName &other) : value(other.value) {} \ @@ -101,6 +102,30 @@ SOFTWARE. TypeName& operator ^=(ValueType mask) { value ^= mask; return *this; } \ TypeName& operator <<=(ValueType distance) { value <<= distance; return *this; } \ TypeName& operator >>=(ValueType distance) { value >>= distance; return *this; } \ + \ + /* Volatile definitions.*/ \ + TypeName(const volatile TypeName &other) : value(other.value) {} \ + void operator=(const volatile TypeName &other) volatile { value = other.value; } \ + explicit operator ValueType() volatile const { return value; } \ + volatile ValueType& get() volatile { return value; } \ + const volatile ValueType& get() volatile const { return value; } \ + void operator ++() volatile { ++value; } \ + volatile TypeName operator ++(int) volatile { volatile TypeName temp(*this); TypeName::operator ++(); return temp; } \ + void operator --() volatile { --value; } \ + volatile TypeName operator --(int) volatile { volatile TypeName temp(*this); TypeName::operator --(); return temp; } \ + void operator +=(const volatile TypeName& rhs) volatile { value += rhs.value; } \ + void operator -=(const volatile TypeName& rhs) volatile { value -= rhs.value; } \ + void operator *=(const volatile TypeName& rhs) volatile { value *= rhs.value; } \ + void operator /=(const volatile TypeName& rhs) volatile { value /= rhs.value; } \ + void operator %=(const volatile TypeName& rhs) volatile { value %= rhs.value; } \ + void operator &=(const volatile TypeName& rhs) volatile { value &= rhs.value; } \ + void operator &=(ValueType mask) volatile { value &= mask; } \ + void operator |=(const volatile TypeName& rhs) volatile { value |= rhs.value; } \ + void operator |=(ValueType mask) volatile { value &= mask; } \ + void operator ^=(const volatile TypeName& rhs) volatile { value ^= rhs.value; } \ + void operator ^=(ValueType mask) volatile { value ^= mask; } \ + void operator <<=(ValueType distance) volatile { value <<= distance; } \ + void operator >>=(ValueType distance) volatile { value >>= distance; } \ private: \ ValueType value; \ public: \ From eac243d8980d30dad8c8cf7cbcbb7d650b021973 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 30 Jan 2017 21:35:34 +0000 Subject: [PATCH 116/168] Added comments and modified starting values. --- src/random.cpp | 9 +++++---- src/random.h | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index 7fc49e6e..c695df5d 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -60,10 +60,11 @@ namespace etl //*************************************************************************** void random::initialise(uint32_t seed) { - state[0] = seed; - state[1] = seed + 3; - state[2] = seed + 5; - state[3] = seed + 7; + // 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; } //*************************************************************************** diff --git a/src/random.h b/src/random.h index be900735..bf65450b 100644 --- a/src/random.h +++ b/src/random.h @@ -36,9 +36,9 @@ SOFTWARE. namespace etl { //*************************************************************************** - /// A 32 bit Mersenne Twister random number generator. - /// Based on C/C++ code on Wikipedia. - /// https://en.wikipedia.org/wiki/Mersenne_Twister#C.2FC.2B.2B_implementation + /// A 32 bit random number generator. + /// Uses a 128 bit XOR shift algorithm. + /// https://en.wikipedia.org/wiki/Xorshift //*************************************************************************** class random { From aaac05900819d35bc34a893047eb7e273a1b1261 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:06:07 +0000 Subject: [PATCH 117/168] Updated tests --- test/test_deque.cpp | 34 +++++-------- test/test_enum_type.cpp | 12 ++--- test/test_flat_multimap.cpp | 68 ++++++++++++------------- test/test_forward_list.cpp | 3 ++ test/test_intrusive_forward_list.cpp | 3 ++ test/test_intrusive_list.cpp | 3 ++ test/test_list.cpp | 25 +++++---- test/test_map.cpp | 2 + test/test_pool.cpp | 76 ++++++++++++++-------------- test/test_type_def.cpp | 52 +++++++++---------- test/test_unordered_map.cpp | 39 ++++++++------ test/test_unordered_multimap.cpp | 32 +++++++----- test/test_unordered_multiset.cpp | 34 ++++++------- test/test_unordered_set.cpp | 36 +++++++------ test/test_vector.cpp | 14 +---- test/test_vector_pointer.cpp | 12 ----- 16 files changed, 221 insertions(+), 224 deletions(-) diff --git a/test/test_deque.cpp b/test/test_deque.cpp index e97efee9..d029ed50 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -41,8 +41,8 @@ SOFTWARE. namespace { - SUITE(test_deque) - { + SUITE(test_deque) + { const size_t SIZE = 14; typedef TestDataDC DC; @@ -84,12 +84,12 @@ namespace std::vector initial_data_dc = { DC("0"), DC("1"), DC("2"), DC("3"), DC("4"), DC("5"), DC("6"), DC("7"), DC("8"), DC("9"), DC("10"), DC("11"), DC("12"), DC("13") }; //************************************************************************* - TEST(test_constructor) - { + TEST(test_constructor) + { DataDC data; CHECK_EQUAL(SIZE, data.max_size()); - } + } //************************************************************************* TEST(test_constructor_fill) @@ -118,24 +118,18 @@ namespace } //************************************************************************* - TEST(test_constructor_range_excess) + TEST(test_copy_constructor) { - CHECK_THROW(DataNDC data(initial_data_excess.begin(), initial_data_excess.end()), etl::deque_full); - } - - //************************************************************************* - TEST(test_copy_constructor) - { DataNDC deque1(initial_data.begin(), initial_data.end()); DataNDC deque2(deque1); CHECK_EQUAL(deque1.size(), deque2.size()); CHECK(std::equal(deque1.begin(), deque1.end(), deque2.begin())); - } + } //************************************************************************* - TEST(test_assignment) - { + TEST(test_assignment) + { DataNDC deque1(initial_data.begin(), initial_data.end()); DataNDC deque2; @@ -143,7 +137,7 @@ namespace CHECK_EQUAL(deque1.size(), deque2.size()); CHECK(std::equal(deque1.begin(), deque1.end(), deque2.begin())); - } + } //************************************************************************* TEST(test_assignment_interface) @@ -1477,8 +1471,8 @@ namespace } //************************************************************************* - TEST(test_equality_operator) - { + TEST(test_equality_operator) + { Compare_Data same = { N1, N2, N3, N4, N5, N6 }; Compare_Data different = { N6, N5, N4, N3, N2, N1 }; @@ -1491,7 +1485,7 @@ namespace std::copy(different.begin(), different.end(), deque2.begin()); CHECK(!(deque1 == deque2)); - } + } //************************************************************************* TEST(test_inequality_operator) @@ -1520,5 +1514,5 @@ namespace CHECK(data.rbegin() == data.rend()); CHECK(data.crbegin() == data.crend()); } - }; + }; } diff --git a/test/test_enum_type.cpp b/test/test_enum_type.cpp index c8b84c77..eebd017c 100644 --- a/test/test_enum_type.cpp +++ b/test/test_enum_type.cpp @@ -41,11 +41,11 @@ struct enum_test FOUR }; - DECLARE_ENUM_TYPE(enum_test, int) - ENUM_TYPE(ZERO, "ZERO") - ENUM_TYPE(ONE, "ONE") - ENUM_TYPE(THREE, "THREE") - END_ENUM_TYPE + ETL_DECLARE_ENUM_TYPE(enum_test, int) + ETL_ENUM_TYPE(ZERO, "ZERO") + ETL_ENUM_TYPE(ONE, "ONE") + ETL_ENUM_TYPE(THREE, "THREE") + ETL_END_ENUM_TYPE }; namespace @@ -75,7 +75,7 @@ namespace value = enum_test::THREE; CHECK_EQUAL(std::string("THREE"), std::string(value.c_str())); - // No ENUM_TYPE definition. + // No ETL_ENUM_TYPE definition. value = enum_test::FOUR; CHECK_EQUAL(std::string("?"), std::string(value.c_str())); diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index 9416de9f..c0d6260a 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -83,7 +83,7 @@ namespace std::vector initial_data; std::vector excess_data; std::vector different_data; - std::vector multi_data; + std::vector multi_data; //************************************************************************* template @@ -127,16 +127,16 @@ namespace ElementNDC(15, N15), ElementNDC(16, N16), ElementNDC(17, N17), ElementNDC(18, N18), ElementNDC(19, N19) }; - ElementNDC n4[] = - { - ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(1, N3), ElementNDC(3, N4), - ElementNDC(4, N5), ElementNDC(4, N6), ElementNDC(5, N7), ElementNDC(4, N8), ElementNDC(0, N9) - }; + ElementNDC n4[] = + { + ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(1, N3), ElementNDC(3, N4), + ElementNDC(4, N5), ElementNDC(4, N6), ElementNDC(5, N7), ElementNDC(4, N8), ElementNDC(0, N9) + }; initial_data.assign(std::begin(n), std::end(n)); excess_data.assign(std::begin(n2), std::end(n2)); different_data.assign(std::begin(n3), std::end(n3)); - multi_data.assign(std::begin(n4), std::end(n4)); + multi_data.assign(std::begin(n4), std::end(n4)); } }; @@ -630,39 +630,39 @@ namespace CHECK(initial1 != different); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_multi) - { - Compare_DataNDC compare_data(multi_data.begin(), multi_data.end()); - DataNDC data(multi_data.begin(), multi_data.end()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_multi) + { + Compare_DataNDC compare_data(multi_data.begin(), multi_data.end()); + DataNDC data(multi_data.begin(), multi_data.end()); - std::pair compare_range; - std::pair test_range; - - compare_range = compare_data.equal_range(0); - test_range = data.equal_range(0); - CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); + std::pair compare_range; + std::pair test_range; + + compare_range = compare_data.equal_range(0); + test_range = data.equal_range(0); + CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); - compare_range = compare_data.equal_range(1); - test_range = data.equal_range(1); - CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); + compare_range = compare_data.equal_range(1); + test_range = data.equal_range(1); + CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); - compare_range = compare_data.equal_range(2); - test_range = data.equal_range(2); - CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); + compare_range = compare_data.equal_range(2); + test_range = data.equal_range(2); + CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); - compare_range = compare_data.equal_range(3); - test_range = data.equal_range(3); - CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); + compare_range = compare_data.equal_range(3); + test_range = data.equal_range(3); + CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); - compare_range = compare_data.equal_range(4); - test_range = data.equal_range(4); - CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); + compare_range = compare_data.equal_range(4); + test_range = data.equal_range(4); + CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); - compare_range = compare_data.equal_range(5); - test_range = data.equal_range(5); - CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); - } + compare_range = compare_data.equal_range(5); + test_range = data.equal_range(5); + CHECK_EQUAL(std::distance(compare_range.first, compare_range.second), std::distance(test_range.first, test_range.second)); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_count) diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 44911f72..03ac1e55 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -765,6 +765,9 @@ namespace compare_data.reverse(); data.reverse(); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + CHECK_EQUAL(data.size(), std::distance(data.begin(), data.end())); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 4c962b37..af5f9bc0 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -718,6 +718,9 @@ namespace data0.reverse(); // Just reverse one of them. + CHECK_EQUAL(data1.size(), data0.size()); + CHECK_EQUAL(data0.size(), std::distance(data0.begin(), data0.end())); + are_equal = std::equal(data0.begin(), data0.end(), sorted_data.rbegin()); CHECK(are_equal); diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 34b3ca54..34e01071 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -760,6 +760,9 @@ namespace data0.reverse(); // Just reverse one of them. + CHECK_EQUAL(data1.size(), data0.size()); + CHECK_EQUAL(data0.size(), std::distance(data0.begin(), data0.end())); + are_equal = std::equal(data0.begin(), data0.end(), sorted_data.rbegin()); CHECK(are_equal); diff --git a/test/test_list.cpp b/test/test_list.cpp index 77ca4200..e8bb91b5 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -833,6 +833,9 @@ namespace compare_data.reverse(); data.reverse(); + CHECK_EQUAL(compare_data.size(), data.size()); + CHECK_EQUAL(data.size(), std::distance(data.begin(), data.end())); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -1316,8 +1319,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(data0.size(), compare0.size()); - CHECK_EQUAL(data1.size(), compare1.size()); + CHECK_EQUAL(compare0.size(), data0.size()); + CHECK_EQUAL(compare1.size(), data1.size()); } //************************************************************************* @@ -1337,8 +1340,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(data0.size(), compare0.size()); - CHECK_EQUAL(data2.size(), compare2.size()); + CHECK_EQUAL(compare0.size(), data0.size()); + CHECK_EQUAL(compare2.size(), data2.size()); } //************************************************************************* @@ -1358,8 +1361,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(data0.size(), compare0.size()); - CHECK_EQUAL(data3.size(), compare3.size()); + CHECK_EQUAL(compare0.size(), data0.size()); + CHECK_EQUAL(compare3.size(), data3.size()); } //************************************************************************* @@ -1379,8 +1382,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(data0.size(), compare0.size()); - CHECK_EQUAL(data4.size(), compare4.size()); + CHECK_EQUAL(compare0.size(), data0.size()); + CHECK_EQUAL(compare4.size(), data4.size()); } //************************************************************************* @@ -1394,6 +1397,8 @@ namespace data0.reverse(); data1.reverse(); + + CompareData compare0(merge_data0.begin(), merge_data0.end()); CompareData compare1(merge_data1.begin(), merge_data1.end()); @@ -1406,8 +1411,8 @@ namespace are_equal = std::equal(data0.begin(), data0.end(), compare0.begin()); CHECK(are_equal); - CHECK_EQUAL(data0.size(), compare0.size()); - CHECK_EQUAL(data1.size(), compare1.size()); + CHECK_EQUAL(compare0.size(), data0.size()); + CHECK_EQUAL(compare1.size(), data1.size()); } //************************************************************************* diff --git a/test/test_map.cpp b/test/test_map.cpp index b88ce7f8..534c7416 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -190,6 +190,8 @@ namespace Data data(compare_data.begin(), compare_data.end()); + size_t d = std::distance(data.begin(), data.end()); + CHECK(data.size() == SIZE); CHECK(!data.empty()); } diff --git a/test/test_pool.cpp b/test/test_pool.cpp index 836823e6..fbe53642 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -58,10 +58,10 @@ namespace Test_Data* p3 = nullptr; Test_Data* p4 = nullptr; - CHECK_NO_THROW(p1 = pool.allocate()); - CHECK_NO_THROW(p2 = pool.allocate()); - CHECK_NO_THROW(p3 = pool.allocate()); - CHECK_NO_THROW(p4 = pool.allocate()); + CHECK_NO_THROW(p1 = pool.allocate()); + CHECK_NO_THROW(p2 = pool.allocate()); + CHECK_NO_THROW(p3 = pool.allocate()); + CHECK_NO_THROW(p4 = pool.allocate()); CHECK(p1 != p2); CHECK(p1 != p3); @@ -70,7 +70,7 @@ namespace CHECK(p2 != p4); CHECK(p3 != p4); - CHECK_THROW(pool.allocate(), etl::pool_no_allocation); + CHECK_THROW(pool.allocate(), etl::pool_no_allocation); } //************************************************************************* @@ -78,21 +78,21 @@ namespace { etl::pool pool; - Test_Data* p1 = pool.allocate(); - Test_Data* p2 = pool.allocate(); - Test_Data* p3 = pool.allocate(); - Test_Data* p4 = pool.allocate(); + Test_Data* p1 = pool.allocate(); + Test_Data* p2 = pool.allocate(); + Test_Data* p3 = pool.allocate(); + Test_Data* p4 = pool.allocate(); CHECK_NO_THROW(pool.release(p2)); - CHECK_NO_THROW(pool.release(*p3)); + CHECK_NO_THROW(pool.release(p3)); CHECK_NO_THROW(pool.release(p1)); - CHECK_NO_THROW(pool.release(*p4)); + CHECK_NO_THROW(pool.release(p4)); CHECK_EQUAL(4U, pool.available()); Test_Data not_in_pool; - CHECK_THROW(pool.release(not_in_pool), etl::pool_object_not_in_pool); + CHECK_THROW(pool.release(¬_in_pool), etl::pool_object_not_in_pool); } //************************************************************************* @@ -100,10 +100,10 @@ namespace { etl::pool pool; - Test_Data* p1 = pool.allocate(); - Test_Data* p2 = pool.allocate(); - Test_Data* p3 = pool.allocate(); - Test_Data* p4 = pool.allocate(); + Test_Data* p1 = pool.allocate(); + Test_Data* p2 = pool.allocate(); + Test_Data* p3 = pool.allocate(); + Test_Data* p4 = pool.allocate(); // Allocated p1, p2, p3, p4 @@ -116,8 +116,8 @@ namespace CHECK_EQUAL(2U, pool.available()); - Test_Data* p5 = pool.allocate(); - Test_Data* p6 = pool.allocate(); + Test_Data* p5 = pool.allocate(); + Test_Data* p6 = pool.allocate(); // Allocated p1, p4, p5, p6 @@ -135,7 +135,7 @@ namespace CHECK_EQUAL(1U, pool.available()); - Test_Data* p7 = pool.allocate(); + Test_Data* p7 = pool.allocate(); // Allocated p1, p4, p6, p7 @@ -154,16 +154,16 @@ namespace Test_Data* p; - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(3U, pool.available()); - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(2U, pool.available()); - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(1U, pool.available()); - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(0U, pool.available()); } @@ -172,7 +172,7 @@ namespace { etl::pool pool; - CHECK(pool.max_size() == 4U); + CHECK(pool.max_items() == 4U); } //************************************************************************* @@ -183,16 +183,16 @@ namespace Test_Data* p; - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(1U, pool.size()); - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(2U, pool.size()); - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(3U, pool.size()); - p = pool.allocate(); + p = pool.allocate(); CHECK_EQUAL(4U, pool.size()); } @@ -205,19 +205,19 @@ namespace Test_Data* p; - p = pool.allocate(); + p = pool.allocate(); CHECK(!pool.empty()); CHECK(!pool.full()); - p = pool.allocate(); + p = pool.allocate(); CHECK(!pool.empty()); CHECK(!pool.full()); - p = pool.allocate(); + p = pool.allocate(); CHECK(!pool.empty()); CHECK(!pool.full()); - p = pool.allocate(); + p = pool.allocate(); CHECK(!pool.empty()); CHECK(pool.full()); } @@ -228,10 +228,10 @@ namespace etl::pool pool; Test_Data not_in_pool; - Test_Data* p1 = pool.allocate(); + Test_Data* p1 = pool.allocate(); CHECK(pool.is_in_pool(p1)); - CHECK(!pool.is_in_pool(not_in_pool)); + CHECK(!pool.is_in_pool(¬_in_pool)); } //************************************************************************* @@ -355,8 +355,8 @@ namespace //Pool pool; //Test_Data not_in_pool; - //Test_Data* p1 = pool.allocate(); - //Test_Data* p2 = pool.allocate(); + //Test_Data* p1 = pool.allocate(); + //Test_Data* p2 = pool.allocate(); //Pool::iterator i_data = pool.get_iterator(*p1); //Pool::iterator i_data2 = pool.get_iterator(*p2); @@ -376,8 +376,8 @@ namespace //Pool pool; //const Test_Data not_in_pool; - //const Test_Data* p1 = pool.allocate(); - //const Test_Data* p2 = pool.allocate(); + //const Test_Data* p1 = pool.allocate(); + //const Test_Data* p2 = pool.allocate(); //Pool::const_iterator i_data = pool.get_iterator(*p1); //Pool::const_iterator i_data2 = pool.get_iterator(*p2); diff --git a/test/test_type_def.cpp b/test/test_type_def.cpp index 9d851909..86e0933b 100644 --- a/test/test_type_def.cpp +++ b/test/test_type_def.cpp @@ -45,8 +45,8 @@ namespace type1_t t1 = type1_t(1); type2_t t2 = type2_t(1); - uint32_t i1 = t1; - uint32_t i2 = t2; + uint32_t i1 = t1.get(); + uint32_t i2 = t2.get(); CHECK_EQUAL(i1, i2); } @@ -63,8 +63,8 @@ namespace type1_t t1 = type1_t(1); type2_t t2 = type2_t(1); - uint32_t i1 = t1; - uint32_t i2 = t2; + uint32_t i1 = t1.get(); + uint32_t i2 = t2.get(); CHECK_EQUAL(i1, i2); } @@ -93,30 +93,30 @@ namespace uint32_t i = 0x5A3D; type_t t(0x5A3D); - CHECK_EQUAL(++i, ++t); - CHECK_EQUAL(i++, t++); - CHECK_EQUAL(--i, --t); - CHECK_EQUAL(i--, t--); - CHECK_EQUAL(i += 2, t += 2); - CHECK_EQUAL(i += 2, t += type_t(2)); - CHECK_EQUAL(i -= 2, t -= 2); - CHECK_EQUAL(i -= 2, t -= type_t(2)); - CHECK_EQUAL(i *= 2, t *= 2); - CHECK_EQUAL(i *= 2, t *= type_t(2)); - CHECK_EQUAL(i /= 2, t /= 2); - CHECK_EQUAL(i /= 2, t /= type_t(2)); - CHECK_EQUAL(i &= 0xFF00, t &= 0xFF00); - CHECK_EQUAL(i &= 0xFF00, t &= type_t(0xFF00)); - CHECK_EQUAL(i |= 0x003D, t |= 0x003D); - CHECK_EQUAL(i |= 0x003D, t |= type_t(0x003D)); - CHECK_EQUAL(i ^= 0xAA55, t ^= 0xAA55); - CHECK_EQUAL(i ^= 0xAA55, t ^= type_t(0xAA55)); - CHECK_EQUAL(i <<= 2, t <<= 2); - CHECK_EQUAL(i >>= 2, t >>= 2); - CHECK_EQUAL(i %= 23, t %= 23); + CHECK_EQUAL(++i, uint32_t(++t)); + CHECK_EQUAL(i++, uint32_t(t++)); + CHECK_EQUAL(--i, uint32_t(--t)); + CHECK_EQUAL(i--, uint32_t(t--)); + CHECK_EQUAL(i += 2, uint32_t(t += 2)); + CHECK_EQUAL(i += 2, uint32_t(t += type_t(2))); + CHECK_EQUAL(i -= 2, uint32_t(t -= 2)); + CHECK_EQUAL(i -= 2, uint32_t(t -= type_t(2))); + CHECK_EQUAL(i *= 2, uint32_t(t *= 2)); + CHECK_EQUAL(i *= 2, uint32_t(t *= type_t(2))); + CHECK_EQUAL(i /= 2, uint32_t(t /= 2)); + CHECK_EQUAL(i /= 2, uint32_t(t /= type_t(2))); + CHECK_EQUAL(i &= 0xFF00, uint32_t(t &= 0xFF00)); + CHECK_EQUAL(i &= 0xFF00, uint32_t(t &= type_t(0xFF00))); + CHECK_EQUAL(i |= 0x003D, uint32_t(t |= 0x003D)); + CHECK_EQUAL(i |= 0x003D, uint32_t(t |= type_t(0x003D))); + CHECK_EQUAL(i ^= 0xAA55, uint32_t(t ^= 0xAA55)); + CHECK_EQUAL(i ^= 0xAA55, uint32_t(t ^= type_t(0xAA55))); + CHECK_EQUAL(i <<= 2, uint32_t(t <<= 2)); + CHECK_EQUAL(i >>= 2, uint32_t(t >>= 2)); + CHECK_EQUAL(i %= 23, uint32_t(t %= 23)); t = type_t(0x1234); - CHECK_EQUAL(0x1234U, t); + CHECK_EQUAL(0x1234U, uint32_t(t)); } //========================================================================= diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 22ffa1ee..35a7f653 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -80,9 +80,9 @@ namespace typedef std::pair ElementDC; typedef std::pair ElementNDC; - typedef etl::unordered_map DataDC; - typedef etl::unordered_map DataNDC; - typedef etl::iunordered_map IDataNDC; + typedef etl::unordered_map DataDC; + typedef etl::unordered_map DataNDC; + typedef etl::iunordered_map IDataNDC; NDC N0 = NDC("A"); NDC N1 = NDC("B"); @@ -462,25 +462,29 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.find(K5); - DataNDC::iterator idata_end = data.find(K8); + DataNDC::iterator idata = data.begin(); + std::advance(idata, 2); - idata = data.erase(idata, idata_end); // Erase K5, K6, K7 + DataNDC::iterator idata_end = data.begin(); + std::advance(idata_end, 5); + data.erase(idata, idata_end); + CHECK_EQUAL(initial_data.size() - 3, data.size()); CHECK(!data.full()); CHECK(!data.empty()); - CHECK(idata == data.find(K8)); + idata = data.find(K8); + CHECK(idata != data.end()); idata = data.find(K0); CHECK(idata != data.end()); idata = data.find(K1); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(K2); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(K3); CHECK(idata != data.end()); @@ -489,13 +493,13 @@ namespace CHECK(idata != data.end()); idata = data.find(K5); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(K6); CHECK(idata == data.end()); idata = data.find(K7); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(K8); CHECK(idata != data.end()); @@ -631,13 +635,18 @@ namespace CHECK_CLOSE(0.0, data.load_factor(), 0.01); // Half the buckets used. - data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 2)); - CHECK_CLOSE(0.5, data.load_factor(), 0.01); + data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 4)); + CHECK_CLOSE(0.4, data.load_factor(), 0.01); // All of the buckets used. - data.clear(); data.assign(initial_data.begin(), initial_data.end()); - CHECK_CLOSE(1.0, data.load_factor(), 0.01); + CHECK_CLOSE(2.0, data.load_factor(), 0.01); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_release) + { + } }; } diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 97d570c9..57f8fb22 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -80,9 +80,9 @@ namespace typedef std::pair ElementDC; typedef std::pair ElementNDC; - typedef etl::unordered_multimap DataDC; - typedef etl::unordered_multimap DataNDC; - typedef etl::iunordered_multimap IDataNDC; + typedef etl::unordered_multimap DataDC; + typedef etl::unordered_multimap DataNDC; + typedef etl::iunordered_multimap IDataNDC; NDC N0 = NDC("A"); NDC N1 = NDC("B"); @@ -407,25 +407,29 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.find(K5); - DataNDC::iterator idata_end = data.find(K8); + DataNDC::iterator idata = data.begin(); + std::advance(idata, 2); - idata = data.erase(idata, idata_end); // Erase K5, K6, K7 + DataNDC::iterator idata_end = data.begin(); + std::advance(idata_end, 5); + + data.erase(idata, idata_end); CHECK_EQUAL(initial_data.size() - 3, data.size()); CHECK(!data.full()); CHECK(!data.empty()); - CHECK(idata == data.find(K8)); + idata = data.find(K8); + CHECK(idata != data.end()); idata = data.find(K0); CHECK(idata != data.end()); idata = data.find(K1); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(K2); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(K3); CHECK(idata != data.end()); @@ -434,13 +438,13 @@ namespace CHECK(idata != data.end()); idata = data.find(K5); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(K6); CHECK(idata == data.end()); idata = data.find(K7); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(K8); CHECK(idata != data.end()); @@ -589,13 +593,13 @@ namespace CHECK_CLOSE(0.0, data.load_factor(), 0.01); // Half the buckets used. - data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 2)); - CHECK_CLOSE(0.5, data.load_factor(), 0.01); + data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 4)); + CHECK_CLOSE(0.4, data.load_factor(), 0.01); // All of the buckets used. data.clear(); data.assign(initial_data.begin(), initial_data.end()); - CHECK_CLOSE(1.0, data.load_factor(), 0.01); + CHECK_CLOSE(2.0, data.load_factor(), 0.01); } }; } diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index c39a06df..f7c62051 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -59,8 +59,8 @@ namespace } }; - typedef etl::unordered_multiset DataDC; - typedef etl::unordered_multiset DataNDC; + typedef etl::unordered_multiset DataDC; + typedef etl::unordered_multiset DataNDC; typedef etl::iunordered_multiset IDataNDC; NDC N0 = NDC("FF"); @@ -332,31 +332,29 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.find(N5); - DataNDC::iterator idata_end = data.find(N8); + DataNDC::iterator idata = data.begin(); + std::advance(idata, 2); - std::vector test; + DataNDC::iterator idata_end = data.begin(); + std::advance(idata_end, 5); - test.assign(data.begin(), data.end()); - - idata = data.erase(idata, idata_end); // Erase N5, N6, N7 + data.erase(idata, idata_end); CHECK_EQUAL(initial_data.size() - 3, data.size()); CHECK(!data.full()); CHECK(!data.empty()); - CHECK(idata == data.find(N8)); - - test.assign(data.begin(), data.end()); + idata = data.find(N8); + CHECK(idata != data.end()); idata = data.find(N0); CHECK(idata != data.end()); idata = data.find(N1); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(N2); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(N3); CHECK(idata != data.end()); @@ -365,13 +363,13 @@ namespace CHECK(idata != data.end()); idata = data.find(N5); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(N6); CHECK(idata == data.end()); idata = data.find(N7); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(N8); CHECK(idata != data.end()); @@ -519,13 +517,13 @@ namespace CHECK_CLOSE(0.0, data.load_factor(), 0.01); // Half the buckets used. - data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 2)); - CHECK_CLOSE(0.5, data.load_factor(), 0.01); + data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 4)); + CHECK_CLOSE(0.4, data.load_factor(), 0.01); // All of the buckets used. data.clear(); data.assign(initial_data.begin(), initial_data.end()); - CHECK_CLOSE(1.0, data.load_factor(), 0.01); + CHECK_CLOSE(2.0, data.load_factor(), 0.01); } }; } diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index ac152d8f..44af7202 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -58,9 +58,9 @@ namespace } }; - typedef etl::unordered_set DataDC; - typedef etl::unordered_set DataNDC; - typedef etl::iunordered_set IDataNDC; + typedef etl::unordered_set DataDC; + typedef etl::unordered_set DataNDC; + typedef etl::iunordered_set IDataNDC; NDC N0 = NDC("FF"); NDC N1 = NDC("FG"); @@ -312,31 +312,29 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.find(N5); - DataNDC::iterator idata_end = data.find(N8); + DataNDC::iterator idata = data.begin(); + std::advance(idata, 2); - std::vector test; + DataNDC::iterator idata_end = data.begin(); + std::advance(idata_end, 5); - test.assign(data.begin(), data.end()); - - idata = data.erase(idata, idata_end); // Erase N5, N6, N7 + data.erase(idata, idata_end); CHECK_EQUAL(initial_data.size() - 3, data.size()); CHECK(!data.full()); CHECK(!data.empty()); - CHECK(idata == data.find(N8)); - - test.assign(data.begin(), data.end()); + idata = data.find(N8); + CHECK(idata != data.end()); idata = data.find(N0); CHECK(idata != data.end()); idata = data.find(N1); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(N2); - CHECK(idata != data.end()); + CHECK(idata == data.end()); idata = data.find(N3); CHECK(idata != data.end()); @@ -345,13 +343,13 @@ namespace CHECK(idata != data.end()); idata = data.find(N5); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(N6); CHECK(idata == data.end()); idata = data.find(N7); - CHECK(idata == data.end()); + CHECK(idata != data.end()); idata = data.find(N8); CHECK(idata != data.end()); @@ -434,13 +432,13 @@ namespace CHECK_CLOSE(0.0, data.load_factor(), 0.01); // Half the buckets used. - data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 2)); - CHECK_CLOSE(0.5, data.load_factor(), 0.01); + data.assign(initial_data.begin(), initial_data.begin() + (initial_data.size() / 4)); + CHECK_CLOSE(0.4, data.load_factor(), 0.01); // All of the buckets used. data.clear(); data.assign(initial_data.begin(), initial_data.end()); - CHECK_CLOSE(1.0, data.load_factor(), 0.01); + CHECK_CLOSE(2.0, data.load_factor(), 0.01); } }; } diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 82f04346..51f1b62c 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -668,6 +668,8 @@ namespace Compare_Data compare_data; Data data; + data.resize(SIZE, -1); + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); data.insert(data.begin() + offset, insert_data.begin(), insert_data.end()); @@ -933,17 +935,5 @@ namespace const Data initial2(initial_data.begin(), initial_data.end()); CHECK((initial >= initial2) == (initial_data >= initial_data)); } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_allocated_size) - { - const size_t INITIAL_SIZE = 5; - - Data data(INITIAL_SIZE); - - size_t expected_size = (SIZE * sizeof(int)) + (2 * sizeof(size_t)) + sizeof(int*); - - CHECK_EQUAL(expected_size, sizeof(Data)); - } }; } diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index 2c337e60..1eb13af3 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -933,17 +933,5 @@ namespace const Data initial2(initial_data.begin(), initial_data.end()); CHECK((initial >= initial2) == (initial_data >= initial_data)); } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_allocated_size) - { - const size_t INITIAL_SIZE = 5; - - Data data(INITIAL_SIZE); - - size_t expected_size = (SIZE * sizeof(int)) + (2 * sizeof(size_t)) + sizeof(int*); - - CHECK_EQUAL(expected_size, sizeof(Data)); - } }; } From 73e65ae0232ce6facded67432088e4f74ccd18e6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:07:21 +0000 Subject: [PATCH 118/168] Updated containers to use the new pool memory manager. --- src/binary.h | 26 ++- src/deque.h | 8 + src/forward_list.h | 12 +- src/ideque.h | 23 +- src/iflat_map.h | 4 +- src/iflat_multimap.h | 12 +- src/iforward_list.h | 151 ++++++------- src/ilist.h | 106 ++++----- src/imap.h | 28 ++- src/imultimap.h | 23 +- src/imultiset.h | 23 +- src/ipool.h | 334 +++++++++++++++------------ src/iqueue.h | 8 +- src/iset.h | 23 +- src/istack.h | 8 +- src/iunordered_map.h | 319 ++++++++++++++------------ src/iunordered_multimap.h | 300 ++++++++++++------------ src/iunordered_multiset.h | 296 ++++++++++++------------ src/iunordered_set.h | 298 ++++++++++++------------ src/ivector.h | 388 +++++++++++++++++++------------- src/list.h | 8 + src/map.h | 10 +- src/multimap.h | 10 +- src/multiset.h | 10 +- src/pool.h | 25 +- src/private/deque_base.h | 8 +- src/private/forward_list_base.h | 50 ++-- src/private/list_base.h | 70 +++--- src/private/map_base.h | 7 + src/private/multimap_base.h | 2 + src/private/multiset_base.h | 2 + src/private/pool_base.h | 49 +--- src/private/queue_base.h | 10 +- src/private/set_base.h | 2 + src/private/stack_base.h | 8 +- src/private/vector_base.h | 6 +- src/set.h | 10 +- src/unordered_map.h | 25 +- src/unordered_multimap.h | 21 +- src/unordered_multiset.h | 20 +- src/unordered_set.h | 21 +- 41 files changed, 1525 insertions(+), 1239 deletions(-) diff --git a/src/binary.h b/src/binary.h index 9ca9cfce..f6558c1c 100644 --- a/src/binary.h +++ b/src/binary.h @@ -396,14 +396,10 @@ namespace etl count_bits(T value) { uint32_t count; - static const int S[] = { 1, 2, 4, 8, 16 }; - static const uint32_t B[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF }; - 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]; + value = value - ((value >> 1) & 0x55555555); + value = (value & 0x33333333) + ((value >> 2) & 0x33333333); + count = ((value + (value >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; return count; } @@ -569,7 +565,9 @@ namespace etl /// Count trailing zeros. bit. /// Uses a binary search. //*************************************************************************** - uint_least8_t count_trailing_zeros(uint8_t value) + template + typename etl::enable_if::type, uint8_t>::value, uint_least8_t>::type + count_trailing_zeros(T value) { uint_least8_t count; @@ -604,7 +602,9 @@ namespace etl /// Count trailing zeros. 16bit. /// Uses a binary search. //*************************************************************************** - uint_least8_t count_trailing_zeros(uint16_t value) + template + typename etl::enable_if::type, uint16_t>::value, uint_least8_t>::type + count_trailing_zeros(T value) { uint_least8_t count; @@ -644,7 +644,9 @@ namespace etl /// Count trailing zeros. 32bit. /// Uses a binary search. //*************************************************************************** - uint_least8_t count_trailing_zeros(uint32_t value) + template + typename etl::enable_if::type, uint32_t>::value, uint_least8_t>::type + count_trailing_zeros(T value) { uint_least8_t count; @@ -690,7 +692,9 @@ namespace etl /// Count trailing zeros. 64bit. /// Uses a binary search. //*************************************************************************** - uint_least8_t count_trailing_zeros(uint64_t value) + template + typename etl::enable_if::type, uint64_t>::value, uint_least8_t>::type + count_trailing_zeros(T value) { uint_least8_t count; diff --git a/src/deque.h b/src/deque.h index 08db51d5..540de43c 100644 --- a/src/deque.h +++ b/src/deque.h @@ -86,6 +86,14 @@ namespace etl ideque::initialise(); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~deque() + { + ideque::initialise(); + } + //************************************************************************* /// Copy constructor. //************************************************************************* diff --git a/src/forward_list.h b/src/forward_list.h index 8ca61191..054a1982 100644 --- a/src/forward_list.h +++ b/src/forward_list.h @@ -89,7 +89,7 @@ namespace etl forward_list(const forward_list& other) : iforward_list(node_pool, MAX_SIZE) { - iforward_list::assign(other.cbegin(), other.cend()); + iforward_list::assign(other.cbegin(), other.cend()); } //************************************************************************* @@ -102,6 +102,14 @@ namespace etl iforward_list::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~forward_list() + { + iforward_list::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -118,7 +126,7 @@ namespace etl private: /// The pool of nodes used in the list. - etl::pool::Data_Node, MAX_SIZE> node_pool; + etl::pool::data_node_t, MAX_SIZE> node_pool; }; } diff --git a/src/ideque.h b/src/ideque.h index 9afcc3bb..51f5d8bd 100644 --- a/src/ideque.h +++ b/src/ideque.h @@ -1251,13 +1251,10 @@ namespace etl //********************************************************************* void create_element_front() { - if (!empty()) - { - --_begin; - } - - new(&(*_begin)) T(); + --_begin; + new (&(*_begin)) T(); ++current_size; + ++construct_count; } //********************************************************************* @@ -1286,9 +1283,10 @@ namespace etl do { - new(&(*item++)) T(*from); + new (&(*item++)) T(*from); ++from; ++current_size; + ++construct_count; } while (n-- != 0); } @@ -1297,9 +1295,10 @@ namespace etl //********************************************************************* void create_element_back() { - new(&(*_end)) T(); + new (&(*_end)) T(); ++_end; ++current_size; + ++construct_count; } //********************************************************************* @@ -1308,8 +1307,9 @@ namespace etl void create_element_front(parameter_t value) { --_begin; - new(&(*_begin)) T(value); + new (&(*_begin)) T(value); ++current_size; + ++construct_count; } //********************************************************************* @@ -1317,9 +1317,10 @@ namespace etl //********************************************************************* void create_element_back(parameter_t value) { - new(&(*_end)) T(value); + new (&(*_end)) T(value); ++_end; ++current_size; + ++construct_count; } //********************************************************************* @@ -1329,6 +1330,7 @@ namespace etl { (*_begin).~T(); --current_size; + --construct_count; ++_begin; } @@ -1340,6 +1342,7 @@ namespace etl --_end; (*_end).~T(); --current_size; + --construct_count; } //************************************************************************* diff --git a/src/iflat_map.h b/src/iflat_map.h index 1e50ea1c..7ffbcee4 100644 --- a/src/iflat_map.h +++ b/src/iflat_map.h @@ -164,7 +164,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return buffer.rbegin(); } //********************************************************************* @@ -224,7 +224,7 @@ namespace etl if (i_element == end()) { // Doesn't exist, so create a new one. - value_type value(key, mapped_type()); + value_type value(key, mapped_type()); i_element = insert(value).first; } diff --git a/src/iflat_multimap.h b/src/iflat_multimap.h index ed4e75ed..31063127 100644 --- a/src/iflat_multimap.h +++ b/src/iflat_multimap.h @@ -164,7 +164,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return buffer.rbegin(); } //********************************************************************* @@ -300,7 +300,7 @@ namespace etl //********************************************************************* size_t erase(key_value_parameter_t key) { - std::pair range = equal_range(key); + std::pair range = equal_range(key); if (range.first == end()) { @@ -308,8 +308,8 @@ namespace etl } else { - size_t count = std::distance(range.first, range.second); - erase(range.first, range.second); + size_t count = std::distance(range.first, range.second); + erase(range.first, range.second); return count; } } @@ -398,9 +398,9 @@ namespace etl //********************************************************************* size_t count(key_value_parameter_t key) const { - std::pair range = equal_range(key); + std::pair range = equal_range(key); - return std::distance(range.first, range.second); + return std::distance(range.first, range.second); } //********************************************************************* diff --git a/src/iforward_list.h b/src/iforward_list.h index c2d2b275..1506dde2 100644 --- a/src/iforward_list.h +++ b/src/iforward_list.h @@ -74,9 +74,9 @@ namespace etl //************************************************************************* /// The data node element in the forward_list. //************************************************************************* - struct Data_Node : public Node + struct data_node_t : public node_t { - explicit Data_Node(parameter_t value) + explicit data_node_t(parameter_t value) : value(value) {} @@ -99,7 +99,7 @@ namespace etl { } - iterator(Node& node) + iterator(node_t& node) : p_node(&node) { } @@ -170,7 +170,7 @@ namespace etl private: - Node* p_node; + node_t* p_node; }; //************************************************************************* @@ -187,12 +187,12 @@ namespace etl { } - const_iterator(Node& node) + const_iterator(node_t& node) : p_node(&node) { } - const_iterator(const Node& node) + const_iterator(const node_t& node) : p_node(&node) { } @@ -253,7 +253,7 @@ namespace etl private: - const Node* p_node; + const node_t* p_node; }; typedef typename std::iterator_traits::difference_type difference_type; @@ -279,7 +279,7 @@ namespace etl //************************************************************************* iterator before_begin() { - return iterator(static_cast(start_node)); + return iterator(static_cast(start_node)); } //************************************************************************* @@ -287,7 +287,7 @@ namespace etl //************************************************************************* const_iterator before_begin() const { - return const_iterator(static_cast(start_node)); + return const_iterator(static_cast(start_node)); } //************************************************************************* @@ -361,18 +361,17 @@ namespace etl initialise(); - Node* p_last_node = &start_node; + node_t* p_last_node = &start_node; // Add all of the elements. while (first != last) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_iterator)); - Data_Node& data_node = allocate_data_node(*first++); + data_node_t& data_node = allocate_data_node(*first++); join(p_last_node, &data_node); data_node.next = nullptr; p_last_node = &data_node; - ++current_size; } } @@ -385,16 +384,15 @@ namespace etl initialise(); - Node* p_last_node = &start_node; - + node_t* p_last_node = &start_node; + // Add all of the elements. - while (current_size < n) + while (size() < n) { - Data_Node& data_node = allocate_data_node(value); + data_node_t& data_node = allocate_data_node(value); join(p_last_node, &data_node); data_node.next = nullptr; p_last_node = &data_node; - ++current_size; } } @@ -403,11 +401,7 @@ namespace etl //************************************************************************* void push_front() { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); -#endif - Data_Node& data_node = allocate_data_node(T()); - insert_node_after(start_node, data_node); + push_front(T()); } //************************************************************************* @@ -418,7 +412,8 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); #endif - Data_Node& data_node = allocate_data_node(value); + + data_node_t& data_node = allocate_data_node(value); insert_node_after(start_node, data_node); } @@ -485,7 +480,7 @@ namespace etl { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); - Data_Node& data_node = allocate_data_node(value); + data_node_t& data_node = allocate_data_node(value); insert_node_after(*position.p_node, data_node); return iterator(data_node); @@ -501,7 +496,7 @@ namespace etl for (size_t i = 0; !full() && (i < n); ++i) { // Set up the next free node. - Data_Node& data_node = allocate_data_node(value); + data_node_t& data_node = allocate_data_node(value); insert_node_after(*position.p_node, data_node); } } @@ -514,13 +509,13 @@ namespace etl { #if defined(_DEBUG) || defined(DEBUG) difference_type count = std::distance(first, last); - ETL_ASSERT((count + current_size) <= MAX_SIZE, ETL_ERROR(forward_list_full)); + ETL_ASSERT((count + size()) <= MAX_SIZE, ETL_ERROR(forward_list_full)); #endif while (first != last) { // Set up the next free node. - Data_Node& data_node = allocate_data_node(*first++); + data_node_t& data_node = allocate_data_node(*first++); insert_node_after(*position.p_node, data_node); ++position; } @@ -552,9 +547,9 @@ namespace etl { if (first != end() && (first != last)) { - Node* p_first = first.p_node; - Node* p_last = last.p_node; - Node* p_next = p_first->next; + node_t* p_first = first.p_node; + node_t* p_last = last.p_node; + node_t* p_next = p_first->next; // Join the ends. join(p_first, p_last); @@ -564,11 +559,8 @@ namespace etl // Erase the ones in between. while (p_first != p_last) { - // One less. - --current_size; - p_next = p_first->next; // Remember the next node. - destroy_data_node(static_cast(*p_first)); // Destroy the pool object. + destroy_data_node(static_cast(*p_first)); // Destroy the pool object. p_first = p_next; // Move to the next node. } @@ -597,10 +589,10 @@ namespace etl return; } - Node* p_from_before = const_cast(from_before.p_node); // We're not changing the value, just it's position. - Node* p_to_before = const_cast(to_before.p_node); // We're not changing the value, just it's position. + node_t* p_from_before = const_cast(from_before.p_node); // We're not changing the value, just it's position. + node_t* p_to_before = const_cast(to_before.p_node); // We're not changing the value, just it's position. - Node* p_from = p_from_before->next; + node_t* p_from = p_from_before->next; // Disconnect from the list. join(p_from_before, p_from->next); @@ -629,11 +621,11 @@ namespace etl } #endif - Node* p_first_before = const_cast(first_before.p_node); // We're not changing the value, just it's position. - Node* p_last = const_cast(last.p_node); // We're not changing the value, just it's position. - Node* p_to_before = const_cast(to_before.p_node); // We're not changing the value, just it's position. - Node* p_first = p_first_before->next; - Node* p_final = p_first_before; + node_t* p_first_before = const_cast(first_before.p_node); // We're not changing the value, just it's position. + node_t* p_last = const_cast(last.p_node); // We're not changing the value, just it's position. + node_t* p_to_before = const_cast(to_before.p_node); // We're not changing the value, just it's position. + node_t* p_first = p_first_before->next; + node_t* p_final = p_first_before; // Find the last node that will be moved. while (p_final->next != p_last) @@ -670,8 +662,8 @@ namespace etl return; } - Node* last = &get_head(); - Node* current = last->next; + node_t* last = &get_head(); + node_t* current = last->next; while (current != nullptr) { @@ -879,9 +871,8 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - iforward_list(etl::ipool& node_pool, size_t max_size_) - : forward_list_base(max_size_), - p_node_pool(&node_pool) + iforward_list(etl::ipool& node_pool, size_t max_size_) + : forward_list_base(node_pool, max_size_) { } @@ -892,57 +883,62 @@ namespace etl { if (!empty()) { - p_node_pool->release_all(); + node_t* p_first = start_node.next; + node_t* p_next; + + // Erase the ones in between. + while (p_first != nullptr) + { + p_next = p_first->next; // Remember the next node. + destroy_data_node(static_cast(*p_first)); // Destroy the pool object. + p_first = p_next; // Move to the next node. + } } - current_size = 0; start_node.next = nullptr; } private: - /// The pool of data nodes used in the list. - etl::ipool* p_node_pool; - //************************************************************************* - /// Downcast a Node* to a Data_Node* + /// Downcast a node_t* to a data_node_t* //************************************************************************* - static Data_Node* data_cast(Node* p_node) + static data_node_t* data_cast(node_t* p_node) { - return static_cast(p_node); + return static_cast(p_node); } //************************************************************************* - /// Downcast a Node& to a Data_Node& + /// Downcast a node_t& to a data_node_t& //************************************************************************* - static Data_Node& data_cast(Node& node) + static data_node_t& data_cast(node_t& node) { - return static_cast(node); + return static_cast(node); } //************************************************************************* - /// Downcast a const Node* to a const Data_Node* + /// Downcast a const node_t* to a const data_node_t* //************************************************************************* - static const Data_Node* data_cast(const Node* p_node) + static const data_node_t* data_cast(const node_t* p_node) { - return static_cast(p_node); + return static_cast(p_node); } //************************************************************************* - /// Downcast a const Node& to a const Data_Node& + /// Downcast a const node_t& to a const data_node_t& //************************************************************************* - static const Data_Node& data_cast(const Node& node) + static const data_node_t& data_cast(const node_t& node) { - return static_cast(node); + return static_cast(node); } //************************************************************************* /// Remove a node. //************************************************************************* - void remove_node_after(Node& node) + void remove_node_after(node_t& node) { // The node to erase. - Node* p_node = node.next; + node_t* p_node = node.next; if (p_node != nullptr) { @@ -950,27 +946,30 @@ namespace etl join(&node, p_node->next); // Destroy the pool object. - destroy_data_node(static_cast(*p_node)); - - // One less. - --current_size; + destroy_data_node(static_cast(*p_node)); } } //************************************************************************* - /// Allocate a Data_Node. + /// Allocate a data_node_t. //************************************************************************* - Data_Node& allocate_data_node(parameter_t value) const + data_node_t& allocate_data_node(parameter_t value) { - return *(p_node_pool->allocate(Data_Node(value))); + data_node_t* p_node = p_node_pool->allocate(); + new (&(p_node->value)) T(value); + ++construct_count; + + return *p_node; } //************************************************************************* - /// Destroy a Data_Node. + /// Destroy a data_node_t. //************************************************************************* - void destroy_data_node(Data_Node& node) const + void destroy_data_node(data_node_t& node) { - p_node_pool->release(node); + node.value.~T(); + p_node_pool->release(&node); + --construct_count; } // Disable copy construction. diff --git a/src/ilist.h b/src/ilist.h index 514ffc7a..3dc1a23b 100644 --- a/src/ilist.h +++ b/src/ilist.h @@ -41,8 +41,8 @@ SOFTWARE. #include "private/list_base.h" #include "type_traits.h" #include "parameter_type.h" -#include "pool.h" #include "platform.h" +#include "algorithm.h" #ifdef ETL_COMPILER_MICROSOFT #undef min @@ -85,15 +85,12 @@ namespace etl private: - /// The pool of data nodes used in the list. - etl::ipool* p_node_pool; - //************************************************************************* /// Downcast a node_t* to a data_node_t* //************************************************************************* static data_node_t* data_cast(node_t* p_node) { - return static_cast(p_node); + return reinterpret_cast(p_node); } //************************************************************************* @@ -101,7 +98,7 @@ namespace etl //************************************************************************* static data_node_t& data_cast(node_t& node) { - return static_cast(node); + return reinterpret_cast(node); } //************************************************************************* @@ -109,7 +106,7 @@ namespace etl //************************************************************************* static const data_node_t* data_cast(const node_t* p_node) { - return static_cast(p_node); + return reinterpret_cast(p_node); } //************************************************************************* @@ -117,7 +114,7 @@ namespace etl //************************************************************************* static const data_node_t& data_cast(const node_t& node) { - return static_cast(node); + return reinterpret_cast(node); } public: @@ -462,11 +459,10 @@ namespace etl // Add all of the elements. while (first != last) { - data_node_t& data_node = allocate_data_node(*first); - join(get_tail(), data_node); - join(data_node, terminal_node); + data_node_t& node = allocate_data_node(*first); + join(get_tail(), node); + join(node, terminal_node); ++first; - ++current_size; } } @@ -482,12 +478,11 @@ namespace etl initialise(); // Add all of the elements. - while (current_size < n) + while (size() < n) { - data_node_t& data_node = allocate_data_node(value); - join(*terminal_node.previous, data_node); - join(data_node, terminal_node); - ++current_size; + data_node_t& node = allocate_data_node(value); + join(*terminal_node.previous, node); + join(node, terminal_node); } } @@ -496,11 +491,7 @@ namespace etl //************************************************************************* void push_front() { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(!full(), ETL_ERROR(list_full)); -#endif - data_node_t& data_node = allocate_data_node(T()); - insert_node(get_head(), data_node); + push_front(T()); } //************************************************************************* @@ -511,8 +502,7 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); #endif - node_t& data_node = allocate_data_node(value); - insert_node(get_head(), data_node); + insert_node(get_head(), allocate_data_node(value)); } //************************************************************************* @@ -532,11 +522,7 @@ namespace etl //************************************************************************* void push_back() { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(!full(), ETL_ERROR(list_full)); -#endif - data_node_t& data_node = allocate_data_node(T()); - insert_node(terminal_node, data_node); + push_back(T()); } //************************************************************************* @@ -547,8 +533,7 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); #endif - data_node_t& data_node = allocate_data_node(value); - insert_node(terminal_node, data_node); + insert_node(terminal_node, allocate_data_node(value)); } //************************************************************************* @@ -586,8 +571,7 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(list_full)); // Set up the next free node and insert. - data_node_t& data_node = allocate_data_node(value); - insert_node(*position.p_node, data_node); + insert_node(*position.p_node, allocate_data_node(value)); } } @@ -602,8 +586,7 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(list_full)); // Set up the next free node and insert. - data_node_t& data_node = allocate_data_node(*first++); - insert_node(*position.p_node, data_node); + insert_node(*position.p_node, allocate_data_node(*first++)); } } @@ -612,12 +595,9 @@ namespace etl //************************************************************************* iterator erase(iterator position) { - iterator next(position); - ++next; - - remove_node(*position.p_node); - - return next; + ++position; + remove_node(*position.p_node->previous); + return position; } //************************************************************************* @@ -635,12 +615,9 @@ namespace etl // Erase the ones in between. while (p_first != p_last) { - // One less. - --current_size; - - p_next = p_first->next; // Remember the next node. + p_next = p_first->next; // Remember the next node. destroy_data_node(static_cast(*p_first)); // Destroy the current node. - p_first = p_next; // Move to the next node. + p_first = p_next; // Move to the next node. } return last; @@ -846,6 +823,9 @@ namespace etl ++this_begin; } + bool t = this_begin != this_end; + bool o = other_begin != other_end; + // Insert. if (this_begin != this_end) { @@ -853,6 +833,8 @@ namespace etl { insert(this_begin, *other_begin); ++other_begin; + + o = other_begin != other_end; } } } @@ -1001,15 +983,14 @@ namespace etl return *this; } - + protected: //************************************************************************* /// Constructor. //************************************************************************* - ilist(etl::ipool& node_pool, size_t max_size_) - : list_base(max_size_), - p_node_pool(&node_pool) + ilist(etl::ipool& node_pool, size_t max_size_) + : list_base(node_pool, max_size_) { } @@ -1020,10 +1001,16 @@ namespace etl { if (!empty()) { - p_node_pool->release_all(); + node_t* p_first = terminal_node.next; + node_t* p_last = &terminal_node; + + while (p_first != p_last) + { + destroy_data_node(static_cast(*p_first)); // Destroy the current node. + p_first = p_first->next; // Move to the next node. + } } - current_size = 0; join(terminal_node, terminal_node); } @@ -1093,25 +1080,28 @@ namespace etl // Destroy the pool object. destroy_data_node(static_cast(node)); - - // One less. - --current_size; } //************************************************************************* /// Allocate a data_node_t. //************************************************************************* - data_node_t& allocate_data_node(parameter_t value) const + data_node_t& allocate_data_node(parameter_t value) { - return *(p_node_pool->allocate(data_node_t(value))); + data_node_t* p_data_node = p_node_pool->allocate(); + new (&(p_data_node->value)) T(value); + ++construct_count; + + return *p_data_node; } //************************************************************************* /// Destroy a data_node_t. //************************************************************************* - void destroy_data_node(data_node_t& node) const + void destroy_data_node(data_node_t& node) { + node.value.~T(); p_node_pool->release(&node); + --construct_count; } // Disable copy construction. diff --git a/src/imap.h b/src/imap.h index ecf4ddbb..906518e3 100644 --- a/src/imap.h +++ b/src/imap.h @@ -103,6 +103,11 @@ namespace etl { } + ~Data_Node() + { + + } + value_type value; }; @@ -128,7 +133,7 @@ namespace etl private: /// The pool of data nodes used in the map. - ipool* p_node_pool; + ipool* p_node_pool; //************************************************************************* /// Downcast a Node* to a Data_Node* @@ -830,7 +835,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - imap(ipool& node_pool, size_t max_size_) + imap(ipool& node_pool, size_t max_size_) : map_base(max_size_) , p_node_pool(&node_pool) { @@ -841,13 +846,7 @@ namespace etl //************************************************************************* void initialise() { - if (!empty()) - { - p_node_pool->release_all(); - } - - current_size = 0; - root_node = nullptr; + erase(begin(), end()); } private: @@ -855,17 +854,22 @@ namespace etl //************************************************************************* /// Allocate a Data_Node. //************************************************************************* - Data_Node& allocate_data_node(value_type value) const + Data_Node& allocate_data_node(value_type value) { - return *(p_node_pool->allocate(Data_Node(value))); + Data_Node& node = *p_node_pool->allocate(); + new (&node.value) const value_type(value); + ++construct_count; + return node; } //************************************************************************* /// Destroy a Data_Node. //************************************************************************* - void destroy_data_node(Data_Node& node) const + void destroy_data_node(Data_Node& node) { + node.value.~value_type(); p_node_pool->release(&node); + --construct_count; } //************************************************************************* diff --git a/src/imultimap.h b/src/imultimap.h index 5291177c..385824f3 100644 --- a/src/imultimap.h +++ b/src/imultimap.h @@ -130,7 +130,7 @@ namespace etl private: /// The pool of data nodes used in the multimap. - ipool* p_node_pool; + ipool* p_node_pool; //************************************************************************* /// Downcast a Node* to a Data_Node* @@ -772,7 +772,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - imultimap(ipool& node_pool, size_t max_size_) + imultimap(ipool& node_pool, size_t max_size_) : multimap_base(max_size_) , p_node_pool(&node_pool) { @@ -783,13 +783,7 @@ namespace etl //************************************************************************* void initialise() { - if (!empty()) - { - p_node_pool->release_all(); - } - - current_size = 0; - root_node = nullptr; + erase(begin(), end()); } private: @@ -797,17 +791,22 @@ namespace etl //************************************************************************* /// Allocate a Data_Node. //************************************************************************* - Data_Node& allocate_data_node(value_type value) const + Data_Node& allocate_data_node(value_type value) { - return *(p_node_pool->allocate(Data_Node(value))); + Data_Node& node = *p_node_pool->allocate(); + new (&node.value) const value_type(value); + ++construct_count; + return node; } //************************************************************************* /// Destroy a Data_Node. //************************************************************************* - void destroy_data_node(Data_Node& node) const + void destroy_data_node(Data_Node& node) { + node.value.~value_type(); p_node_pool->release(&node); + --construct_count; } //************************************************************************* diff --git a/src/imultiset.h b/src/imultiset.h index c0c96840..5c81053b 100644 --- a/src/imultiset.h +++ b/src/imultiset.h @@ -126,7 +126,7 @@ namespace etl private: /// The pool of data nodes used in the multiset. - ipool* p_node_pool; + ipool* p_node_pool; //************************************************************************* /// Downcast a Node* to a Data_Node* @@ -753,7 +753,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - imultiset(ipool& node_pool, size_t max_size_) + imultiset(ipool& node_pool, size_t max_size_) : multiset_base(max_size_) , p_node_pool(&node_pool) { @@ -764,13 +764,7 @@ namespace etl //************************************************************************* void initialise() { - if (!empty()) - { - p_node_pool->release_all(); - } - - current_size = 0; - root_node = nullptr; + erase(begin(), end()); } private: @@ -778,17 +772,22 @@ namespace etl //************************************************************************* /// Allocate a Data_Node. //************************************************************************* - Data_Node& allocate_data_node(value_type value) const + Data_Node& allocate_data_node(value_type value) { - return *(p_node_pool->allocate(Data_Node(value))); + Data_Node& node = *p_node_pool->allocate(); + new ((void*)&node.value) value_type(value); + ++construct_count; + return node; } //************************************************************************* /// Destroy a Data_Node. //************************************************************************* - void destroy_data_node(Data_Node& node) const + void destroy_data_node(Data_Node& node) { + node.value.~value_type(); p_node_pool->release(&node); + --construct_count; } //************************************************************************* diff --git a/src/ipool.h b/src/ipool.h index 7f30650b..f7ec3d3d 100644 --- a/src/ipool.h +++ b/src/ipool.h @@ -28,46 +28,70 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -//***************************************************************************** -// The algorithm for this implementation is based on this paper. -// -// Fast Efficient Fixed-Size Memory Pool -// https://www.thinkmind.org/index.php?view=article&articleid=computation_tools_2012_1_10_80006 -// -// Ben Kenwright -// School of Computer Science -// Newcastle University -// Newcastle, United Kingdom, -// b.kenwright@ncl.ac.uk -//***************************************************************************** - #ifndef __ETL_IPOOL__ #define __ETL_IPOOL__ #define __ETL_IN_IPOOL_H__ #include -#include "private/pool_base.h" #include "nullptr.h" -//#include "ibitset.h" +#include "alignment.h" #include "error_handler.h" +#include + +#undef ETL_FILE +#define ETL_FILE "11" + namespace etl { //*************************************************************************** + /// The base class for pool exceptions. ///\ingroup pool //*************************************************************************** - template - class ipool : public pool_base + class pool_exception : public exception { 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; + pool_exception(string_type what, string_type file_name, numeric_type line_number) + : exception(what, file_name, line_number) + {} + }; + + //*************************************************************************** + /// The exception thrown when the pool has no more free items. + ///\ingroup pool + //*************************************************************************** + class pool_no_allocation : public pool_exception + { + public: + + explicit pool_no_allocation(string_type file_name, numeric_type line_number) + : pool_exception(ETL_ERROR_TEXT("pool:allocation", ETL_FILE"A"), file_name, line_number) + {} + }; + + //*************************************************************************** + /// The exception thrown when an object is released which does not belong to the pool. + ///\ingroup pool + //*************************************************************************** + class pool_object_not_in_pool : public pool_exception + { + public: + + pool_object_not_in_pool(string_type file_name, numeric_type line_number) + : pool_exception(ETL_ERROR_TEXT("pool:notinpool", ETL_FILE"B"), file_name, line_number) + {} + }; + + //*************************************************************************** + ///\ingroup pool + //*************************************************************************** + class ipool + { + public: + + typedef size_t size_type; //************************************************************************* /// Allocate an object from the pool. @@ -75,39 +99,10 @@ namespace etl /// 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* allocate() { - return allocate(T()); - } - - //************************************************************************* - /// Allocate an object from the pool from an initial value. - /// 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. - //************************************************************************* - T* allocate(const T& initial) - { - ETL_ASSERT(items_allocated < MAX_SIZE, ETL_ERROR(pool_no_allocation)); - - T* p_value = nullptr; - - if (available() > 0) - { - p_value = new(&p_next->value) T(initial); - p_next->index = -p_next->index; - ++items_allocated; - - if (available() != 0) - { - p_next = AddressFromIndex(p_next->index); - } - else - { - p_next = nullptr; - } - } - - return p_value; + return reinterpret_cast(allocate_item()); } //************************************************************************* @@ -116,58 +111,18 @@ namespace etl /// pool then an etl::pool_object_not_in_pool is thrown. /// \param p_object A pointer to the object to be released. //************************************************************************* - void release(const T& object) + void release(const void* p_object) { - release(&object); + release_item((char*)p_object); } //************************************************************************* - /// Release an object in the pool. - /// If asserts or exceptions are enabled and the object does not belong to this - /// pool then an etl::pool_object_not_in_pool is thrown. - /// \param p_object A pointer to the object to be released. - //************************************************************************* - void release(const T* const p_object) - { - // Does it belong to me? - ETL_ASSERT(is_in_pool(p_object), ETL_ERROR(pool_object_not_in_pool)); - - // Get the pointer to the element by adjusting for the index. - uintptr_t p = (uintptr_t)p_object - offsetof(Element, value); - - Element* p_element = reinterpret_cast(p); - - if (p_next != nullptr) - { - p_element->index = -IndexFromAddress(p_next); - } - else - { - p_element->index = -TIndex(MAX_SIZE); - } - - p_object->~T(); - - p_next = p_element; - --items_allocated; - } - - //************************************************************************* - /// Releases all objects in the pool. + /// Release all objects in the pool. //************************************************************************* void release_all() { - for (size_t i = 0; i < MAX_SIZE; ++i) - { - if (p_buffer[i].index > 0) - { - p_buffer[i].value.~T(); - } - - p_buffer[i].index = -int32_t(i + 1); - } - - items_allocated = 0; + items_allocated = 0; + items_initialised = 0; p_next = p_buffer; } @@ -176,82 +131,173 @@ namespace etl /// \param p_object A pointer to the object to be checked. /// \return true<\b> if it does, otherwise false //************************************************************************* - bool is_in_pool(const T& object) const + //template + bool is_in_pool(const void* p_object) const { - return is_in_pool(&object); + return is_item_in_pool((const char*)p_object); } //************************************************************************* - /// Check to see if the object belongs to the pool. - /// \param p_object A pointer to the object to be checked. - /// \return true<\b> if it does, otherwise false + /// Returns the maximum number of items in the pool. //************************************************************************* - bool is_in_pool(const T* p_object) const + size_t max_items() const { - // Does this object belong to this pool? - // Get the pointer to the element by adjusting for the index. - uintptr_t p = (uintptr_t)p_object - sizeof(TIndex); + return MAX_ITEMS; + } - Element* p_element = reinterpret_cast(p); + //************************************************************************* + /// Returns the number of free items in the pool. + //************************************************************************* + size_t available() const + { + return MAX_ITEMS - items_allocated; + } - // Within the range of the buffer? - intptr_t distance = p_element - p_buffer; - return ((distance >= 0) && (distance < static_cast(MAX_SIZE))); + //************************************************************************* + /// Returns the number of allocated items in the pool. + //************************************************************************* + size_t size() const + { + return items_allocated; + } + + //************************************************************************* + /// Checks to see if there are no allocated items in the pool. + /// \return true if there are none allocated. + //************************************************************************* + bool empty() const + { + return items_allocated == 0; + } + + //************************************************************************* + /// Checks to see if there are no free items in the pool. + /// \return true if there are none free. + //************************************************************************* + bool full() const + { + return items_allocated == MAX_ITEMS; } protected: - - struct Element - { - TIndex index; - T value; - }; - + //************************************************************************* /// Constructor //************************************************************************* - ipool(Element* p_buffer, size_t size) - : pool_base(size), - p_buffer(p_buffer), - p_next(p_buffer) - + ipool(char* p_buffer_, uint32_t item_size, uint32_t max_items) + : p_buffer(p_buffer_), + p_next(p_buffer_), + items_allocated(0), + items_initialised(0), + ITEM_SIZE(item_size), + MAX_ITEMS(max_items) { - for (int32_t i = 0; i < MAX_SIZE; ++i) - { - p_buffer[i].index = -(i + 1); - } - } - - //************************************************************************* - /// Destructor - //************************************************************************* - ~ipool() - { - release_all(); } private: - Element* AddressFromIndex(TIndex i) const + //************************************************************************* + /// Allocate an item from the pool. + //************************************************************************* + char* allocate_item() { - i = (i < 0) ? -i : i; - return &p_buffer[i]; + char* p_value = nullptr; + + // Any free space left? + if (items_allocated < MAX_ITEMS) + { + // Initialise another one if necessary. + if (items_initialised < MAX_ITEMS) + { + uintptr_t p = reinterpret_cast(p_buffer + (items_initialised * ITEM_SIZE)); + *reinterpret_cast(p) = p + ITEM_SIZE; + ++items_initialised; + } + + // Get the address of new allocated item. + p_value = p_next; + + ++items_allocated; + if (items_allocated != MAX_ITEMS) + { + // Set up the pointer to the next free item + p_next = *reinterpret_cast(p_next); + } + else + { + // No more left! + p_next = nullptr; + } + } + else + { + ETL_ASSERT(false, ETL_ERROR(etl::pool_no_allocation)); + } + + return p_value; } - TIndex IndexFromAddress(const Element* p_element) const + //************************************************************************* + /// Release an item back to the pool. + //************************************************************************* + void release_item(char* p_value) { - return TIndex(p_element - p_buffer); + // Does it belong to us? + ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool)); + + if (p_next != nullptr) + { + // Point it to the current free item. + *(uintptr_t*)p_value = reinterpret_cast(p_next); + } + else + { + // This is the only free item. + *((uintptr_t*)p_value) = 0; + } + + p_next = p_value; + + --items_allocated; } - + + //************************************************************************* + /// Check if the item belongs to this pool. + //************************************************************************* + bool is_item_in_pool(const char* p) const + { + // Within the range of the buffer? + intptr_t distance = p - p_buffer; + bool is_within_range = (distance >= 0) && (distance <= intptr_t((ITEM_SIZE * MAX_ITEMS) - ITEM_SIZE)); + + // Modulus and division can be slow on some architectures, so only do this in debug. +#if defined(_DEBUG) || defined(DEBUG) + // Is the address on a valid object boundary? + bool is_valid_address = ((distance % ITEM_SIZE) == 0); +#else + bool is_valid_address = true; +#endif + + return is_within_range && is_valid_address; + } + // Disable copy construction and assignment. ipool(const ipool&); ipool& operator =(const ipool&); - Element* p_buffer; - Element* p_next; + char* p_buffer; + char* p_next; + + uint32_t items_allocated; ///< The number of items allocated. + uint32_t items_initialised; ///< The number of items initialised. + + const uint32_t ITEM_SIZE; ///< The size of allocated items. + const uint32_t MAX_ITEMS; ///< The maximum number of objects that can be allocated. }; } +#undef ETL_FILE + #undef __ETL_IN_IPOOL_H__ #endif diff --git a/src/iqueue.h b/src/iqueue.h index 0f55963c..56bb32b4 100644 --- a/src/iqueue.h +++ b/src/iqueue.h @@ -117,9 +117,10 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - new(&p_buffer[in]) T(value); + new (&p_buffer[in]) T(value); in = (in == (MAX_SIZE - 1)) ? 0 : in + 1; ++current_size; + ++construct_count; } //************************************************************************* @@ -137,9 +138,10 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - new(&p_buffer[in]) T(); + new (&p_buffer[in]) T(); in = (in == (MAX_SIZE - 1)) ? 0 : in + 1; ++current_size; + ++construct_count; return p_buffer[next]; } @@ -154,6 +156,7 @@ namespace etl p_buffer[out].~T(); out = (out == (MAX_SIZE - 1)) ? 0 : out + 1; --current_size; + --construct_count; } in = 0; @@ -172,6 +175,7 @@ namespace etl p_buffer[out].~T(); out = (out == (MAX_SIZE - 1)) ? 0 : out + 1; --current_size; + --construct_count; } //************************************************************************* diff --git a/src/iset.h b/src/iset.h index 83f495cb..5288c6be 100644 --- a/src/iset.h +++ b/src/iset.h @@ -126,7 +126,7 @@ namespace etl private: /// The pool of data nodes used in the set. - ipool* p_node_pool; + etl::ipool* p_node_pool; //************************************************************************* /// Downcast a Node* to a Data_Node* @@ -761,7 +761,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - iset(ipool& node_pool, size_t max_size_) + iset(ipool& node_pool, size_t max_size_) : set_base(max_size_) , p_node_pool(&node_pool) { @@ -772,13 +772,7 @@ namespace etl //************************************************************************* void initialise() { - if (!empty()) - { - p_node_pool->release_all(); - } - - current_size = 0; - root_node = nullptr; + erase(begin(), end()); } private: @@ -786,17 +780,22 @@ namespace etl //************************************************************************* /// Allocate a Data_Node. //************************************************************************* - Data_Node& allocate_data_node(value_type value) const + Data_Node& allocate_data_node(value_type value) { - return *(p_node_pool->allocate(Data_Node(value))); + Data_Node& node = *p_node_pool->allocate(); + new ((void*)&node.value) value_type(value); + ++construct_count; + return node; } //************************************************************************* /// Destroy a Data_Node. //************************************************************************* - void destroy_data_node(Data_Node& node) const + void destroy_data_node(Data_Node& node) { + node.value.~value_type(); p_node_pool->release(&node); + --construct_count; } //************************************************************************* diff --git a/src/istack.h b/src/istack.h index 35e8107c..ff961f59 100644 --- a/src/istack.h +++ b/src/istack.h @@ -90,7 +90,8 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif top_index = current_size++; - new(&p_buffer[top_index]) T(value); + new (&p_buffer[top_index]) T(value); + ++construct_count; } //************************************************************************* @@ -106,7 +107,8 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif top_index = current_size++; - new(&p_buffer[top_index]) T(); + new (&p_buffer[top_index]) T(); + ++construct_count; return p_buffer[top_index]; } @@ -130,6 +132,7 @@ namespace etl p_buffer[top_index].~T(); --top_index; --current_size; + --construct_count; } } @@ -145,6 +148,7 @@ namespace etl p_buffer[top_index].~T(); --top_index; --current_size; + --construct_count; } //************************************************************************* diff --git a/src/iunordered_map.h b/src/iunordered_map.h index bfd5ef6c..9f00fd3b 100644 --- a/src/iunordered_map.h +++ b/src/iunordered_map.h @@ -47,6 +47,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "exception.h" #include "error_handler.h" +#include "debug_count.h" #undef ETL_FILE #define ETL_FILE "16" @@ -149,10 +150,7 @@ namespace etl private: typedef etl::intrusive_forward_list bucket_t; - typedef etl::ipool pool_t; - typedef etl::ivector bucket_list_t; - - typedef typename bucket_list_t::iterator bucket_list_iterator; + typedef etl::ipool pool_t; public: @@ -185,8 +183,8 @@ namespace etl //********************************* iterator(const iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -197,19 +195,19 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -227,8 +225,8 @@ namespace etl //********************************* iterator operator =(const iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -284,9 +282,9 @@ namespace etl private: //********************************* - iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -300,13 +298,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t* get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -315,9 +313,9 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; - local_iterator inode; + bucket_t* pbuckets_end; + bucket_t* pbucket; + local_iterator inode; }; //********************************************************************* @@ -346,16 +344,16 @@ namespace etl //********************************* const_iterator(const typename iunordered_map::iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } //********************************* const_iterator(const const_iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -366,20 +364,19 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -397,8 +394,8 @@ namespace etl //********************************* const_iterator operator =(const const_iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -436,9 +433,9 @@ namespace etl private: //********************************* - const_iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + const_iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -452,13 +449,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t* get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -467,9 +464,9 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; - local_iterator inode; + bucket_t* pbuckets_end; + bucket_t* pbucket; + local_iterator inode; }; typedef typename std::iterator_traits::difference_type difference_type; @@ -480,7 +477,7 @@ namespace etl //********************************************************************* iterator begin() { - return iterator(pbuckets->end(), first, first->begin()); + return iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -489,7 +486,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -498,7 +495,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -534,7 +531,7 @@ namespace etl //********************************************************************* iterator end() { - return iterator(pbuckets->end(), last, last->end()); + return iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -543,7 +540,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -552,7 +549,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -588,7 +585,7 @@ namespace etl //********************************************************************* size_type bucket(key_value_parameter_t key) const { - return key_hash_function(key) % pbuckets->size(); + return key_hash_function(key) % number_of_buckets; } //********************************************************************* @@ -608,7 +605,7 @@ namespace etl //********************************************************************* size_type max_bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -617,7 +614,7 @@ namespace etl //********************************************************************* size_type bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -628,13 +625,13 @@ namespace etl mapped_type& operator [](key_value_parameter_t key) { // Find the bucket. - bucket_list_iterator ibucket = pbuckets->begin() + bucket(key); + bucket_t* pbucket = pbuckets + bucket(key); // Find the first node in the bucket. - local_iterator inode = ibucket->begin(); + local_iterator inode = pbucket->begin(); // Walk the list looking for the right one. - while (inode != ibucket->end()) + while (inode != pbucket->end()) { // Equal keys? if (key_equal_function(key, inode->key_value_pair.first)) @@ -650,10 +647,13 @@ namespace etl // Doesn't exist, so add a new one. // Get a new node. - node_t& node = *pnodepool->allocate(node_t(value_type(key, T()))); - ibucket->insert_after(ibucket->before_begin(), node); + node_t& node = *pnodepool->allocate(); + new (&node.key_value_pair) value_type(key, T()); + ++construct_count; - return ibucket->begin()->key_value_pair.second; + pbucket->insert_after(pbucket->before_begin(), node); + + return pbucket->begin()->key_value_pair.second; } //********************************************************************* @@ -665,13 +665,13 @@ namespace etl mapped_type& at(key_value_parameter_t key) { // Find the bucket. - bucket_list_iterator ibucket = pbuckets->begin() + bucket(key); + bucket_t* pbucket = pbuckets + bucket(key); // Find the first node in the bucket. - local_iterator inode = ibucket->begin(); + local_iterator inode = pbucket->begin(); // Walk the list looking for the right one. - while (inode != ibucket->end()) + while (inode != pbucket->end()) { // Equal keys? if (key_equal_function(key, inode->key_value_pair.first)) @@ -700,13 +700,13 @@ namespace etl const mapped_type& at(key_value_parameter_t key) const { // Find the bucket. - typename bucket_list_t::const_iterator ibucket = pbuckets->begin() + bucket(key); + bucket_t* pbucket = pbuckets + bucket(key); // Find the first node in the bucket. - typename bucket_t::const_iterator inode = ibucket->begin(); + local_iterator inode = pbucket->begin(); // Walk the list looking for the right one. - while (inode != ibucket->end()) + while (inode != pbucket->end()) { // Equal keys? if (key_equal_function(key, inode->key_value_pair.first)) @@ -768,22 +768,26 @@ namespace etl size_t index = bucket(key); // Get the bucket & bucket iterator. - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + size_t s = pbuckets->size(); // The first one in the bucket? if (bucket.empty()) { // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key_value_pair)); + node_t& node = *pnodepool->allocate(); + new (&node.key_value_pair) value_type(key_value_pair); + ++construct_count; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); - result.first = iterator(pbuckets->end(), ibucket, ibucket->begin()); + result.first = iterator((pbuckets + number_of_buckets), pbucket, pbucket->begin()); result.second = true; - adjust_first_last_markers(ibucket); + adjust_first_last_markers(pbucket); } else { @@ -807,13 +811,15 @@ namespace etl if (inode == bucket.end()) { // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key_value_pair)); + node_t& node = *pnodepool->allocate(); + new (&node.key_value_pair) value_type(key_value_pair); + ++construct_count; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); ++inode_previous; - result.first = iterator(pbuckets->end(), ibucket, inode_previous); + result.first = iterator((pbuckets + number_of_buckets), pbucket, inode_previous); result.second = true; } } @@ -856,24 +862,28 @@ namespace etl size_t erase(key_value_parameter_t key) { size_t count = 0; - size_t bucket_id = bucket(key); + size_t index = bucket(key); - bucket_t& bucket = (*pbuckets)[bucket_id]; + bucket_t& bucket = pbuckets[index]; local_iterator iprevious = bucket.before_begin(); local_iterator icurrent = bucket.begin(); + // Search for the key, if we have it. while ((icurrent != bucket.end()) && (icurrent->key_value_pair.first != key)) { ++iprevious; ++icurrent; } + // Did we find it? if (icurrent != bucket.end()) { - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key_value_pair.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. count = 1; + --construct_count; } return count; @@ -886,21 +896,23 @@ namespace etl iterator erase(const_iterator ielement) { // Make a note of the next one. - iterator inext(pbuckets->end(), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); + iterator inext((pbuckets + number_of_buckets), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); ++inext; bucket_t& bucket = ielement.get_bucket(); - local_iterator icurrent = ielement.get_local_iterator(); local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = ielement.get_local_iterator(); - // Find the node we're interested in. + // Find the node previous to the one we're interested in. while (iprevious->etl_next != &*icurrent) { ++iprevious; } - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key_value_pair.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; return inext; } @@ -915,57 +927,45 @@ namespace etl iterator erase(const_iterator first, const_iterator last) { // Make a note of the last. - iterator result(pbuckets->end(), last.get_bucket_list_iterator(), last.get_local_iterator()); + iterator result((pbuckets + number_of_buckets), last.get_bucket_list_iterator(), last.get_local_iterator()); // Get the starting point. - bucket_list_iterator ibucket = first.get_bucket_list_iterator(); - local_iterator ifirst = first.get_local_iterator(); - local_iterator iprevious = ibucket->before_begin(); - local_iterator iend; + bucket_t* pbucket = first.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first.get_local_iterator(); + local_iterator iend = last.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the first node we're interested in. - while (iprevious->etl_next != &*ifirst) + // Find the node previous to the first one. + while (iprevious->etl_next != &*icurrent) { - ++iprevious; + ++iprevious; } - - iend = iprevious; - iend++; - - while (first != last) + + while (icurrent != iend) { - // Find how far we can go in this bucket. - while ((first != last) && (iend != ibucket->end())) - { - ++first; - ++iend; - } - // Erase the range. - local_iterator irelease = iprevious; - ++irelease; + local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. + icurrent->key_value_pair.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; - ibucket->erase_after(iprevious, iend); + icurrent = inext; - while (irelease != iend) + // Are we there yet? + if (icurrent != iend) { - pnodepool->release(*irelease); - ++irelease; - } + // At the end of this bucket? + if ((icurrent == pbucket->end())) + { + // Find the next non-empty one. + do + { + ++pbucket; + } while (pbucket->empty()); - // At the end of this bucket? - if (iend == ibucket->end()) - { - // Move on to the next bucket. - ++ibucket; - iprevious = ibucket->before_begin(); - iend = iprevious; - ++iend; - } - else - { - // Still in the same bucket. - iprevious = iend; + iprevious = pbucket->before_begin(); + icurrent = pbucket->begin(); + } } } @@ -999,8 +999,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -1014,7 +1014,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key_value_pair.first)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -1033,8 +1033,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -1048,7 +1048,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key_value_pair.first)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -1113,7 +1113,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return pnodepool->max_size(); + return pnodepool->max_items(); } //************************************************************************* @@ -1187,9 +1187,10 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iunordered_map(pool_t& node_pool, bucket_list_t& buckets) + iunordered_map(pool_t& node_pool, bucket_t* pbuckets_, size_t number_of_buckets) : pnodepool(&node_pool), - pbuckets(&buckets) + pbuckets(pbuckets_), + number_of_buckets(number_of_buckets) { } @@ -1198,19 +1199,37 @@ namespace etl //********************************************************************* void initialise() { - pbuckets->resize(pnodepool->max_size()); - if (!empty()) { - pnodepool->release_all(); - - for (size_t i = 0; i < pbuckets->size(); ++i) + // For each bucket... + for (size_t i = 0; i < number_of_buckets; ++i) { - (*pbuckets)[i].clear(); + bucket_t& bucket = pbuckets[i]; + + if (!bucket.empty()) + { + // For each item in the bucket... + local_iterator it = bucket.begin(); + + while (it != bucket.end()) + { + // Destroy the value contents. + it->key_value_pair.~value_type(); + --construct_count; + + ++it; + } + + // Now it's safe to clear the bucket. + bucket.clear(); + } } + + // Now it's safe to clear the entire pool in one go. + pnodepool->release_all(); } - first = pbuckets->begin(); + first = pbuckets; last = first; } @@ -1219,15 +1238,15 @@ namespace etl //********************************************************************* /// Adjust the first and last markers according to the new entry. //********************************************************************* - void adjust_first_last_markers(bucket_list_iterator ibucket) + void adjust_first_last_markers(bucket_t* pbucket) { - if (ibucket < first) + if (pbucket < first) { - first = ibucket; + first = pbucket; } - else if (ibucket > last) + else if (pbucket > last) { - last = ibucket; + last = pbucket; } } @@ -1238,17 +1257,23 @@ namespace etl pool_t* pnodepool; /// The bucket list. - bucket_list_t* pbuckets; + bucket_t* pbuckets; - /// The first and last iterators to buckets with values. - bucket_list_iterator first; - bucket_list_iterator last; + /// The number of buckets. + const size_t number_of_buckets; + + /// The first and last pointers to buckets with values. + bucket_t* first; + bucket_t* last; /// The function that creates the hashes. hasher key_hash_function; /// The function that compares the keys for equality. key_equal key_equal_function; + + /// For library debugging purposes only. + etl::debug_count construct_count; }; //*************************************************************************** diff --git a/src/iunordered_multimap.h b/src/iunordered_multimap.h index 6f369585..4f136a4c 100644 --- a/src/iunordered_multimap.h +++ b/src/iunordered_multimap.h @@ -47,6 +47,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "exception.h" #include "error_handler.h" +#include "debug_count.h" #undef ETL_FILE #define ETL_FILE "25" @@ -149,10 +150,7 @@ namespace etl private: typedef etl::intrusive_forward_list bucket_t; - typedef etl::ipool pool_t; - typedef etl::ivector bucket_list_t; - - typedef typename bucket_list_t::iterator bucket_list_iterator; + typedef etl::ipool pool_t; public: @@ -185,8 +183,8 @@ namespace etl //********************************* iterator(const iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -197,19 +195,19 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -227,8 +225,8 @@ namespace etl //********************************* iterator operator =(const iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -284,9 +282,9 @@ namespace etl private: //********************************* - iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -300,13 +298,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t*& get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -315,8 +313,8 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; + bucket_t* pbuckets_end; + bucket_t* pbucket; local_iterator inode; }; @@ -346,16 +344,16 @@ namespace etl //********************************* const_iterator(const typename iunordered_multimap::iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } //********************************* const_iterator(const const_iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -366,20 +364,20 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -397,8 +395,8 @@ namespace etl //********************************* const_iterator operator =(const const_iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -436,9 +434,9 @@ namespace etl private: //********************************* - const_iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + const_iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -452,13 +450,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t*& get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -467,8 +465,8 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; + bucket_t* pbuckets_end; + bucket_t* pbucket; local_iterator inode; }; @@ -480,7 +478,7 @@ namespace etl //********************************************************************* iterator begin() { - return iterator(pbuckets->end(), first, first->begin()); + return iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -489,7 +487,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -498,7 +496,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -507,7 +505,7 @@ namespace etl //********************************************************************* local_iterator begin(size_t i) { - return (*pbuckets)[i].begin(); + return pbuckets[i].begin(); } //********************************************************************* @@ -516,7 +514,7 @@ namespace etl //********************************************************************* local_const_iterator begin(size_t i) const { - return (*pbuckets)[i].cbegin(); + return pbuckets[i].cbegin(); } //********************************************************************* @@ -525,7 +523,7 @@ namespace etl //********************************************************************* local_const_iterator cbegin(size_t i) const { - return (*pbuckets)[i].cbegin(); + return pbuckets[i].cbegin(); } //********************************************************************* @@ -534,7 +532,7 @@ namespace etl //********************************************************************* iterator end() { - return iterator(pbuckets->end(), last, last->end()); + return iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -543,7 +541,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -552,7 +550,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -561,7 +559,7 @@ namespace etl //********************************************************************* local_iterator end(size_t i) { - return (*pbuckets)[i].end(); + return pbuckets[i].end(); } //********************************************************************* @@ -570,7 +568,7 @@ namespace etl //********************************************************************* local_const_iterator end(size_t i) const { - return (*pbuckets)[i].cend(); + return pbuckets[i].cend(); } //********************************************************************* @@ -579,7 +577,7 @@ namespace etl //********************************************************************* local_const_iterator cend(size_t i) const { - return (*pbuckets)[i].cend(); + return pbuckets[i].cend(); } //********************************************************************* @@ -588,7 +586,7 @@ namespace etl //********************************************************************* size_type bucket(key_value_parameter_t key) const { - return key_hash_function(key) % pbuckets->size(); + return key_hash_function(key) % number_of_buckets; } //********************************************************************* @@ -599,7 +597,7 @@ namespace etl { size_t index = bucket(key); - return std::distance((*pbuckets)[index].begin(), (*pbuckets)[index].end()); + return std::distance(pbuckets[index].begin(), pbuckets[index].end()); } //********************************************************************* @@ -608,7 +606,7 @@ namespace etl //********************************************************************* size_type max_bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -617,7 +615,7 @@ namespace etl //********************************************************************* size_type bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -649,9 +647,9 @@ namespace etl /// If asserts or exceptions are enabled, emits unordered_multimap_full if the unordered_multimap is already full. ///\param value The value to insert. //********************************************************************* - std::pair insert(const value_type& key_value_pair) + iterator insert(const value_type& key_value_pair) { - std::pair result(end(), false); + iterator result = end(); ETL_ASSERT(!full(), ETL_ERROR(unordered_multimap_full)); @@ -662,22 +660,23 @@ namespace etl size_t index = bucket(key); // Get the bucket & bucket iterator. - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // The first one in the bucket? if (bucket.empty()) { // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key_value_pair)); + node_t& node = *pnodepool->allocate(); + new (&node.key_value_pair) value_type(key_value_pair); + ++construct_count; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); - result.first = iterator(pbuckets->end(), ibucket, ibucket->begin()); - result.second = true; + result = iterator((pbuckets + number_of_buckets), pbucket, pbucket->begin()); - adjust_first_last_markers(ibucket); + adjust_first_last_markers(pbucket); } else { @@ -698,14 +697,15 @@ namespace etl } // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key_value_pair)); + node_t& node = *pnodepool->allocate(); + new (&node.key_value_pair) value_type(key_value_pair); + ++construct_count; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); ++inode_previous; - result.first = iterator(pbuckets->end(), ibucket, inode_previous); - result.second = true; + result = iterator((pbuckets + number_of_buckets), pbucket, inode_previous); } return result; @@ -719,7 +719,7 @@ namespace etl //********************************************************************* iterator insert(const_iterator position, const value_type& key_value_pair) { - return insert(key_value_pair).first; + return insert(key_value_pair); } //********************************************************************* @@ -748,7 +748,7 @@ namespace etl size_t count = 0; size_t bucket_id = bucket(key); - bucket_t& bucket = (*pbuckets)[bucket_id]; + bucket_t& bucket = pbuckets[bucket_id]; local_iterator iprevious = bucket.before_begin(); local_iterator icurrent = bucket.begin(); @@ -757,10 +757,12 @@ namespace etl { if (icurrent->key_value_pair.first == key) { - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key_value_pair.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. ++count; icurrent = iprevious; + --construct_count; } else { @@ -780,21 +782,23 @@ namespace etl iterator erase(const_iterator ielement) { // Make a note of the next one. - iterator inext(pbuckets->end(), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); + iterator inext((pbuckets + number_of_buckets), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); ++inext; - bucket_t& bucket = ielement.get_bucket(); - local_iterator icurrent = ielement.get_local_iterator(); + bucket_t& bucket = ielement.get_bucket(); local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = ielement.get_local_iterator(); - // Find the node we're interested in. + // Find the node previous to the one we're interested in. while (iprevious->etl_next != &*icurrent) { ++iprevious; } - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key_value_pair.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; return inext; } @@ -809,57 +813,45 @@ namespace etl iterator erase(const_iterator first, const_iterator last) { // Make a note of the last. - iterator result(pbuckets->end(), last.get_bucket_list_iterator(), last.get_local_iterator()); + iterator result((pbuckets + number_of_buckets), last.get_bucket_list_iterator(), last.get_local_iterator()); // Get the starting point. - bucket_list_iterator ibucket = first.get_bucket_list_iterator(); - local_iterator ifirst = first.get_local_iterator(); - local_iterator iprevious = ibucket->before_begin(); - local_iterator iend; + bucket_t* pbucket = first.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first.get_local_iterator(); + local_iterator iend = last.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the first node we're interested in. - while (iprevious->etl_next != &*ifirst) + // Find the node previous to the first one. + while (iprevious->etl_next != &*icurrent) { ++iprevious; } - iend = iprevious; - iend++; - - while (first != last) + while (icurrent != iend) { - // Find how far we can go in this bucket. - while ((first != last) && (iend != ibucket->end())) - { - ++first; - ++iend; - } - // Erase the range. - local_iterator irelease = iprevious; - ++irelease; + local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. + icurrent->key_value_pair.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; - ibucket->erase_after(iprevious, iend); + icurrent = inext; - while (irelease != iend) + // Are we there yet? + if (icurrent != iend) { - pnodepool->release(*irelease); - ++irelease; - } + // At the end of this bucket? + if ((icurrent == pbucket->end())) + { + // Find the next non-empty one. + do + { + ++pbucket; + } while (pbucket->empty()); - // At the end of this bucket? - if (iend == ibucket->end()) - { - // Move on to the next bucket. - ++ibucket; - iprevious = ibucket->before_begin(); - iend = iprevious; - ++iend; - } - else - { - // Still in the same bucket. - iprevious = iend; + iprevious = pbucket->before_begin(); + icurrent = pbucket->begin(); + } } } @@ -909,8 +901,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -924,7 +916,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key_value_pair.first)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -943,8 +935,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -958,7 +950,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key_value_pair.first)) { - return const_iterator(pbuckets->end(), ibucket, inode); + return const_iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -1033,7 +1025,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return pnodepool->max_size(); + return pnodepool->max_items(); } //************************************************************************* @@ -1107,9 +1099,10 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iunordered_multimap(pool_t& node_pool, bucket_list_t& buckets) + iunordered_multimap(pool_t& node_pool, bucket_t* pbuckets_, size_t number_of_buckets) : pnodepool(&node_pool), - pbuckets(&buckets) + pbuckets(pbuckets_), + number_of_buckets(number_of_buckets) { } @@ -1118,20 +1111,37 @@ namespace etl //********************************************************************* void initialise() { - pbuckets->resize(pnodepool->max_size()); - if (!empty()) { - pnodepool->release_all(); - - for (size_t i = 0; i < pbuckets->size(); ++i) + // For each bucket... + for (size_t i = 0; i < number_of_buckets; ++i) { - (*pbuckets)[i].clear(); + bucket_t& bucket = pbuckets[i]; + + if (!bucket.empty()) + { + // For each item in the bucket... + local_iterator it = bucket.begin(); + + while (it != bucket.end()) + { + // Destroy the value contents. + it->key_value_pair.~value_type(); + ++it; + --construct_count; + } + + // Now it's safe to clear the bucket. + bucket.clear(); + } } + + // Now it's safe to clear the entire pool in one go. + pnodepool->release_all(); } - first = pbuckets->begin(); - last = first; + first = pbuckets; + last = first; } private: @@ -1139,15 +1149,15 @@ namespace etl //********************************************************************* /// Adjust the first and last markers according to the new entry. //********************************************************************* - void adjust_first_last_markers(bucket_list_iterator ibucket) + void adjust_first_last_markers(bucket_t* pbucket) { - if (ibucket < first) + if (pbucket < first) { - first = ibucket; + first = pbucket; } - else if (ibucket > last) + else if (pbucket > last) { - last = ibucket; + last = pbucket; } } @@ -1158,17 +1168,23 @@ namespace etl pool_t* pnodepool; /// The bucket list. - bucket_list_t* pbuckets; + bucket_t* pbuckets; + + /// The number of buckets. + const size_t number_of_buckets; /// The first and last iterators to buckets with values. - bucket_list_iterator first; - bucket_list_iterator last; + bucket_t* first; + bucket_t* last; /// The function that creates the hashes. hasher key_hash_function; /// The function that compares the keys for equality. key_equal key_equal_function; + + /// For library debugging purposes only. + etl::debug_count construct_count; }; //*************************************************************************** diff --git a/src/iunordered_multiset.h b/src/iunordered_multiset.h index 994c1e9d..fecab3a0 100644 --- a/src/iunordered_multiset.h +++ b/src/iunordered_multiset.h @@ -47,6 +47,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "exception.h" #include "error_handler.h" +#include "debug_count.h" #undef ETL_FILE #define ETL_FILE "26" @@ -146,10 +147,7 @@ namespace etl private: typedef etl::intrusive_forward_list bucket_t; - typedef etl::ipool pool_t; - typedef etl::ivector bucket_list_t; - - typedef typename bucket_list_t::iterator bucket_list_iterator; + typedef etl::ipool pool_t; public: @@ -181,8 +179,8 @@ namespace etl //********************************* iterator(const iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -193,19 +191,19 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -223,8 +221,8 @@ namespace etl //********************************* iterator operator =(const iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -280,9 +278,9 @@ namespace etl private: //********************************* - iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -296,13 +294,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t*& get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -311,9 +309,9 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; - local_iterator inode; + bucket_t* pbuckets_end; + bucket_t* pbucket; + local_iterator inode; }; //********************************************************************* @@ -341,16 +339,16 @@ namespace etl //********************************* const_iterator(const typename iunordered_multiset::iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } //********************************* const_iterator(const const_iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -361,20 +359,20 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -392,8 +390,8 @@ namespace etl //********************************* const_iterator operator =(const const_iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -431,9 +429,9 @@ namespace etl private: //********************************* - const_iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + const_iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -447,13 +445,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t*& get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -462,9 +460,9 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; - local_iterator inode; + bucket_t* pbuckets_end; + bucket_t* pbucket; + local_iterator inode; }; typedef typename std::iterator_traits::difference_type difference_type; @@ -475,7 +473,7 @@ namespace etl //********************************************************************* iterator begin() { - return iterator(pbuckets->end(), first, first->begin()); + return iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -484,7 +482,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -493,7 +491,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator((pbuckets + number_of_buckets), first, first->begin()); } //********************************************************************* @@ -502,7 +500,7 @@ namespace etl //********************************************************************* local_iterator begin(size_t i) { - return (*pbuckets)[i].begin(); + return pbuckets[i].begin(); } //********************************************************************* @@ -511,7 +509,7 @@ namespace etl //********************************************************************* local_const_iterator begin(size_t i) const { - return (*pbuckets)[i].cbegin(); + return pbuckets[i].cbegin(); } //********************************************************************* @@ -520,7 +518,7 @@ namespace etl //********************************************************************* local_const_iterator cbegin(size_t i) const { - return (*pbuckets)[i].cbegin(); + return pbuckets[i].cbegin(); } //********************************************************************* @@ -529,7 +527,7 @@ namespace etl //********************************************************************* iterator end() { - return iterator(pbuckets->end(), last, last->end()); + return iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -538,7 +536,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -547,7 +545,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator((pbuckets + number_of_buckets), last, last->end()); } //********************************************************************* @@ -556,7 +554,7 @@ namespace etl //********************************************************************* local_iterator end(size_t i) { - return (*pbuckets)[i].end(); + return pbuckets[i].end(); } //********************************************************************* @@ -565,7 +563,7 @@ namespace etl //********************************************************************* local_const_iterator end(size_t i) const { - return (*pbuckets)[i].cend(); + return pbuckets[i].cend(); } //********************************************************************* @@ -574,7 +572,7 @@ namespace etl //********************************************************************* local_const_iterator cend(size_t i) const { - return (*pbuckets)[i].cend(); + return pbuckets[i].cend(); } //********************************************************************* @@ -583,7 +581,7 @@ namespace etl //********************************************************************* size_type bucket(key_value_parameter_t key) const { - return key_hash_function(key) % pbuckets->size(); + return key_hash_function(key) % number_of_buckets; } //********************************************************************* @@ -594,7 +592,7 @@ namespace etl { size_t index = bucket(key); - return std::distance((*pbuckets)[index].begin(), (*pbuckets)[index].end()); + return std::distance(pbuckets[index].begin(), pbuckets[index].end()); } //********************************************************************* @@ -603,7 +601,7 @@ namespace etl //********************************************************************* size_type max_bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -612,7 +610,7 @@ namespace etl //********************************************************************* size_type bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -654,22 +652,24 @@ namespace etl size_t index = bucket(key); // Get the bucket & bucket iterator. - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // The first one in the bucket? if (bucket.empty()) { // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key)); + node_t& node = *pnodepool->allocate(); + new (&node.key) value_type(key); + ++construct_count; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); - result.first = iterator(pbuckets->end(), ibucket, ibucket->begin()); + result.first = iterator((pbuckets + number_of_buckets), pbucket, pbucket->begin()); result.second = true; - adjust_first_last_markers(ibucket); + adjust_first_last_markers(pbucket); } else { @@ -690,13 +690,15 @@ namespace etl } // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key)); + node_t& node = *pnodepool->allocate(); + new (&node.key) value_type(key); + ++construct_count; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); ++inode_previous; - result.first = iterator(pbuckets->end(), ibucket, inode_previous); + result.first = iterator((pbuckets + number_of_buckets), pbucket, inode_previous); result.second = true; } @@ -740,7 +742,7 @@ namespace etl size_t count = 0; size_t bucket_id = bucket(key); - bucket_t& bucket = (*pbuckets)[bucket_id]; + bucket_t& bucket = pbuckets[bucket_id]; local_iterator iprevious = bucket.before_begin(); local_iterator icurrent = bucket.begin(); @@ -749,10 +751,12 @@ namespace etl { if (icurrent->key == key) { - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. ++count; icurrent = iprevious; + --construct_count; } else { @@ -772,21 +776,23 @@ namespace etl iterator erase(const_iterator ielement) { // Make a note of the next one. - iterator inext(pbuckets->end(), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); + iterator inext((pbuckets + number_of_buckets), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); ++inext; - bucket_t& bucket = ielement.get_bucket(); - local_iterator icurrent = ielement.get_local_iterator(); + bucket_t& bucket = ielement.get_bucket(); local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = ielement.get_local_iterator(); - // Find the node we're interested in. + // Find the node previous to the one we're interested in. while (iprevious->etl_next != &*icurrent) { ++iprevious; } - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; return inext; } @@ -801,57 +807,45 @@ namespace etl iterator erase(const_iterator first, const_iterator last) { // Make a note of the last. - iterator result(pbuckets->end(), last.get_bucket_list_iterator(), last.get_local_iterator()); + iterator result((pbuckets + number_of_buckets), last.get_bucket_list_iterator(), last.get_local_iterator()); // Get the starting point. - bucket_list_iterator ibucket = first.get_bucket_list_iterator(); - local_iterator ifirst = first.get_local_iterator(); - local_iterator iprevious = ibucket->before_begin(); - local_iterator iend; + bucket_t* pbucket = first.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first.get_local_iterator(); + local_iterator iend = last.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the first node we're interested in. - while (iprevious->etl_next != &*ifirst) + // Find the node previous to the first one. + while (iprevious->etl_next != &*icurrent) { ++iprevious; } - iend = iprevious; - iend++; - - while (first != last) + while (icurrent != iend) { - // Find how far we can go in this bucket. - while ((first != last) && (iend != ibucket->end())) - { - ++first; - ++iend; - } - // Erase the range. - local_iterator irelease = iprevious; - ++irelease; + local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. + icurrent->key.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; - ibucket->erase_after(iprevious, iend); + icurrent = inext; - while (irelease != iend) + // Are we there yet? + if (icurrent != iend) { - pnodepool->release(*irelease); - ++irelease; - } + // At the end of this bucket? + if ((icurrent == pbucket->end())) + { + // Find the next non-empty one. + do + { + ++pbucket; + } while (pbucket->empty()); - // At the end of this bucket? - if (iend == ibucket->end()) - { - // Move on to the next bucket. - ++ibucket; - iprevious = ibucket->before_begin(); - iend = iprevious; - ++iend; - } - else - { - // Still in the same bucket. - iprevious = iend; + iprevious = pbucket->before_begin(); + icurrent = pbucket->begin(); + } } } @@ -901,8 +895,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -916,7 +910,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -935,8 +929,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -950,7 +944,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -1025,7 +1019,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return pnodepool->max_size(); + return pnodepool->max_items(); } //************************************************************************* @@ -1099,9 +1093,10 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iunordered_multiset(pool_t& node_pool, bucket_list_t& buckets) + iunordered_multiset(pool_t& node_pool, bucket_t* pbuckets_, size_t number_of_buckets) : pnodepool(&node_pool), - pbuckets(&buckets) + pbuckets(pbuckets_), + number_of_buckets(number_of_buckets) { } @@ -1110,20 +1105,37 @@ namespace etl //********************************************************************* void initialise() { - pbuckets->resize(pnodepool->max_size()); - if (!empty()) { - pnodepool->release_all(); - - for (size_t i = 0; i < pbuckets->size(); ++i) + // For each bucket... + for (size_t i = 0; i < number_of_buckets; ++i) { - (*pbuckets)[i].clear(); + bucket_t& bucket = pbuckets[i]; + + if (!bucket.empty()) + { + // For each item in the bucket... + local_iterator it = bucket.begin(); + + while (it != bucket.end()) + { + // Destroy the value contents. + it->key.~value_type(); + ++it; + --construct_count; + } + + // Now it's safe to clear the bucket. + bucket.clear(); + } } + + // Now it's safe to clear the entire pool in one go. + pnodepool->release_all(); } - first = pbuckets->begin(); - last = first; + first = pbuckets; + last = first; } private: @@ -1131,15 +1143,15 @@ namespace etl //********************************************************************* /// Adjust the first and last markers according to the new entry. //********************************************************************* - void adjust_first_last_markers(bucket_list_iterator ibucket) + void adjust_first_last_markers(bucket_t* pbucket) { - if (ibucket < first) + if (pbucket < first) { - first = ibucket; + first = pbucket; } - else if (ibucket > last) + else if (pbucket > last) { - last = ibucket; + last = pbucket; } } @@ -1150,17 +1162,23 @@ namespace etl pool_t* pnodepool; /// The bucket list. - bucket_list_t* pbuckets; + bucket_t* pbuckets; + + /// The number of buckets. + const size_t number_of_buckets; /// The first and last iterators to buckets with values. - bucket_list_iterator first; - bucket_list_iterator last; + bucket_t* first; + bucket_t* last; /// The function that creates the hashes. hasher key_hash_function; /// The function that compares the keys for equality. key_equal key_equal_function; + + /// For library debugging purposes only. + etl::debug_count construct_count; }; //*************************************************************************** diff --git a/src/iunordered_set.h b/src/iunordered_set.h index d47ef3c6..aaef8819 100644 --- a/src/iunordered_set.h +++ b/src/iunordered_set.h @@ -47,6 +47,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "exception.h" #include "error_handler.h" +#include "debug_count.h" #undef ETL_FILE #define ETL_FILE "23" @@ -146,10 +147,7 @@ namespace etl private: typedef etl::intrusive_forward_list bucket_t; - typedef etl::ipool pool_t; - typedef etl::ivector bucket_list_t; - - typedef typename bucket_list_t::iterator bucket_list_iterator; + typedef etl::ipool pool_t; public: @@ -181,8 +179,8 @@ namespace etl //********************************* iterator(const iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -193,19 +191,19 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -223,8 +221,8 @@ namespace etl //********************************* iterator operator =(const iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -280,9 +278,9 @@ namespace etl private: //********************************* - iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -296,13 +294,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t*& get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -311,8 +309,8 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; + bucket_t* pbuckets_end; + bucket_t* pbucket; local_iterator inode; }; @@ -341,16 +339,16 @@ namespace etl //********************************* const_iterator(const typename iunordered_set::iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } //********************************* const_iterator(const const_iterator& other) - : ibuckets_end(other.ibuckets_end), - ibucket(other.ibucket), + : pbuckets_end(other.pbuckets_end), + pbucket(other.pbucket), inode(other.inode) { } @@ -361,20 +359,20 @@ namespace etl ++inode; // The end of this node list? - if (inode == ibucket->end()) + if (inode == pbucket->end()) { // Search for the next non-empty bucket. - ++ibucket; - while ((ibucket != ibuckets_end) && (ibucket->empty())) + ++pbucket; + while ((pbucket != pbuckets_end) && (pbucket->empty())) { - ++ibucket; + ++pbucket; } // If not past the end, get the first node in the bucket. - if (ibucket != ibuckets_end) + if (pbucket != pbuckets_end) { - inode = ibucket->begin(); + inode = pbucket->begin(); } } @@ -392,8 +390,8 @@ namespace etl //********************************* const_iterator operator =(const const_iterator& other) { - ibuckets_end = other.ibuckets_end; - ibucket = other.ibucket; + pbuckets_end = other.pbuckets_end; + pbucket = other.pbucket; inode = other.inode; return *this; } @@ -431,9 +429,9 @@ namespace etl private: //********************************* - const_iterator(bucket_list_iterator ibuckets_end, bucket_list_iterator ibucket, local_iterator inode) - : ibuckets_end(ibuckets_end), - ibucket(ibucket), + const_iterator(bucket_t* pbuckets_end, bucket_t* pbucket, local_iterator inode) + : pbuckets_end(pbuckets_end), + pbucket(pbucket), inode(inode) { } @@ -447,13 +445,13 @@ namespace etl //********************************* bucket_t& get_bucket() { - return *ibucket; + return *pbucket; } //********************************* - bucket_list_iterator& get_bucket_list_iterator() + bucket_t*& get_bucket_list_iterator() { - return ibucket; + return pbucket; } //********************************* @@ -462,8 +460,8 @@ namespace etl return inode; } - bucket_list_iterator ibuckets_end; - bucket_list_iterator ibucket; + bucket_t* pbuckets_end; + bucket_t* pbucket; local_iterator inode; }; @@ -475,7 +473,7 @@ namespace etl //********************************************************************* iterator begin() { - return iterator(pbuckets->end(), first, first->begin()); + return iterator(pbuckets + number_of_buckets, first, first->begin()); } //********************************************************************* @@ -484,7 +482,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator(pbuckets + number_of_buckets, first, first->begin()); } //********************************************************************* @@ -493,7 +491,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return const_iterator(pbuckets->end(), first, first->begin()); + return const_iterator(pbuckets + number_of_buckets, first, first->begin()); } //********************************************************************* @@ -502,7 +500,7 @@ namespace etl //********************************************************************* local_iterator begin(size_t i) { - return (*pbuckets)[i].begin(); + return pbuckets[i].begin(); } //********************************************************************* @@ -511,7 +509,7 @@ namespace etl //********************************************************************* local_const_iterator begin(size_t i) const { - return (*pbuckets)[i].cbegin(); + return pbuckets[i].cbegin(); } //********************************************************************* @@ -520,7 +518,7 @@ namespace etl //********************************************************************* local_const_iterator cbegin(size_t i) const { - return (*pbuckets)[i].cbegin(); + return pbuckets[i].cbegin(); } //********************************************************************* @@ -529,7 +527,7 @@ namespace etl //********************************************************************* iterator end() { - return iterator(pbuckets->end(), last, last->end()); + return iterator(pbuckets + number_of_buckets, last, last->end()); } //********************************************************************* @@ -538,7 +536,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator(pbuckets + number_of_buckets, last, last->end()); } //********************************************************************* @@ -547,7 +545,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return const_iterator(pbuckets->end(), last, last->end()); + return const_iterator(pbuckets + number_of_buckets, last, last->end()); } //********************************************************************* @@ -556,7 +554,7 @@ namespace etl //********************************************************************* local_iterator end(size_t i) { - return (*pbuckets)[i].end(); + return pbuckets[i].end(); } //********************************************************************* @@ -565,7 +563,7 @@ namespace etl //********************************************************************* local_const_iterator end(size_t i) const { - return (*pbuckets)[i].cend(); + return pbuckets[i].cend(); } //********************************************************************* @@ -574,7 +572,7 @@ namespace etl //********************************************************************* local_const_iterator cend(size_t i) const { - return (*pbuckets)[i].cend(); + return pbuckets[i].cend(); } //********************************************************************* @@ -583,7 +581,7 @@ namespace etl //********************************************************************* size_type bucket(key_value_parameter_t key) const { - return key_hash_function(key) % pbuckets->size(); + return key_hash_function(key) % number_of_buckets; } //********************************************************************* @@ -594,7 +592,7 @@ namespace etl { size_t index = bucket(key); - return std::distance((*pbuckets)[index].begin(), (*pbuckets)[index].end()); + return std::distance(pbuckets[index].begin(), pbuckets[index].end()); } //********************************************************************* @@ -603,7 +601,7 @@ namespace etl //********************************************************************* size_type max_bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -612,7 +610,7 @@ namespace etl //********************************************************************* size_type bucket_count() const { - return max_size(); + return number_of_buckets; } //********************************************************************* @@ -654,22 +652,24 @@ namespace etl size_t index = bucket(key); // Get the bucket & bucket iterator. - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // The first one in the bucket? if (bucket.empty()) { // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key)); + node_t& node = *pnodepool->allocate(); + new (&node.key) value_type(key); + ++construct_count; // Just add the pointer to the bucket; bucket.insert_after(bucket.before_begin(), node); - result.first = iterator(pbuckets->end(), ibucket, ibucket->begin()); + result.first = iterator(pbuckets + number_of_buckets, pbucket, pbucket->begin()); result.second = true; - adjust_first_last_markers(ibucket); + adjust_first_last_markers(pbucket); } else { @@ -693,13 +693,15 @@ namespace etl if (inode == bucket.end()) { // Get a new node. - node_t& node = *pnodepool->allocate(node_t(key)); + node_t& node = *pnodepool->allocate(); + new (&node.key) value_type(key); + ++construct_count; // Add the node to the end of the bucket; bucket.insert_after(inode_previous, node); ++inode_previous; - result.first = iterator(pbuckets->end(), ibucket, inode_previous); + result.first = iterator(pbuckets + number_of_buckets, pbucket, inode_previous); result.second = true; } } @@ -742,24 +744,28 @@ namespace etl size_t erase(key_value_parameter_t key) { size_t count = 0; - size_t bucket_id = bucket(key); + size_t index = bucket(key); - bucket_t& bucket = (*pbuckets)[bucket_id]; + bucket_t& bucket = pbuckets[index]; local_iterator iprevious = bucket.before_begin(); - local_iterator icurrent = bucket.begin(); + local_iterator icurrent = bucket.begin(); + // Search for the key, if we have it. while ((icurrent != bucket.end()) && (icurrent->key != key)) { ++iprevious; ++icurrent; } + // Did we find it? if (icurrent != bucket.end()) { - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. count = 1; + --construct_count; } return count; @@ -772,21 +778,23 @@ namespace etl iterator erase(const_iterator ielement) { // Make a note of the next one. - iterator inext(pbuckets->end(), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); + iterator inext((pbuckets + number_of_buckets), ielement.get_bucket_list_iterator(), ielement.get_local_iterator()); ++inext; - bucket_t& bucket = ielement.get_bucket(); - local_iterator icurrent = ielement.get_local_iterator(); + bucket_t& bucket = ielement.get_bucket(); local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = ielement.get_local_iterator(); - // Find the node we're interested in. + // Find the node previous to the one we're interested in. while (iprevious->etl_next != &*icurrent) { ++iprevious; } - bucket.erase_after(iprevious); - pnodepool->release(*icurrent); + bucket.erase_after(iprevious); // Unlink from the bucket. + icurrent->key.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; return inext; } @@ -801,57 +809,45 @@ namespace etl iterator erase(const_iterator first, const_iterator last) { // Make a note of the last. - iterator result(pbuckets->end(), last.get_bucket_list_iterator(), last.get_local_iterator()); + iterator result((pbuckets + number_of_buckets), last.get_bucket_list_iterator(), last.get_local_iterator()); // Get the starting point. - bucket_list_iterator ibucket = first.get_bucket_list_iterator(); - local_iterator ifirst = first.get_local_iterator(); - local_iterator iprevious = ibucket->before_begin(); - local_iterator iend; + bucket_t* pbucket = first.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first.get_local_iterator(); + local_iterator iend = last.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the first node we're interested in. - while (iprevious->etl_next != &*ifirst) + // Find the node previous to the first one. + while (iprevious->etl_next != &*icurrent) { ++iprevious; } - iend = iprevious; - iend++; - - while (first != last) + while (icurrent != iend) { - // Find how far we can go in this bucket. - while ((first != last) && (iend != ibucket->end())) - { - ++first; - ++iend; - } - // Erase the range. - local_iterator irelease = iprevious; - ++irelease; + local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. + icurrent->key.~value_type(); // Destroy the value. + pnodepool->release(&*icurrent); // Release it back to the pool. + --construct_count; - ibucket->erase_after(iprevious, iend); + icurrent = inext; - while (irelease != iend) + // Are we there yet? + if (icurrent != iend) { - pnodepool->release(*irelease); - ++irelease; - } + // At the end of this bucket? + if ((icurrent == pbucket->end())) + { + // Find the next non-empty one. + do + { + ++pbucket; + } while (pbucket->empty()); - // At the end of this bucket? - if (iend == ibucket->end()) - { - // Move on to the next bucket. - ++ibucket; - iprevious = ibucket->before_begin(); - iend = iprevious; - ++iend; - } - else - { - // Still in the same bucket. - iprevious = iend; + iprevious = pbucket->before_begin(); + icurrent = pbucket->begin(); + } } } @@ -885,8 +881,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -900,7 +896,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator(pbuckets + number_of_buckets, pbucket, inode); } ++inode; @@ -919,8 +915,8 @@ namespace etl { size_t index = bucket(key); - bucket_list_iterator ibucket = pbuckets->begin() + index; - bucket_t& bucket = *ibucket; + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; // Is the bucket not empty? if (!bucket.empty()) @@ -934,7 +930,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key)) { - return iterator(pbuckets->end(), ibucket, inode); + return iterator(pbuckets + number_of_buckets, pbucket, inode); } ++inode; @@ -999,7 +995,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return pnodepool->max_size(); + return pnodepool->max_items(); } //************************************************************************* @@ -1073,9 +1069,10 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iunordered_set(pool_t& node_pool, bucket_list_t& buckets) + iunordered_set(pool_t& node_pool, bucket_t* pbuckets_, size_t number_of_buckets) : pnodepool(&node_pool), - pbuckets(&buckets) + pbuckets(pbuckets_), + number_of_buckets(number_of_buckets) { } @@ -1084,20 +1081,37 @@ namespace etl //********************************************************************* void initialise() { - pbuckets->resize(pnodepool->max_size()); - if (!empty()) { - pnodepool->release_all(); - - for (size_t i = 0; i < pbuckets->size(); ++i) + // For each bucket... + for (size_t i = 0; i < number_of_buckets; ++i) { - (*pbuckets)[i].clear(); + bucket_t& bucket = pbuckets[i]; + + if (!bucket.empty()) + { + // For each item in the bucket... + local_iterator it = bucket.begin(); + + while (it != bucket.end()) + { + // Destroy the value contents. + it->key.~value_type(); + ++it; + --construct_count; + } + + // Now it's safe to clear the bucket. + bucket.clear(); + } } + + // Now it's safe to clear the entire pool in one go. + pnodepool->release_all(); } - first = pbuckets->begin(); - last = first; + first = pbuckets; + last = first; } private: @@ -1105,15 +1119,15 @@ namespace etl //********************************************************************* /// Adjust the first and last markers according to the new entry. //********************************************************************* - void adjust_first_last_markers(bucket_list_iterator ibucket) + void adjust_first_last_markers(bucket_t* pbucket) { - if (ibucket < first) + if (pbucket < first) { - first = ibucket; + first = pbucket; } - else if (ibucket > last) + else if (pbucket > last) { - last = ibucket; + last = pbucket; } } @@ -1124,17 +1138,23 @@ namespace etl pool_t* pnodepool; /// The bucket list. - bucket_list_t* pbuckets; + bucket_t* pbuckets; + + /// The number of buckets. + const size_t number_of_buckets; /// The first and last iterators to buckets with values. - bucket_list_iterator first; - bucket_list_iterator last; + bucket_t* first; + bucket_t* last; /// The function that creates the hashes. hasher key_hash_function; /// The function that compares the keys for equality. key_equal key_equal_function; + + /// For library debugging purposes only. + etl::debug_count construct_count; }; //*************************************************************************** diff --git a/src/ivector.h b/src/ivector.h index de7c5cd8..b18e7a77 100644 --- a/src/ivector.h +++ b/src/ivector.h @@ -208,6 +208,12 @@ namespace etl // The unused branch should be optimised away. if (is_simple_type::value) { + // Size up if necessary. + if (current_size < new_size) + { + std::fill_n(&p_buffer[current_size], new_size - current_size, 0); + } + current_size = new_size; } else @@ -215,6 +221,7 @@ namespace etl // Size up or size down? if (new_size > current_size) { + // Up. while (current_size < new_size) { create_element(); @@ -222,12 +229,15 @@ namespace etl } else if (new_size < current_size) { + // Down. while (current_size > new_size) { destroy_element(); } } } + + } //********************************************************************* @@ -246,34 +256,42 @@ namespace etl if (is_simple_type::value) { // Size up if necessary. - while (current_size < new_size) + if (current_size < new_size) { - p_buffer[current_size++] = value; + std::fill_n(&p_buffer[current_size], new_size - current_size, value); } current_size = new_size; } else { - // Size up? + // Size up or size down? if (new_size > current_size) { + // Up. while (current_size < new_size) { create_element(value); } } - // Size down? else if (new_size < current_size) { + // Down. while (current_size > new_size) { destroy_element(); } - } + } } } + //********************************************************************* + /// Does nothing. + //********************************************************************* + void reserve(size_t) + { + } + //********************************************************************* /// Returns a reference to the value at index 'i' ///\param i The index. @@ -400,10 +418,14 @@ namespace etl } else { + T* p = &p_buffer[0]; while (first != last) { - create_element(*first); + new (p) T(*first); + ++p; ++first; + ++current_size; + ++construct_count; } } } @@ -432,10 +454,14 @@ namespace etl } else { + T* p = &p_buffer[0]; while (n > 0) { - create_element(value); + new (p) T(value); + ++p; --n; + ++current_size; + ++construct_count; } } } @@ -497,8 +523,9 @@ namespace etl if (position != end()) { - create_element(); - std::copy_backward(position, end() - 1, end()); + T* p_last = &p_buffer[current_size - 1]; + create_element(*p_last); + std::copy_backward(position, p_last, p_last + 1); *position = value; } else @@ -516,56 +543,95 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(iterator position, size_t n, parameter_t value) + template + typename etl::enable_if::value, void>::type + insert(iterator position, size_t n, parameter_t value) { - ETL_ASSERT((current_size)+1 <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(vector_full)); - if (position == end()) + T* p_end = &p_buffer[current_size]; + + std::copy_backward(position, p_end, p_end + n); + std::fill_n(position, n, value); + + current_size += n; + } + + //********************************************************************* + /// 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. + //********************************************************************* + template + typename etl::enable_if::value, void>::type + insert(iterator position, size_t n, parameter_t value) + { + ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(vector_full)); + + U v = value; + + size_t insert_n = n; + + size_t insert_begin = std::distance(begin(), position); + size_t insert_end = insert_begin + insert_n; + size_t new_size = current_size + n; + + size_t old_move_n = new_size - insert_end; + size_t new_copy_n = insert_n; + + // Move old. + if (old_move_n > 0) { - while (n > 0) + size_t index = new_size; + T* from = &p_buffer[size() - 1]; + T* to = &p_buffer[size() - 1 + insert_n]; + + while (index > insert_end) { - create_element(value); - --n; + if (index > size()) + { + // Construct. + new (to--) U(*from--); + ++construct_count; + } + else + { + // Copy + *to-- = *from--; + } + + --index; } } - else + + // Copy new. + if (new_copy_n > 0) { - // Create copy (backwards). - size_t n_insert = n; - size_t from = size() - 1; - size_t to = from + n_insert; - size_t n_move = std::distance(position, end()); - size_t n_create_copy = std::min(n_insert, n_move); + size_t index = insert_begin; + T* begin = &p_buffer[insert_begin]; + T* end = &p_buffer[insert_end]; - for (size_t i = 0; i < n_create_copy; ++i) + while (begin != end) { - create_element_at(to--, p_buffer[from--]); + if (index > size()) + { + // Construct. + new (begin++) U(v); + ++construct_count; + } + else + { + // Copy. + *begin++ = v; + } + + ++index; } - - // Copy old. - size_t insert_index = std::distance(begin(), position); - from = insert_index; - to = from + n_insert; - size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0; - etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]); - - // Copy new. - to = insert_index; - - size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0; - size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0; - std::fill_n(&p_buffer[to], n_copy_new, value); - - // Create new. - to = size(); - - for (size_t i = 0; i < n_create_new; ++i) - { - create_element_at(to++, value); - } - - current_size += n_insert; } + + current_size += n; } //********************************************************************* @@ -576,125 +642,98 @@ namespace etl ///\param first The first element to add. ///\param last The last + 1 element to add. //********************************************************************* - template - typename etl::enable_if::value_type>::value, void>::type - insert(iterator position, TIterator first, TIterator last) + template + typename etl::enable_if::value, void>::type + insert(iterator position, TIterator first, TIterator last) { size_t count = std::distance(first, last); - ETL_ASSERT((current_size)+count <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT((current_size + count) <= MAX_SIZE, ETL_ERROR(vector_full)); - if (position == end()) - { - while (first != last) - { - p_buffer[current_size++] = *first++; - } - } - else - { - size_t insert_index = std::distance(begin(), position); - size_t n_insert = count; + U* p_end = &p_buffer[current_size]; - // Create copy (backwards). - size_t from = size() - 1; - size_t to = from + n_insert; - size_t n_move = std::distance(position, end()); - size_t n_create_copy = std::min(n_insert, n_move); - - for (size_t i = 0; i < n_create_copy; ++i) - { - p_buffer[to--] = p_buffer[from--]; - } - - // Copy old. - from = insert_index; - to = from + n_insert; - size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0; - etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]); - - // Copy new. - to = insert_index; - size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0; - size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0; - etl::copy_n(first, n_copy_new, &p_buffer[to]); - first += n_copy_new; - - // Create new. - to = size(); - for (size_t i = 0; i < n_create_new; ++i) - { - p_buffer[to++] = *first++; - } - - current_size += n_insert; - } + std::copy_backward(position, p_end, p_end + count); + std::copy(first, last, position); } - + //********************************************************************* /// Inserts a range of values to the vector. /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. - /// For non-fundamental types. + /// For fundamental and pointer types. ///\param position The position to insert before. ///\param first The first element to add. ///\param last The last + 1 element to add. //********************************************************************* - template - typename etl::enable_if::value_type>::value, void>::type - insert(iterator position, TIterator first, TIterator last) + template + typename etl::enable_if::value, void>::type + insert(iterator position, TIterator first, TIterator last) { size_t count = std::distance(first, last); - ETL_ASSERT((current_size)+count <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT((current_size + count) <= MAX_SIZE, ETL_ERROR(vector_full)); - if (position == end()) + size_t insert_n = count; + + size_t insert_begin = std::distance(begin(), position); + size_t insert_end = insert_begin + insert_n; + size_t new_size = current_size + insert_n; + + size_t old_move_n = new_size - insert_end; + size_t new_copy_n = insert_n; + + // Move old. + if (old_move_n > 0) { - while (first != last) + size_t index = new_size; + U* from = &p_buffer[size() - 1]; + U* to = &p_buffer[size() - 1 + insert_n]; + + while (index > insert_end) { - create_element(*first); - ++first; + if (index > size()) + { + // Construct. + new (to--) U(*from--); + ++construct_count; + } + else + { + // Copy + *to-- = *from--; + } + + --index; } } - else + + // Copy new. + if (new_copy_n > 0) { - size_t insert_index = std::distance(begin(), position); - size_t n_insert = count; + size_t index = insert_begin; + U* begin = &p_buffer[insert_begin]; + U* end = &p_buffer[insert_end]; - // Create copy (backwards). - size_t from = size() - 1; - size_t to = from + n_insert; - size_t n_move = std::distance(position, end()); - size_t n_create_copy = std::min(n_insert, n_move); - for (size_t i = 0; i < n_create_copy; ++i) + while (begin != end) { - create_element_at(to--, p_buffer[from--]); + if (index >= size()) + { + // Construct. + new (begin++) T(*first++); + ++construct_count; + } + else + { + // Copy. + *begin++ = *first++; + } + + ++index; } - - // Copy old. - from = insert_index; - to = from + n_insert; - size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0; - etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]); - - // Copy new. - to = insert_index; - size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0; - size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0; - etl::copy_n(first, n_copy_new, &p_buffer[to]); - first += n_copy_new; - - // Create new. - to = size(); - for (size_t i = 0; i < n_create_new; ++i) - { - create_element_at(to++, *first); - ++first; - } - - current_size += n_insert; } + + current_size += count; } - + //********************************************************************* /// Erases an element. ///\param i_element Iterator to the element. @@ -704,7 +743,7 @@ namespace etl { std::copy(i_element + 1, end(), i_element); destroy_element(); - + return i_element; } @@ -718,20 +757,27 @@ namespace etl //********************************************************************* iterator erase(iterator first, iterator last) { - std::copy(last, end(), first); - size_t n_delete = std::distance(first, last); - - if (is_simple_type::value) + if (first == begin() && last == end()) { - // Just adjust the count. - current_size -= n_delete; + clear(); } else { - // Destroy the elements left over at the end. - while (n_delete-- > 0) + std::copy(last, end(), first); + size_t n_delete = std::distance(first, last); + + if (is_simple_type::value) { - destroy_element(); + // Just adjust the count. + current_size -= n_delete; + } + else + { + // Destroy the elements left over at the end. + while (n_delete-- > 0) + { + destroy_element(); + } } } @@ -786,12 +832,22 @@ namespace etl private: + + //********************************************************************* /// Create a new element with a default value at the back. //********************************************************************* inline void create_element() { - new(&p_buffer[current_size++]) T(); + if (is_simple_type::value) + { + current_size++; + } + else + { + new (&p_buffer[current_size++]) T(); + ++construct_count; + } } //********************************************************************* @@ -799,7 +855,15 @@ namespace etl //********************************************************************* inline void create_element(parameter_t value) { - new(&p_buffer[current_size++]) T(value); + if (is_simple_type::value) + { + p_buffer[current_size++] = value; + } + else + { + new (&p_buffer[current_size++]) T(value); + ++construct_count; + } } //********************************************************************* @@ -807,15 +871,29 @@ namespace etl //********************************************************************* inline void create_element_at(size_t index, parameter_t value) { - new(&p_buffer[index]) T(value); + new (&p_buffer[index]) T(value); + ++construct_count; } //********************************************************************* /// Destroy an element at the back. //********************************************************************* - inline void destroy_element() + template + typename etl::enable_if::value, void>::type + destroy_element() { - p_buffer[--current_size].~T(); + --current_size; + } + + //********************************************************************* + /// Destroy an element at the back. + //********************************************************************* + template + typename etl::enable_if::value, void>::type + destroy_element() + { + p_buffer[--current_size].~U(); + --construct_count; } // Disable copy construction. diff --git a/src/list.h b/src/list.h index 361d1a87..b85a74b2 100644 --- a/src/list.h +++ b/src/list.h @@ -74,6 +74,14 @@ namespace etl ilist::initialise(); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~list() + { + ilist::initialise(); + } + //************************************************************************* /// Construct from size. //************************************************************************* diff --git a/src/map.h b/src/map.h index 9ec0c71e..b489e1a3 100644 --- a/src/map.h +++ b/src/map.h @@ -72,7 +72,7 @@ namespace etl map(const map& other) : imap(node_pool, MAX_SIZE) { - imap::assign(other.cbegin(), other.cend()); + imap::assign(other.cbegin(), other.cend()); } //************************************************************************* @@ -88,6 +88,14 @@ namespace etl imap::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~map() + { + imap::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* diff --git a/src/multimap.h b/src/multimap.h index 06658b4b..57299b49 100644 --- a/src/multimap.h +++ b/src/multimap.h @@ -68,7 +68,7 @@ namespace etl //************************************************************************* /// Copy constructor. //************************************************************************* - explicit multimap(const multimap& other) + multimap(const multimap& other) : imultimap(node_pool, MAX_SIZE) { imultimap::assign(other.cbegin(), other.cend()); @@ -87,6 +87,14 @@ namespace etl imultimap::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~multimap() + { + imultimap::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* diff --git a/src/multiset.h b/src/multiset.h index 0668f9a8..e3142a8a 100644 --- a/src/multiset.h +++ b/src/multiset.h @@ -68,7 +68,7 @@ namespace etl //************************************************************************* /// Copy constructor. //************************************************************************* - explicit multiset(const multiset& other) + multiset(const multiset& other) : imultiset(node_pool, MAX_SIZE) { imultiset::assign(other.cbegin(), other.cend()); @@ -87,6 +87,14 @@ namespace etl imultiset::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~multiset() + { + imultiset::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* diff --git a/src/pool.h b/src/pool.h index 5d669fc3..52eb8446 100644 --- a/src/pool.h +++ b/src/pool.h @@ -33,10 +33,12 @@ SOFTWARE. #include "alignment.h" #include "array.h" -#include "bitset.h" +#include "container.h" +#include "integral_limits.h" #include "ipool.h" #include +#include //***************************************************************************** ///\defgroup pool pool @@ -50,8 +52,8 @@ namespace etl /// A templated pool implementation that uses a fixed size pool. ///\ingroup pool //************************************************************************* - template - class pool : public ipool + template + class pool : public ipool { public: @@ -61,25 +63,30 @@ namespace etl /// Constructor //************************************************************************* pool() - : ipool(reinterpret_cast(&buffer[0]), SIZE) + : ipool(reinterpret_cast(&buffer[0]), ELEMENT_SIZE, SIZE) { } - //************************************************************************* - /// Destructor - //************************************************************************* ~pool() { - ipool::release_all(); + } private: - typedef typename ipool::Element Element; + // The pool element. + union Element + { + uint32_t next; ///< Index of the next free element. + char value[sizeof(T)]; ///< Storage for value type. + typename etl::type_with_alignment::value>::type dummy; ///< Dummy item to get correct alignment. + }; ///< The memory for the pool of objects. typename etl::aligned_storage::value>::type buffer[SIZE]; + static const uint32_t ELEMENT_SIZE = sizeof(Element); + // Should not be copied. pool(const pool&); pool& operator =(const pool&); diff --git a/src/private/deque_base.h b/src/private/deque_base.h index 79755433..cd6fe64e 100644 --- a/src/private/deque_base.h +++ b/src/private/deque_base.h @@ -39,6 +39,7 @@ SOFTWARE. #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "1" @@ -168,9 +169,10 @@ namespace etl { } - size_type current_size; ///< The current number of elements in the deque. - const size_type MAX_SIZE; ///< The maximum number of elements in the deque. - const size_type BUFFER_SIZE; ///< The number of elements in the buffer. + size_type current_size; ///< The current number of elements in the deque. + const size_type MAX_SIZE; ///< The maximum number of elements in the deque. + const size_type BUFFER_SIZE; ///< The number of elements in the buffer. + etl::debug_count construct_count; ///< Internal debugging. }; } diff --git a/src/private/forward_list_base.h b/src/private/forward_list_base.h index d11fd82e..9364a9b7 100644 --- a/src/private/forward_list_base.h +++ b/src/private/forward_list_base.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "6" @@ -111,14 +112,14 @@ namespace etl //************************************************************************* /// The node element in the forward_list. //************************************************************************* - struct Node + struct node_t { - Node() + node_t() : next(nullptr) { } - Node* next; + node_t* next; }; public: @@ -130,7 +131,7 @@ namespace etl //************************************************************************* size_type size() const { - return current_size; + return p_node_pool->size(); } //************************************************************************* @@ -146,7 +147,7 @@ namespace etl //************************************************************************* bool empty() const { - return current_size == 0; + return p_node_pool->empty(); } //************************************************************************* @@ -154,7 +155,7 @@ namespace etl //************************************************************************* bool full() const { - return current_size == MAX_SIZE; + return p_node_pool->full(); } //************************************************************************* @@ -163,7 +164,7 @@ namespace etl //************************************************************************* size_t available() const { - return max_size() - size(); + return p_node_pool->available(); } //************************************************************************* @@ -176,9 +177,9 @@ namespace etl return; } - Node* p_last = &start_node; - Node* p_current = p_last->next; - Node* p_next = p_current->next; + node_t* p_last = &start_node; + node_t* p_current = p_last->next; + node_t* p_next = p_current->next; p_current->next = nullptr; @@ -199,9 +200,8 @@ namespace etl //************************************************************************* /// The constructor that is called from derived classes. //************************************************************************* - forward_list_base(size_type max_size) - : next_free(0), - current_size(0), + forward_list_base(etl::ipool& node_pool, size_type max_size) + : p_node_pool(&node_pool), MAX_SIZE(max_size) { } @@ -209,7 +209,7 @@ namespace etl //************************************************************************* /// Get the head node. //************************************************************************* - Node& get_head() + node_t& get_head() { return *start_node.next; } @@ -217,7 +217,7 @@ namespace etl //************************************************************************* /// Get the head node. //************************************************************************* - const Node& get_head() const + const node_t& get_head() const { return *start_node.next; } @@ -225,17 +225,13 @@ namespace etl //************************************************************************* /// Insert a node. //************************************************************************* - void insert_node_after(Node& position, Node& node) + inline void insert_node_after(node_t& position, node_t& node) { // Connect to the forward_list. - node.next = position.next; - + join(&node, position.next); join(&position, &node); - - // One more. - ++current_size; } - + //************************************************************************* /// Is the forward_list a trivial length? //************************************************************************* @@ -247,15 +243,15 @@ namespace etl //************************************************************************* /// Join two nodes. //************************************************************************* - void join(Node* left, Node* right) + void join(node_t* left, node_t* right) { left->next = right; } - Node start_node; ///< The node that acts as the forward_list start. - size_type next_free; ///< The index of the next free node. - size_type current_size; ///< The number of items in the list. - const size_type MAX_SIZE; ///< The maximum size of the forward_list. + 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::debug_count construct_count; ///< Internal debugging. }; } diff --git a/src/private/list_base.h b/src/private/list_base.h index 1b363a4b..2b3ca1e1 100644 --- a/src/private/list_base.h +++ b/src/private/list_base.h @@ -36,8 +36,10 @@ SOFTWARE. #define __ETL_LIST_BASE__ #include +#include "pool.h" #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "7" @@ -141,7 +143,7 @@ namespace etl //*********************************************************************** /// Reverses the previous & next pointers. //*********************************************************************** - void reverse() + inline void reverse() { std::swap(previous, next); } @@ -163,21 +165,18 @@ namespace etl node_t* p_node = terminal_node.next; while (p_node != &terminal_node) - { - p_node->reverse(); - p_node = p_node->previous; // Now we've reversed it, we must go to the previous node. + { + node_t* p_temp = p_node->previous; + p_node->previous = p_node->next; + p_node->next = p_temp; + p_node = p_node->previous; } // Terminal node. - p_node->reverse(); - } - - //************************************************************************* - /// Gets the size of the list. - //************************************************************************* - size_type size() const - { - return current_size; + node_t* p_temp = p_node->previous; + p_node->previous = p_node->next; + p_node->next = p_temp; + p_node = p_node->previous; } //************************************************************************* @@ -188,12 +187,20 @@ namespace etl return MAX_SIZE; } + //************************************************************************* + /// Gets the size of the list. + //************************************************************************* + size_type size() const + { + return p_node_pool->size(); + } + //************************************************************************* /// Checks to see if the list is empty. //************************************************************************* bool empty() const { - return current_size == 0; + return p_node_pool->empty(); } //************************************************************************* @@ -201,7 +208,7 @@ namespace etl //************************************************************************* bool full() const { - return current_size == MAX_SIZE; + return p_node_pool->size() == MAX_SIZE; } //************************************************************************* @@ -213,6 +220,15 @@ namespace etl return max_size() - size(); } + //************************************************************************* + /// Is the list a trivial length? + //************************************************************************* + bool is_trivial_list() const + { + return (size() < 2); + } + + protected: //************************************************************************* @@ -255,17 +271,6 @@ namespace etl // Connect to the list. join(*position.previous, node); join(node, position); - - // One more. - ++current_size; - } - - //************************************************************************* - /// Is the list a trivial length? - //************************************************************************* - bool is_trivial_list() const - { - return (size() < 2); } //************************************************************************* @@ -280,17 +285,18 @@ namespace etl //************************************************************************* /// The constructor that is called from derived classes. //************************************************************************* - list_base(size_type max_size) - : current_size(0), + list_base(etl::ipool& node_pool, + size_type max_size) + : p_node_pool(&node_pool), MAX_SIZE(max_size) { } - - node_t terminal_node; ///< The node that acts as the list start and end. - size_type current_size; ///< The number of the used nodes. - const size_type MAX_SIZE; ///< The maximum size of the list. + etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. + node_t terminal_node; ///< The node that acts as the list start and end. + const size_type MAX_SIZE; ///< The maximum size of the list. + etl::debug_count construct_count; ///< Internal debugging. }; } diff --git a/src/private/map_base.h b/src/private/map_base.h index 2ac3256f..d10df500 100644 --- a/src/private/map_base.h +++ b/src/private/map_base.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "8" @@ -183,6 +184,11 @@ namespace etl { } + ~Node() + { + + } + //*********************************************************************** /// Marks the node as a leaf. //*********************************************************************** @@ -419,6 +425,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type MAX_SIZE; ///< The maximum size of the map. Node* root_node; ///< The node that acts as the map root. + etl::debug_count construct_count; }; } diff --git a/src/private/multimap_base.h b/src/private/multimap_base.h index 39afb67c..845d6241 100644 --- a/src/private/multimap_base.h +++ b/src/private/multimap_base.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "9" @@ -580,6 +581,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type MAX_SIZE; ///< The maximum size of the map. Node* root_node; ///< The node that acts as the multimap root. + etl::debug_count construct_count; }; } diff --git a/src/private/multiset_base.h b/src/private/multiset_base.h index cad7120c..d7573d65 100644 --- a/src/private/multiset_base.h +++ b/src/private/multiset_base.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "10" @@ -579,6 +580,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type MAX_SIZE; ///< The maximum size of the set. Node* root_node; ///< The node that acts as the multiset root. + etl::debug_count construct_count; }; } diff --git a/src/private/pool_base.h b/src/private/pool_base.h index 020a2aad..b53b26bb 100644 --- a/src/private/pool_base.h +++ b/src/private/pool_base.h @@ -93,47 +93,7 @@ namespace etl { public: - //************************************************************************* - /// Returns the maximum number of items in the pool. - //************************************************************************* - size_t max_size() const - { - return MAX_SIZE; - } - //************************************************************************* - /// Returns the number of free items in the pool. - //************************************************************************* - size_t available() const - { - return MAX_SIZE - items_allocated; - } - - //************************************************************************* - /// Returns the number of allocated items in the pool. - //************************************************************************* - size_t size() const - { - return items_allocated; - } - - //************************************************************************* - /// Checks to see if there are no allocated items in the pool. - /// \return true if there are none allocated. - //************************************************************************* - bool empty() const - { - return items_allocated == 0; - } - - //************************************************************************* - /// Checks to see if there are no free items in the pool. - /// \return true if there are none free. - //************************************************************************* - bool full() const - { - return items_allocated == MAX_SIZE; - } protected: @@ -142,16 +102,11 @@ namespace etl //************************************************************************* pool_base(size_t max_size) : next_free(0), - items_allocated(0), - items_initialised(0), - MAX_SIZE(max_size) + { } - size_t next_free; ///< The next free slot in the block. - size_t items_allocated; ///< The number of items allocated. - size_t items_initialised; ///< The number of items that have been initialised with an index; - const size_t MAX_SIZE; ///< The maximum number of objects that can be allocated. + }; } diff --git a/src/private/queue_base.h b/src/private/queue_base.h index c7a0aadc..78627097 100644 --- a/src/private/queue_base.h +++ b/src/private/queue_base.h @@ -39,6 +39,7 @@ SOFTWARE. #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "13" @@ -153,10 +154,11 @@ namespace etl { } - size_type in; ///< Where to input new data. - size_type out; ///< Where to get the oldest data. - size_type current_size; ///< The number of items in the queue. - const size_type MAX_SIZE; ///< The maximum number of items in the queue. + size_type in; ///< Where to input new data. + size_type out; ///< Where to get the oldest data. + size_type current_size; ///< The number of items in the queue. + const size_type MAX_SIZE; ///< The maximum number of items in the queue. + etl::debug_count construct_count; ///< For internal debugging purposes. }; } diff --git a/src/private/set_base.h b/src/private/set_base.h index a4eab8c2..0fa929dd 100644 --- a/src/private/set_base.h +++ b/src/private/set_base.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #define ETL_FILE "14" @@ -419,6 +420,7 @@ namespace etl size_type current_size; ///< The number of the used nodes. const size_type MAX_SIZE; ///< The maximum size of the set. Node* root_node; ///< The node that acts as the set root. + etl::debug_count construct_count; }; } diff --git a/src/private/stack_base.h b/src/private/stack_base.h index e3e6c556..60807a30 100644 --- a/src/private/stack_base.h +++ b/src/private/stack_base.h @@ -39,6 +39,7 @@ SOFTWARE. #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #define ETL_FILE "15" @@ -152,9 +153,10 @@ namespace etl { } - size_type top_index; ///< The index of the top of the stack. - size_type current_size; ///< The number of items in the stack. - const size_type MAX_SIZE; ///< The maximum number of items in the stack. + size_type top_index; ///< The index of the top of the stack. + size_type current_size; ///< The number of items in the stack. + const size_type MAX_SIZE; ///< The maximum number of items in the stack. + etl::debug_count construct_count; ///< For internal debugging purposes. }; } diff --git a/src/private/vector_base.h b/src/private/vector_base.h index 4c78b41b..69c5494e 100644 --- a/src/private/vector_base.h +++ b/src/private/vector_base.h @@ -39,6 +39,7 @@ SOFTWARE. #include "../exception.h" #include "../error_handler.h" +#include "../debug_count.h" #define ETL_FILE "17" @@ -175,8 +176,9 @@ namespace etl { } - size_type current_size; ///(node_pool, MAX_SIZE) { iset::assign(other.cbegin(), other.cend()); @@ -88,6 +88,14 @@ namespace etl iset::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~set() + { + iset::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* diff --git a/src/unordered_map.h b/src/unordered_map.h index e4c1f1ea..dcc34abf 100644 --- a/src/unordered_map.h +++ b/src/unordered_map.h @@ -38,7 +38,7 @@ SOFTWARE. #include "iunordered_map.h" #include "container.h" #include "pool.h" -#include "vector.h" +#include "array.h" #include "intrusive_forward_list.h" #include "hash.h" @@ -53,7 +53,7 @@ namespace etl //************************************************************************* /// A templated unordered_map implementation that uses a fixed size buffer. //************************************************************************* - template , typename TKeyEqual = std::equal_to > + template , typename TKeyEqual = std::equal_to > class unordered_map : public iunordered_map { private: @@ -62,13 +62,14 @@ namespace etl public: - static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_BUCKETS = MAX_BUCKETS_; //************************************************************************* /// Default constructor. //************************************************************************* unordered_map() - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS_) { base::initialise(); } @@ -77,9 +78,9 @@ namespace etl /// Copy constructor. //************************************************************************* unordered_map(const unordered_map& other) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS_) { - base::assign(other.cbegin(), other.cend()); + base::assign(other.cbegin(), other.cend()); } //************************************************************************* @@ -90,11 +91,19 @@ namespace etl //************************************************************************* template unordered_map(TIterator first, TIterator last) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS_) { base::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~unordered_map() + { + base::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -115,7 +124,7 @@ namespace etl etl::pool node_pool; /// The buckets of node lists. - etl::vector, MAX_SIZE> buckets; + etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; } diff --git a/src/unordered_multimap.h b/src/unordered_multimap.h index 14746fee..6c264bee 100644 --- a/src/unordered_multimap.h +++ b/src/unordered_multimap.h @@ -53,7 +53,7 @@ namespace etl //************************************************************************* /// A templated unordered_multimap implementation that uses a fixed size buffer. //************************************************************************* - template , typename TKeyEqual = std::equal_to > + template , typename TKeyEqual = std::equal_to > class unordered_multimap : public iunordered_multimap { private: @@ -62,13 +62,14 @@ namespace etl public: - static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_BUCKETS = MAX_BUCKETS_; //************************************************************************* /// Default constructor. //************************************************************************* unordered_multimap() - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::initialise(); } @@ -77,7 +78,7 @@ namespace etl /// Copy constructor. //************************************************************************* unordered_multimap(const unordered_multimap& other) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::assign(other.cbegin(), other.cend()); } @@ -90,11 +91,19 @@ namespace etl //************************************************************************* template unordered_multimap(TIterator first, TIterator last) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~unordered_multimap() + { + base::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -115,7 +124,7 @@ namespace etl etl::pool node_pool; /// The buckets of node lists. - etl::vector, MAX_SIZE> buckets; + etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; } diff --git a/src/unordered_multiset.h b/src/unordered_multiset.h index c4e1ce37..f061b1ae 100644 --- a/src/unordered_multiset.h +++ b/src/unordered_multiset.h @@ -53,7 +53,7 @@ namespace etl //************************************************************************* /// A templated unordered_multiset implementation that uses a fixed size buffer. //************************************************************************* - template , typename TKeyEqual = std::equal_to > + template , typename TKeyEqual = std::equal_to > class unordered_multiset : public iunordered_multiset { private: @@ -63,12 +63,14 @@ namespace etl public: static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_BUCKETS = MAX_BUCKETS_; + //************************************************************************* /// Default constructor. //************************************************************************* unordered_multiset() - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::initialise(); } @@ -77,7 +79,7 @@ namespace etl /// Copy constructor. //************************************************************************* unordered_multiset(const unordered_multiset& other) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::assign(other.cbegin(), other.cend()); } @@ -90,11 +92,19 @@ namespace etl //************************************************************************* template unordered_multiset(TIterator first, TIterator last) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~unordered_multiset() + { + base::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -115,7 +125,7 @@ namespace etl etl::pool node_pool; /// The buckets of node lists. - etl::vector, MAX_SIZE> buckets; + etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; } diff --git a/src/unordered_set.h b/src/unordered_set.h index e9171566..ac5912e3 100644 --- a/src/unordered_set.h +++ b/src/unordered_set.h @@ -53,7 +53,7 @@ namespace etl //************************************************************************* /// A templated unordered_set implementation that uses a fixed size buffer. //************************************************************************* - template , typename TKeyEqual = std::equal_to > + template , typename TKeyEqual = std::equal_to > class unordered_set : public iunordered_set { private: @@ -62,13 +62,14 @@ namespace etl public: - static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_SIZE = MAX_SIZE_; + static const size_t MAX_BUCKETS = MAX_BUCKETS_; //************************************************************************* /// Default constructor. //************************************************************************* unordered_set() - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::initialise(); } @@ -77,7 +78,7 @@ namespace etl /// Copy constructor. //************************************************************************* unordered_set(const unordered_set& other) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::assign(other.cbegin(), other.cend()); } @@ -90,11 +91,19 @@ namespace etl //************************************************************************* template unordered_set(TIterator first, TIterator last) - : base(node_pool, buckets) + : base(node_pool, buckets, MAX_BUCKETS) { base::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~unordered_set() + { + base::initialise(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -115,7 +124,7 @@ namespace etl etl::pool node_pool; /// The buckets of node lists. - etl::vector, MAX_SIZE> buckets; + etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; } From a470d4f8c90e981dac8c825c04784cec9c3e113a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:08:16 +0000 Subject: [PATCH 119/168] Minor layout changes --- src/variant.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/variant.h b/src/variant.h index 767432a8..99641bbe 100644 --- a/src/variant.h +++ b/src/variant.h @@ -711,7 +711,7 @@ namespace etl { STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); - new(static_cast(data)) T(value); + new (static_cast(data)) T(value); type_id = Type_Id_Lookup::type_id; } @@ -723,14 +723,14 @@ namespace etl { switch (other.type_id) { - case 0: new(static_cast(data)) T1(other.get()); break; - case 1: new(static_cast(data)) T2(other.get()); break; - case 2: new(static_cast(data)) T3(other.get()); break; - case 3: new(static_cast(data)) T4(other.get()); break; - case 4: new(static_cast(data)) T5(other.get()); break; - case 5: new(static_cast(data)) T6(other.get()); break; - case 6: new(static_cast(data)) T7(other.get()); break; - case 7: new(static_cast(data)) T8(other.get()); break; + case 0: new (static_cast(data)) T1(other.get()); break; + case 1: new (static_cast(data)) T2(other.get()); break; + case 2: new (static_cast(data)) T3(other.get()); break; + case 3: new (static_cast(data)) T4(other.get()); break; + case 4: new (static_cast(data)) T5(other.get()); break; + case 5: new (static_cast(data)) T6(other.get()); break; + case 6: new (static_cast(data)) T7(other.get()); break; + case 7: new (static_cast(data)) T8(other.get()); break; default: break; } @@ -747,7 +747,7 @@ namespace etl STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); destruct_current(); - new(static_cast(data)) T(value); + new (static_cast(data)) T(value); type_id = Type_Id_Lookup::type_id; return *this; @@ -765,14 +765,14 @@ namespace etl switch (other.type_id) { - case 0: new(static_cast(data)) T1(other.get()); break; - case 1: new(static_cast(data)) T2(other.get()); break; - case 2: new(static_cast(data)) T3(other.get()); break; - case 3: new(static_cast(data)) T4(other.get()); break; - case 4: new(static_cast(data)) T5(other.get()); break; - case 5: new(static_cast(data)) T6(other.get()); break; - case 6: new(static_cast(data)) T7(other.get()); break; - case 7: new(static_cast(data)) T8(other.get()); break; + case 0: new (static_cast(data)) T1(other.get()); break; + case 1: new (static_cast(data)) T2(other.get()); break; + case 2: new (static_cast(data)) T3(other.get()); break; + case 3: new (static_cast(data)) T4(other.get()); break; + case 4: new (static_cast(data)) T5(other.get()); break; + case 5: new (static_cast(data)) T6(other.get()); break; + case 6: new (static_cast(data)) T7(other.get()); break; + case 7: new (static_cast(data)) T8(other.get()); break; default: break; } From 0605dfd9576926e336aca48c4cf3c3588c21b333 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:08:41 +0000 Subject: [PATCH 120/168] Prefix macros with ETL_ --- src/endian.h | 10 +++++----- src/enum_type.h | 4 ++-- src/radix.h | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/endian.h b/src/endian.h index 35ad8d34..c5600534 100644 --- a/src/endian.h +++ b/src/endian.h @@ -54,11 +54,11 @@ namespace etl native }; - DECLARE_ENUM_TYPE(endian, int) - ENUM_TYPE(little, "little") - ENUM_TYPE(big, "big") - ENUM_TYPE(native, "native") - END_ENUM_TYPE + ETL_DECLARE_ENUM_TYPE(endian, int) + ETL_ENUM_TYPE(little, "little") + ETL_ENUM_TYPE(big, "big") + ETL_ENUM_TYPE(native, "native") + ETL_END_ENUM_TYPE }; //*************************************************************************** diff --git a/src/enum_type.h b/src/enum_type.h index ca0c9f55..82415064 100644 --- a/src/enum_type.h +++ b/src/enum_type.h @@ -72,9 +72,9 @@ SOFTWARE. /// /// std::cout << "Direction = " << direction.c_str(); // Prints "Direction = North" ///\endcode -/// If a conversion to a string is not required then the 'ENUM_TYPE' declaration may be omitted. +/// If a conversion to a string is not required then the 'ETL_ENUM_TYPE' declaration may be omitted. /// In that case the c_str() function will return a "?". This will also be the case for any -/// enumeration value that does not have an ENUM_TYPE entry. +/// enumeration value that does not have an ETL_ENUM_TYPE entry. ///\ingroup utilities //***************************************************************************** diff --git a/src/radix.h b/src/radix.h index 48c8ac1c..a2a1a8d9 100644 --- a/src/radix.h +++ b/src/radix.h @@ -53,13 +53,13 @@ namespace etl hex = 16 }; - DECLARE_ENUM_TYPE(radix, uint_least8_t) - ENUM_TYPE(undefined, "undefined") - ENUM_TYPE(binary, "binary") - ENUM_TYPE(octal, "octal") - ENUM_TYPE(decimal, "decimal") - ENUM_TYPE(hex, "hex") - END_ENUM_TYPE + ETL_DECLARE_ENUM_TYPE(radix, uint_least8_t) + ETL_ENUM_TYPE(undefined, "undefined") + ETL_ENUM_TYPE(binary, "binary") + ETL_ENUM_TYPE(octal, "octal") + ETL_ENUM_TYPE(decimal, "decimal") + ETL_ENUM_TYPE(hex, "hex") + ETL_END_ENUM_TYPE }; } From 37efd986dee813d396b1f6a75a33b5a31291cc68 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:09:01 +0000 Subject: [PATCH 121/168] Changed pool_base to ipool --- src/file_error_numbers.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_error_numbers.txt b/src/file_error_numbers.txt index 48b14101..fc8953bc 100644 --- a/src/file_error_numbers.txt +++ b/src/file_error_numbers.txt @@ -8,7 +8,7 @@ 8 map_base 9 multimap_base 10 multiset_base -11 pool_base +11 ipool 12 ipriority_queue 13 queue_base 14 set_base From 23d248e0ac6497df0f9171d729259cac1451cada Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:09:20 +0000 Subject: [PATCH 122/168] Minor layout changes --- src/largest.h | 88 +++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/largest.h b/src/largest.h index 9eae7abd..bb4ddce9 100644 --- a/src/largest.h +++ b/src/largest.h @@ -38,24 +38,24 @@ SOFTWARE. namespace etl { - //*************************************************************************** - /// Template to determine the largest type and size. + //*************************************************************************** + /// Template to determine the largest type and size. /// Supports up to 16 types. - /// Defines 'value_type' which is the type of the largest parameter. - /// Defines 'size' which is the size of the largest parameter. + /// Defines 'value_type' which is the type of the largest parameter. + /// Defines 'size' which is the size of the largest parameter. ///\ingroup largest - //*************************************************************************** - template - struct largest_type - { - private: + //*************************************************************************** + template + struct largest_type + { + private: // Declaration. - template - struct choose_type; + template + struct choose_type; // Specialisation for 'true'. // Defines 'type' as 'TrueType'. @@ -65,49 +65,49 @@ namespace etl typedef TrueType type; }; - // Specialisation for 'false'. + // Specialisation for 'false'. // Defines 'type' as 'FalseType'. template struct choose_type - { + { typedef FalseType type; - }; + }; - public: + public: - // Define 'largest_other' as 'largest_type' with all but the first parameter. - typedef typename largest_type::type largest_other; + // Define 'largest_other' as 'largest_type' with all but the first parameter. + typedef typename largest_type::type largest_other; - // Set 'type' to be the largest of the first parameter and any of the others. + // Set 'type' to be the largest of the first parameter and any of the others. // This is recursive. typedef typename choose_type<(sizeof(T1) > sizeof(largest_other)), // Boolean - T1, // TrueType - largest_other> // FalseType - ::type type; // The largest type of the two. + T1, // TrueType + largest_other> // FalseType + ::type type; // The largest type of the two. - // The size of the largest type. - enum - { - size = sizeof(type) - }; - }; + // The size of the largest type. + enum + { + size = sizeof(type) + }; + }; //*************************************************************************** - // Specialisation for one template parameter. - //*************************************************************************** - template - struct largest_type - { - typedef T1 type; + // Specialisation for one template parameter. + //*************************************************************************** + template + struct largest_type + { + typedef T1 type; - enum - { - size = sizeof(type) - }; - }; + enum + { + size = sizeof(type) + }; + }; //*************************************************************************** /// Template to determine the largest alignment. From cd2c5c22ee687907a3a2b8bc1c32f87c4d536c2c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:09:34 +0000 Subject: [PATCH 123/168] Minor layout changes --- src/optional.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/optional.h b/src/optional.h index 7795a8c8..d0787782 100644 --- a/src/optional.h +++ b/src/optional.h @@ -128,7 +128,7 @@ namespace etl { if (valid) { - new (storage.template get_address()) T(other.value()); + new (storage.template get_address()) T(other.value()); } } @@ -137,7 +137,7 @@ namespace etl //*************************************************************************** optional(const T& value) { - new (storage.template get_address()) T(value); + new (storage.template get_address()) T(value); valid = true; } @@ -186,7 +186,7 @@ namespace etl } else { - new (storage.template get_address()) T(other.value()); + new (storage.template get_address()) T(other.value()); valid = true; } } @@ -206,7 +206,7 @@ namespace etl } else { - new (storage.template get_address()) T(value); + new (storage.template get_address()) T(value); valid = true; } From b87a9f50a169ddc04ccdccf06796526c548a8877 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 31 Jan 2017 21:10:12 +0000 Subject: [PATCH 124/168] New class for internal container pool debugging --- src/debug_count.h | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/debug_count.h diff --git a/src/debug_count.h b/src/debug_count.h new file mode 100644 index 00000000..ac545f86 --- /dev/null +++ b/src/debug_count.h @@ -0,0 +1,113 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_DEBUG_COUNT__ +#define __ETL_DEBUG_COUNT__ + +#include +#include + +///\defgroup debug_count debug count +///\ingroup utilities + +namespace etl +{ + //*************************************************************************** + /// Used to count instances. + /// Asserts if the count is decremented below zero. + /// Asserts if the count is not zero when destructed. + /// Does nothing in a non-debug build. + ///\ingroup reference + //*************************************************************************** + class debug_count + { + public: + +#if defined(_DEBUG) || defined(DEBUG) + inline debug_count() + : count(0) + { + } + + inline ~debug_count() + { + assert(count == 0); + } + + inline debug_count& operator ++() + { + ++count; + return *this; + } + + inline debug_count& operator --() + { + --count; + assert(count >= 0); + return *this; + } + + inline operator int32_t() + { + return count; + } + + private: + + int32_t count; +#else + inline debug_count() + { + } + + inline ~debug_count() + { + } + + inline debug_count& operator ++() + { + return *this; + } + + inline debug_count& operator --() + { + return *this; + } + + inline operator int32_t() + { + return 0; + } +#endif + }; +} + +#endif + From 841e8db73bea58ac37c8b2f782a74fb62c9bbf6f Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 1 Feb 2017 08:26:22 +0000 Subject: [PATCH 125/168] Remove unused class --- src/private/pool_base.h | 116 ---------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/private/pool_base.h diff --git a/src/private/pool_base.h b/src/private/pool_base.h deleted file mode 100644 index b53b26bb..00000000 --- a/src/private/pool_base.h +++ /dev/null @@ -1,116 +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. -******************************************************************************/ - -#ifndef __ETL_IN_IPOOL_H__ -#error This header is a private element of etl::pool & etl::ipool -#endif - -#ifndef __ETL_POOL_BASE__ -#define __ETL_POOL_BASE__ - -#include - -#include "../exception.h" -#include "../error_handler.h" -#include "../error_handler.h" - -#undef ETL_FILE -#define ETL_FILE "11" - -namespace etl -{ - //*************************************************************************** - /// The base class for pool exceptions. - ///\ingroup pool - //*************************************************************************** - class pool_exception : public exception - { - public: - - pool_exception(string_type what, string_type file_name, numeric_type line_number) - : exception(what, file_name, line_number) - {} - }; - - //*************************************************************************** - /// The exception thrown when the pool has no more free items. - ///\ingroup pool - //*************************************************************************** - class pool_no_allocation : public pool_exception - { - public: - - explicit pool_no_allocation(string_type file_name, numeric_type line_number) - : pool_exception(ETL_ERROR_TEXT("pool:allocation", ETL_FILE"A"), file_name, line_number) - {} - }; - - //*************************************************************************** - /// The exception thrown when an object is released which does not belong to the pool. - ///\ingroup pool - //*************************************************************************** - class pool_object_not_in_pool : public pool_exception - { - public: - - pool_object_not_in_pool(string_type file_name, numeric_type line_number) - : pool_exception(ETL_ERROR_TEXT("pool:notinpool", ETL_FILE"B"), file_name, line_number) - {} - }; - - //************************************************************************* - /// The base class for all templated pool types. - ///\ingroup pool - //************************************************************************* - class pool_base - { - public: - - - - protected: - - //************************************************************************* - /// Constructor - //************************************************************************* - pool_base(size_t max_size) - : next_free(0), - - { - } - - - }; -} - -#undef ETL_FILE - -#endif - From eab150e4e62e9c41bcd3cd79940c153a060408a2 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 6 Feb 2017 10:19:56 +0000 Subject: [PATCH 126/168] New 'unitialized' fill and copy algorithms. --- src/memory.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/memory.h diff --git a/src/memory.h b/src/memory.h new file mode 100644 index 00000000..4ee02807 --- /dev/null +++ b/src/memory.h @@ -0,0 +1,98 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_MEMORY__ +#define __ETL_MEMORY__ + +#include + +///\defgroup memory memory +///\ingroup etl +namespace etl +{ + //***************************************************************************** + /// Fills uninitailised memory with N values. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_fill_n(TIterator o_begin, TSize count, const T& value) + { + return etl::uninitialized_fill(o_begin, o_begin + count, value); + } + + //***************************************************************************** + /// Fills uninitailised memory range with a value. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_fill(TIterator o_begin, TIterator o_end, const T& value) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(&*o_begin))) value_type(value); + ++o_begin; + } + + return o_begin; + } + + //***************************************************************************** + /// Copies N objects to uninitailised memory. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_copy_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin) + { + return etl::uninitialized_copy(i_begin, i_begin + count, o_begin); + } + + //***************************************************************************** + /// Copies a range of objects to uninitailised memory. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) + { + typedef typename std::iterator_traits::value_type value_type; + + while (i_begin != i_end) + { + ::new (static_cast(&*o_begin))) value_type(*i_begin); + ++i_begin + ++o_begin + } + + return o_begin; + } +} + +#endif \ No newline at end of file From 87c54f255a79f34292d9b39b6e4d534e33c70fc2 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 13 Feb 2017 10:55:22 +0000 Subject: [PATCH 127/168] Fix various compilation errors. Added variants with debug count parameter. --- src/memory.h | 103 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 22 deletions(-) diff --git a/src/memory.h b/src/memory.h index 4ee02807..c858194b 100644 --- a/src/memory.h +++ b/src/memory.h @@ -38,17 +38,7 @@ SOFTWARE. namespace etl { //***************************************************************************** - /// Fills uninitailised memory with N values. - ///\ingroup memory - //***************************************************************************** - template - TIterator uninitialized_fill_n(TIterator o_begin, TSize count, const T& value) - { - return etl::uninitialized_fill(o_begin, o_begin + count, value); - } - - //***************************************************************************** - /// Fills uninitailised memory range with a value. + /// Fills uninitialised memory range with a value. ///\ingroup memory //***************************************************************************** template @@ -58,7 +48,7 @@ namespace etl while (o_begin != o_end) { - ::new (static_cast(&*o_begin))) value_type(value); + ::new (static_cast(&*o_begin)) value_type(value); ++o_begin; } @@ -66,33 +56,102 @@ namespace etl } //***************************************************************************** - /// Copies N objects to uninitailised memory. + /// Fills uninitialised memory range with a value. ///\ingroup memory //***************************************************************************** - template - TIterator uninitialized_copy_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin) + template + TIterator uninitialized_fill(TIterator o_begin, TIterator o_end, const T& value, TCounter& count) { - return etl::uninitialized_copy(i_begin, i_begin + count, o_begin); + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(&*o_begin)) value_type(value); + ++o_begin; + ++count; + } + + return o_begin; } //***************************************************************************** - /// Copies a range of objects to uninitailised memory. + /// Fills uninitialised memory with N values. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_fill_n(TIterator o_begin, TSize n, const T& value) + { + return etl::uninitialized_fill(o_begin, o_begin + n, value); + } + + //***************************************************************************** + /// Fills uninitialised memory with N values. + ///\ingroup memory + //***************************************************************************** + template + TIterator uninitialized_fill_n(TIterator o_begin, TSize n, const T& value, TCounter& count) + { + return etl::uninitialized_fill(o_begin, o_begin + n, value, count); + } + + //***************************************************************************** + /// Copies a range of objects to uninitialised memory. ///\ingroup memory //***************************************************************************** template - TIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) + TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { typedef typename std::iterator_traits::value_type value_type; while (i_begin != i_end) { - ::new (static_cast(&*o_begin))) value_type(*i_begin); - ++i_begin - ++o_begin + ::new (static_cast(&*o_begin)) value_type(*i_begin); + ++i_begin; + ++o_begin; } return o_begin; } + + //***************************************************************************** + /// Copies a range of objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) + { + typedef typename std::iterator_traits::value_type value_type; + + while (i_begin != i_end) + { + ::new (static_cast(&*o_begin)) value_type(*i_begin); + ++i_begin; + ++o_begin; + ++count; + } + + return o_begin; + } + + //***************************************************************************** + /// Copies N objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin) + { + return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); + } + + //***************************************************************************** + /// Copies N objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) + { + return etl::uninitialized_copy(i_begin, i_begin + n, o_begin, count); + } } -#endif \ No newline at end of file +#endif From 33223405e93dfd4a417716db54aac9f0b84e8600 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 14 Feb 2017 10:29:00 +0000 Subject: [PATCH 128/168] Added more algorithms from STL's --- src/memory.h | 256 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 242 insertions(+), 14 deletions(-) diff --git a/src/memory.h b/src/memory.h index c858194b..0fba9d67 100644 --- a/src/memory.h +++ b/src/memory.h @@ -37,18 +37,28 @@ SOFTWARE. ///\ingroup etl namespace etl { + //***************************************************************************** + /// Gets the address of an object. + ///\ingroup memory + //***************************************************************************** + template + T* addressof(T& t) + { + return reinterpret_cast(&const_cast(reinterpret_cast(t))); + } + //***************************************************************************** /// Fills uninitialised memory range with a value. ///\ingroup memory //***************************************************************************** - template - TIterator uninitialized_fill(TIterator o_begin, TIterator o_end, const T& value) + template + TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value) { - typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { - ::new (static_cast(&*o_begin)) value_type(value); + ::new (static_cast(etl::addressof(*o_begin))) value_type(value); ++o_begin; } @@ -57,16 +67,17 @@ namespace etl //***************************************************************************** /// Fills uninitialised memory range with a value. + /// Debug counter version. ///\ingroup memory //***************************************************************************** - template - TIterator uninitialized_fill(TIterator o_begin, TIterator o_end, const T& value, TCounter& count) + template + TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { - typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { - ::new (static_cast(&*o_begin)) value_type(value); + ::new (static_cast(etl::addressof(*o_begin))) value_type(value); ++o_begin; ++count; } @@ -78,18 +89,19 @@ namespace etl /// Fills uninitialised memory with N values. ///\ingroup memory //***************************************************************************** - template - TIterator uninitialized_fill_n(TIterator o_begin, TSize n, const T& value) + template + TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value) { return etl::uninitialized_fill(o_begin, o_begin + n, value); } //***************************************************************************** /// Fills uninitialised memory with N values. + /// Debug counter version. ///\ingroup memory //***************************************************************************** - template - TIterator uninitialized_fill_n(TIterator o_begin, TSize n, const T& value, TCounter& count) + template + TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) { return etl::uninitialized_fill(o_begin, o_begin + n, value, count); } @@ -105,7 +117,7 @@ namespace etl while (i_begin != i_end) { - ::new (static_cast(&*o_begin)) value_type(*i_begin); + ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); ++i_begin; ++o_begin; } @@ -115,6 +127,7 @@ namespace etl //***************************************************************************** /// Copies a range of objects to uninitialised memory. + /// Debug counter version. ///\ingroup memory //***************************************************************************** template @@ -124,7 +137,7 @@ namespace etl while (i_begin != i_end) { - ::new (static_cast(&*o_begin)) value_type(*i_begin); + ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); ++i_begin; ++o_begin; ++count; @@ -145,6 +158,7 @@ namespace etl //***************************************************************************** /// Copies N objects to uninitialised memory. + /// Debug counter version. ///\ingroup memory //***************************************************************************** template @@ -152,6 +166,220 @@ namespace etl { return etl::uninitialized_copy(i_begin, i_begin + n, o_begin, count); } + + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type; + ++o_begin; + } + } + + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type; + ++o_begin; + ++count; + } + } + + //***************************************************************************** + /// Default initialises N objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) + { + TOutputIterator o_end = o_begin + n; + + etl::uninitialized_default_construct(o_begin, o_end); + + return o_end; + } + + //***************************************************************************** + /// Default initialises N objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) + { + TOutputIterator o_end = o_begin + n; + + etl::uninitialized_default_construct(o_begin, o_end, count); + + return o_end; + } + + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type(); + ++o_begin; + } + } + + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type(); + ++o_begin; + ++count; + } + } + + //***************************************************************************** + /// Default initialises N objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n) + { + TOutputIterator o_end = o_begin + n; + + etl::uninitialized_value_construct(o_begin, o_end); + + return o_end; + } + + //***************************************************************************** + /// Default initialises N objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) + { + TOutputIterator o_end = o_begin + n; + + etl::uninitialized_value_construct(o_begin, o_end, count); + + return o_end; + } + + //***************************************************************************** + /// Destroys an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void destroy_at(T* p) + { + p->~T(); + } + + //***************************************************************************** + /// Destroys an item at address p. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + inline void destroy_at(T* p, TCounter& count) + { + p->~T(); + --count; + } + + //***************************************************************************** + /// Destroys a range of items. + ///\ingroup memory + //***************************************************************************** + template + void destroy(TIterator i_begin, TIterator i_end) + { + while (i_begin != i_end) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + } + } + + //***************************************************************************** + /// Destroys a range of items. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + void destroy(TIterator i_begin, TIterator i_end, TCounter& count) + { + while (i_begin != i_end) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --count; + } + } + + //***************************************************************************** + /// Destroys a number of items. + ///\ingroup memory + //***************************************************************************** + template + TIterator destroy_n(TIterator i_begin, TSize n) + { + while (n > 0) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --n; + } + + return i_begin; + } + + //***************************************************************************** + /// Destroys a number of items. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + TIterator destroy_n(TIterator i_begin, TSize n, TCounter& count) + { + while (n > 0) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --n; + --count; + } + + return i_begin; + } } #endif From 259c7a170c6fd3623e2c17b9667fc3717f1715bf Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 14 Feb 2017 12:36:21 +0000 Subject: [PATCH 129/168] Added simple is_pod --- src/type_traits.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/type_traits.h b/src/type_traits.h index 71768f09..3602e6e9 100644 --- a/src/type_traits.h +++ b/src/type_traits.h @@ -232,6 +232,12 @@ namespace etl template struct is_reference : false_type {}; template struct is_reference : true_type {}; + /// is_pod + /// For C++03 only fundamental and pointers types can be detected. + ///\ingroup type_traits + template struct is_pod : etl::integral_constant::value || + etl::is_pointer::value> {}; + /// conditional ///\ingroup type_traits template struct conditional { typedef T type; }; From da3510d818b6614d3fb274eb3187929f8ea0eeb7 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 14 Feb 2017 12:36:53 +0000 Subject: [PATCH 130/168] Added is_pod variants. WORK IN PROGRESS --- src/memory.h | 142 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 107 insertions(+), 35 deletions(-) diff --git a/src/memory.h b/src/memory.h index 0fba9d67..c7abe285 100644 --- a/src/memory.h +++ b/src/memory.h @@ -32,6 +32,9 @@ SOFTWARE. #define __ETL_MEMORY__ #include +#include + +#include "type_traits.h" ///\defgroup memory memory ///\ingroup etl @@ -174,12 +177,15 @@ namespace etl template void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) { - typedef typename std::iterator_traits::value_type value_type; - - while (o_begin != o_end) + if (!etl::is_pod::type>::value) { - ::new (static_cast(etl::addressof(*o_begin))) value_type; - ++o_begin; + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type; + ++o_begin; + } } } @@ -191,13 +197,20 @@ namespace etl template void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { - typedef typename std::iterator_traits::value_type value_type; - - while (o_begin != o_end) + if (!etl::is_pod::type>::value) { - ::new (static_cast(etl::addressof(*o_begin))) value_type; - ++o_begin; - ++count; + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type; + ++o_begin; + ++count; + } + } + else + { + count = std::distance(o_begin, o_end); } } @@ -210,7 +223,10 @@ namespace etl { TOutputIterator o_end = o_begin + n; - etl::uninitialized_default_construct(o_begin, o_end); + if (!etl::is_pod::type>::value) + { + etl::uninitialized_default_construct(o_begin, o_end); + } return o_end; } @@ -225,7 +241,14 @@ namespace etl { TOutputIterator o_end = o_begin + n; - etl::uninitialized_default_construct(o_begin, o_end, count); + if (!etl::is_pod::type>::value) + { + etl::uninitialized_default_construct(o_begin, o_end, count); + } + else + { + count += n; + } return o_end; } @@ -298,7 +321,18 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void destroy_at(T* p) + typename etl::enable_if::value, void>::type + destroy_at(T* p) + { + } + + //***************************************************************************** + /// Destroys an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + destroy_at(T* p) { p->~T(); } @@ -309,7 +343,20 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void destroy_at(T* p, TCounter& count) + typename etl::enable_if::value, void>::type + destroy_at(T* p, TCounter& count) + { + --count; + } + + //***************************************************************************** + /// Destroys an item at address p. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + destroy_at(T* p, TCounter& count) { p->~T(); --count; @@ -322,10 +369,13 @@ namespace etl template void destroy(TIterator i_begin, TIterator i_end) { - while (i_begin != i_end) + if (!etl::is_pod::type>::value) { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; + while (i_begin != i_end) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + } } } @@ -337,11 +387,18 @@ namespace etl template void destroy(TIterator i_begin, TIterator i_end, TCounter& count) { - while (i_begin != i_end) + if (!etl::is_pod::type>::value) { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - --count; + while (i_begin != i_end) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --count; + } + } + else + { + count -= std::distance(i_begin, i_end); } } @@ -352,14 +409,21 @@ namespace etl template TIterator destroy_n(TIterator i_begin, TSize n) { - while (n > 0) + if (!etl::is_pod::type>::value) { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - --n; - } + while (n > 0) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --n; + } - return i_begin; + return i_begin; + } + else + { + return i_begin + n; + } } //***************************************************************************** @@ -370,15 +434,23 @@ namespace etl template TIterator destroy_n(TIterator i_begin, TSize n, TCounter& count) { - while (n > 0) + if (!etl::is_pod::type>::value) { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - --n; - --count; - } + while (n > 0) + { + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --n; + --count; + } - return i_begin; + return i_begin; + } + else + { + count -= n; + return i_begin + n; + } } } From 241cac9f425dd40f17dc23f17b5934a1dd367ab8 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 15 Feb 2017 09:29:56 +0000 Subject: [PATCH 131/168] Added more is_pod variants. WORK IN PROGRESS --- src/memory.h | 310 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 216 insertions(+), 94 deletions(-) diff --git a/src/memory.h b/src/memory.h index c7abe285..e276d875 100644 --- a/src/memory.h +++ b/src/memory.h @@ -55,7 +55,21 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value) + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value) + { + std::fill(o_begin, o_end, value); + + return o_end; + } + + //***************************************************************************** + /// Fills uninitialised memory range with a value. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value) { typedef typename std::iterator_traits::value_type value_type; @@ -65,7 +79,7 @@ namespace etl ++o_begin; } - return o_begin; + return o_end; } //***************************************************************************** @@ -74,7 +88,23 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value, TCounter& count) + { + std::fill(o_begin, o_end, value); + count += std::distance(o_begin, o_end); + + return o_end; + } + + //***************************************************************************** + /// Fills uninitialised memory range with a value. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { typedef typename std::iterator_traits::value_type value_type; @@ -85,7 +115,7 @@ namespace etl ++count; } - return o_begin; + return o_end; } //***************************************************************************** @@ -93,7 +123,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value) + inline TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value) { return etl::uninitialized_fill(o_begin, o_begin + n, value); } @@ -104,7 +134,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) + inline TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) { return etl::uninitialized_fill(o_begin, o_begin + n, value, count); } @@ -113,8 +143,23 @@ namespace etl /// Copies a range of objects to uninitialised memory. ///\ingroup memory //***************************************************************************** - template - TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) + { + TOutputIterator o_end = std::copy(i_begin, i_end, o_begin); + count += std::distance(o_begin, o_end); + + return o_end; + } + + //***************************************************************************** + /// Copies a range of objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { typedef typename std::iterator_traits::value_type value_type; @@ -123,6 +168,7 @@ namespace etl ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); ++i_begin; ++o_begin; + ++count; } return o_begin; @@ -134,7 +180,23 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) + { + TOutputIterator o_end = std::copy(i_begin, i_end, o_begin); + count += std::distance(o_begin, o_end); + + return o_end; + } + + //***************************************************************************** + /// Copies a range of objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) { typedef typename std::iterator_traits::value_type value_type; @@ -154,7 +216,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin) + inline TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin) { return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); } @@ -165,7 +227,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) + inline TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) { return etl::uninitialized_copy(i_begin, i_begin + n, o_begin, count); } @@ -175,17 +237,25 @@ namespace etl ///\ingroup memory //***************************************************************************** template - void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) + typename etl::enable_if::value_type>::value, void>::type + uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) { - if (!etl::is_pod::type>::value) - { - typedef typename std::iterator_traits::value_type value_type; + } - while (o_begin != o_end) - { - ::new (static_cast(etl::addressof(*o_begin))) value_type; - ++o_begin; - } + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, void>::type + uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) + { + ::new (static_cast(etl::addressof(*o_begin))) value_type; + ++o_begin; } } @@ -195,22 +265,28 @@ namespace etl ///\ingroup memory //***************************************************************************** template - void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) + typename etl::enable_if::value_type>::value, void>::type + uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { - if (!etl::is_pod::type>::value) - { - typedef typename std::iterator_traits::value_type value_type; + count = std::distance(o_begin, o_end); + } - while (o_begin != o_end) - { - ::new (static_cast(etl::addressof(*o_begin))) value_type; - ++o_begin; - ++count; - } - } - else + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, void>::type + uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) + { + typedef typename std::iterator_traits::value_type value_type; + + while (o_begin != o_end) { - count = std::distance(o_begin, o_end); + ::new (static_cast(etl::addressof(*o_begin))) value_type; + ++o_begin; + ++count; } } @@ -219,14 +295,25 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; - if (!etl::is_pod::type>::value) - { - etl::uninitialized_default_construct(o_begin, o_end); - } + return o_end; + } + + //***************************************************************************** + /// Default initialises N objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) + { + TOutputIterator o_end = o_begin + n; + + etl::uninitialized_default_construct(o_begin, o_end); return o_end; } @@ -237,18 +324,28 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; - if (!etl::is_pod::type>::value) - { - etl::uninitialized_default_construct(o_begin, o_end, count); - } - else - { - count += n; - } + count += n; + + return o_end; + } + + //***************************************************************************** + /// Default initialises N objects to uninitialised memory. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TOutputIterator>::type + uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) + { + TOutputIterator o_end = o_begin + n; + + etl::uninitialized_default_construct(o_begin, o_end, count); return o_end; } @@ -367,15 +464,23 @@ namespace etl ///\ingroup memory //***************************************************************************** template - void destroy(TIterator i_begin, TIterator i_end) + typename etl::enable_if::value_type>::value, void>::type + destroy(TIterator i_begin, TIterator i_end) { - if (!etl::is_pod::type>::value) + } + + //***************************************************************************** + /// Destroys a range of items. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, void>::type + destroy(TIterator i_begin, TIterator i_end) + { + while (i_begin != i_end) { - while (i_begin != i_end) - { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - } + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; } } @@ -385,20 +490,26 @@ namespace etl ///\ingroup memory //***************************************************************************** template - void destroy(TIterator i_begin, TIterator i_end, TCounter& count) + typename etl::enable_if::value_type>::value, void>::type + destroy(TIterator i_begin, TIterator i_end, TCounter& count) { - if (!etl::is_pod::type>::value) + count -= std::distance(i_begin, i_end); + } + + //***************************************************************************** + /// Destroys a range of items. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, void>::type + destroy(TIterator i_begin, TIterator i_end, TCounter& count) + { + while (i_begin != i_end) { - while (i_begin != i_end) - { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - --count; - } - } - else - { - count -= std::distance(i_begin, i_end); + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --count; } } @@ -407,23 +518,28 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TIterator destroy_n(TIterator i_begin, TSize n) + typename etl::enable_if::value_type>::value, TIterator>::type + destroy_n(TIterator i_begin, TSize n) { - if (!etl::is_pod::type>::value) - { - while (n > 0) - { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - --n; - } + return i_begin + n; + } - return i_begin; - } - else + //***************************************************************************** + /// Destroys a number of items. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TIterator>::type + destroy_n(TIterator i_begin, TSize n) + { + while (n > 0) { - return i_begin + n; + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --n; } + + return i_begin; } //***************************************************************************** @@ -432,25 +548,31 @@ namespace etl ///\ingroup memory //***************************************************************************** template - TIterator destroy_n(TIterator i_begin, TSize n, TCounter& count) + typename etl::enable_if::value_type>::value, TIterator>::type + destroy_n(TIterator i_begin, TSize n, TCounter& count) { - if (!etl::is_pod::type>::value) - { - while (n > 0) - { - etl::destroy_at(etl::addressof(*i_begin)); - ++i_begin; - --n; - --count; - } + count -= n; + return i_begin + n; + } - return i_begin; - } - else + //***************************************************************************** + /// Destroys a number of items. + /// Debug counter version. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, TIterator>::type + destroy_n(TIterator i_begin, TSize n, TCounter& count) + { + while (n > 0) { - count -= n; - return i_begin + n; + etl::destroy_at(etl::addressof(*i_begin)); + ++i_begin; + --n; + --count; } + + return i_begin; } } From aca086b22d33366a5292d04d80d3ba9f948fc49a Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 15 Feb 2017 10:40:33 +0000 Subject: [PATCH 132/168] Further optimisations. --- src/memory.h | 75 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/memory.h b/src/memory.h index e276d875..08a35217 100644 --- a/src/memory.h +++ b/src/memory.h @@ -106,13 +106,14 @@ namespace etl typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { + count += std::distance(o_begin, o_end); + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { ::new (static_cast(etl::addressof(*o_begin))) value_type(value); ++o_begin; - ++count; } return o_end; @@ -136,42 +137,42 @@ namespace etl template inline TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) { - return etl::uninitialized_fill(o_begin, o_begin + n, value, count); + count += n; + + return etl::uninitialized_fill(o_begin, o_begin + n, value); } //***************************************************************************** /// Copies a range of objects to uninitialised memory. ///\ingroup memory //***************************************************************************** - template + template typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { - TOutputIterator o_end = std::copy(i_begin, i_end, o_begin); - count += std::distance(o_begin, o_end); - - return o_end; + return std::copy(i_begin, i_end, o_begin); } //***************************************************************************** /// Copies a range of objects to uninitialised memory. ///\ingroup memory //***************************************************************************** - template + template typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { typedef typename std::iterator_traits::value_type value_type; + TOutputIterator o_end = o_begin; + while (i_begin != i_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); + ::new (static_cast(etl::addressof(*o_end))) value_type(*i_begin); ++i_begin; - ++o_begin; - ++count; + ++o_end; } - return o_begin; + return o_end; } //***************************************************************************** @@ -200,15 +201,18 @@ namespace etl { typedef typename std::iterator_traits::value_type value_type; + TOutputIterator o_end = o_begin; + while (i_begin != i_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); + ::new (static_cast(etl::addressof(*o_end))) value_type(*i_begin); ++i_begin; - ++o_begin; - ++count; + ++o_end; } - return o_begin; + count += std::distance(o_begin, o_end); + + return o_end; } //***************************************************************************** @@ -229,7 +233,9 @@ namespace etl template inline TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) { - return etl::uninitialized_copy(i_begin, i_begin + n, o_begin, count); + count += n; + + return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); } //***************************************************************************** @@ -238,7 +244,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, void>::type - uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) + uninitialized_default_construct(TOutputIterator /*o_begin*/, TOutputIterator /*o_end*/) { } @@ -280,13 +286,14 @@ namespace etl typename etl::enable_if::value_type>::value, void>::type uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { + count += std::distance(o_begin, o_end); + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { ::new (static_cast(etl::addressof(*o_begin))) value_type; ++o_begin; - ++count; } } @@ -295,7 +302,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; @@ -308,7 +315,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; @@ -324,7 +331,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; @@ -340,12 +347,14 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; - etl::uninitialized_default_construct(o_begin, o_end, count); + etl::uninitialized_default_construct(o_begin, o_end); + + count += n; return o_end; } @@ -374,13 +383,14 @@ namespace etl template void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { + count += std::distance(o_begin, o_end); + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { ::new (static_cast(etl::addressof(*o_begin))) value_type(); - ++o_begin; - ++count; + ++o_begin; } } @@ -408,7 +418,9 @@ namespace etl { TOutputIterator o_end = o_begin + n; - etl::uninitialized_value_construct(o_begin, o_end, count); + etl::uninitialized_value_construct(o_begin, o_end); + + count += n; return o_end; } @@ -419,7 +431,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - destroy_at(T* p) + destroy_at(T* /*p*/) { } @@ -441,7 +453,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - destroy_at(T* p, TCounter& count) + destroy_at(T* /*p*/, TCounter& count) { --count; } @@ -465,7 +477,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, void>::type - destroy(TIterator i_begin, TIterator i_end) + destroy(TIterator /*i_begin*/, TIterator /*i_end*/) { } @@ -564,12 +576,13 @@ namespace etl typename etl::enable_if::value_type>::value, TIterator>::type destroy_n(TIterator i_begin, TSize n, TCounter& count) { + count -= n; + while (n > 0) { etl::destroy_at(etl::addressof(*i_begin)); ++i_begin; --n; - --count; } return i_begin; From 09705bdd7f99584fa73d49f9c22aca35a81487a4 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Wed, 15 Feb 2017 18:03:31 +0000 Subject: [PATCH 133/168] Added += and -= operators --- src/debug_count.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/debug_count.h b/src/debug_count.h index ac545f86..dd6dfe32 100644 --- a/src/debug_count.h +++ b/src/debug_count.h @@ -74,6 +74,18 @@ namespace etl return *this; } + inline debug_count& operator +=(int32_t n) + { + count += n; + return *this; + } + + inline debug_count& operator -=(int32_t n) + { + count -= n; + return *this; + } + inline operator int32_t() { return count; @@ -101,6 +113,16 @@ namespace etl return *this; } + inline debug_count& operator +=(int32_t /*n*/) + { + return *this; + } + + inline debug_count& operator -=(int32_t /*n*/) + { + return *this; + } + inline operator int32_t() { return 0; From bdd1f7e837863f289614e63ce2cac9cda6007e5c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 17:03:26 +0000 Subject: [PATCH 134/168] Additional safe 4 parameter versions of copy, copy_if & copy_n --- src/algorithm.h | 107 +++++++++++++++++++++++---- test/test_algorithm.cpp | 155 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 247 insertions(+), 15 deletions(-) diff --git a/src/algorithm.h b/src/algorithm.h index f3afa52b..18f4a844 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -33,14 +33,17 @@ SOFTWARE. ///\defgroup algorithm algorithm /// Reverse engineered algorithms from C++ 0x11 +/// Additional new variants of certain algorithms. ///\ingroup utilities #include #include #include #include +#include #include +#include "iterator.h" #include "type_traits.h" namespace etl @@ -67,7 +70,7 @@ namespace etl { maximum = begin; } - + ++begin; } @@ -95,7 +98,7 @@ namespace etl template std::pair minmax(const T& a, const T& b) { - return (b < a) ? std::pair(b, a) : std::pair(a, b); + return (b < a) ? std::pair(b, a) : std::pair(a, b); } //*************************************************************************** @@ -183,6 +186,55 @@ namespace etl return etl::is_sorted_until(begin, end, compare) == end; } + //*************************************************************************** + /// copy + /// A form of copy where the smallest of the two ranges is used. + /// There is currently no STL equivalent. + /// Specialisation for random access iterators. + ///\param i_begin Beginning of the input range. + ///\param i_end End of the input range. + ///\param o_begin Beginning of the output range. + ///\param o_end End of the output range. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value && + etl::is_random_iterator::value, TOutputIterator>::type + copy(TInputIterator i_begin, TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end) + { + size_t s_size = std::distance(i_begin, i_end); + size_t d_size = std::distance(o_begin, o_end); + size_t size = (s_size < d_size) ? s_size : d_size; + + return std::copy(i_begin, i_begin + size, o_begin); + } + + //*************************************************************************** + /// copy + /// A form of copy where the smallest of the two ranges is used. + /// There is currently no STL equivalent. + /// Specialisation for non random access iterators. + ///\param i_begin Beginning of the input range. + ///\param i_end End of the input range. + ///\param o_begin Beginning of the output range. + ///\param o_end End of the output range. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value || + !etl::is_random_iterator::value, TOutputIterator>::type + copy(TInputIterator i_begin, TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end) + { + while ((i_begin != i_end) && (o_begin != o_end)) + { + *o_begin++ = *i_begin++; + } + + return o_begin; + } + //*************************************************************************** /// copy_n ///\ingroup algorithm @@ -191,15 +243,18 @@ namespace etl template TOutputIterator copy_n(TInputIterator begin, Size count, TOutputIterator result) { - if (count > 0) - { - for (Size i = 0; i < count; ++i) - { - *result++ = *begin++; - } - } + return std::copy(begin, begin + count, result); + } - return result; + //*************************************************************************** + /// copy_n + /// A form of copy_n where the smallest of the two ranges is used. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator copy_n(TInputIterator i_begin, Size count, TOutputIterator o_begin, TOutputIterator o_end) + { + return etl::copy(i_begin, i_begin + count, o_begin, o_end);; } //*************************************************************************** @@ -223,6 +278,30 @@ namespace etl return out; } + //*************************************************************************** + /// copy_if + /// A form of copy_if where it terminates when the first end iterator is reached. + /// There is currently no STL equivelent. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator copy_if(TInputIterator i_begin, TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end, + TUnaryPredicate predicate) + { + while ((i_begin != i_end) && (o_begin != o_end)) + { + if (predicate(*i_begin)) + { + *o_begin++ = *i_begin; + } + + ++i_begin; + } + + return o_begin; + } + //*************************************************************************** /// find_if_not ///\ingroup algorithm @@ -449,10 +528,10 @@ namespace etl //*************************************************************************** template std::pair partition_copy(TSource begin, - TSource end, - TDestinationTrue destination_true, - TDestinationFalse destination_false, - TUnaryPredicate predicate) + TSource end, + TDestinationTrue destination_true, + TDestinationFalse destination_false, + TUnaryPredicate predicate) { while (begin != end) { diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 91782b90..cc678d46 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -32,6 +32,7 @@ SOFTWARE. #include "../src/container.h" #include +#include #include #include #include @@ -143,6 +144,80 @@ namespace CHECK(!is_sorted); } + //========================================================================= + TEST(copy_4_parameter_random_iterator) + { + int data1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int data2[] = { 1, 2, 3, 4, 5 }; + + int out1[10]; + int out2[5]; + + int check1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int check2[] = { 1, 2, 3, 4, 5 }; + int check3[] = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }; + + int* result; + + // Same size. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy(std::begin(data1), std::end(data1), std::begin(out1), std::end(out1)); + CHECK_EQUAL(std::end(out1), result); + bool is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check1)); + CHECK(is_same); + + // Destination smaller. + std::fill(std::begin(out2), std::end(out2), 0); + result = etl::copy(std::begin(data1), std::end(data1), std::begin(out2), std::end(out2)); + CHECK_EQUAL(std::end(out2), result); + is_same = std::equal(std::begin(out2), std::end(out2), std::begin(check2)); + CHECK(is_same); + + // Source smaller. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy(std::begin(data2), std::end(data2), std::begin(out1), std::end(out1)); + CHECK_EQUAL(std::begin(out1) + 5, result); + is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check3)); + CHECK(is_same); + } + + //========================================================================= + TEST(copy_4_parameter_non_random_iterator) + { + std::list data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + std::list data2 = { 1, 2, 3, 4, 5 }; + + int out1[10]; + int out2[5]; + + int check1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int check2[] = { 1, 2, 3, 4, 5 }; + int check3[] = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }; + + int* result; + + // Same size. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy(std::begin(data1), std::end(data1), std::begin(out1), std::end(out1)); + CHECK_EQUAL(std::end(out1), result); + bool is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check1)); + CHECK(is_same); + + // Destination smaller. + std::fill(std::begin(out2), std::end(out2), 0); + result = etl::copy(std::begin(data1), std::end(data1), std::begin(out2), std::end(out2)); + CHECK_EQUAL(std::end(out2), result); + is_same = std::equal(std::begin(out2), std::end(out2), std::begin(check2)); + CHECK(is_same); + + // Source smaller. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy(std::begin(data2), std::end(data2), std::begin(out1), std::end(out1)); + CHECK_EQUAL(std::begin(out1) + 5, result); + is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check3)); + CHECK(is_same); + } + //========================================================================= TEST(copy_n) { @@ -150,13 +225,53 @@ namespace int data2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int data3[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int* result; + std::copy_n(std::begin(data1), 4, std::begin(data2)); - etl::copy_n(std::begin(data1), 4, std::begin(data3)); + result = etl::copy_n(std::begin(data1), 4, std::begin(data3)); + + CHECK_EQUAL(std::begin(data3) + 4, result); bool is_same = std::equal(std::begin(data2), std::end(data2), std::begin(data3)); CHECK(is_same); } + //========================================================================= + TEST(copy_n_4_parameter) + { + int data1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + int out1[10]; + int out2[5]; + + int check1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int check2[] = { 1, 2, 3, 4, 5 }; + int check3[] = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }; + + int* result; + + // Same size. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy_n(std::begin(data1), 10, std::begin(out1), std::end(out1)); + CHECK_EQUAL(std::end(out1), result); + bool is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check1)); + CHECK(is_same); + + // Destination smaller. + std::fill(std::begin(out2), std::end(out2), 0); + result = etl::copy_n(std::begin(data1), 10, std::begin(out2), std::end(out2)); + CHECK_EQUAL(std::end(out2), result); + is_same = std::equal(std::begin(out2), std::end(out2), std::begin(check2)); + CHECK(is_same); + + // Source smaller. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy_n(std::begin(data1), 5, std::begin(out1), std::end(out1)); + CHECK_EQUAL(std::begin(out1) + 5, result); + is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check3)); + CHECK(is_same); + } + //========================================================================= TEST(copy_if) { @@ -172,6 +287,44 @@ namespace CHECK(is_same); } + //========================================================================= + TEST(copy_if_4_parameter) + { + int data1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int data2[] = { 1, 8, 2, 7, 3 }; + + int out1[4]; + int out2[2]; + int out3[10]; + + int check1[] = { 1, 2, 3, 4 }; + int check2[] = { 1, 2 }; + int check3[] = { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0 }; + + int* result; + + // Exact size. + std::fill(std::begin(out1), std::end(out1), 0); + result = etl::copy_if(std::begin(data1), std::end(data1), std::begin(out1), std::end(out1), std::bind2nd(std::less(), 5)); + CHECK_EQUAL(std::end(out1), result); + bool is_same = std::equal(std::begin(out1), std::end(out1), std::begin(check1)); + CHECK(is_same); + + // Destination smaller. + std::fill(std::begin(out2), std::end(out2), 0); + result = etl::copy_if(std::begin(data1), std::end(data1), std::begin(out2), std::end(out2), std::bind2nd(std::less(), 5)); + CHECK_EQUAL(std::end(out2), result); + is_same = std::equal(std::begin(out2), std::end(out2), std::begin(check2)); + CHECK(is_same); + + // Destination larger. + std::fill(std::begin(out3), std::end(out3), 0); + result = etl::copy_if(std::begin(data1), std::end(data1), std::begin(out3), std::end(out3), std::bind2nd(std::less(), 5)); + CHECK_EQUAL(std::begin(out3) + 4, result); + is_same = std::equal(std::begin(out3), std::end(out3), std::begin(check3)); + CHECK(is_same); + } + //========================================================================= TEST(any_of) { From 1527e9781f65222f22c1ad77b5743c0e6fa0c752 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 17:19:05 +0000 Subject: [PATCH 135/168] Added assign, insert and erase member functions. --- src/array.h | 390 +++++++++++++++++++++++++++++++++----------- test/test_array.cpp | 226 +++++++++++++++++++++++++ 2 files changed, 519 insertions(+), 97 deletions(-) diff --git a/src/array.h b/src/array.h index f6c64a80..1e514c98 100644 --- a/src/array.h +++ b/src/array.h @@ -41,6 +41,7 @@ SOFTWARE. #include "parameter_type.h" #include "static_assert.h" #include "error_handler.h" +#include "algorithm.h" ///\defgroup array array /// A replacement for std::array if you haven't got C++0x11. @@ -76,18 +77,18 @@ namespace etl } }; - //*************************************************************************** + //*************************************************************************** ///\ingroup array /// A replacement for std::array if you haven't got C++0x11. - //*************************************************************************** + //*************************************************************************** template class array - { + { private: typedef typename parameter_type::type parameter_t; - public: + public: enum { @@ -102,9 +103,9 @@ namespace etl typedef T* pointer; typedef const T* const_pointer; typedef T* iterator; - typedef const T* const_iterator; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; + typedef const T* const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; //************************************************************************* // Element access @@ -204,29 +205,29 @@ namespace etl // Iterators //************************************************************************* - //************************************************************************* - /// Returns an iterator to the beginning of the array. - //************************************************************************* - iterator begin() - { - return &_buffer[0]; - } - - //************************************************************************* - /// Returns a const iterator to the beginning of the array. - //************************************************************************* - const_iterator begin() const - { - return &_buffer[0]; - } + //************************************************************************* + /// Returns an iterator to the beginning of the array. + //************************************************************************* + iterator begin() + { + return &_buffer[0]; + } - //************************************************************************* - /// Returns a const iterator to the beginning of the array. - //************************************************************************* - const_iterator cbegin() const - { - return begin(); - } + //************************************************************************* + /// Returns a const iterator to the beginning of the array. + //************************************************************************* + const_iterator begin() const + { + return &_buffer[0]; + } + + //************************************************************************* + /// Returns a const iterator to the beginning of the array. + //************************************************************************* + const_iterator cbegin() const + { + return begin(); + } //************************************************************************* /// Returns an iterator to the end of the array. @@ -252,53 +253,53 @@ namespace etl return &_buffer[SIZE]; } - //************************************************************************* - // Returns an reverse iterator to the reverse beginning of the array. - //************************************************************************* - reverse_iterator rbegin() - { - return reverse_iterator(end()); - } - - //************************************************************************* - /// Returns a const reverse iterator to the reverse beginning of the array. - //************************************************************************* - const_reverse_iterator rbegin() const - { - return const_reverse_iterator(end()); - } + //************************************************************************* + // Returns an reverse iterator to the reverse beginning of the array. + //************************************************************************* + reverse_iterator rbegin() + { + return reverse_iterator(end()); + } - //************************************************************************* - /// Returns a const reverse iterator to the reverse beginning of the array. - //************************************************************************* - const_reverse_iterator crbegin() const - { - return const_reverse_iterator(end()); - } + //************************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the array. + //************************************************************************* + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(end()); + } - //************************************************************************* - /// Returns a reverse iterator to the end of the array. - //************************************************************************* - reverse_iterator rend() - { - return reverse_iterator(begin()); - } - - //************************************************************************* - /// Returns a const reverse iterator to the end of the array. - //************************************************************************* - const_reverse_iterator rend() const - { - return const_reverse_iterator(begin()); - } + //************************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the array. + //************************************************************************* + const_reverse_iterator crbegin() const + { + return const_reverse_iterator(end()); + } - //************************************************************************* - /// Returns a const reverse iterator to the end of the array. - //************************************************************************* - const_reverse_iterator crend() const - { - return const_reverse_iterator(begin()); - } + //************************************************************************* + /// Returns a reverse iterator to the end of the array. + //************************************************************************* + reverse_iterator rend() + { + return reverse_iterator(begin()); + } + + //************************************************************************* + /// Returns a const reverse iterator to the end of the array. + //************************************************************************* + const_reverse_iterator rend() const + { + return const_reverse_iterator(begin()); + } + + //************************************************************************* + /// Returns a const reverse iterator to the end of the array. + //************************************************************************* + const_reverse_iterator crend() const + { + return const_reverse_iterator(begin()); + } //************************************************************************* // Capacity @@ -312,21 +313,21 @@ namespace etl return (SIZE == 0); } - //************************************************************************* - /// Returns the size of the array. - //************************************************************************* - size_t size() const - { - return SIZE; - } + //************************************************************************* + /// Returns the size of the array. + //************************************************************************* + size_t size() const + { + return SIZE; + } - //************************************************************************* - /// Returns the maximum possible size of the array. - //************************************************************************* - size_t max_size() const - { - return SIZE; - } + //************************************************************************* + /// Returns the maximum possible size of the array. + //************************************************************************* + size_t max_size() const + { + return SIZE; + } //************************************************************************* // Operations @@ -353,20 +354,215 @@ namespace etl } } + //************************************************************************* + /// Fills the array from the range. + /// If the range is larger than the array then the extra data is ignored. + /// If the range is smaller than the array then the unused array elements are left unmodified. + ///\param first The iterator to the first item in the ramge. + ///\param last The iterator to one past the final item in the range. + //************************************************************************* + template + void assign(TIterator first, const TIterator last) + { + iterator itr = begin(); + + etl::copy(first, last, begin(), end()); + } + + //************************************************************************* + /// Fills the array from the range. + /// If the range is larger than the array then the extra data is ignored. + /// If the range is smaller than the array then the unused array elements are initialised with the supplied value. + ///\param first The iterator to the first item in the ramge. + ///\param last The iterator to one past the final item in the range. + //************************************************************************* + template + void assign(TIterator first, const TIterator last, parameter_t value) + { + // Copy from the range. + iterator p = etl::copy(first, last, begin(), end()); + + // Default initialise any that are left. + std::fill(p, end(), value); + } + + //************************************************************************* + /// Inserts a value into the array. + ///\param position The index of the position to insert at. + ///\param value The value to insert. + //************************************************************************* + inline iterator insert_at(size_t position, parameter_t value) + { + return insert(begin() + position, value); + } + + //************************************************************************* + /// Inserts a value into the array. + ///\param position The iterator to the position to insert at. + ///\param value The value to insert. + //************************************************************************* + iterator insert(const_iterator position, parameter_t value) + { + iterator p = const_cast(position); + + std::copy_backward(p, end() - 1, end()); + *p = value; + + return p; + } + + //************************************************************************* + /// Insert into the array from the range. + ///\param position The position to insert at. + ///\param first The iterator to the first item in the range. + ///\param last The iterator to one past the final item in the range. + //************************************************************************* + template + inline iterator insert_at(size_t position, TIterator first, const TIterator last) + { + return insert(begin() + position, first, last); + } + + //************************************************************************* + /// Insert into the array from the range. + ///\param position The position to insert at. + ///\param first The iterator to the first item in the range. + ///\param last The iterator to one past the final item in the range. + //************************************************************************* + template + iterator insert(const_iterator position, TIterator first, const TIterator last) + { + iterator p = const_cast(position); + iterator result(p); + + size_t source_size = std::distance(first, last); + size_t destination_space = std::distance(position, cend()); + + // Do we need to move anything? + if (source_size < destination_space) + { + size_t length = SIZE - (std::distance(begin(), p) + source_size); + std::copy_backward(p, p + length, end()); + } + + // Copy from the range. + etl::copy(first, last, p, end()); + + return result; + } + + //************************************************************************* + /// Erases a value from the array. + /// The after erase, the last value in the array will be unmodified. + ///\param position The index of the position to erase at. + //************************************************************************* + inline iterator erase_at(size_t position) + { + return erase(begin() + position); + } + + //************************************************************************* + /// Inserts a value into the array. + /// The after erase, the last value in the array will be unmodified. + ///\param position The iterator to the position to erase at. + //************************************************************************* + iterator erase(const_iterator position) + { + iterator p = const_cast(position); + std::copy(p + 1, end(), p); + + return p; + } + + //************************************************************************* + /// Erases a range of values from the array. + /// The after erase, the last values in the array will be unmodified. + ///\param first The first item to erase. + ///\param last The one past the last item to erase. + //************************************************************************* + iterator erase_range(size_t first, size_t last) + { + return erase(begin() + first, begin() + last); + } + + //************************************************************************* + /// Erases a range of values from the array. + /// The after erase, the last values in the array will be unmodified. + ///\param first The first item to erase. + ///\param last The one past the last item to erase. + //************************************************************************* + iterator erase(const_iterator first, const_iterator last) + { + iterator p = const_cast(first); + std::copy(last, cend(), p); + return p; + } + + //************************************************************************* + /// Erases a value from the array. + ///\param position The index of the position to erase at. + ///\param value The value to use to overwrite the last element in the array. + //************************************************************************* + inline iterator erase_at(size_t position, parameter_t value) + { + return erase(begin() + position, value); + } + + //************************************************************************* + /// Inserts a value into the array. + ///\param position The iterator to the position to erase at. + ///\param value The value to use to overwrite the last element in the array. + //************************************************************************* + iterator erase(const_iterator position, parameter_t value) + { + iterator p = const_cast(position); + + std::copy(p + 1, end(), p); + back() = value; + + return p; + } + + //************************************************************************* + /// Erases a range of values from the array. + ///\param first The first item to erase. + ///\param last The one past the last item to erase. + ///\param value The value to use to overwrite the last elements in the array. + //************************************************************************* + iterator erase_range(size_t first, size_t last, parameter_t value) + { + return erase(begin() + first, begin() + last, value); + } + + //************************************************************************* + /// Erases a range of values from the array. + ///\param position The iterator to the position to erase at. + ///\param value The value to use to overwrite the last elements in the array. + //************************************************************************* + iterator erase(const_iterator first, const_iterator last, parameter_t value) + { + iterator p = const_cast(first); + + p = std::copy(last, cend(), p); + std::fill(p, end(), value); + + return const_cast(first); + } + /// The array data. T _buffer[SIZE]; }; //************************************************************************* - /// Overloaded swap for etl::array - ///\param lhs The first array. - ///\param rhs The second array. - //************************************************************************* + /// Overloaded swap for etl::array + ///\param lhs The first array. + ///\param rhs The second array. + //************************************************************************* template void swap(etl::array &lhs, etl::array &rhs) - { - lhs.swap(rhs); - } + { + lhs.swap(rhs); + } //************************************************************************* /// Equal operator. @@ -391,7 +587,7 @@ namespace etl { return !(lhs == rhs); } - + //************************************************************************* /// Less than operator. ///\param lhs The first array. @@ -402,8 +598,8 @@ namespace etl bool operator <(const etl::array& lhs, const etl::array& rhs) { return std::lexicographical_compare(lhs.cbegin(), - lhs.cend(), - rhs.cbegin(), + lhs.cend(), + rhs.cbegin(), rhs.cend()); } diff --git a/test/test_array.cpp b/test/test_array.cpp index 527e8343..69073e35 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -348,6 +348,232 @@ namespace //int i = etl::get<11>(data2); } + //************************************************************************* + TEST(test_assign) + { + int initial[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + int source[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int check1[] = { 0, 1, 2, 3, 4, -1, -1, -1, -1, -1 }; + int check2[] = { 0, 1, 2, 3, 4, 99, 99, 99, 99, 99 }; + int check3[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + Data data; + + // Initial data. + data.assign(std::begin(initial), std::end(initial)); + bool isEqual = std::equal(data.begin(), data.end(), std::begin(initial)); + CHECK(isEqual); + + // Assign smaller. + data.assign(std::begin(initial), std::end(initial)); + data.assign(&source[0], &source[5]); + isEqual = std::equal(data.begin(), data.end(), std::begin(check1)); + CHECK(isEqual); + + // Assign smaller + default. + data.assign(std::begin(initial), std::end(initial)); + data.assign(&source[0], &source[5], 99); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2)); + CHECK(isEqual); + + // Assign larger. + data.assign(std::begin(initial), std::end(initial)); + data.assign(&source[0], &source[13]); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(test_insert_value) + { + int initial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int check1[] = { 99, 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + int check2[] = { 0, 1, 2, 3, 4, 99, 5, 6, 7, 8 }; + int check3[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 99 }; + + Data data; + Data::iterator result; + + // Insert beginning. + data.assign(std::begin(initial), std::end(initial)); + result = data.insert_at(0, 99); + CHECK_EQUAL(data[0], *result); + bool isEqual = std::equal(data.begin(), data.end(), std::begin(check1)); + CHECK(isEqual); + + // Insert middle. + data.assign(std::begin(initial), std::end(initial)); + result = data.insert_at(5, 99); + CHECK_EQUAL(data[5], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2)); + CHECK(isEqual); + + // Insert end. + data.assign(std::begin(initial), std::end(initial)); + result = data.insert_at(9, 99); + CHECK_EQUAL(data[9], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(test_insert_range) + { + int source1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int source2[] = { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; + int check1[] = { 12, 11, 10, 0, 1, 2, 3, 4, 5, 6 }; + int check2[] = { 0, 1, 2, 3, 12, 11, 10, 4, 5, 6 }; + int check3[] = { 0, 1, 2, 3, 4, 5, 6, 12, 11, 10 }; + int check4[] = { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3 }; + int check5[] = { 0, 1, 2, 3, 12, 11, 10, 9, 8, 7, 6 }; + + Data data; + Data::iterator result; + + // Insert smaller, beginning. + data.assign(std::begin(source1), std::end(source1)); + result = data.insert_at(0, &source2[0], &source2[3]); + CHECK_EQUAL(data[0], *result); + bool isEqual = std::equal(data.begin(), data.end(), std::begin(check1)); + CHECK(isEqual); + + // Insert smaller, middle. + data.assign(std::begin(source1), std::end(source1)); + result = data.insert_at(4, &source2[0], &source2[3]); + CHECK_EQUAL(data[4], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2)); + CHECK(isEqual); + + // Insert smaller, end. + data.assign(std::begin(source1), std::end(source1)); + result = data.insert_at(7, &source2[0], &source2[3]); + CHECK_EQUAL(data[7], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3)); + CHECK(isEqual); + + // Insert larger, beginning. + data.assign(std::begin(source1), std::end(source1)); + result = data.insert_at(0, &source2[0], &source2[13]); + CHECK_EQUAL(data[0], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check4)); + CHECK(isEqual); + + // Insert larger, middle. + data.assign(std::begin(source1), std::end(source1)); + result = data.insert_at(4, &source2[0], &source2[13]); + CHECK_EQUAL(data[4], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check5)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(test_erase_single) + { + int initial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int check1a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 9 }; + int check1b[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 99 }; + int check2a[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 9 }; + int check2b[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 99 }; + int check3a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int check3b[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 99 }; + + Data data; + Data::iterator result; + + // Erase beginning. + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_at(0); + CHECK_EQUAL(data[0], *result); + bool isEqual = std::equal(data.begin(), data.end(), std::begin(check1a)); + CHECK(isEqual); + + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_at(0, 99); + CHECK_EQUAL(data[0], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check1b)); + CHECK(isEqual); + + // Erase middle. + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_at(5); + CHECK_EQUAL(data[5], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2a)); + CHECK(isEqual); + + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_at(5, 99); + CHECK_EQUAL(data[5], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2b)); + CHECK(isEqual); + + // Erase last. + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_at(9); + CHECK_EQUAL(data[9], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3a)); + CHECK(isEqual); + + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_at(9, 99); + CHECK_EQUAL(data[9], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3b)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(test_erase_range) + { + int initial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int check1a[] = { 5, 6, 7, 8, 9, 5, 6, 7, 8, 9 }; + int check1b[] = { 5, 6, 7, 8, 9, 99, 99, 99, 99, 99 }; + int check2a[] = { 0, 1, 7, 8, 9, 5, 6, 7, 8, 9 }; + int check2b[] = { 0, 1, 7, 8, 9, 99, 99, 99, 99, 99 }; + int check3a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int check3b[] = { 0, 1, 2, 3, 4, 99, 99, 99, 99, 99 }; + + Data data; + Data::iterator result; + + // Erase beginning. + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_range(0, 5); + CHECK_EQUAL(data[0], *result); + bool isEqual = std::equal(data.begin(), data.end(), std::begin(check1a)); + CHECK(isEqual); + + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_range(0, 5, 99); + CHECK_EQUAL(data[0], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check1b)); + CHECK(isEqual); + + // Erase middle. + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_range(2, 7); + CHECK_EQUAL(data[2], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2a)); + CHECK(isEqual); + + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_range(2, 7, 99); + CHECK_EQUAL(data[2], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check2b)); + CHECK(isEqual); + + // Erase last. + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_range(5, 10); + CHECK_EQUAL(data[5], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3a)); + CHECK(isEqual); + + data.assign(std::begin(initial), std::end(initial)); + result = data.erase_range(5, 10, 99); + CHECK_EQUAL(data[5], *result); + isEqual = std::equal(data.begin(), data.end(), std::begin(check3b)); + CHECK(isEqual); + } + //************************************************************************* TEST(test_equal) { From 68675c372067b7d86c95bb7d141f1863a2a83e44 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 17:19:36 +0000 Subject: [PATCH 136/168] Updated project files. --- test/vs2015/etl.vcxproj | 30 ++++++++++++++++++---- test/vs2015/etl.vcxproj.filters | 45 ++++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index cde6fd79..52d7585a 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -63,6 +63,7 @@ false + true @@ -111,8 +112,9 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions) ../../../unittest-cpp + false Console @@ -172,6 +174,7 @@ + @@ -220,6 +223,7 @@ + @@ -269,6 +273,7 @@ + @@ -281,8 +286,10 @@ + + @@ -320,6 +327,7 @@ + @@ -347,8 +355,12 @@ - - + + true + + + true + false false @@ -383,7 +395,10 @@ false false - + + true + false + @@ -398,7 +413,12 @@ - + + true + + + true + diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index 6a2486b7..58efe487 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -531,6 +531,21 @@ ETL\Containers + + ETL\Containers + + + ETL\Utilities + + + ETL\Utilities + + + ETL\Utilities + + + ETL\Utilities +
@@ -632,9 +647,6 @@ Source Files - - Source Files - Source Files @@ -713,15 +725,6 @@ Source Files - - Source Files - - - Source Files - - - Source Files - Source Files @@ -827,6 +830,24 @@ Source Files + + ETL\Utilities + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + From 8f609f448e0d350338c2d69e27ec601cef88a5c8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 18:26:00 +0000 Subject: [PATCH 137/168] Added iterator property type templates. --- src/iterator.h | 115 +++++++++++++++++++++++++++ test/test_iterator.cpp | 172 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 src/iterator.h create mode 100644 test/test_iterator.cpp diff --git a/src/iterator.h b/src/iterator.h new file mode 100644 index 00000000..b6d04c6e --- /dev/null +++ b/src/iterator.h @@ -0,0 +1,115 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_ITERATOR__ +#define __ETL_ITERATOR__ + +#include + +#include "type_traits.h" + +///\defgroup iterator iterator +///\ingroup utilities + +namespace etl +{ + template + struct is_input_iterator + { + static const bool value = etl::is_same::iterator_category, std::input_iterator_tag>::value; + }; + + template + struct is_output_iterator + { + static const bool value = etl::is_same::iterator_category, std::output_iterator_tag>::value; + }; + + template + struct is_forward_iterator + { + static const bool value = etl::is_same::iterator_category, std::forward_iterator_tag>::value; + }; + + template + struct is_bidirectional_iterator + { + static const bool value = etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value; + }; + + template + struct is_random_iterator + { + static const bool value = etl::is_same::iterator_category, std::random_access_iterator_tag>::value; + }; + + template + struct is_input_iterator_concept + { + static const bool value = etl::is_input_iterator::value || + etl::is_forward_iterator::value || + etl::is_bidirectional_iterator::value || + etl::is_random_iterator::value; + }; + + template + struct is_output_iterator_concept + { + static const bool value = etl::is_output_iterator::value || + etl::is_forward_iterator::value || + etl::is_bidirectional_iterator::value || + etl::is_random_iterator::value; + }; + + template + struct is_forward_iterator_concept + { + static const bool value = etl::is_forward_iterator::value || + etl::is_bidirectional_iterator::value || + etl::is_random_iterator::value; + }; + + template + struct is_bidirectional_iterator_concept + { + static const bool value = etl::is_bidirectional_iterator::value || + etl::is_random_iterator::value; + }; + + template + struct is_random_iterator_concept + { + static const bool value = etl::is_random_iterator::value; + }; + +} + +#endif + diff --git a/test/test_iterator.cpp b/test/test_iterator.cpp new file mode 100644 index 00000000..f77c6b71 --- /dev/null +++ b/test/test_iterator.cpp @@ -0,0 +1,172 @@ +/****************************************************************************** +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 "../src/iterator.h" + +#include + +struct input : public std::iterator +{ + +}; + +struct output : public std::iterator +{ + +}; + +struct forward : public std::iterator +{ + +}; + +struct bidirectional : public std::iterator +{ + +}; + +struct random : public std::iterator +{ + +}; + +typedef int* pointer; +typedef const int* const_pointer; + +namespace +{ + SUITE(test_iterator) + { + TEST(test_input) + { + CHECK(etl::is_input_iterator::value); + CHECK(!etl::is_output_iterator::value); + CHECK(!etl::is_forward_iterator::value); + CHECK(!etl::is_bidirectional_iterator::value); + CHECK(!etl::is_random_iterator::value); + + CHECK(etl::is_input_iterator_concept::value); + CHECK(!etl::is_output_iterator_concept::value); + CHECK(!etl::is_forward_iterator_concept::value); + CHECK(!etl::is_bidirectional_iterator_concept::value); + CHECK(!etl::is_random_iterator_concept::value); + } + + TEST(test_output) + { + CHECK(!etl::is_input_iterator::value); + CHECK(etl::is_output_iterator::value); + CHECK(!etl::is_forward_iterator::value); + CHECK(!etl::is_bidirectional_iterator::value); + CHECK(!etl::is_random_iterator::value); + + CHECK(!etl::is_input_iterator_concept::value); + CHECK(etl::is_output_iterator_concept::value); + CHECK(!etl::is_forward_iterator_concept::value); + CHECK(!etl::is_bidirectional_iterator_concept::value); + CHECK(!etl::is_random_iterator_concept::value); + } + + TEST(test_forward) + { + CHECK(!etl::is_input_iterator::value); + CHECK(!etl::is_output_iterator::value); + CHECK(etl::is_forward_iterator::value); + CHECK(!etl::is_bidirectional_iterator::value); + CHECK(!etl::is_random_iterator::value); + + CHECK(etl::is_input_iterator_concept::value); + CHECK(etl::is_output_iterator_concept::value); + CHECK(etl::is_forward_iterator_concept::value); + CHECK(!etl::is_bidirectional_iterator_concept::value); + CHECK(!etl::is_random_iterator_concept::value); + } + + TEST(test_bidirectional) + { + CHECK(!etl::is_input_iterator::value); + CHECK(!etl::is_output_iterator::value); + CHECK(!etl::is_forward_iterator::value); + CHECK(etl::is_bidirectional_iterator::value); + CHECK(!etl::is_random_iterator::value); + + CHECK(etl::is_input_iterator_concept::value); + CHECK(etl::is_output_iterator_concept::value); + CHECK(etl::is_forward_iterator_concept::value); + CHECK(etl::is_bidirectional_iterator_concept::value); + CHECK(!etl::is_random_iterator_concept::value); + } + + TEST(test_random) + { + CHECK(!etl::is_input_iterator::value); + CHECK(!etl::is_output_iterator::value); + CHECK(!etl::is_forward_iterator::value); + CHECK(!etl::is_bidirectional_iterator::value); + CHECK(etl::is_random_iterator::value); + + CHECK(etl::is_input_iterator_concept::value); + CHECK(etl::is_output_iterator_concept::value); + CHECK(etl::is_forward_iterator_concept::value); + CHECK(etl::is_bidirectional_iterator_concept::value); + CHECK(etl::is_random_iterator_concept::value); + } + + TEST(test_pointer) + { + CHECK(!etl::is_input_iterator::value); + CHECK(!etl::is_output_iterator::value); + CHECK(!etl::is_forward_iterator::value); + CHECK(!etl::is_bidirectional_iterator::value); + CHECK(etl::is_random_iterator::value); + + CHECK(etl::is_input_iterator_concept::value); + CHECK(etl::is_output_iterator_concept::value); + CHECK(etl::is_forward_iterator_concept::value); + CHECK(etl::is_bidirectional_iterator_concept::value); + CHECK(etl::is_random_iterator_concept::value); + } + + TEST(test_const_pointer) + { + CHECK(!etl::is_input_iterator::value); + CHECK(!etl::is_output_iterator::value); + CHECK(!etl::is_forward_iterator::value); + CHECK(!etl::is_bidirectional_iterator::value); + CHECK(etl::is_random_iterator::value); + + CHECK(etl::is_input_iterator_concept::value); + CHECK(etl::is_output_iterator_concept::value); + CHECK(etl::is_forward_iterator_concept::value); + CHECK(etl::is_bidirectional_iterator_concept::value); + CHECK(etl::is_random_iterator_concept::value); + } + }; +} From 53d65cc6f773a5563713d6bc7a573e75fb04bce6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 18:32:52 +0000 Subject: [PATCH 138/168] Tests for etl::random --- test/test_random.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/test_random.cpp diff --git a/test/test_random.cpp b/test/test_random.cpp new file mode 100644 index 00000000..7aa79429 --- /dev/null +++ b/test/test_random.cpp @@ -0,0 +1,65 @@ +/****************************************************************************** +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 + +#include "../src/random.h" + +#include +#include +#include + +namespace +{ + SUITE(test_random) + { + //========================================================================= + TEST(test_sequence) + { + std::vector out1(32768); + + etl::random r; + + std::generate(out1.begin(), out1.end(), r); + + std::ofstream file("random.csv"); + + if (!file.fail()) + { + for (size_t i = 0; i < out1.size(); i += 2) + { + file << (out1[i] >> 16) << "," << (out1[i + 1] >> 16) << "\n"; + } + } + + file.close(); + } + }; +} From 59b08366edb1bb920eb9db3b0dd5271c31bdcee3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 19:13:28 +0000 Subject: [PATCH 139/168] Derived random generators from base random class. --- src/random.cpp | 10 +++++----- src/random.h | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/random.cpp b/src/random.cpp index c695df5d..8bd87e6b 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -36,7 +36,7 @@ namespace etl /// Default constructor. /// Attempts to come up with a reasonable non-zero seed. //*************************************************************************** - random::random() + random_xorshift::random_xorshift() { // An attempt to come up with a reasonable non-zero seed, // based on the address of the instance. @@ -49,7 +49,7 @@ namespace etl /// Constructor with seed value. ///\param seed The new seed value. //*************************************************************************** - random::random(uint32_t seed) + random_xorshift::random_xorshift(uint32_t seed) { initialise(seed); } @@ -58,7 +58,7 @@ namespace etl /// Initialises the sequence with a new seed value. ///\param seed The new seed value. //*************************************************************************** - void random::initialise(uint32_t seed) + void random_xorshift::initialise(uint32_t seed) { // Add the first four primes to ensure that the seed isn't zero. state[0] = seed + 3; @@ -68,9 +68,9 @@ namespace etl } //*************************************************************************** - /// Get the next random number. + /// Get the next random_xorshift number. //*************************************************************************** - uint32_t random::operator()() + uint32_t random_xorshift::operator()() { uint32_t n = state[3]; n ^= n << 11; diff --git a/src/random.h b/src/random.h index bf65450b..b41a7262 100644 --- a/src/random.h +++ b/src/random.h @@ -35,17 +35,28 @@ SOFTWARE. namespace etl { + class random + { + public: + + virtual ~random() + { + } + + virtual uint32_t operator()() = 0; + }; + //*************************************************************************** /// A 32 bit random number generator. /// Uses a 128 bit XOR shift algorithm. /// https://en.wikipedia.org/wiki/Xorshift //*************************************************************************** - class random + class random_xorshift : public random { public: - random(); - random(uint32_t seed); + random_xorshift(); + random_xorshift(uint32_t seed); void initialise(uint32_t seed); uint32_t operator()(); From 62199d78721416d9108fcfa64e0f52fb938feae9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 19:13:40 +0000 Subject: [PATCH 140/168] Tests for etl::random --- test/test_random.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/test_random.cpp b/test/test_random.cpp index 7aa79429..704477fa 100644 --- a/test/test_random.cpp +++ b/test/test_random.cpp @@ -44,10 +44,24 @@ namespace TEST(test_sequence) { std::vector out1(32768); - - etl::random r; + etl::random_xorshift r; - std::generate(out1.begin(), out1.end(), 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.csv"); From 73e1da2e9f80c4dc2fb5ebcc4c8c882dbc5783e1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Feb 2017 19:15:12 +0000 Subject: [PATCH 141/168] Added more comments --- src/random.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/random.h b/src/random.h index b41a7262..f85ca167 100644 --- a/src/random.h +++ b/src/random.h @@ -35,6 +35,9 @@ SOFTWARE. namespace etl { + //*************************************************************************** + /// The base for all 32 bit random number generators. + //*************************************************************************** class random { public: From f180f63d94e9d54476c474449038149afd213650 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 16 Feb 2017 16:59:09 +0000 Subject: [PATCH 142/168] Added... has_trivial_constructor has_trivial_copy_constructor has_trivial_destructor has_trivial_assignment --- src/memory.h | 56 +++++++++++++++++++++++------------------------ src/type_traits.h | 22 ++++++++++++++++++- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/memory.h b/src/memory.h index 08a35217..69a3e3af 100644 --- a/src/memory.h +++ b/src/memory.h @@ -55,7 +55,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value) { std::fill(o_begin, o_end, value); @@ -68,7 +68,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value) { typedef typename std::iterator_traits::value_type value_type; @@ -88,7 +88,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value, TCounter& count) { std::fill(o_begin, o_end, value); @@ -103,7 +103,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { count += std::distance(o_begin, o_end); @@ -147,7 +147,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { return std::copy(i_begin, i_end, o_begin); @@ -158,7 +158,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { typedef typename std::iterator_traits::value_type value_type; @@ -181,7 +181,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) { TOutputIterator o_end = std::copy(i_begin, i_end, o_begin); @@ -196,7 +196,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) { typedef typename std::iterator_traits::value_type value_type; @@ -243,7 +243,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type uninitialized_default_construct(TOutputIterator /*o_begin*/, TOutputIterator /*o_end*/) { } @@ -253,7 +253,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) { typedef typename std::iterator_traits::value_type value_type; @@ -271,7 +271,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { count = std::distance(o_begin, o_end); @@ -283,7 +283,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { count += std::distance(o_begin, o_end); @@ -302,7 +302,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; @@ -315,7 +315,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; @@ -331,7 +331,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; @@ -347,7 +347,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; @@ -430,7 +430,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type destroy_at(T* /*p*/) { } @@ -440,7 +440,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type destroy_at(T* p) { p->~T(); @@ -452,7 +452,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type destroy_at(T* /*p*/, TCounter& count) { --count; @@ -464,7 +464,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type destroy_at(T* p, TCounter& count) { p->~T(); @@ -476,7 +476,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type destroy(TIterator /*i_begin*/, TIterator /*i_end*/) { } @@ -486,7 +486,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type destroy(TIterator i_begin, TIterator i_end) { while (i_begin != i_end) @@ -502,7 +502,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type destroy(TIterator i_begin, TIterator i_end, TCounter& count) { count -= std::distance(i_begin, i_end); @@ -514,7 +514,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, void>::type + typename etl::enable_if::value_type>::value, void>::type destroy(TIterator i_begin, TIterator i_end, TCounter& count) { while (i_begin != i_end) @@ -530,7 +530,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TIterator>::type + typename etl::enable_if::value_type>::value, TIterator>::type destroy_n(TIterator i_begin, TSize n) { return i_begin + n; @@ -541,7 +541,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TIterator>::type + typename etl::enable_if::value_type>::value, TIterator>::type destroy_n(TIterator i_begin, TSize n) { while (n > 0) @@ -560,7 +560,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TIterator>::type + typename etl::enable_if::value_type>::value, TIterator>::type destroy_n(TIterator i_begin, TSize n, TCounter& count) { count -= n; @@ -573,7 +573,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TIterator>::type + typename etl::enable_if::value_type>::value, TIterator>::type destroy_n(TIterator i_begin, TSize n, TCounter& count) { count -= n; diff --git a/src/type_traits.h b/src/type_traits.h index 3602e6e9..8d08e219 100644 --- a/src/type_traits.h +++ b/src/type_traits.h @@ -233,11 +233,31 @@ namespace etl template struct is_reference : true_type {}; /// is_pod - /// For C++03 only fundamental and pointers types can be detected. + /// For C++03, only fundamental and pointers types are recognised. ///\ingroup type_traits template struct is_pod : etl::integral_constant::value || etl::is_pointer::value> {}; + /// has_trivial_constructor + /// For C++03, only POD types are recognised. + ///\ingroup type_traits + template struct has_trivial_constructor : etl::is_pod {}; + + /// has_trivial_copy_constructor + /// For C++03, only POD types are recognised. + ///\ingroup type_traits + template struct has_trivial_copy_constructor : etl::is_pod {}; + + /// has_trivial_destructor + /// For C++03, only POD types are recognised. + ///\ingroup type_traits + template struct has_trivial_destructor : etl::is_pod {}; + + /// has_trivial_assignment + /// For C++03, only POD types are recognised. + ///\ingroup type_traits + template struct has_trivial_assignment : etl::is_pod {}; + /// conditional ///\ingroup type_traits template struct conditional { typedef T type; }; From 9300b00646474f1a678d86b89634b4413d5dd260 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 17 Feb 2017 11:21:21 +0000 Subject: [PATCH 143/168] Added... uninitialized_default_construct uninitialized_value_construct for single items. --- src/memory.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/memory.h b/src/memory.h index 69a3e3af..2f8597f4 100644 --- a/src/memory.h +++ b/src/memory.h @@ -56,7 +56,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, TOutputIterator>::type - uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value) + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value) { std::fill(o_begin, o_end, value); @@ -89,7 +89,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, TOutputIterator>::type - uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value, TCounter& count) + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { std::fill(o_begin, o_end, value); count += std::distance(o_begin, o_end); @@ -238,6 +238,50 @@ namespace etl return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); } + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* /*p*/) + { + } + + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* /*p*/, TCounter& count) + { + ++count; + } + + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* p) + { + ::new (p) T; + } + + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* p, TCounter& count) + { + ::new (p) T; + ++count; + } + //***************************************************************************** /// Default initialises a range of objects to uninitialised memory. ///\ingroup memory @@ -359,6 +403,48 @@ namespace etl return o_end; } + //***************************************************************************** + /// Value construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p) + { + ::new (p) T(); + } + + //***************************************************************************** + /// Value construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p, TCounter& count) + { + ::new (p) T(); + ++count; + } + + //***************************************************************************** + /// Copy construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p, const T& value) + { + ::new (p) T(value); + } + + //***************************************************************************** + /// Copy construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p, const T& value, TCounter& count) + { + ::new (p) T(value); + ++count; + } + //***************************************************************************** /// Default initialises a range of objects to uninitialised memory. ///\ingroup memory @@ -521,8 +607,9 @@ namespace etl { etl::destroy_at(etl::addressof(*i_begin)); ++i_begin; - --count; } + + count -= std::distance(i_begin, i_end); } //***************************************************************************** From 2a4886b8d1396f2543b35c66c978d5d55597b507 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 17 Feb 2017 12:10:06 +0000 Subject: [PATCH 144/168] Renamed single item construct functions. --- src/memory.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/memory.h b/src/memory.h index 2f8597f4..bf6b5185 100644 --- a/src/memory.h +++ b/src/memory.h @@ -244,7 +244,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - uninitialized_default_construct(T* /*p*/) + construct_default_at(T* /*p*/) { } @@ -254,7 +254,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - uninitialized_default_construct(T* /*p*/, TCounter& count) + construct_default_at(T* /*p*/, TCounter& count) { ++count; } @@ -265,7 +265,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - uninitialized_default_construct(T* p) + construct_default_at(T* p) { ::new (p) T; } @@ -276,7 +276,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - uninitialized_default_construct(T* p, TCounter& count) + construct_default_at(T* p, TCounter& count) { ::new (p) T; ++count; @@ -408,7 +408,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void uninitialized_value_construct(T* p) + inline void construct_value_at(T* p) { ::new (p) T(); } @@ -418,7 +418,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void uninitialized_value_construct(T* p, TCounter& count) + inline void construct_value_at(T* p, TCounter& count) { ::new (p) T(); ++count; @@ -429,7 +429,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void uninitialized_value_construct(T* p, const T& value) + inline void construct_copy_at(T* p, const T& value) { ::new (p) T(value); } @@ -439,7 +439,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void uninitialized_value_construct(T* p, const T& value, TCounter& count) + inline void construct_copy_at(T* p, const T& value, TCounter& count) { ::new (p) T(value); ++count; From d72737d9b4c07c2b1412f39658fc10d776d8229b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 22 Feb 2017 20:25:14 +0000 Subject: [PATCH 145/168] Added for_each_if & transform_if --- src/algorithm.h | 39 ++++++++++++++++++++++++++++++++++ test/test_algorithm.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/src/algorithm.h b/src/algorithm.h index 18f4a844..2d8218c4 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -547,6 +547,45 @@ namespace etl return std::pair(destination_true, destination_false); } + + //*************************************************************************** + /// Like for_each but applies a predicate before calling the function. + ///\ingroup algorithm + //*************************************************************************** + template + TUnaryFunction for_each_if(TIterator begin, const TIterator end, TUnaryFunction function, TUnaryPredicate predicate) + { + while (begin != end) + { + if (predicate(*begin)) + { + function(*begin); + } + + ++begin; + } + + return function; + } + + //*************************************************************************** + /// Like transform but applies a predicate before calling the function. + ///\ingroup algorithm + //*************************************************************************** + template + void transform_if(TInputIterator i_begin, const TInputIterator i_end, TOutputIterator o_begin, TUnaryFunction function, TUnaryPredicate predicate) + { + while (i_begin != i_end) + { + if (predicate(*i_begin)) + { + *o_begin = function(*i_begin); + } + + ++i_begin; + ++o_begin; + } + } } #endif diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index cc678d46..f89da223 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -471,5 +471,51 @@ namespace int* p = std::find_if_not(std::begin(data1), std::end(data1), std::bind2nd(std::less(), 4)); CHECK_EQUAL(5, *p); } + + //========================================================================= + TEST(for_each_if) + { + int data1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + + struct Sum + { + Sum() : sum(0) { } + + Sum& operator()(int i) + { + sum += i; + + return *this; + } + + int sum; + } accumulator; + + // For each if everything less than 5. + accumulator = etl::for_each_if(std::begin(data1), + std::end(data1), + accumulator, + std::bind2nd(std::less(), 5)); + + CHECK_EQUAL(10, accumulator.sum); + } + + //========================================================================= + TEST(transform_if) + { + int data1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int data2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int data3[] = { 2, 0, 4, 0, 6, 0, 8, 0, 0, 0 }; + + // Double everything less than 5. + etl::transform_if(std::begin(data1), + std::end(data1), + std::begin(data2), + std::bind2nd(std::multiplies(), 2), + std::bind2nd(std::less(), 5)); + + bool is_same = std::equal(std::begin(data2), std::end(data2), std::begin(data3)); + CHECK(is_same); + } }; } From 21e848df9e7640abe8dfe3fdb09af640208ce1e4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 22 Feb 2017 20:33:57 +0000 Subject: [PATCH 146/168] Removed 'explicit' for conversion operator. --- src/type_def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type_def.h b/src/type_def.h index ce1435c3..e35257b1 100644 --- a/src/type_def.h +++ b/src/type_def.h @@ -74,7 +74,7 @@ namespace etl } //********************************************************************* - explicit operator TValue() const + operator TValue() const { return value; } From 258bddccbaba8d7771473956e8976cb331ff24c1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 22 Feb 2017 20:38:45 +0000 Subject: [PATCH 147/168] Removed 'explicit' for conversion operator. --- src/type_def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type_def.h b/src/type_def.h index ce1435c3..e35257b1 100644 --- a/src/type_def.h +++ b/src/type_def.h @@ -74,7 +74,7 @@ namespace etl } //********************************************************************* - explicit operator TValue() const + operator TValue() const { return value; } From 536ad7f3846b0ea4151d8412bf12daf8316e32b4 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 23 Feb 2017 08:21:47 +0000 Subject: [PATCH 148/168] Corrected operation of transform_if --- src/algorithm.h | 5 ++--- test/test_algorithm.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/algorithm.h b/src/algorithm.h index 2d8218c4..5ae0de1e 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -253,7 +253,7 @@ namespace etl //*************************************************************************** template TOutputIterator copy_n(TInputIterator i_begin, Size count, TOutputIterator o_begin, TOutputIterator o_end) - { + { return etl::copy(i_begin, i_begin + count, o_begin, o_end);; } @@ -579,11 +579,10 @@ namespace etl { if (predicate(*i_begin)) { - *o_begin = function(*i_begin); + *o_begin++ = function(*i_begin); } ++i_begin; - ++o_begin; } } } diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index f89da223..4c400faf 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -476,7 +476,7 @@ namespace TEST(for_each_if) { int data1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; - + struct Sum { Sum() : sum(0) { } @@ -503,18 +503,18 @@ namespace //========================================================================= TEST(transform_if) { - int data1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; - int data2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - int data3[] = { 2, 0, 4, 0, 6, 0, 8, 0, 0, 0 }; + int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare[] = { 2, 4, 6, 8, 0, 0, 0, 0, 0, 0 }; - // Double everything less than 5. - etl::transform_if(std::begin(data1), - std::end(data1), - std::begin(data2), + // Double everything less than 5 and copy to output. + etl::transform_if(std::begin(input), + std::end(input), + std::begin(output), std::bind2nd(std::multiplies(), 2), std::bind2nd(std::less(), 5)); - bool is_same = std::equal(std::begin(data2), std::end(data2), std::begin(data3)); + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); CHECK(is_same); } }; From 54714f1eda176f075396c3fa7ce1c0276054b974 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Thu, 23 Feb 2017 08:37:56 +0000 Subject: [PATCH 149/168] Added for_each_if & transform_if Corrected operation of transform_if --- src/algorithm.h | 145 ++++++++++++++++++++++++++++++++++++---- test/test_algorithm.cpp | 46 +++++++++++++ 2 files changed, 177 insertions(+), 14 deletions(-) diff --git a/src/algorithm.h b/src/algorithm.h index f3afa52b..5ae0de1e 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -33,14 +33,17 @@ SOFTWARE. ///\defgroup algorithm algorithm /// Reverse engineered algorithms from C++ 0x11 +/// Additional new variants of certain algorithms. ///\ingroup utilities #include #include #include #include +#include #include +#include "iterator.h" #include "type_traits.h" namespace etl @@ -67,7 +70,7 @@ namespace etl { maximum = begin; } - + ++begin; } @@ -95,7 +98,7 @@ namespace etl template std::pair minmax(const T& a, const T& b) { - return (b < a) ? std::pair(b, a) : std::pair(a, b); + return (b < a) ? std::pair(b, a) : std::pair(a, b); } //*************************************************************************** @@ -183,6 +186,55 @@ namespace etl return etl::is_sorted_until(begin, end, compare) == end; } + //*************************************************************************** + /// copy + /// A form of copy where the smallest of the two ranges is used. + /// There is currently no STL equivalent. + /// Specialisation for random access iterators. + ///\param i_begin Beginning of the input range. + ///\param i_end End of the input range. + ///\param o_begin Beginning of the output range. + ///\param o_end End of the output range. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value && + etl::is_random_iterator::value, TOutputIterator>::type + copy(TInputIterator i_begin, TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end) + { + size_t s_size = std::distance(i_begin, i_end); + size_t d_size = std::distance(o_begin, o_end); + size_t size = (s_size < d_size) ? s_size : d_size; + + return std::copy(i_begin, i_begin + size, o_begin); + } + + //*************************************************************************** + /// copy + /// A form of copy where the smallest of the two ranges is used. + /// There is currently no STL equivalent. + /// Specialisation for non random access iterators. + ///\param i_begin Beginning of the input range. + ///\param i_end End of the input range. + ///\param o_begin Beginning of the output range. + ///\param o_end End of the output range. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value || + !etl::is_random_iterator::value, TOutputIterator>::type + copy(TInputIterator i_begin, TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end) + { + while ((i_begin != i_end) && (o_begin != o_end)) + { + *o_begin++ = *i_begin++; + } + + return o_begin; + } + //*************************************************************************** /// copy_n ///\ingroup algorithm @@ -191,15 +243,18 @@ namespace etl template TOutputIterator copy_n(TInputIterator begin, Size count, TOutputIterator result) { - if (count > 0) - { - for (Size i = 0; i < count; ++i) - { - *result++ = *begin++; - } - } + return std::copy(begin, begin + count, result); + } - return result; + //*************************************************************************** + /// copy_n + /// A form of copy_n where the smallest of the two ranges is used. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator copy_n(TInputIterator i_begin, Size count, TOutputIterator o_begin, TOutputIterator o_end) + { + return etl::copy(i_begin, i_begin + count, o_begin, o_end);; } //*************************************************************************** @@ -223,6 +278,30 @@ namespace etl return out; } + //*************************************************************************** + /// copy_if + /// A form of copy_if where it terminates when the first end iterator is reached. + /// There is currently no STL equivelent. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator copy_if(TInputIterator i_begin, TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end, + TUnaryPredicate predicate) + { + while ((i_begin != i_end) && (o_begin != o_end)) + { + if (predicate(*i_begin)) + { + *o_begin++ = *i_begin; + } + + ++i_begin; + } + + return o_begin; + } + //*************************************************************************** /// find_if_not ///\ingroup algorithm @@ -449,10 +528,10 @@ namespace etl //*************************************************************************** template std::pair partition_copy(TSource begin, - TSource end, - TDestinationTrue destination_true, - TDestinationFalse destination_false, - TUnaryPredicate predicate) + TSource end, + TDestinationTrue destination_true, + TDestinationFalse destination_false, + TUnaryPredicate predicate) { while (begin != end) { @@ -468,6 +547,44 @@ namespace etl return std::pair(destination_true, destination_false); } + + //*************************************************************************** + /// Like for_each but applies a predicate before calling the function. + ///\ingroup algorithm + //*************************************************************************** + template + TUnaryFunction for_each_if(TIterator begin, const TIterator end, TUnaryFunction function, TUnaryPredicate predicate) + { + while (begin != end) + { + if (predicate(*begin)) + { + function(*begin); + } + + ++begin; + } + + return function; + } + + //*************************************************************************** + /// Like transform but applies a predicate before calling the function. + ///\ingroup algorithm + //*************************************************************************** + template + void transform_if(TInputIterator i_begin, const TInputIterator i_end, TOutputIterator o_begin, TUnaryFunction function, TUnaryPredicate predicate) + { + while (i_begin != i_end) + { + if (predicate(*i_begin)) + { + *o_begin++ = function(*i_begin); + } + + ++i_begin; + } + } } #endif diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 91782b90..806d7a0d 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -318,5 +318,51 @@ namespace int* p = std::find_if_not(std::begin(data1), std::end(data1), std::bind2nd(std::less(), 4)); CHECK_EQUAL(5, *p); } + + //========================================================================= + TEST(for_each_if) + { + int data1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + + struct Sum + { + Sum() : sum(0) { } + + Sum& operator()(int i) + { + sum += i; + + return *this; + } + + int sum; + } accumulator; + + // For each if everything less than 5. + accumulator = etl::for_each_if(std::begin(data1), + std::end(data1), + accumulator, + std::bind2nd(std::less(), 5)); + + CHECK_EQUAL(10, accumulator.sum); + } + + //========================================================================= + TEST(transform_if) + { + int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare[] = { 2, 4, 6, 8, 0, 0, 0, 0, 0, 0 }; + + // Double everything less than 5 and copy to output. + etl::transform_if(std::begin(input), + std::end(input), + std::begin(output), + std::bind2nd(std::multiplies(), 2), + std::bind2nd(std::less(), 5)); + + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); + CHECK(is_same); + } }; } From 7238f11ea4956cdf8e1ecaa260fab465ef33a1ad Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 23 Feb 2017 23:11:21 +0000 Subject: [PATCH 150/168] Added more transform algorithms --- src/algorithm.h | 117 ++++++++++++++++++++++++++++++++++++++- test/test_algorithm.cpp | 119 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 233 insertions(+), 3 deletions(-) diff --git a/src/algorithm.h b/src/algorithm.h index 5ae0de1e..58e05eb1 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -549,7 +549,7 @@ namespace etl } //*************************************************************************** - /// Like for_each but applies a predicate before calling the function. + /// Like std::for_each but applies a predicate before calling the function. ///\ingroup algorithm //*************************************************************************** template @@ -569,11 +569,66 @@ namespace etl } //*************************************************************************** - /// Like transform but applies a predicate before calling the function. + /// A form of std::transform where the transform returns when the first range + /// end is reached. + /// There is currently no STL equivalent. + ///\ingroup algorithm + //*************************************************************************** + template + void transform(TInputIterator i_begin, + TInputIterator i_end, + TOutputIterator o_begin, + TOutputIterator o_end, + TUnaryFunction function) + { + while ((i_begin != i_end) && (o_begin != o_end)) + { + *o_begin++ = function(*i_begin++); + } + } + + //*************************************************************************** + /// Transform 'n' items. + /// There is currently no STL equivalent. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + transform_n(TInputIterator i_begin, + TSize n, + TOutputIterator o_begin, + TUnaryFunction function) + { + std::transform(i_begin, i_begin + n, o_begin, function); + } + + //*************************************************************************** + /// Transform 'n' items. + /// There is currently no STL equivalent. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + transform_n(TInputIterator i_begin, + TSize n, + TOutputIterator o_begin, + TUnaryFunction function) + { + while (n > 0) + { + *o_begin++ = function(*i_begin++); + --n; + } + } + + //*************************************************************************** + /// Like std::transform but applies a predicate before calling the function. ///\ingroup algorithm //*************************************************************************** template - void transform_if(TInputIterator i_begin, const TInputIterator i_end, TOutputIterator o_begin, TUnaryFunction function, TUnaryPredicate predicate) + TOutputIterator transform_if(TInputIterator i_begin, const TInputIterator i_end, + TOutputIterator o_begin, TUnaryFunction function, + TUnaryPredicate predicate) { while (i_begin != i_end) { @@ -584,6 +639,62 @@ namespace etl ++i_begin; } + + return o_begin; + } + + //*************************************************************************** + /// Like std::transform but applies a predicate before calling the function. + /// Returns when the first range end is reached. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator transform_if(TInputIterator i_begin, const TInputIterator i_end, + TOutputIterator o_begin, TOutputIterator o_end, + TUnaryFunction function, + TUnaryPredicate predicate) + { + while ((i_begin != i_end) && (o_begin != o_end)) + { + if (predicate(*i_begin)) + { + *o_begin++ = function(*i_begin); + } + + ++i_begin; + } + + return o_begin; + } + + //*************************************************************************** + /// Transforms the elements from the range (begin, end) to two different ranges + /// depending on the value returned by the predicate.
+ ///\ingroup algorithm + //*************************************************************************** + template + std::pair partition_transform(TSource begin, + TSource end, + TDestinationTrue destination_true, + TDestinationFalse destination_false, + TUnaryFunctionTrue function_true, + TUnaryFunctionFalse function_false, + TUnaryPredicate predicate) + { + while (begin != end) + { + if (predicate(*begin)) + { + *destination_true++ = function_true(*begin++); + } + else + { + *destination_false++ = function_false(*begin++); + } + } + + return std::pair(destination_true, destination_false); } } diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 4c400faf..7284731b 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -500,6 +500,67 @@ namespace CHECK_EQUAL(10, accumulator.sum); } + //========================================================================= + TEST(transform_4_parameter) + { + int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare[] = { 2, 16, 4, 14, 6, 0, 0, 0, 0, 0 }; + + // Double everything and copy to output. + etl::transform(std::begin(input), + std::end(input), + std::begin(output), + std::begin(output) + (etl::size(output) / 2), + std::bind2nd(std::multiplies(), 2)); + + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); + CHECK(is_same); + + std::fill(std::begin(output), std::end(output), 0); + + etl::transform(std::begin(input), + std::begin(input) + (etl::size(input) / 2), + std::begin(output), + std::end(output), + std::bind2nd(std::multiplies(), 2)); + + is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); + CHECK(is_same); + } + + //========================================================================= + TEST(transform_n_random_iterator) + { + int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare[] = { 2, 16, 4, 14, 6, 12, 8, 0, 0, 0 }; + + etl::transform_n(std::begin(input), + 7, + std::begin(output), + std::bind2nd(std::multiplies(), 2)); + + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); + CHECK(is_same); + } + + //========================================================================= + TEST(transform_n_non_random_iterator) + { + std::list input = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare[] = { 2, 16, 4, 14, 6, 12, 8, 0, 0, 0 }; + + etl::transform_n(std::begin(input), + 7, + std::begin(output), + std::bind2nd(std::multiplies(), 2)); + + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); + CHECK(is_same); + } + //========================================================================= TEST(transform_if) { @@ -517,5 +578,63 @@ namespace bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); CHECK(is_same); } + + //========================================================================= + TEST(transform_if_4_parameter) + { + int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare1[] = { 2, 4, 6, 8, 0, 0, 0, 0, 0, 0 }; + int compare2[] = { 2, 4, 6, 0, 0, 0, 0, 0, 0, 0 }; + + // Double everything and copy to output. + etl::transform_if(std::begin(input), + std::end(input), + std::begin(output), + std::begin(output) + (etl::size(output) / 2), + std::bind2nd(std::multiplies(), 2), + std::bind2nd(std::less(), 5)); + + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare1)); + CHECK(is_same); + + std::fill(std::begin(output), std::end(output), 0); + + etl::transform_if(std::begin(input), + std::begin(input) + (etl::size(input) / 2), + std::begin(output), + std::end(output), + std::bind2nd(std::multiplies(), 2), + std::bind2nd(std::less(), 5)); + + is_same = std::equal(std::begin(output), std::end(output), std::begin(compare2)); + CHECK(is_same); + } + + //========================================================================= + TEST(partition_transform) + { + int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int output_true[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int output_false[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare_true[] = { 2, 4, 6, 8, 0, 0, 0, 0, 0, 0 }; + int compare_false[] = { -16, -14, -12, -10, -20, -18, 0, 0, 0, 0 }; + + // Multiply everything less than 5 by 2 and copy to output_true. + // Multiply everything not less than 5 by -2 and copy to output_false. + etl::partition_transform(std::begin(input), + std::end(input), + std::begin(output_true), + std::begin(output_false), + std::bind2nd(std::multiplies(), 2), + std::bind2nd(std::multiplies(), -2), + std::bind2nd(std::less(), 5)); + + bool is_same = std::equal(std::begin(output_true), std::end(output_true), std::begin(compare_true)); + CHECK(is_same); + + is_same = std::equal(std::begin(output_false), std::end(output_false), std::begin(compare_false)); + CHECK(is_same); + } }; } From 1e6fc88ab92f476000bf59b1e9603a7c88421922 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 23 Feb 2017 23:12:48 +0000 Subject: [PATCH 151/168] memory algorithm updates --- src/memory.h | 74 +++---- test/test_memory.cpp | 449 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 480 insertions(+), 43 deletions(-) create mode 100644 test/test_memory.cpp diff --git a/src/memory.h b/src/memory.h index bf6b5185..1e05579e 100644 --- a/src/memory.h +++ b/src/memory.h @@ -91,9 +91,10 @@ namespace etl typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { - std::fill(o_begin, o_end, value); count += std::distance(o_begin, o_end); + std::fill(o_begin, o_end, value); + return o_end; } @@ -108,13 +109,7 @@ namespace etl { count += std::distance(o_begin, o_end); - typedef typename std::iterator_traits::value_type value_type; - - while (o_begin != o_end) - { - ::new (static_cast(etl::addressof(*o_begin))) value_type(value); - ++o_begin; - } + etl::uninitialized_fill(o_begin, o_end, value); return o_end; } @@ -199,16 +194,7 @@ namespace etl typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count) { - typedef typename std::iterator_traits::value_type value_type; - - TOutputIterator o_end = o_begin; - - while (i_begin != i_end) - { - ::new (static_cast(etl::addressof(*o_end))) value_type(*i_begin); - ++i_begin; - ++o_end; - } + TOutputIterator o_end = etl::uninitialized_copy(i_begin, i_end, o_begin); count += std::distance(o_begin, o_end); @@ -244,7 +230,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - construct_default_at(T* /*p*/) + create_default_at(T* /*p*/) { } @@ -254,7 +240,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - construct_default_at(T* /*p*/, TCounter& count) + create_default_at(T* /*p*/, TCounter& count) { ++count; } @@ -265,7 +251,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - construct_default_at(T* p) + create_default_at(T* p) { ::new (p) T; } @@ -276,7 +262,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - construct_default_at(T* p, TCounter& count) + create_default_at(T* p, TCounter& count) { ::new (p) T; ++count; @@ -332,13 +318,7 @@ namespace etl { count += std::distance(o_begin, o_end); - typedef typename std::iterator_traits::value_type value_type; - - while (o_begin != o_end) - { - ::new (static_cast(etl::addressof(*o_begin))) value_type; - ++o_begin; - } + etl::uninitialized_default_construct(o_begin, o_end); } //***************************************************************************** @@ -408,7 +388,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void construct_value_at(T* p) + inline void create_value_at(T* p) { ::new (p) T(); } @@ -418,7 +398,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void construct_value_at(T* p, TCounter& count) + inline void create_value_at(T* p, TCounter& count) { ::new (p) T(); ++count; @@ -429,7 +409,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void construct_copy_at(T* p, const T& value) + inline void create_copy_at(T* p, const T& value) { ::new (p) T(value); } @@ -439,7 +419,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - inline void construct_copy_at(T* p, const T& value, TCounter& count) + inline void create_copy_at(T* p, const T& value, TCounter& count) { ::new (p) T(value); ++count; @@ -450,7 +430,21 @@ namespace etl ///\ingroup memory //***************************************************************************** template - void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end) + typename etl::enable_if::value_type>::value, void>::type + uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end) + { + typedef typename std::iterator_traits::value_type value_type; + + std::fill(o_begin, o_end, value_type()); + } + + //***************************************************************************** + /// Default initialises a range of objects to uninitialised memory. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value_type>::value, void>::type + uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end) { typedef typename std::iterator_traits::value_type value_type; @@ -471,13 +465,7 @@ namespace etl { count += std::distance(o_begin, o_end); - typedef typename std::iterator_traits::value_type value_type; - - while (o_begin != o_end) - { - ::new (static_cast(etl::addressof(*o_begin))) value_type(); - ++o_begin; - } + etl::uninitialized_value_construct(o_begin, o_end); } //***************************************************************************** @@ -603,13 +591,13 @@ namespace etl typename etl::enable_if::value_type>::value, void>::type destroy(TIterator i_begin, TIterator i_end, TCounter& count) { + count -= std::distance(i_begin, i_end); + while (i_begin != i_end) { etl::destroy_at(etl::addressof(*i_begin)); ++i_begin; } - - count -= std::distance(i_begin, i_end); } //***************************************************************************** diff --git a/test/test_memory.cpp b/test/test_memory.cpp new file mode 100644 index 00000000..6cc2ee0d --- /dev/null +++ b/test/test_memory.cpp @@ -0,0 +1,449 @@ +/****************************************************************************** +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 + +#include "../src/memory.h" +#include "../src/debug_count.h" + +#include +#include +#include +#include +#include + +#include + +namespace +{ + typedef std::string non_trivial_t; + typedef uint32_t trivial_t; + + const size_t SIZE = 10; + + std::array test_data_non_trivial = + { + "one", "two", "three", "four", "five", + "six", "seven", "eight", "nine", "ten" + }; + + std::array test_data_trivial = + { + 0x11223344, 0x22334455, 0x33445566, 0x44556677, 0x55667788, + 0x66778899, 0x778899AA, 0x8899AABB, 0x99AABBCC, 0xAABBCCDD + }; + + non_trivial_t test_item_non_trivial("eleven"); + non_trivial_t test_item_non_trivial_null(""); + trivial_t test_item_trivial(0xBBCCDDEE); + + char buffer_non_trivial[sizeof(non_trivial_t) * SIZE]; + char buffer_trivial[sizeof(trivial_t) * SIZE]; + + non_trivial_t* output_non_trivial = reinterpret_cast(buffer_non_trivial); + trivial_t* output_trivial = reinterpret_cast(buffer_trivial); + + struct overloaded + { + overloaded* operator&() + { + return nullptr; + } + }; +} + +namespace +{ + SUITE(test_memory) + { + //************************************************************************* + TEST(test_addressof) + { + int i; + CHECK(&i == etl::addressof(i)); + + overloaded ol; + CHECK(&ol != etl::addressof(ol)); + CHECK(reinterpret_cast(&reinterpret_cast(ol)) == etl::addressof(ol)); + } + + //************************************************************************* + TEST(test_create_destroy_trivial) + { + char n[sizeof(trivial_t)]; + trivial_t* pn = reinterpret_cast(n); + + // Non count. + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_default_at(pn); + CHECK_EQUAL(0xFFFFFFFF, *pn); + etl::destroy_at(pn); + CHECK_EQUAL(0xFFFFFFFF, *pn); + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_value_at(pn); + CHECK_EQUAL(0x0000000, *pn); + etl::destroy_at(pn); + CHECK_EQUAL(0x0000000, *pn); + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_copy_at(pn, test_item_trivial); + CHECK_EQUAL(test_item_trivial, *pn); + etl::destroy_at(pn); + CHECK_EQUAL(test_item_trivial, *pn); + + // Count. + size_t count = 0; + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_default_at(pn, count); + CHECK_EQUAL(0xFFFFFFFF, *pn); + CHECK_EQUAL(1, count); + etl::destroy_at(pn, count); + CHECK_EQUAL(0xFFFFFFFF, *pn); + CHECK_EQUAL(0, count); + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_value_at(pn, count); + CHECK_EQUAL(0x0000000, *pn); + CHECK_EQUAL(1, count); + etl::destroy_at(pn, count); + CHECK_EQUAL(0x0000000, *pn); + CHECK_EQUAL(0, count); + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_copy_at(pn, test_item_trivial, count); + CHECK_EQUAL(test_item_trivial, *pn); + CHECK_EQUAL(1, count); + etl::destroy_at(pn, count); + CHECK_EQUAL(test_item_trivial, *pn); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_create_destroy_non_trivial) + { + char n[sizeof(non_trivial_t)]; + non_trivial_t* pn = reinterpret_cast(n); + + // Non count. + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_default_at(pn); + CHECK_EQUAL(test_item_non_trivial_null, *pn); + etl::destroy_at(pn); + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_value_at(pn); + CHECK_EQUAL(test_item_non_trivial_null, *pn); + etl::destroy_at(pn); + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_copy_at(pn, test_item_non_trivial); + CHECK_EQUAL(test_item_non_trivial, *pn); + etl::destroy_at(pn); + + // Count. + size_t count = 0; + + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_default_at(pn, count); + CHECK_EQUAL(test_item_non_trivial_null, *pn); + CHECK_EQUAL(1, count); + etl::destroy_at(pn, count); + CHECK_EQUAL(0, count); + + count = 0; + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_value_at(pn, count); + CHECK_EQUAL(test_item_non_trivial_null, *pn); + CHECK_EQUAL(1, count); + etl::destroy_at(pn, count); + CHECK_EQUAL(0, count); + + count = 0; + std::fill(std::begin(n), std::end(n), 0xFF); + etl::create_copy_at(pn, test_item_non_trivial, count); + CHECK_EQUAL(test_item_non_trivial, *pn); + CHECK_EQUAL(1, count); + etl::destroy_at(pn, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_fill_n_trivial) + { + // Also tests uninitialized_fill. + + // Non count. + trivial_t* p = reinterpret_cast(buffer_trivial); + + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0); + etl::uninitialized_fill_n(p, SIZE, test_item_trivial); + + trivial_t* result; + + result = std::find_if_not(output_trivial, output_trivial + SIZE, [](trivial_t i) { return i == test_item_trivial; }); + + CHECK(result == output_trivial + SIZE); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0); + etl::uninitialized_fill_n(p, SIZE, test_item_trivial, count); + + result = std::find_if_not(output_trivial, output_trivial + SIZE, [](trivial_t i) { return i == test_item_trivial; }); + + CHECK(result == output_trivial + SIZE); + CHECK_EQUAL(SIZE, count); + + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_fill_n_non_trivial) + { + // Also tests uninitialized_fill. + + // Non count. + non_trivial_t* p = reinterpret_cast(buffer_non_trivial); + + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0); + etl::uninitialized_fill_n(p, SIZE, test_item_non_trivial); + + non_trivial_t* result; + + result = std::find_if_not(output_non_trivial, output_non_trivial + SIZE, [](const non_trivial_t& i) { return i == test_item_non_trivial; }); + + CHECK(result == output_non_trivial + SIZE); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0); + etl::uninitialized_fill_n(p, SIZE, test_item_non_trivial, count); + + result = std::find_if_not(output_non_trivial, + output_non_trivial + SIZE, + [](non_trivial_t i) { return i == test_item_non_trivial; }); + + CHECK(result == output_non_trivial + SIZE); + CHECK_EQUAL(SIZE, count); + + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_copy_n_trivial) + { + // Also tests uninitialized_copy. + + bool is_equal; + + // Non count. + trivial_t* p = reinterpret_cast(buffer_trivial); + + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0); + etl::uninitialized_copy_n(test_data_trivial.begin(), SIZE, p); + + is_equal = std::equal(output_trivial, output_trivial + SIZE, test_data_trivial.begin()); + CHECK(is_equal); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0); + etl::uninitialized_copy_n(test_data_trivial.begin(), SIZE, p, count); + + is_equal = std::equal(output_trivial, output_trivial + SIZE, test_data_trivial.begin()); + CHECK(is_equal); + CHECK_EQUAL(SIZE, count); + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_copy_n_non_trivial) + { + // Also tests uninitialized_copy. + + bool is_equal; + + // Non count. + non_trivial_t* p = reinterpret_cast(buffer_non_trivial); + + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0); + etl::uninitialized_copy_n(test_data_non_trivial.begin(), SIZE, p); + + is_equal = std::equal(output_non_trivial, output_non_trivial + SIZE, test_data_non_trivial.begin()); + CHECK(is_equal); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0); + etl::uninitialized_copy_n(test_data_non_trivial.begin(), SIZE, p, count); + + is_equal = std::equal(output_non_trivial, output_non_trivial + SIZE, test_data_non_trivial.begin()); + CHECK(is_equal); + CHECK_EQUAL(SIZE, count); + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_default_construct_n_trivial) + { + // Also tests uninitialized_default_construct. + + // Non count. + trivial_t* p = reinterpret_cast(buffer_trivial); + + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0xFF); + etl::uninitialized_default_construct_n(p, SIZE); + + trivial_t* result; + + result = std::find_if_not(output_trivial, output_trivial + SIZE, [](trivial_t i) { return i == 0xFFFFFFFF; }); + + CHECK(result == output_trivial + SIZE); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0xFF); + etl::uninitialized_default_construct_n(p, SIZE, count); + + result = std::find_if_not(output_trivial, output_trivial + SIZE, [](trivial_t i) { return i == 0xFFFFFFFF; }); + + CHECK(result == output_trivial + SIZE); + CHECK_EQUAL(SIZE, count); + + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_default_construct_n_non_trivial) + { + // Also tests uninitialized_default_construct. + + // Non count. + non_trivial_t* p = reinterpret_cast(buffer_non_trivial); + + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0xFF); + etl::uninitialized_default_construct_n(p, SIZE); + + non_trivial_t* result; + + result = std::find_if_not(output_non_trivial, output_non_trivial + SIZE, [](non_trivial_t i) { return i == test_item_non_trivial_null; }); + + CHECK(result == output_non_trivial + SIZE); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0xFF); + etl::uninitialized_default_construct_n(p, SIZE, count); + + result = std::find_if_not(output_non_trivial, output_non_trivial + SIZE, [](non_trivial_t i) { return i == test_item_non_trivial_null; }); + + CHECK(result == output_non_trivial + SIZE); + CHECK_EQUAL(SIZE, count); + + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_value_construct_n_trivial) + { + // Also tests uninitialized_default_construct. + + // Non count. + trivial_t* p = reinterpret_cast(buffer_trivial); + + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0xFF); + etl::uninitialized_value_construct_n(p, SIZE); + + trivial_t* result; + + result = std::find_if_not(output_trivial, output_trivial + SIZE, [](trivial_t i) { return i == trivial_t(); }); + + CHECK(result == output_trivial + SIZE); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_trivial), std::end(buffer_trivial), 0xFF); + etl::uninitialized_value_construct_n(p, SIZE, count); + + result = std::find_if_not(output_trivial, output_trivial + SIZE, [](trivial_t i) { return i == trivial_t(); }); + + CHECK(result == output_trivial + SIZE); + CHECK_EQUAL(SIZE, count); + + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + + //************************************************************************* + TEST(test_uninitialized_value_construct_n_non_trivial) + { + // Also tests uninitialized_default_construct. + + // Non count. + non_trivial_t* p = reinterpret_cast(buffer_non_trivial); + + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0xFF); + etl::uninitialized_value_construct_n(p, SIZE); + + non_trivial_t* result; + + result = std::find_if_not(output_non_trivial, output_non_trivial + SIZE, [](non_trivial_t i) { return i == non_trivial_t(); }); + + CHECK(result == output_non_trivial + SIZE); + etl::destroy(p, p + SIZE); + + // Count. + size_t count = 0; + std::fill(std::begin(buffer_non_trivial), std::end(buffer_non_trivial), 0xFF); + etl::uninitialized_value_construct_n(p, SIZE, count); + + result = std::find_if_not(output_non_trivial, output_non_trivial + SIZE, [](non_trivial_t i) { return i == non_trivial_t(); }); + + CHECK(result == output_non_trivial + SIZE); + CHECK_EQUAL(SIZE, count); + + etl::destroy(p, p + SIZE, count); + CHECK_EQUAL(0, count); + } + }; +} From 0508d796bcd1d10e372fabcd8ca164ed21c3bf49 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 23 Feb 2017 23:14:07 +0000 Subject: [PATCH 152/168] Added extra size tests --- test/test_forward_list.cpp | 91 +++++++++++++++++++++----------- test/test_list.cpp | 105 ++++++++++++++++++++++++++++++++----- test/test_vector.cpp | 20 +++++++ 3 files changed, 171 insertions(+), 45 deletions(-) diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 03ac1e55..50169e7d 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -168,8 +168,9 @@ namespace CompareDataNDC compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -186,8 +187,9 @@ namespace CompareDataNDC compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE, VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -213,8 +215,9 @@ namespace CompareDataNDC compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -231,8 +234,9 @@ namespace CompareDataNDC compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE, VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -255,8 +259,9 @@ namespace data.assign(compare_data.begin(), compare_data.end()); data.assign(compare_data.begin(), compare_data.end()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -273,8 +278,9 @@ namespace data.assign(INITIAL_SIZE, VALUE); data.assign(INITIAL_SIZE, VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -309,8 +315,9 @@ namespace data.insert_after(i_data, INSERT_VALUE); compare_data.insert_after(i_compare_data, INSERT_VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); offset = 0; @@ -324,8 +331,9 @@ namespace data.insert_after(i_data, INSERT_VALUE); compare_data.insert_after(i_compare_data, INSERT_VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -350,8 +358,9 @@ namespace data.insert_after(i_data, 2, INSERT_VALUE); compare_data.insert_after(i_compare_data, 2, INSERT_VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); offset = 0; @@ -365,8 +374,9 @@ namespace data.insert_after(i_data, 2, INSERT_VALUE); compare_data.insert_after(i_compare_data, 2, INSERT_VALUE); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -382,8 +392,9 @@ namespace compare_data.insert_after(compare_data.before_begin(), test2.begin(), test2.end()); data.insert_after(data.before_begin(), test2.begin(), test2.end()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); compare_data.assign(test1.begin(), test1.end()); @@ -398,8 +409,9 @@ namespace compare_data.insert_after(icd, test2.begin(), test2.end()); data.insert_after(id, test2.begin(), test2.end()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -426,8 +438,9 @@ namespace CHECK_EQUAL(6U, data.size()); CHECK_EQUAL(6, std::distance(data.begin(), data.end())); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -552,16 +565,18 @@ namespace i_compare_data = compare_data.erase_after(i_compare_data); i_data = data.erase_after(i_data); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); CHECK(*i_compare_data == *i_data); i_compare_data = compare_data.erase_after(compare_data.begin()); i_data = data.erase_after(data.begin()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); are_equal = *i_data == *i_compare_data; @@ -576,6 +591,8 @@ namespace //std::advance(i_data, data.size() - 1); i_data = data.erase_after(i_data); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -607,6 +624,8 @@ namespace CHECK_EQUAL(*i_compare_result, *i_result); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -629,6 +648,8 @@ namespace CHECK(i_result == data.end()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -664,7 +685,6 @@ namespace CHECK_EQUAL(data.size(), other_data.size()); are_equal = std::equal(data.begin(), data.end(), other_data.begin()); - CHECK(are_equal); } @@ -680,7 +700,6 @@ namespace idata2 = idata1; bool isEqual = std::equal(data1.begin(), data1.end(), data2.begin()); - CHECK(isEqual); } @@ -696,7 +715,6 @@ namespace CHECK_EQUAL(data.size(), other_data.size()); are_equal = std::equal(data.begin(), data.end(), other_data.begin()); - CHECK(are_equal); } @@ -709,8 +727,9 @@ namespace compare_data.unique(); data.unique(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -723,8 +742,9 @@ namespace compare_data.unique(); data.unique(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -737,8 +757,9 @@ namespace compare_data.remove(ItemNDC("7")); data.remove(ItemNDC("7")); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -751,8 +772,9 @@ namespace compare_data.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); data.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -768,8 +790,9 @@ namespace CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); CHECK_EQUAL(data.size(), std::distance(data.begin(), data.end())); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -783,7 +806,6 @@ namespace data.reverse(); are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); - CHECK(are_equal); } @@ -796,8 +818,9 @@ namespace compare_data.sort(); data.sort(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -810,8 +833,9 @@ namespace compare_data.sort(); data.sort(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -840,8 +864,9 @@ namespace compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); data.move_after(i_from_before, i_to_before); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); // Move to the end. @@ -860,8 +885,9 @@ namespace compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); data.move_after(i_from_before, i_to_before); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); // Move to nearby. @@ -880,8 +906,9 @@ namespace compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); data.move_after(i_from_before, i_to_before); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); // Move to same. @@ -900,8 +927,9 @@ namespace compare_data.splice_after(i_compare_to_before, compare_data, i_compare_from_before); data.move_after(i_from_before, i_to_before); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -938,8 +966,9 @@ namespace compare_data.splice_after(i_compare_to_before, compare_data, i_compare_first_before, i_compare_last); data.move_after(i_first_before, i_last, i_to_before); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); // Move to the end. diff --git a/test/test_list.cpp b/test/test_list.cpp index e8bb91b5..cc80886a 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -235,6 +235,8 @@ namespace CompareData compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE, VALUE); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -385,8 +387,9 @@ namespace compare_data.insert(compare_data.begin(), test2.begin(), test2.end()); data.insert(data.begin(), test2.begin(), test2.end()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); compare_data.assign(test1.begin(), test1.end()); @@ -395,8 +398,9 @@ namespace compare_data.insert(compare_data.end(), test2.begin(), test2.end()); data.insert(data.end(), test2.begin(), test2.end()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); compare_data.assign(test1.begin(), test1.end()); @@ -411,8 +415,9 @@ namespace compare_data.insert(icd, test2.begin(), test2.end()); data.insert(id, test2.begin(), test2.end()); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -436,8 +441,9 @@ namespace CHECK_NO_THROW(data.push_front(ItemNDC("5"))); CHECK_NO_THROW(data.push_front(ItemNDC("6"))); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -536,8 +542,9 @@ namespace CHECK_NO_THROW(data.push_back(ItemNDC("5"))); CHECK_NO_THROW(data.push_back(ItemNDC("6"))); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -572,8 +579,9 @@ namespace data.pop_back(); data.pop_back(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -608,6 +616,8 @@ namespace i_compare_data = compare_data.erase(i_compare_data); i_data = data.erase(i_data); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -616,6 +626,8 @@ namespace i_compare_data = compare_data.erase(compare_data.begin()); i_data = data.erase(data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -632,6 +644,8 @@ namespace std::advance(i_data, data.size() - 1); i_data = data.erase(i_data); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -661,8 +675,9 @@ namespace data.erase(i_data_1, i_data_2); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -764,7 +779,6 @@ namespace CHECK_EQUAL(data.size(), other_data.size()); are_equal = std::equal(data.begin(), data.end(), other_data.begin()); - CHECK(are_equal); } @@ -777,8 +791,9 @@ namespace compare_data.unique(); data.unique(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -791,8 +806,9 @@ namespace compare_data.unique(); data.unique(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -805,8 +821,9 @@ namespace compare_data.remove(ItemNDC("7")); data.remove(ItemNDC("7")); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -819,8 +836,9 @@ namespace compare_data.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); data.remove_if(std::bind2nd(std::equal_to(), ItemNDC("7"))); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -850,8 +868,9 @@ namespace compare_data.sort(); data.sort(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -864,8 +883,9 @@ namespace compare_data.sort(); data.sort(); - are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -892,6 +912,8 @@ namespace to = data.begin(); data.splice(to, data, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -906,6 +928,8 @@ namespace to = data.end(); data.splice(to, data, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -922,6 +946,8 @@ namespace std::advance(to, 6); data.splice(to, data, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -938,6 +964,8 @@ namespace std::advance(to, 4); data.splice(to, data, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); } @@ -968,9 +996,13 @@ namespace to = data.begin(); data.splice(to, data2, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -991,9 +1023,13 @@ namespace to = data.end(); data.splice(to, data2, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -1016,9 +1052,13 @@ namespace std::advance(to, 6); data.splice(to, data2, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -1041,9 +1081,13 @@ namespace std::advance(to, 4); data.splice(to, data2, from); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); } @@ -1077,6 +1121,8 @@ namespace to = data.begin(); data.splice(to, data, begin, end); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -1095,6 +1141,8 @@ namespace to = data.end(); data.splice(to, data, begin, end); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -1115,6 +1163,8 @@ namespace std::advance(to, 7); data.splice(to, data, begin, end); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); @@ -1128,6 +1178,9 @@ namespace DataNDC data2(data); data.splice(to, data, begin, end); + + CHECK_EQUAL(data.size(), data2.size()); + are_equal = std::equal(data.begin(), data.end(), data2.begin()); CHECK(are_equal); @@ -1173,9 +1226,13 @@ namespace to = data.begin(); data.splice(to, data2, begin, end); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -1200,9 +1257,13 @@ namespace to = data.end(); data.splice(to, data2, begin, end); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -1229,9 +1290,13 @@ namespace std::advance(to, 7); data.splice(to, data2, begin, end); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); } @@ -1255,9 +1320,13 @@ namespace to = data.begin(); data.splice(to, data2); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -1274,9 +1343,13 @@ namespace to = data.end(); data.splice(to, data2); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); @@ -1295,9 +1368,13 @@ namespace std::advance(to, 7); data.splice(to, data2); + CHECK_EQUAL(compare_data.size(), data.size()); + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(are_equal); + CHECK_EQUAL(compare_data2.size(), data2.size()); + are_equal = std::equal(data2.begin(), data2.end(), compare_data2.begin()); CHECK(are_equal); } diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 51f1b62c..2785bb6b 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -244,6 +244,8 @@ namespace std::array compare_data; compare_data.fill(INITIAL_VALUE); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); @@ -432,6 +434,8 @@ namespace data.assign(compare_data.begin(), compare_data.end()); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -450,6 +454,8 @@ namespace Data data; data.assign(INITIAL_SIZE, INITIAL_VALUE); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -487,6 +493,8 @@ namespace data.push_back(i); } + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -505,6 +513,8 @@ namespace data.push_back(); data[0] = 1; + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -537,6 +547,8 @@ namespace data.pop_back(); data.pop_back(); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -623,6 +635,8 @@ namespace data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_data.insert(compare_data.begin() + offset, INSERT_SIZE, INITIAL_VALUE); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -675,6 +689,8 @@ namespace data.insert(data.begin() + offset, insert_data.begin(), insert_data.end()); compare_data.insert(compare_data.begin() + offset, insert_data.begin(), insert_data.end()); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -719,6 +735,8 @@ namespace data.erase(data.begin() + 2); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -736,6 +754,8 @@ namespace data.erase(data.begin() + 2, data.begin() + 4); + CHECK_EQUAL(compare_data.size(), data.size()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); From 46a11d1747a902322f661340c4b647cbf2548b78 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 23 Feb 2017 23:14:58 +0000 Subject: [PATCH 153/168] Performance enhancements --- src/ivector.h | 706 +++++++++++++++++------------------ src/private/ivectorpointer.h | 2 +- 2 files changed, 338 insertions(+), 370 deletions(-) diff --git a/src/ivector.h b/src/ivector.h index b18e7a77..056ebd7c 100644 --- a/src/ivector.h +++ b/src/ivector.h @@ -43,6 +43,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" #include "error_handler.h" +#include "memory.h" #ifdef ETL_COMPILER_GCC #pragma GCC diagnostic ignored "-Wunused-variable" @@ -72,14 +73,6 @@ namespace etl typedef size_t size_type; typedef typename std::iterator_traits::difference_type difference_type; - private: - - // Type trait to allow selection of simple algorithms for simple types. - template - struct is_simple_type : integral_constant::value || etl::is_pointer::value> - { - }; - protected: typedef typename parameter_type::type parameter_t; @@ -92,7 +85,7 @@ namespace etl //********************************************************************* iterator begin() { - return &p_buffer[0]; + return p_buffer; } //********************************************************************* @@ -101,7 +94,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return &p_buffer[0]; + return p_buffer; } //********************************************************************* @@ -110,7 +103,7 @@ namespace etl //********************************************************************* iterator end() { - return &p_buffer[current_size]; + return p_end; } //********************************************************************* @@ -119,7 +112,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return &p_buffer[current_size]; + return p_end; } //********************************************************************* @@ -128,7 +121,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return &p_buffer[0]; + return p_buffer; } //********************************************************************* @@ -137,7 +130,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return &p_buffer[current_size]; + return p_end; } //********************************************************************* @@ -202,42 +195,7 @@ namespace etl //********************************************************************* void resize(size_t new_size) { - ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); - - // Choose the algorithm according to type. - // The unused branch should be optimised away. - if (is_simple_type::value) - { - // Size up if necessary. - if (current_size < new_size) - { - std::fill_n(&p_buffer[current_size], new_size - current_size, 0); - } - - current_size = new_size; - } - else - { - // Size up or size down? - if (new_size > current_size) - { - // Up. - while (current_size < new_size) - { - create_element(); - } - } - else if (new_size < current_size) - { - // Down. - while (current_size > new_size) - { - destroy_element(); - } - } - } - - + resize(new_size, T()); } //********************************************************************* @@ -247,42 +205,65 @@ namespace etl ///\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, T value) + template + typename etl::enable_if::value, void>::type + resize(size_t new_size, T value) { ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); - // Choose the algorithm according to type. - // The unused branch should be optimised away. - if (is_simple_type::value) - { - // Size up if necessary. - if (current_size < new_size) - { - std::fill_n(&p_buffer[current_size], new_size - current_size, value); - } + const size_t current_size = size(); + size_t delta = (current_size < new_size) ? new_size - current_size : current_size - new_size; - current_size = new_size; + if (current_size < new_size) + { + std::fill_n(p_end, delta, value); +#if defined(ETL_DEBUG) + construct_count += delta; +#endif } else { - // Size up or size down? - if (new_size > current_size) - { - // Up. - while (current_size < new_size) - { - create_element(value); - } - } - else if (new_size < current_size) - { - // Down. - while (current_size > new_size) - { - destroy_element(); - } - } + p_end -= delta; +#if defined(ETL_DEBUG) + construct_count -= delta; +#endif } + + 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. + //********************************************************************* + template + typename etl::enable_if::value, void>::type + resize(size_t new_size, T value) + { + ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); + + const size_t current_size = size(); + size_t delta = (current_size < new_size) ? new_size - current_size : current_size - new_size; + + if (current_size < new_size) + { + etl::uninitialized_fill_n(p_end, delta, value); +#if defined(ETL_DEBUG) + construct_count += delta; +#endif + } + else + { + etl::destroy_n(p_end - delta, delta); +#if defined(ETL_DEBUG) + construct_count -= delta; +#endif + } + + p_end = p_buffer + new_size; } //********************************************************************* @@ -320,7 +301,7 @@ namespace etl //********************************************************************* reference at(size_t i) { - ETL_ASSERT(i < current_size, ETL_ERROR(vector_out_of_bounds)); + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -332,7 +313,7 @@ namespace etl //********************************************************************* const_reference at(size_t i) const { - ETL_ASSERT(i < current_size, ETL_ERROR(vector_out_of_bounds)); + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -342,7 +323,7 @@ namespace etl //********************************************************************* reference front() { - return p_buffer[0]; + return *p_buffer; } //********************************************************************* @@ -351,7 +332,7 @@ namespace etl //********************************************************************* const_reference front() const { - return p_buffer[0]; + return *p_buffer; } //********************************************************************* @@ -360,7 +341,7 @@ namespace etl //********************************************************************* reference back() { - return p_buffer[current_size - 1]; + return *(p_end - 1); } //********************************************************************* @@ -369,7 +350,7 @@ namespace etl //********************************************************************* const_reference back() const { - return p_buffer[current_size - 1]; + return *(p_end - 1); } //********************************************************************* @@ -400,34 +381,18 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(static_cast(count) <= MAX_SIZE, ETL_ERROR(vector_full)); #endif initialise(); - // Choose the algorithm according to type. - // The unused branch should be optimised away. - if (is_simple_type::value) - { - while (first != last) - { - p_buffer[current_size++] = *first++; - } - } - else - { - T* p = &p_buffer[0]; - while (first != last) - { - new (p) T(*first); - ++p; - ++first; - ++current_size; - ++construct_count; - } - } +#if defined(ETL_DEBUG) + p_end = etl::uninitialized_copy(first, last, p_buffer, construct_count); +#else + p_end = etl::uninitialized_copy(first, last, p_buffer); +#endif } //********************************************************************* @@ -438,32 +403,15 @@ namespace etl //********************************************************************* void assign(size_t n, parameter_t value) { - initialise(); - ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(vector_full)); - // Choose the algorithm according to type. - // The unused branch should be optimised away. - if (is_simple_type::value) - { - while (n > 0) - { - p_buffer[current_size++] = value; - --n; - } - } - else - { - T* p = &p_buffer[0]; - while (n > 0) - { - new (p) T(value); - ++p; - --n; - ++current_size; - ++construct_count; - } - } + initialise(); + +#if defined(ETL_DEBUG) + p_end = etl::uninitialized_fill_n(p_buffer, n, value, construct_count); +#else + p_end = etl::uninitialized_fill_n(p_buffer, n, value); +#endif } //************************************************************************* @@ -481,9 +429,10 @@ namespace etl void push_back() { #if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT(size() != MAX_SIZE, ETL_ERROR(vector_full)); #endif - create_element(); + + create_back(); } //********************************************************************* @@ -494,9 +443,9 @@ namespace etl void push_back(parameter_t value) { #if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT(size() != MAX_SIZE, ETL_ERROR(vector_full)); #endif - create_element(value); + create_back(value); } //************************************************************************* @@ -506,9 +455,9 @@ namespace etl void pop_back() { #if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(current_size > 0, ETL_ERROR(vector_empty)); + ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty)); #endif - destroy_element(); + destroy_back(); } //********************************************************************* @@ -519,18 +468,17 @@ namespace etl //********************************************************************* iterator insert(iterator position, parameter_t value) { - ETL_ASSERT((current_size)+1 <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT(size() + 1 <= MAX_SIZE, ETL_ERROR(vector_full)); - if (position != end()) + if (position == end()) { - T* p_last = &p_buffer[current_size - 1]; - create_element(*p_last); - std::copy_backward(position, p_last, p_last + 1); - *position = value; + create_back(value); } else { - create_element(value); + create_back(back()); + std::copy_backward(position, p_end - 1, p_end); + *position = value; } return position; @@ -544,17 +492,16 @@ namespace etl ///\param value The value to insert. //********************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type insert(iterator position, size_t n, parameter_t value) { - ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(vector_full)); - - T* p_end = &p_buffer[current_size]; + ETL_ASSERT((size() + n) <= MAX_SIZE, ETL_ERROR(vector_full)); std::copy_backward(position, p_end, p_end + n); std::fill_n(position, n, value); - current_size += n; + construct_count += n; + p_end += n; } //********************************************************************* @@ -565,173 +512,163 @@ namespace etl ///\param value The value to insert. //********************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type insert(iterator position, size_t n, parameter_t value) { - ETL_ASSERT((current_size + n) <= MAX_SIZE, ETL_ERROR(vector_full)); - - U v = value; + ETL_ASSERT((size() + n) <= MAX_SIZE, ETL_ERROR(vector_full)); size_t insert_n = n; - size_t insert_begin = std::distance(begin(), position); size_t insert_end = insert_begin + insert_n; - size_t new_size = current_size + n; - size_t old_move_n = new_size - insert_end; - size_t new_copy_n = insert_n; + // Copy old data. + size_t copy_old_n; + size_t construct_old_n; + iterator p_construct_old; - // Move old. - if (old_move_n > 0) + if (insert_end > size()) { - size_t index = new_size; - T* from = &p_buffer[size() - 1]; - T* to = &p_buffer[size() - 1 + insert_n]; - - while (index > insert_end) - { - if (index > size()) - { - // Construct. - new (to--) U(*from--); - ++construct_count; - } - else - { - // Copy - *to-- = *from--; - } - - --index; - } + copy_old_n = 0; + construct_old_n = size() - insert_begin; + p_construct_old = p_buffer + insert_end; } + else + { + copy_old_n = size() - insert_begin - insert_n; + construct_old_n = insert_n; + p_construct_old = p_end; + } + + size_t copy_new_n = construct_old_n; + size_t construct_new_n = insert_n - copy_new_n; + +#if defined(ETL_DEBUG) + // Construct old. + etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old, construct_count); + + // Copy old. + etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); + + // Construct new. + etl::uninitialized_fill_n(p_end, construct_new_n, value, construct_count); // Copy new. - if (new_copy_n > 0) + std::fill_n(p_buffer + insert_begin, copy_new_n, value); +#else + // Construct old. + etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old); + + // Copy old. + etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); + + // Construct new. + etl::uninitialized_fill_n(p_end, construct_new_n, value); + + // Copy new. + std::fill_n(p_buffer + insert_begin, copy_new_n, value); +#endif + + p_end += n; + } + + //********************************************************************* + /// Inserts a range of values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + /// For fundamental and pointer types. + ///\param position The position to insert before. + ///\param first The first element to add. + ///\param last The last + 1 element to add. + //********************************************************************* + template + typename etl::enable_if::value, void>::type + insert(iterator position, TIterator first, TIterator last) + { + size_t count = std::distance(first, last); + + ETL_ASSERT((size() + count) <= MAX_SIZE, ETL_ERROR(vector_full)); + + construct_count += count; + + if (position == end()) { - size_t index = insert_begin; - T* begin = &p_buffer[insert_begin]; - T* end = &p_buffer[insert_end]; - - while (begin != end) - { - if (index > size()) - { - // Construct. - new (begin++) U(v); - ++construct_count; - } - else - { - // Copy. - *begin++ = v; - } - - ++index; - } + p_end = std::copy(first, last, p_end); } + else + { + std::copy_backward(position, p_end, p_end + count); + std::copy(first, last, position); + p_end += count; + } + } + + //********************************************************************* + /// Inserts a range of values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + /// For fundamental and pointer types. + ///\param position The position to insert before. + ///\param first The first element to add. + ///\param last The last + 1 element to add. + //********************************************************************* + template + typename etl::enable_if::value, void>::type + insert(iterator position, TIterator first, TIterator last) + { + size_t count = std::distance(first, last); + + ETL_ASSERT((size() + count) <= MAX_SIZE, ETL_ERROR(vector_full)); + + size_t insert_n = count; + size_t insert_begin = std::distance(begin(), position); + size_t insert_end = insert_begin + insert_n; + + // Copy old data. + size_t copy_old_n; + size_t construct_old_n; + iterator p_construct_old; + + if (insert_end > size()) + { + copy_old_n = 0; + construct_old_n = size() - insert_begin; + p_construct_old = p_buffer + insert_end; + } + else + { + copy_old_n = size() - insert_begin - insert_n; + construct_old_n = insert_n; + p_construct_old = p_end; + } + + size_t copy_new_n = construct_old_n; + size_t construct_new_n = insert_n - copy_new_n; - current_size += n; - } +#if defined(ETL_DEBUG) + // Construct old. + etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old, construct_count); - //********************************************************************* - /// Inserts a range of values to the vector. - /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. - /// For fundamental and pointer types. - ///\param position The position to insert before. - ///\param first The first element to add. - ///\param last The last + 1 element to add. - //********************************************************************* - template - typename etl::enable_if::value, void>::type - insert(iterator position, TIterator first, TIterator last) - { - size_t count = std::distance(first, last); + // Copy old. + etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); - ETL_ASSERT((current_size + count) <= MAX_SIZE, ETL_ERROR(vector_full)); - - U* p_end = &p_buffer[current_size]; - - std::copy_backward(position, p_end, p_end + count); - std::copy(first, last, position); - } - - //********************************************************************* - /// Inserts a range of values to the vector. - /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. - /// For fundamental and pointer types. - ///\param position The position to insert before. - ///\param first The first element to add. - ///\param last The last + 1 element to add. - //********************************************************************* - template - typename etl::enable_if::value, void>::type - insert(iterator position, TIterator first, TIterator last) - { - size_t count = std::distance(first, last); - - ETL_ASSERT((current_size + count) <= MAX_SIZE, ETL_ERROR(vector_full)); - - size_t insert_n = count; - - size_t insert_begin = std::distance(begin(), position); - size_t insert_end = insert_begin + insert_n; - size_t new_size = current_size + insert_n; - - size_t old_move_n = new_size - insert_end; - size_t new_copy_n = insert_n; - - // Move old. - if (old_move_n > 0) - { - size_t index = new_size; - U* from = &p_buffer[size() - 1]; - U* to = &p_buffer[size() - 1 + insert_n]; - - while (index > insert_end) - { - if (index > size()) - { - // Construct. - new (to--) U(*from--); - ++construct_count; - } - else - { - // Copy - *to-- = *from--; - } - - --index; - } - } + // Construct new. + etl::uninitialized_copy_n(first + copy_new_n, construct_new_n, p_end, construct_count); // Copy new. - if (new_copy_n > 0) - { - size_t index = insert_begin; - U* begin = &p_buffer[insert_begin]; - U* end = &p_buffer[insert_end]; + etl::copy_n(first, copy_new_n, p_buffer + insert_begin); +#else + // Construct old. + etl::uninitialized_copy_n(p_end - construct_old_n, construct_old_n, p_construct_old); - while (begin != end) - { - if (index >= size()) - { - // Construct. - new (begin++) T(*first++); - ++construct_count; - } - else - { - // Copy. - *begin++ = *first++; - } + // Copy old. + etl::copy_n(p_buffer + insert_begin, copy_old_n, p_buffer + insert_end); - ++index; - } - } + // Construct new. + etl::uninitialized_copy_n(first + copy_new_n, construct_new_n, p_end); - current_size += count; + // Copy new. + etl::copy_n(first, copy_new_n, p_buffer + insert_begin); +#endif + + p_end += count; } //********************************************************************* @@ -742,7 +679,7 @@ namespace etl iterator erase(iterator i_element) { std::copy(i_element + 1, end(), i_element); - destroy_element(); + destroy_back(); return i_element; } @@ -755,7 +692,36 @@ namespace etl ///\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) + template + typename etl::enable_if::value, iterator>::type + erase(iterator first, iterator last) + { + if (first == begin() && last == end()) + { + clear(); + } + else + { + std::copy(last, end(), first); + size_t n_delete = std::distance(first, last); + construct_count -= n_delete; + p_end -= n_delete; + } + + return first; + } + + //********************************************************************* + /// 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. + //********************************************************************* + template + typename etl::enable_if::value, iterator>::type + erase(iterator first, iterator last) { if (first == begin() && last == end()) { @@ -766,19 +732,13 @@ namespace etl std::copy(last, end(), first); size_t n_delete = std::distance(first, last); - if (is_simple_type::value) - { - // Just adjust the count. - current_size -= n_delete; - } - else - { - // Destroy the elements left over at the end. - while (n_delete-- > 0) - { - destroy_element(); - } - } + // Destroy the elements left over at the end. +#if defined(ETL_DEBUG) + etl::destroy(p_end - n_delete, p_end, construct_count); +#else + etl::destroy(p_end - n_delete, p_end); +#endif + p_end -= n_delete; } return first; @@ -797,14 +757,51 @@ namespace etl 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() == MAX_SIZE; + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return max_size() - size(); + } + protected: //********************************************************************* /// Constructor. //********************************************************************* - ivector(T* p_buffer, size_t MAX_SIZE) + ivector(T* p_buffer_, size_t MAX_SIZE) : vector_base(MAX_SIZE), - p_buffer(p_buffer) + p_buffer(p_buffer_), + p_end(p_buffer_) { } @@ -813,87 +810,58 @@ namespace etl //********************************************************************* void initialise() { - // Choose the algorithm according to type. - // The unused branch should be optimised away. - if (is_simple_type::value) - { - current_size = 0; - } - else - { - while (current_size > 0) - { - destroy_element(); - } - } - } +#if defined(ETL_DEBUG) + etl::destroy(p_buffer, p_end, construct_count); +#else + etl::destroy(p_buffer, p_end); +#endif - T* p_buffer; + p_end = p_buffer; + } private: - + pointer p_buffer; ///< Pointer to the start of the buffer. + pointer p_end; ///< Pointer to one past the last element in the buffer. //********************************************************************* /// Create a new element with a default value at the back. //********************************************************************* - inline void create_element() + inline void create_back() { - if (is_simple_type::value) - { - current_size++; - } - else - { - new (&p_buffer[current_size++]) T(); - ++construct_count; - } +#if defined(ETL_DEBUG) + etl::create_value_at(p_end, construct_count); +#else + etl::create_value_at(p_end); +#endif + ++p_end; } //********************************************************************* /// Create a new element with a value at the back //********************************************************************* - inline void create_element(parameter_t value) + inline void create_back(parameter_t value) { - if (is_simple_type::value) - { - p_buffer[current_size++] = value; - } - else - { - new (&p_buffer[current_size++]) T(value); - ++construct_count; - } - } - - //********************************************************************* - /// Create a new element with a value at the index - //********************************************************************* - inline void create_element_at(size_t index, parameter_t value) - { - new (&p_buffer[index]) T(value); - ++construct_count; +#if defined(ETL_DEBUG) + etl::create_copy_at(p_end, value, construct_count); +#else + etl::create_copy_at(p_end, value); +#endif + ++p_end; } //********************************************************************* /// Destroy an element at the back. //********************************************************************* - template - typename etl::enable_if::value, void>::type - destroy_element() + inline void destroy_back() { - --current_size; - } + --p_end; - //********************************************************************* - /// Destroy an element at the back. - //********************************************************************* - template - typename etl::enable_if::value, void>::type - destroy_element() - { - p_buffer[--current_size].~U(); - --construct_count; +#if defined(ETL_DEBUG) + etl::destroy_at(p_end, construct_count); +#else + etl::destroy_at(p_end); +#endif } // Disable copy construction. diff --git a/src/private/ivectorpointer.h b/src/private/ivectorpointer.h index 1aae4e5c..da1ae67b 100644 --- a/src/private/ivectorpointer.h +++ b/src/private/ivectorpointer.h @@ -312,7 +312,7 @@ namespace etl while (first != last) { - p_buffer[current_size++] = (void*)*first++; + *p_end++ = (void*)*first++; } } From 1a1283308dd48fcf2880a45cba15662ee1e70dcb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 23 Feb 2017 23:15:18 +0000 Subject: [PATCH 154/168] Performance enhancements --- src/private/pvoidvector.h | 200 +++++++++++++++----------------------- 1 file changed, 79 insertions(+), 121 deletions(-) diff --git a/src/private/pvoidvector.h b/src/private/pvoidvector.h index f44b4bed..77ba1721 100644 --- a/src/private/pvoidvector.h +++ b/src/private/pvoidvector.h @@ -82,7 +82,7 @@ namespace etl //********************************************************************* iterator begin() { - return &p_buffer[0]; + return p_buffer; } //********************************************************************* @@ -91,7 +91,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return const_iterator(&p_buffer[0]); + return const_iterator(p_buffer); } //********************************************************************* @@ -100,7 +100,7 @@ namespace etl //********************************************************************* iterator end() { - return &p_buffer[current_size]; + return p_end; } //********************************************************************* @@ -109,7 +109,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return const_iterator(&p_buffer[current_size]); + return const_iterator(p_end); } //********************************************************************* @@ -118,7 +118,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return const_iterator(&p_buffer[0]); + return const_iterator(p_buffer); } //********************************************************************* @@ -127,7 +127,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return const_iterator(&p_buffer[current_size]); + return const_iterator(p_end); } //********************************************************************* @@ -194,7 +194,7 @@ namespace etl { ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); - current_size = new_size; + p_end = p_buffer + new_size; } //********************************************************************* @@ -208,13 +208,15 @@ namespace etl { ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); + pointer p_new_end = p_buffer + new_size; + // Size up if necessary. - while (current_size < new_size) + if (p_end < p_new_end) { - p_buffer[current_size++] = value; + std::fill(p_end, p_new_end, value); } - current_size = new_size; + p_end = p_new_end; } //********************************************************************* @@ -245,7 +247,7 @@ namespace etl //********************************************************************* reference at(size_t i) { - ETL_ASSERT(i < current_size, ETL_ERROR(vector_out_of_bounds)); + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -257,7 +259,7 @@ namespace etl //********************************************************************* const_reference at(size_t i) const { - ETL_ASSERT(i < current_size, ETL_ERROR(vector_out_of_bounds)); + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); return const_reference(p_buffer[i]); } @@ -285,7 +287,7 @@ namespace etl //********************************************************************* reference back() { - return p_buffer[current_size - 1]; + return *(p_end -1); } //********************************************************************* @@ -294,7 +296,7 @@ namespace etl //********************************************************************* const_reference back() const { - return const_reference(p_buffer[current_size - 1]); + return const_reference(*(p_end - 1)); } //********************************************************************* @@ -325,7 +327,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(static_cast(count) <= MAX_SIZE, ETL_ERROR(vector_full)); #endif @@ -334,7 +336,7 @@ namespace etl while (first != last) { - p_buffer[current_size++] = const_cast(*first++); + *p_end++ = const_cast(*first++); } } @@ -352,7 +354,7 @@ namespace etl for (size_t current_size = 0; current_size < n; ++current_size) { - p_buffer[current_size] = value; + *p_end++ = value; } } @@ -371,10 +373,10 @@ namespace etl void push_back() { #if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT(size() != MAX_SIZE, ETL_ERROR(vector_full)); #endif - ++current_size; + ++p_end; } //********************************************************************* @@ -385,9 +387,9 @@ namespace etl void push_back(value_type value) { #if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(current_size != MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT(size() != MAX_SIZE, ETL_ERROR(vector_full)); #endif - p_buffer[current_size++] = value; + *p_end++ = value; } //************************************************************************* @@ -397,9 +399,9 @@ namespace etl void pop_back() { #if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(current_size > 0, ETL_ERROR(vector_empty)); + ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty)); #endif - --current_size; + --p_end; } //********************************************************************* @@ -410,17 +412,17 @@ namespace etl //********************************************************************* iterator insert(iterator position, value_type value) { - ETL_ASSERT((current_size)+1 <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT(size() + 1 <= MAX_SIZE, ETL_ERROR(vector_full)); if (position != end()) { - ++current_size; + ++p_end; std::copy_backward(position, end() - 1, end()); *position = value; } else { - p_buffer[current_size++] = value; + *p_end++ = value; } return position; @@ -435,53 +437,12 @@ namespace etl //********************************************************************* void insert(iterator position, size_t n, value_type value) { - ETL_ASSERT((current_size)+1 <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT((size() + 1) <= MAX_SIZE, ETL_ERROR(vector_full)); - if (position == end()) - { - while (n > 0) - { - p_buffer[current_size++] = value; - --n; - } - } - else - { - // Create copy (backwards). - size_t n_insert = n; - size_t from = size() - 1; - size_t to = from + n_insert; - size_t n_move = std::distance(position, end()); - size_t n_create_copy = std::min(n_insert, n_move); + std::copy_backward(position, p_end, p_end + n); + std::fill_n(position, n, value); - for (size_t i = 0; i < n_create_copy; ++i) - { - p_buffer[to--] = p_buffer[from--]; - } - - // Copy old. - size_t insert_index = std::distance(begin(), position); - from = insert_index; - to = from + n_insert; - size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0; - etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]); - - // Copy new. - to = insert_index; - - size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0; - size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0; - std::fill_n(&p_buffer[to], n_copy_new, value); - - // Create new. - to = size(); - for (size_t i = 0; i < n_create_new; ++i) - { - p_buffer[to++] = value; - } - - current_size += n_insert; - } + p_end += n; } //********************************************************************* @@ -497,52 +458,11 @@ namespace etl { size_t count = std::distance(first, last); - ETL_ASSERT((current_size)+count <= MAX_SIZE, ETL_ERROR(vector_full)); + ETL_ASSERT((size() + count) <= MAX_SIZE, ETL_ERROR(vector_full)); - if (position == end()) - { - while (first != last) - { - p_buffer[current_size++] = *first++; - } - } - else - { - size_t insert_index = std::distance(begin(), position); - size_t n_insert = count; - - // Create copy (backwards). - size_t from = size() - 1; - size_t to = from + n_insert; - size_t n_move = std::distance(position, end()); - size_t n_create_copy = std::min(n_insert, n_move); - for (size_t i = 0; i < n_create_copy; ++i) - { - p_buffer[to--] = p_buffer[from--]; - } - - // Copy old. - from = insert_index; - to = from + n_insert; - size_t n_copy_old = (size() > n_insert) ? size() - n_insert : 0; - etl::copy_n(&p_buffer[from], n_copy_old, &p_buffer[to]); - - // Copy new. - to = insert_index; - size_t n_create_new = (n_insert > n_create_copy) ? n_insert - n_create_copy : 0; - size_t n_copy_new = (n_insert > n_create_new) ? n_insert - n_create_new : 0; - etl::copy_n(first, n_copy_new, &p_buffer[to]); - first += n_copy_new; - - // Create new. - to = size(); - for (size_t i = 0; i < n_create_new; ++i) - { - p_buffer[to++] = *first++; - } - - current_size += n_insert; - } + std::copy_backward(position, p_end, p_end + count); + std::copy(first, last, position); + p_end += count; } //********************************************************************* @@ -553,7 +473,7 @@ namespace etl iterator erase(iterator i_element) { std::copy(i_element + 1, end(), i_element); - --current_size; + --p_end; return i_element; } @@ -572,7 +492,7 @@ namespace etl size_t n_delete = std::distance(first, last); // Just adjust the count. - current_size -= n_delete; + p_end -= n_delete; return first; } @@ -590,14 +510,51 @@ namespace etl 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() == MAX_SIZE; + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return max_size() - size(); + } + protected: //********************************************************************* /// Constructor. //********************************************************************* - pvoidvector(void** p_buffer, size_t MAX_SIZE) + pvoidvector(void** p_buffer_, size_t MAX_SIZE) : vector_base(MAX_SIZE), - p_buffer(p_buffer) + p_buffer(p_buffer_), + p_end(p_buffer_) { } @@ -606,10 +563,11 @@ namespace etl //********************************************************************* void initialise() { - current_size = 0; + p_end = p_buffer; } void** p_buffer; + void** p_end; private: From 9e01d876045f63505e0cfda1ebfd13a14d870006 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 23 Feb 2017 23:15:55 +0000 Subject: [PATCH 155/168] Moved some base functions to ivector --- src/private/vector_base.h | 40 +-------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/src/private/vector_base.h b/src/private/vector_base.h index 69c5494e..44fb0673 100644 --- a/src/private/vector_base.h +++ b/src/private/vector_base.h @@ -111,33 +111,6 @@ namespace etl typedef size_t size_type; - //************************************************************************* - /// Gets the current size of the vector. - ///\return The current size of the vector. - //************************************************************************* - size_type size() const - { - return current_size; - } - - //************************************************************************* - /// Checks the 'empty' state of the vector. - ///\return true if empty. - //************************************************************************* - bool empty() const - { - return (current_size == 0); - } - - //************************************************************************* - /// Checks the 'full' state of the vector. - ///\return true if full. - //************************************************************************* - bool full() const - { - return current_size == MAX_SIZE; - } - //************************************************************************* /// Returns the capacity of the vector. ///\return The capacity of the vector. @@ -156,27 +129,16 @@ namespace etl return MAX_SIZE; } - //************************************************************************* - /// Returns the remaining capacity. - ///\return The remaining capacity. - //************************************************************************* - size_t available() const - { - return max_size() - size(); - } - protected: //************************************************************************* /// Constructor. //************************************************************************* vector_base(size_t max_size) - : current_size(0), - MAX_SIZE(max_size) + : MAX_SIZE(max_size) { } - size_type current_size; /// Date: Sat, 25 Feb 2017 20:30:07 +0000 Subject: [PATCH 156/168] Vector tests using non-trivial types. --- test/test_vector_non_trivial.cpp | 960 +++++++++++++++++++++++++++++++ 1 file changed, 960 insertions(+) create mode 100644 test/test_vector_non_trivial.cpp diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp new file mode 100644 index 00000000..843c2e82 --- /dev/null +++ b/test/test_vector_non_trivial.cpp @@ -0,0 +1,960 @@ +///****************************************************************************** +//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 +#include +#include + +#include "../src/vector.h" +#include "data.h" + +namespace +{ + SUITE(test_vector_non_trivial) + { + static const size_t SIZE = 10; + + typedef TestDataNDC NDC; + typedef TestDataDC DC; + + typedef etl::vector DataNDC; + typedef etl::ivector IDataNDC; + typedef std::vector CompareDataNDC; + + typedef etl::vector DataDC; + typedef etl::ivector IDataDC; + typedef std::vector CompareDataDC; + + CompareDataNDC initial_data; + CompareDataNDC less_data; + CompareDataNDC greater_data; + CompareDataNDC shorter_data; + CompareDataNDC different_data; + CompareDataNDC insert_data; + + //************************************************************************* + struct SetupFixture + { + SetupFixture() + { + NDC n[] = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + NDC n_insert[] = { NDC("11"), NDC("12"), NDC("13") }; + NDC n_less[] = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("3"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + NDC n_greater[] = { NDC("0"), NDC("1"), NDC("2"), NDC("4"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + + initial_data.assign(std::begin(n), std::end(n)); + insert_data.assign(std::begin(n_insert), std::end(n_insert)); + less_data.assign(std::begin(n_less), std::end(n_less)); + greater_data.assign(std::begin(n_greater), std::end(n_greater)); + shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1); + different_data.assign(initial_data.rbegin(), initial_data.rend()); + } + }; + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor) + { + DataDC data; + + CHECK_EQUAL(data.size(), size_t(0)); + CHECK(data.empty()); + CHECK_EQUAL(data.capacity(), SIZE); + CHECK_EQUAL(data.max_size(), SIZE); + } + + //************************************************************************* + TEST(test_iterator_comparison_empty) + { + DataDC data; + + CHECK(data.begin() == data.end()); + CHECK(data.cbegin() == data.cend()); + CHECK(data.rbegin() == data.rend()); + CHECK(data.crbegin() == data.crend()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size) + { + const size_t INITIAL_SIZE = 5; + DataDC data(INITIAL_SIZE); + + CHECK(data.size() == INITIAL_SIZE); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_value) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + + std::vector compare_data(INITIAL_SIZE, INITIAL_VALUE); + DataNDC data(size_t(5), NDC("1")); + + CHECK(data.size() == INITIAL_SIZE); + CHECK(!data.empty()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_excess) + { + CHECK_THROW(DataDC data(SIZE + 1), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_range) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + + CHECK(data.size() == SIZE); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor) + { + DataNDC data(initial_data.begin(), initial_data.end()); + DataNDC data2(data); + CHECK(data2 == data); + + data2[2] = NDC("X"); + CHECK(data2 != data); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment) + { + DataNDC data(initial_data.begin(), initial_data.end()); + DataNDC other_data; + + other_data = data; + + bool is_equal = std::equal(data.begin(), + data.end(), + other_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_iterface) + { + DataNDC data1(initial_data.begin(), initial_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool is_equal = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment) + { + DataNDC data(initial_data.begin(), initial_data.end()); + DataNDC other_data(data); + + other_data = other_data; + + bool is_equal = std::equal(data.begin(), + data.end(), + other_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_begin) + { + DataDC data(10); + const DataDC constData(10); + + CHECK_EQUAL(&data[0], data.begin()); + CHECK_EQUAL(&constData[0], constData.begin()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_end) + { + DataDC data(10); + const DataDC constData(10); + + CHECK_EQUAL(&data[10], data.end()); + CHECK_EQUAL(&constData[10], constData.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_up) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 8; + + DataDC data(INITIAL_SIZE); + data.resize(NEW_SIZE); + + CHECK_EQUAL(data.size(), NEW_SIZE); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_up_value) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 8; + const NDC INITIAL_VALUE("1"); + + DataNDC data(INITIAL_SIZE, INITIAL_VALUE); + data.resize(NEW_SIZE, INITIAL_VALUE); + + std::vector compare_data(NEW_SIZE, INITIAL_VALUE); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_excess) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = SIZE + 1; + + DataDC data(INITIAL_SIZE); + + CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_down) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 2; + + DataDC data(INITIAL_SIZE); + data.resize(NEW_SIZE); + + CHECK_EQUAL(data.size(), NEW_SIZE); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_down_value) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 2; + const NDC INITIAL_VALUE("1"); + + DataNDC data(INITIAL_SIZE, INITIAL_VALUE); + data.resize(NEW_SIZE, INITIAL_VALUE); + + CHECK_EQUAL(data.size(), NEW_SIZE); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_empty) + { + DataDC data; + data.resize(data.max_size()); + + CHECK(data.full()); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full) + { + DataNDC data; + + CHECK(!data.full()); + CHECK(data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_index) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data[i], compare_data[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_index_const) + { + const CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + const DataNDC data(compare_data.begin(), compare_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data[i], compare_data[i]); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_at) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data.at(i), compare_data.at(i)); + } + + CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_at_const) + { + const CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + const DataNDC data(initial_data.begin(), initial_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data.at(i), compare_data.at(i)); + } + + CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_front) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK(data.front() == compare_data.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_front_const) + { + const CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + const DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK(data.front() == compare_data.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_back) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK(data.back() == compare_data.back()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_back_const) + { + const CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + const DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK(data.back() == compare_data.back()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_data) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.data(), + data.data() + data.size(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_data_const) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + const DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.data(), + data.data() + data.size(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data; + + data.assign(compare_data.begin(), compare_data.end()); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_size_value) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + std::vector compare_data(INITIAL_SIZE, INITIAL_VALUE); + + DataNDC data; + data.assign(INITIAL_SIZE, INITIAL_VALUE); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) + { + const size_t INITIAL_SIZE = SIZE; + const size_t EXCESS_SIZE = SIZE + 1; + const NDC INITIAL_VALUE("1"); + std::vector compare_data(INITIAL_SIZE, INITIAL_VALUE); + + DataNDC data; + + CHECK_THROW(data.assign(EXCESS_SIZE, INITIAL_VALUE), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_push_back) + { + CompareDataNDC compare_data; + DataNDC data; + + for (size_t i = 0; i < SIZE; ++i) + { + std::string value(" "); + value[0] = char('A' + i); + compare_data.push_back(value); + data.push_back(NDC(value)); + } + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_push_back_null) + { + CompareDataDC compare_data; + DataDC data; + + compare_data.push_back(DC("1")); + + data.push_back(); + data[0] = DC("1"); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_push_back_excess) + { + DataNDC data; + + for (size_t i = 0; i < SIZE; ++i) + { + std::string value(" "); + value[0] = char('A' + i); + data.push_back(NDC(value)); + } + + CHECK_THROW(data.push_back(NDC("Z")), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_pop_back) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + compare_data.pop_back(); + compare_data.pop_back(); + + data.pop_back(); + data.pop_back(); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_pop_back_exception) + { + DataDC data; + + data.resize(2); + + data.pop_back(); + data.pop_back(); + + CHECK_THROW(data.pop_back(), etl::vector_empty); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + { + CompareDataNDC compare_data; + DataNDC data; + + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + + data.insert(data.begin() + offset, INITIAL_VALUE); + compare_data.insert(compare_data.begin() + offset, INITIAL_VALUE); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) + { + const size_t INITIAL_SIZE = SIZE; + const NDC INITIAL_VALUE("1"); + const NDC UNINITIALISED_VALUE("Z"); + + DataNDC data(INITIAL_SIZE, INITIAL_VALUE); + + size_t offset = 2; + + CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full); + + offset = 0; + + CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full); + + offset = data.size(); + + CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value) + { + const size_t INITIAL_SIZE = 5; + const size_t INSERT_SIZE = 3; + const NDC INITIAL_VALUE("1"); + + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + { + CompareDataNDC compare_data; + DataNDC data; + + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE); + compare_data.insert(compare_data.begin() + offset, INSERT_SIZE, INITIAL_VALUE); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) + { + const size_t INITIAL_SIZE = SIZE; + const size_t INSERT_SIZE = 4; + const NDC INITIAL_VALUE("1"); + + DataNDC data(INITIAL_SIZE, INITIAL_VALUE); + + size_t offset = 0; + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + + offset = 2; + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + + offset = 4; + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + + offset = data.size(); + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + { + CompareDataNDC compare_data; + DataNDC data; + + data.resize(SIZE, NDC("Z")); + + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + data.insert(data.begin() + offset, insert_data.begin(), insert_data.end()); + compare_data.insert(compare_data.begin() + offset, insert_data.begin(), insert_data.end()); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + + DataNDC data(INITIAL_SIZE, INITIAL_VALUE); + + size_t offset = 0; + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + + offset = 2; + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + + offset = 4; + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + + offset = data.size(); + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + compare_data.erase(compare_data.begin() + 2); + + data.erase(data.begin() + 2); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + + data.erase(data.begin() + 2, data.begin() + 4); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_clear) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + data.clear(); + + CHECK_EQUAL(data.size(), size_t(0)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_iterator) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_iterator) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_reverse_iterator) + { + CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.rbegin(), + data.rend(), + compare_data.rbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) + { + const CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + const DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.crbegin(), + data.crend(), + compare_data.crbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_reverse_iterator2) + { + const CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); + + const DataNDC data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.rbegin(), + data.rend(), + compare_data.rbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal) + { + const DataNDC initial1(initial_data.begin(), initial_data.end()); + const DataNDC initial2(initial_data.begin(), initial_data.end()); + + CHECK(initial1 == initial2); + + const DataNDC different(different_data.begin(), different_data.end()); + + CHECK(!(initial1 == different)); + + const DataNDC shorter(shorter_data.begin(), shorter_data.end()); + + CHECK(!(shorter == initial1)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_not_equal) + { + const DataNDC initial1(initial_data.begin(), initial_data.end()); + const DataNDC initial2(initial_data.begin(), initial_data.end()); + + CHECK(!(initial1 != initial2)); + + const DataNDC different(different_data.begin(), different_data.end()); + + CHECK(initial1 != different); + + const DataNDC shorter(shorter_data.begin(), shorter_data.end()); + + CHECK(shorter != initial1); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_less_than) + { + const DataNDC less(less_data.begin(), less_data.end()); + const DataNDC initial(initial_data.begin(), initial_data.end()); + + CHECK((less < initial) == (less_data < initial_data)); + + const DataNDC greater(greater_data.begin(), greater_data.end()); + + CHECK((greater < initial) == (greater_data < initial_data)); + + const DataNDC shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter < initial) == (shorter_data < initial_data)); + CHECK((initial < shorter) == (initial_data < shorter_data)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_less_than_or_equal) + { + const DataNDC less(less_data.begin(), less_data.end()); + const DataNDC initial(initial_data.begin(), initial_data.end()); + + CHECK((less <= initial) == (less_data <= initial_data)); + + const DataNDC greater(greater_data.begin(), greater_data.end()); + + CHECK((greater <= initial) == (greater_data <= initial_data)); + + const DataNDC shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter <= initial) == (shorter_data <= initial_data)); + CHECK((initial <= shorter) == (initial_data <= shorter_data)); + + const DataNDC initial2(initial_data.begin(), initial_data.end()); + CHECK((initial <= initial2) == (initial_data <= initial_data)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_greater_than) + { + const DataNDC less(less_data.begin(), less_data.end()); + const DataNDC initial(initial_data.begin(), initial_data.end()); + + CHECK((less > initial) == (less_data > initial_data)); + + const DataNDC greater(greater_data.begin(), greater_data.end()); + + CHECK((greater > initial) == (greater_data > initial_data)); + + const DataNDC shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter > initial) == (shorter_data > initial_data)); + CHECK((initial > shorter) == (initial_data > shorter_data)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_greater_than_or_equal) + { + const DataNDC less(less_data.begin(), less_data.end()); + const DataNDC initial(initial_data.begin(), initial_data.end()); + + CHECK((less >= initial) == (less_data >= initial_data)); + + const DataNDC greater(greater_data.begin(), greater_data.end()); + + CHECK((greater >= initial) == (greater_data >= initial_data)); + + const DataNDC shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter >= initial) == (shorter_data >= initial_data)); + CHECK((initial >= shorter) == (initial_data > shorter_data)); + + const DataNDC initial2(initial_data.begin(), initial_data.end()); + CHECK((initial >= initial2) == (initial_data >= initial_data)); + } + }; +} From 79e33fbe8178f11bd3723a7ac9bce25ed21f35b9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 25 Feb 2017 20:32:27 +0000 Subject: [PATCH 157/168] Removed default constructor from 'non-default constructor' type. Modified tests to compensate. --- test/test_flat_map.cpp | 45 +++++++++++++--- test/test_forward_list.cpp | 43 +++++++-------- test/test_unordered_map.cpp | 96 +++++++++++++++++++++------------ test/vs2015/etl.vcxproj | 5 ++ test/vs2015/etl.vcxproj.filters | 12 +++++ 5 files changed, 139 insertions(+), 62 deletions(-) diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index 2c8ab72c..37d3444a 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -98,6 +98,28 @@ namespace NDC N18 = NDC("S"); NDC N19 = NDC("T"); + DC M0 = DC("A"); + DC M1 = DC("B"); + DC M2 = DC("C"); + DC M3 = DC("D"); + DC M4 = DC("E"); + DC M5 = DC("F"); + DC M6 = DC("G"); + DC M7 = DC("H"); + DC M8 = DC("I"); + DC M9 = DC("J"); + DC M10 = DC("K"); + DC M11 = DC("L"); + DC M12 = DC("M"); + DC M13 = DC("N"); + DC M14 = DC("O"); + DC M15 = DC("P"); + DC M16 = DC("Q"); + DC M17 = DC("R"); + DC M18 = DC("S"); + DC M19 = DC("T"); + + std::vector initial_data_dc; std::vector initial_data; std::vector excess_data; std::vector different_data; @@ -144,9 +166,16 @@ namespace ElementNDC(15, N15), ElementNDC(16, N16), ElementNDC(17, N17), ElementNDC(18, N18), ElementNDC(19, N19) }; + ElementDC n4[] = + { + ElementDC(0, M0), ElementDC(1, M1), ElementDC(2, M2), ElementDC(3, M3), ElementDC(4, M4), + ElementDC(5, M5), ElementDC(6, M6), ElementDC(7, M7), ElementDC(8, M8), ElementDC(9, M9) + }; + initial_data.assign(std::begin(n), std::end(n)); excess_data.assign(std::begin(n2), std::end(n2)); different_data.assign(std::begin(n3), std::end(n3)); + initial_data_dc.assign(std::begin(n4), std::end(n4)); } }; @@ -262,9 +291,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + Compare_DataDC compare_data(initial_data_dc.begin(), initial_data_dc.end()); - DataNDC data(compare_data.begin(), compare_data.end()); + DataDC data(compare_data.begin(), compare_data.end()); CHECK_EQUAL(compare_data[0], data[0]); CHECK_EQUAL(compare_data[1], data[1]); @@ -281,11 +310,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_value_changed) { - Compare_DataNDC compare_data; - DataNDC data; + Compare_DataDC compare_data; + DataDC data; - data[0] = N0; - compare_data[0] = N0; + data[0] = M0; + compare_data[0] = M0; bool isEqual = Check_Equal(data.begin(), data.end(), @@ -293,8 +322,8 @@ namespace CHECK(isEqual); - data[0] = N2; - compare_data[0] = N2; + data[0] = M2; + compare_data[0] = M2; isEqual = Check_Equal(data.begin(), data.end(), diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 50169e7d..e5944874 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -52,6 +52,7 @@ namespace typedef etl::forward_list DataNDC; typedef etl::iforward_list IDataNDC; + typedef std::forward_list CompareDataDC; typedef std::forward_list CompareDataNDC; typedef std::vector InitialDataNDC; @@ -77,7 +78,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor) { - DataNDC data; + DataDC data; CHECK(data.empty()); CHECK_EQUAL(data.max_size(), SIZE); @@ -160,12 +161,12 @@ namespace { const size_t INITIAL_SIZE = 4; const size_t NEW_SIZE = 8; - const ItemNDC VALUE("1"); + const ItemDC VALUE("1"); - DataNDC data(INITIAL_SIZE, VALUE); + DataDC data(INITIAL_SIZE, VALUE); data.resize(NEW_SIZE); - CompareDataNDC compare_data(INITIAL_SIZE, VALUE); + CompareDataDC compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); @@ -207,12 +208,12 @@ namespace { const size_t INITIAL_SIZE = 4; const size_t NEW_SIZE = 2; - const ItemNDC VALUE("1"); + const ItemDC VALUE("1"); - DataNDC data(INITIAL_SIZE, VALUE); + DataDC data(INITIAL_SIZE, VALUE); data.resize(NEW_SIZE); - CompareDataNDC compare_data(INITIAL_SIZE, VALUE); + CompareDataDC compare_data(INITIAL_SIZE, VALUE); compare_data.resize(NEW_SIZE); CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), data.size()); @@ -447,28 +448,28 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_front_null) { - CompareDataNDC compare_data; - DataNDC data; + CompareDataDC compare_data; + DataDC data; - 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")); + compare_data.push_front(ItemDC("1")); + compare_data.push_front(ItemDC("2")); + compare_data.push_front(ItemDC("3")); + compare_data.push_front(ItemDC("4")); + compare_data.push_front(ItemDC("5")); + compare_data.push_front(ItemDC("6")); CHECK_NO_THROW(data.push_front()); - data.front() = ItemNDC("1"); + data.front() = ItemDC("1"); CHECK_NO_THROW(data.push_front()); - data.front() = ItemNDC("2"); + data.front() = ItemDC("2"); CHECK_NO_THROW(data.push_front()); - data.front() = ItemNDC("3"); + data.front() = ItemDC("3"); CHECK_NO_THROW(data.push_front()); - data.front() = ItemNDC("4"); + data.front() = ItemDC("4"); CHECK_NO_THROW(data.push_front()); - data.front() = ItemNDC("5"); + data.front() = ItemDC("5"); CHECK_NO_THROW(data.push_front()); - data.front() = ItemNDC("6"); + data.front() = ItemDC("6"); CHECK_EQUAL(6U, data.size()); CHECK_EQUAL(6, std::distance(data.begin(), data.end())); diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 35a7f653..7c713b93 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -105,6 +105,27 @@ namespace NDC N18 = NDC("S"); NDC N19 = NDC("T"); + DC M0 = DC("A"); + DC M1 = DC("B"); + DC M2 = DC("C"); + DC M3 = DC("D"); + DC M4 = DC("E"); + DC M5 = DC("F"); + DC M6 = DC("G"); + DC M7 = DC("H"); + DC M8 = DC("I"); + DC M9 = DC("J"); + DC M10 = DC("K"); + DC M11 = DC("L"); + DC M12 = DC("M"); + DC M13 = DC("N"); + DC M14 = DC("O"); + DC M15 = DC("P"); + DC M16 = DC("Q"); + DC M17 = DC("R"); + DC M18 = DC("S"); + DC M19 = DC("T"); + const char* K0 = "FF"; // 0 const char* K1 = "FG"; // 1 const char* K2 = "FH"; // 2 @@ -128,6 +149,8 @@ namespace std::string K[] = { K0, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, K12, K13, K14, K15, K16, K17, K18, K19 }; + std::vector initial_data_dc; + std::vector initial_data; std::vector excess_data; std::vector different_data; @@ -174,9 +197,16 @@ namespace ElementNDC(K15, N15), ElementNDC(K16, N16), ElementNDC(K17, N17), ElementNDC(K18, N18), ElementNDC(K19, N19) }; + ElementDC n4[] = + { + ElementDC(K0, M0), ElementDC(K1, M1), ElementDC(K2, M2), ElementDC(K3, M3), ElementDC(K4, M4), + ElementDC(K5, M5), ElementDC(K6, M6), ElementDC(K7, M7), ElementDC(K8, M8), ElementDC(K9, M9) + }; + initial_data.assign(std::begin(n), std::end(n)); excess_data.assign(std::begin(n2), std::end(n2)); different_data.assign(std::begin(n3), std::end(n3)); + initial_data_dc.assign(std::begin(n4), std::end(n4)); } }; @@ -194,7 +224,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - DataNDC data(initial_data.begin(), initial_data.end()); + DataDC data(initial_data_dc.begin(), initial_data_dc.end()); CHECK(data.size() == SIZE); CHECK(!data.empty()); @@ -266,46 +296,46 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_read) { - DataNDC data(initial_data.begin(), initial_data.end()); + DataDC data(initial_data_dc.begin(), initial_data_dc.end()); - CHECK_EQUAL(N0, data[K0]); - CHECK_EQUAL(N1, data[K1]); - CHECK_EQUAL(N2, data[K2]); - CHECK_EQUAL(N3, data[K3]); - CHECK_EQUAL(N4, data[K4]); - CHECK_EQUAL(N5, data[K5]); - CHECK_EQUAL(N6, data[K6]); - CHECK_EQUAL(N7, data[K7]); - CHECK_EQUAL(N8, data[K8]); - CHECK_EQUAL(N9, data[K9]); + CHECK_EQUAL(M0, data[K0]); + CHECK_EQUAL(M1, data[K1]); + CHECK_EQUAL(M2, data[K2]); + CHECK_EQUAL(M3, data[K3]); + CHECK_EQUAL(M4, data[K4]); + CHECK_EQUAL(M5, data[K5]); + CHECK_EQUAL(M6, data[K6]); + CHECK_EQUAL(M7, data[K7]); + CHECK_EQUAL(M8, data[K8]); + CHECK_EQUAL(M9, data[K9]); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_write) { - DataNDC data(initial_data.begin(), initial_data.end()); + DataDC data(initial_data_dc.begin(), initial_data_dc.end()); - data[K0] = N9; - data[K1] = N8; - data[K2] = N7; - data[K3] = N6; - data[K4] = N5; - data[K5] = N4; - data[K6] = N3; - data[K7] = N2; - data[K8] = N1; - data[K9] = N0; + data[K0] = M9; + data[K1] = M8; + data[K2] = M7; + data[K3] = M6; + data[K4] = M5; + data[K5] = M4; + data[K6] = M3; + data[K7] = M2; + data[K8] = M1; + data[K9] = M0; - CHECK_EQUAL(N9, data[K0]); - CHECK_EQUAL(N8, data[K1]); - CHECK_EQUAL(N7, data[K2]); - CHECK_EQUAL(N6, data[K3]); - CHECK_EQUAL(N5, data[K4]); - CHECK_EQUAL(N4, data[K5]); - CHECK_EQUAL(N3, data[K6]); - CHECK_EQUAL(N2, data[K7]); - CHECK_EQUAL(N1, data[K8]); - CHECK_EQUAL(N0, data[K9]); + CHECK_EQUAL(M9, data[K0]); + CHECK_EQUAL(M8, data[K1]); + CHECK_EQUAL(M7, data[K2]); + CHECK_EQUAL(M6, data[K3]); + CHECK_EQUAL(M5, data[K4]); + CHECK_EQUAL(M4, data[K5]); + CHECK_EQUAL(M3, data[K6]); + CHECK_EQUAL(M2, data[K7]); + CHECK_EQUAL(M1, data[K8]); + CHECK_EQUAL(M0, data[K9]); } //************************************************************************* diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index 52d7585a..f2e8c9b6 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -19,6 +19,7 @@ Win32Proj unittest etl + 10.0.10586.0 @@ -239,6 +240,7 @@ true
+ @@ -388,6 +390,7 @@ false + @@ -400,6 +403,7 @@ false + @@ -434,6 +438,7 @@ + diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index 58efe487..cdf1831e 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -546,6 +546,9 @@ ETL\Utilities + + ETL\Utilities + @@ -848,6 +851,15 @@ Source Files + + Source Files + + + Source Files + + + Source Files + From a33ee11ef80ab30e883c5b76a94c20aa2fc68212 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 26 Feb 2017 09:09:49 +0000 Subject: [PATCH 158/168] Removed default constructor from 'non-default constructor' type. Modified tests to compensate. --- test/data.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/data.h b/test/data.h index bc5db259..15c10dd4 100644 --- a/test/data.h +++ b/test/data.h @@ -89,10 +89,6 @@ class TestDataNDC { public: - TestDataNDC() - : value(T()) - {} - TestDataNDC(const T& value) : value(value) {} From 824ff8e96e94b2cb29e7b6341b23e5d13f3032e2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 26 Feb 2017 09:10:35 +0000 Subject: [PATCH 159/168] Moved some member functions to derived classes. --- src/private/flat_map_base.h | 66 -------------------------------- src/private/flat_multimap_base.h | 66 -------------------------------- src/private/flat_multiset_base.h | 59 +--------------------------- src/private/flat_set_base.h | 66 -------------------------------- 4 files changed, 1 insertion(+), 256 deletions(-) diff --git a/src/private/flat_map_base.h b/src/private/flat_map_base.h index 16fd8587..eb237767 100644 --- a/src/private/flat_map_base.h +++ b/src/private/flat_map_base.h @@ -97,72 +97,6 @@ namespace etl public: typedef size_t size_type; - - //************************************************************************* - /// Gets the current size of the flat_map. - ///\return The current size of the flat_map. - //************************************************************************* - size_type size() const - { - return vbase.size(); - } - - //************************************************************************* - /// Checks the 'empty' state of the flat_map. - ///\return true if empty. - //************************************************************************* - bool empty() const - { - return vbase.empty(); - } - - //************************************************************************* - /// Checks the 'full' state of the flat_map. - ///\return true if full. - //************************************************************************* - bool full() const - { - return vbase.full(); - } - - //************************************************************************* - /// Returns the capacity of the flat_map. - ///\return The capacity of the flat_map. - //************************************************************************* - size_type capacity() const - { - return vbase.capacity(); - } - - //************************************************************************* - /// Returns the maximum possible size of the flat_map. - ///\return The maximum size of the flat_map. - //************************************************************************* - size_type max_size() const - { - return vbase.max_size(); - } - - //************************************************************************* - /// Returns the remaining capacity. - ///\return The remaining capacity. - //************************************************************************* - size_t available() const - { - return vbase.available(); - } - - protected: - - //************************************************************************* - /// Constructor. - //************************************************************************* - flat_map_base(vector_base& vbase) - : vbase(vbase) - { - } - - vector_base& vbase; }; } diff --git a/src/private/flat_multimap_base.h b/src/private/flat_multimap_base.h index eb9840f2..b9c0fc2b 100644 --- a/src/private/flat_multimap_base.h +++ b/src/private/flat_multimap_base.h @@ -83,72 +83,6 @@ namespace etl public: typedef size_t size_type; - - //************************************************************************* - /// Gets the current size of the flat_multimap. - ///\return The current size of the flat_multimap. - //************************************************************************* - size_type size() const - { - return vbase.size(); - } - - //************************************************************************* - /// Checks the 'empty' state of the flat_multimap. - ///\return true if empty. - //************************************************************************* - bool empty() const - { - return vbase.empty(); - } - - //************************************************************************* - /// Checks the 'full' state of the flat_multimap. - ///\return true if full. - //************************************************************************* - bool full() const - { - return vbase.full(); - } - - //************************************************************************* - /// Returns the capacity of the flat_multimap. - ///\return The capacity of the flat_multimap. - //************************************************************************* - size_type capacity() const - { - return vbase.capacity(); - } - - //************************************************************************* - /// Returns the maximum possible size of the flat_multimap. - ///\return The maximum size of the flat_multimap. - //************************************************************************* - size_type max_size() const - { - return vbase.max_size(); - } - - //************************************************************************* - /// Returns the remaining capacity. - ///\return The remaining capacity. - //************************************************************************* - size_t available() const - { - return vbase.available(); - } - - protected: - - //************************************************************************* - /// Constructor. - //************************************************************************* - flat_multimap_base(vector_base& vbase) - : vbase(vbase) - { - } - - vector_base& vbase; }; } diff --git a/src/private/flat_multiset_base.h b/src/private/flat_multiset_base.h index 4b495ddf..3bcd337e 100644 --- a/src/private/flat_multiset_base.h +++ b/src/private/flat_multiset_base.h @@ -84,71 +84,14 @@ namespace etl typedef size_t size_type; - //************************************************************************* - /// Gets the current size of the flat_multiset. - ///\return The current size of the flat_multiset. - //************************************************************************* - size_type size() const - { - return vbase.size(); - } - - //************************************************************************* - /// Checks the 'empty' state of the flat_multiset. - ///\return true if empty. - //************************************************************************* - bool empty() const - { - return vbase.empty(); - } - - //************************************************************************* - /// Checks the 'full' state of the flat_multiset. - ///\return true if full. - //************************************************************************* - bool full() const - { - return vbase.full(); - } - - //************************************************************************* - /// Returns the capacity of the flat_multiset. - ///\return The capacity of the flat_multiset. - //************************************************************************* - size_type capacity() const - { - return vbase.capacity(); - } - - //************************************************************************* - /// Returns the maximum possible size of the flat_multiset. - ///\return The maximum size of the flat_multiset. - //************************************************************************* - size_type max_size() const - { - return vbase.max_size(); - } - - //************************************************************************* - /// Returns the remaining capacity. - ///\return The remaining capacity. - //************************************************************************* - size_t available() const - { - return vbase.available(); - } - protected: //************************************************************************* /// Constructor. //************************************************************************* - flat_multiset_base(vector_base& vbase) - : vbase(vbase) + flat_multiset_base() { } - - vector_base& vbase; }; } diff --git a/src/private/flat_set_base.h b/src/private/flat_set_base.h index 22d1c58f..d494cfb4 100644 --- a/src/private/flat_set_base.h +++ b/src/private/flat_set_base.h @@ -97,72 +97,6 @@ namespace etl public: typedef size_t size_type; - - //************************************************************************* - /// Gets the current size of the flat_set. - ///\return The current size of the flat_set. - //************************************************************************* - size_type size() const - { - return vbase.size(); - } - - //************************************************************************* - /// Checks the 'empty' state of the flat_set. - ///\return true if empty. - //************************************************************************* - bool empty() const - { - return vbase.empty(); - } - - //************************************************************************* - /// Checks the 'full' state of the flat_set. - ///\return true if full. - //************************************************************************* - bool full() const - { - return vbase.full(); - } - - //************************************************************************* - /// Returns the capacity of the flat_set. - ///\return The capacity of the flat_set. - //************************************************************************* - size_type capacity() const - { - return vbase.capacity(); - } - - //************************************************************************* - /// Returns the maximum possible size of the flat_set. - ///\return The maximum size of the flat_set. - //************************************************************************* - size_type max_size() const - { - return vbase.max_size(); - } - - //************************************************************************* - /// Returns the remaining capacity. - ///\return The remaining capacity. - //************************************************************************* - size_t available() const - { - return vbase.available(); - } - - protected: - - //************************************************************************* - /// Constructor. - //************************************************************************* - flat_set_base(vector_base& vbase) - : vbase(vbase) - { - } - - vector_base& vbase; }; } From 8dbd6904b70496358eab8d661b7dd6568dbc9902 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 26 Feb 2017 09:14:58 +0000 Subject: [PATCH 160/168] Changed occurrences of 'new' to '::new' Added a ETL_DEBUG macro to platform.h to simplify selecting condition code for debugging. --- src/debug_count.h | 4 ++- src/ibasic_string.h | 6 ++-- src/ideque.h | 10 +++--- src/iflat_map.h | 60 ++++++++++++++++++++++++++++++++-- src/iflat_multimap.h | 60 ++++++++++++++++++++++++++++++++-- src/iflat_multiset.h | 60 ++++++++++++++++++++++++++++++++-- src/iflat_set.h | 62 +++++++++++++++++++++++++++++++++--- src/iforward_list.h | 8 ++--- src/ilist.h | 10 +++--- src/imap.h | 2 +- src/imultimap.h | 2 +- src/imultiset.h | 2 +- src/intrusive_forward_list.h | 3 +- src/intrusive_list.h | 3 +- src/ipool.h | 3 +- src/ipriority_queue.h | 3 +- src/iqueue.h | 4 +-- src/iset.h | 2 +- src/istack.h | 4 +-- src/iunordered_map.h | 9 +++--- src/iunordered_multimap.h | 7 ++-- src/iunordered_multiset.h | 7 ++-- src/iunordered_set.h | 7 ++-- src/optional.h | 21 ++++++------ src/platform.h | 3 ++ src/variant.h | 36 ++++++++++----------- 26 files changed, 314 insertions(+), 84 deletions(-) diff --git a/src/debug_count.h b/src/debug_count.h index dd6dfe32..45c55414 100644 --- a/src/debug_count.h +++ b/src/debug_count.h @@ -34,6 +34,8 @@ SOFTWARE. #include #include +#include "platform.h" + ///\defgroup debug_count debug count ///\ingroup utilities @@ -50,7 +52,7 @@ namespace etl { public: -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) inline debug_count() : count(0) { diff --git a/src/ibasic_string.h b/src/ibasic_string.h index a6f3616d..88fbf484 100644 --- a/src/ibasic_string.h +++ b/src/ibasic_string.h @@ -400,7 +400,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(string_iterator)); #endif @@ -893,7 +893,7 @@ namespace etl //********************************************************************* size_t find(const_pointer s, size_t pos = 0) const { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) if ((pos + etl::strlen(s)) > size()) { return npos; @@ -920,7 +920,7 @@ namespace etl //********************************************************************* size_t find(const_pointer s, size_t pos, size_t n) const { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) if ((pos + etl::strlen(s) - n) > size()) { return npos; diff --git a/src/ideque.h b/src/ideque.h index 51f5d8bd..d5d47141 100644 --- a/src/ideque.h +++ b/src/ideque.h @@ -1252,7 +1252,7 @@ namespace etl void create_element_front() { --_begin; - new (&(*_begin)) T(); + ::new (&(*_begin)) T(); ++current_size; ++construct_count; } @@ -1283,7 +1283,7 @@ namespace etl do { - new (&(*item++)) T(*from); + ::new (&(*item++)) T(*from); ++from; ++current_size; ++construct_count; @@ -1295,7 +1295,7 @@ namespace etl //********************************************************************* void create_element_back() { - new (&(*_end)) T(); + ::new (&(*_end)) T(); ++_end; ++current_size; ++construct_count; @@ -1307,7 +1307,7 @@ namespace etl void create_element_front(parameter_t value) { --_begin; - new (&(*_begin)) T(value); + ::new (&(*_begin)) T(value); ++current_size; ++construct_count; } @@ -1317,7 +1317,7 @@ namespace etl //********************************************************************* void create_element_back(parameter_t value) { - new (&(*_end)) T(value); + ::new (&(*_end)) T(value); ++_end; ++current_size; ++construct_count; diff --git a/src/iflat_map.h b/src/iflat_map.h index 7ffbcee4..ded0c413 100644 --- a/src/iflat_map.h +++ b/src/iflat_map.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "private/flat_map_base.h" #include "type_traits.h" #include "parameter_type.h" @@ -271,7 +272,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_map_full)); #endif @@ -531,14 +532,67 @@ namespace etl return *this; } + //************************************************************************* + /// Gets the current size of the flat_map. + ///\return The current size of the flat_map. + //************************************************************************* + size_type size() const + { + return buffer.size(); + } + + //************************************************************************* + /// Checks the 'empty' state of the flat_map. + ///\return true if empty. + //************************************************************************* + bool empty() const + { + return buffer.empty(); + } + + //************************************************************************* + /// Checks the 'full' state of the flat_map. + ///\return true if full. + //************************************************************************* + bool full() const + { + return buffer.full(); + } + + //************************************************************************* + /// Returns the capacity of the flat_map. + ///\return The capacity of the flat_map. + //************************************************************************* + size_type capacity() const + { + return buffer.capacity(); + } + + //************************************************************************* + /// Returns the maximum possible size of the flat_map. + ///\return The maximum size of the flat_map. + //************************************************************************* + size_type max_size() const + { + return buffer.max_size(); + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return buffer.available(); + } + protected: //********************************************************************* /// Constructor. //********************************************************************* iflat_map(buffer_t& buffer) - : flat_map_base(buffer), - buffer(buffer) + : buffer(buffer) { } diff --git a/src/iflat_multimap.h b/src/iflat_multimap.h index 31063127..86728f0b 100644 --- a/src/iflat_multimap.h +++ b/src/iflat_multimap.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "private/flat_multimap_base.h" #include "type_traits.h" #include "parameter_type.h" @@ -222,7 +223,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_multimap_full)); #endif @@ -480,14 +481,67 @@ namespace etl return *this; } + //************************************************************************* + /// Gets the current size of the flat_multiset. + ///\return The current size of the flat_multiset. + //************************************************************************* + size_type size() const + { + return buffer.size(); + } + + //************************************************************************* + /// Checks the 'empty' state of the flat_multiset. + ///\return true if empty. + //************************************************************************* + bool empty() const + { + return buffer.empty(); + } + + //************************************************************************* + /// Checks the 'full' state of the flat_multiset. + ///\return true if full. + //************************************************************************* + bool full() const + { + return buffer.full(); + } + + //************************************************************************* + /// Returns the capacity of the flat_multiset. + ///\return The capacity of the flat_multiset. + //************************************************************************* + size_type capacity() const + { + return buffer.capacity(); + } + + //************************************************************************* + /// Returns the maximum possible size of the flat_multiset. + ///\return The maximum size of the flat_multiset. + //************************************************************************* + size_type max_size() const + { + return buffer.max_size(); + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return buffer.available(); + } + protected: //********************************************************************* /// Constructor. //********************************************************************* iflat_multimap(buffer_t& buffer) - : flat_multimap_base(buffer), - buffer(buffer) + : buffer(buffer) { } diff --git a/src/iflat_multiset.h b/src/iflat_multiset.h index e06995a4..4a40ba7a 100644 --- a/src/iflat_multiset.h +++ b/src/iflat_multiset.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "private/flat_multiset_base.h" #include "type_traits.h" #include "parameter_type.h" @@ -198,7 +199,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_multiset_full)); #endif @@ -452,14 +453,67 @@ namespace etl return *this; } + //************************************************************************* + /// Gets the current size of the flat_multiset. + ///\return The current size of the flat_multiset. + //************************************************************************* + size_type size() const + { + return buffer.size(); + } + + //************************************************************************* + /// Checks the 'empty' state of the flat_multiset. + ///\return true if empty. + //************************************************************************* + bool empty() const + { + return buffer.empty(); + } + + //************************************************************************* + /// Checks the 'full' state of the flat_multiset. + ///\return true if full. + //************************************************************************* + bool full() const + { + return buffer.full(); + } + + //************************************************************************* + /// Returns the capacity of the flat_multiset. + ///\return The capacity of the flat_multiset. + //************************************************************************* + size_type capacity() const + { + return buffer.capacity(); + } + + //************************************************************************* + /// Returns the maximum possible size of the flat_multiset. + ///\return The maximum size of the flat_multiset. + //************************************************************************* + size_type max_size() const + { + return buffer.max_size(); + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return buffer.available(); + } + protected: //********************************************************************* /// Constructor. //********************************************************************* iflat_multiset(buffer_t& buffer) - : flat_multiset_base(buffer), - buffer(buffer) + : buffer(buffer) { } diff --git a/src/iflat_set.h b/src/iflat_set.h index be975c69..e692e143 100644 --- a/src/iflat_set.h +++ b/src/iflat_set.h @@ -38,6 +38,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "private/flat_set_base.h" #include "type_traits.h" #include "parameter_type.h" @@ -140,7 +141,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return buffer.rbegin(); } //********************************************************************* @@ -198,7 +199,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count <= difference_type(capacity()), ETL_ERROR(flat_set_full)); #endif @@ -458,14 +459,67 @@ namespace etl return *this; } + //************************************************************************* + /// Gets the current size of the flat_set. + ///\return The current size of the flat_set. + //************************************************************************* + size_type size() const + { + return buffer.size(); + } + + //************************************************************************* + /// Checks the 'empty' state of the flat_set. + ///\return true if empty. + //************************************************************************* + bool empty() const + { + return buffer.empty(); + } + + //************************************************************************* + /// Checks the 'full' state of the flat_set. + ///\return true if full. + //************************************************************************* + bool full() const + { + return buffer.full(); + } + + //************************************************************************* + /// Returns the capacity of the flat_set. + ///\return The capacity of the flat_set. + //************************************************************************* + size_type capacity() const + { + return buffer.capacity(); + } + + //************************************************************************* + /// Returns the maximum possible size of the flat_set. + ///\return The maximum size of the flat_set. + //************************************************************************* + size_type max_size() const + { + return buffer.max_size(); + } + + //************************************************************************* + /// Returns the remaining capacity. + ///\return The remaining capacity. + //************************************************************************* + size_t available() const + { + return buffer.available(); + } + protected: //********************************************************************* /// Constructor. //********************************************************************* iflat_set(buffer_t& buffer) - : flat_set_base(buffer), - buffer(buffer) + : buffer(buffer) { } diff --git a/src/iforward_list.h b/src/iforward_list.h index 1506dde2..c128ec55 100644 --- a/src/iforward_list.h +++ b/src/iforward_list.h @@ -354,7 +354,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(forward_list_iterator)); #endif @@ -507,7 +507,7 @@ namespace etl template void insert_after(iterator position, TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT((count + size()) <= MAX_SIZE, ETL_ERROR(forward_list_full)); #endif @@ -613,7 +613,7 @@ namespace etl return; // Can't more to before yourself! } -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) // Check that we are not doing an illegal move! for (const_iterator item = first_before; item != last; ++item) { @@ -956,7 +956,7 @@ namespace etl data_node_t& allocate_data_node(parameter_t value) { data_node_t* p_node = p_node_pool->allocate(); - new (&(p_node->value)) T(value); + ::new (&(p_node->value)) T(value); ++construct_count; return *p_node; diff --git a/src/ilist.h b/src/ilist.h index 3dc1a23b..9d42904a 100644 --- a/src/ilist.h +++ b/src/ilist.h @@ -37,11 +37,11 @@ SOFTWARE. #include #include +#include "platform.h" #include "nullptr.h" #include "private/list_base.h" #include "type_traits.h" #include "parameter_type.h" -#include "platform.h" #include "algorithm.h" #ifdef ETL_COMPILER_MICROSOFT @@ -449,7 +449,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(list_iterator)); ETL_ASSERT(size_t(count) <= MAX_SIZE, ETL_ERROR(list_full)); @@ -471,7 +471,7 @@ namespace etl //************************************************************************* void assign(size_t n, parameter_t value) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(list_full)); #endif @@ -1049,7 +1049,7 @@ namespace etl return; // Can't more to before yourself! } -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) // Check that we are not doing an illegal move! for (const_iterator item = first; item != last; ++item) { @@ -1088,7 +1088,7 @@ namespace etl data_node_t& allocate_data_node(parameter_t value) { data_node_t* p_data_node = p_node_pool->allocate(); - new (&(p_data_node->value)) T(value); + ::new (&(p_data_node->value)) T(value); ++construct_count; return *p_data_node; diff --git a/src/imap.h b/src/imap.h index 906518e3..1bc48cdd 100644 --- a/src/imap.h +++ b/src/imap.h @@ -857,7 +857,7 @@ namespace etl Data_Node& allocate_data_node(value_type value) { Data_Node& node = *p_node_pool->allocate(); - new (&node.value) const value_type(value); + ::new (&node.value) const value_type(value); ++construct_count; return node; } diff --git a/src/imultimap.h b/src/imultimap.h index 385824f3..d9cc7084 100644 --- a/src/imultimap.h +++ b/src/imultimap.h @@ -794,7 +794,7 @@ namespace etl Data_Node& allocate_data_node(value_type value) { Data_Node& node = *p_node_pool->allocate(); - new (&node.value) const value_type(value); + ::new (&node.value) const value_type(value); ++construct_count; return node; } diff --git a/src/imultiset.h b/src/imultiset.h index 5c81053b..632c7f91 100644 --- a/src/imultiset.h +++ b/src/imultiset.h @@ -775,7 +775,7 @@ namespace etl Data_Node& allocate_data_node(value_type value) { Data_Node& node = *p_node_pool->allocate(); - new ((void*)&node.value) value_type(value); + ::new ((void*)&node.value) value_type(value); ++construct_count; return node; } diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index 1ed9fcaa..00019df8 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -42,6 +42,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "nullptr.h" #include "type_traits.h" #include "exception.h" @@ -439,7 +440,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(intrusive_forward_list_iterator_exception)); #endif diff --git a/src/intrusive_list.h b/src/intrusive_list.h index 298c0ab3..4d72abe2 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -42,6 +42,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "nullptr.h" #include "type_traits.h" #include "exception.h" @@ -457,7 +458,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(intrusive_list_iterator_exception)); #endif diff --git a/src/ipool.h b/src/ipool.h index f7ec3d3d..18a196ea 100644 --- a/src/ipool.h +++ b/src/ipool.h @@ -34,6 +34,7 @@ SOFTWARE. #include +#include "platform.h" #include "nullptr.h" #include "alignment.h" #include "error_handler.h" @@ -271,7 +272,7 @@ namespace etl bool is_within_range = (distance >= 0) && (distance <= intptr_t((ITEM_SIZE * MAX_ITEMS) - ITEM_SIZE)); // Modulus and division can be slow on some architectures, so only do this in debug. -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) // Is the address on a valid object boundary? bool is_valid_address = ((distance % ITEM_SIZE) == 0); #else diff --git a/src/ipriority_queue.h b/src/ipriority_queue.h index 2992acc5..b00bd5f7 100644 --- a/src/ipriority_queue.h +++ b/src/ipriority_queue.h @@ -34,6 +34,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "type_traits.h" #include "parameter_type.h" #include "error_handler.h" @@ -167,7 +168,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(priority_queue_iterator)); ETL_ASSERT(static_cast(count) <= max_size(), ETL_ERROR(priority_queue_full)); diff --git a/src/iqueue.h b/src/iqueue.h index 56bb32b4..952484b4 100644 --- a/src/iqueue.h +++ b/src/iqueue.h @@ -117,7 +117,7 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - new (&p_buffer[in]) T(value); + ::new (&p_buffer[in]) T(value); in = (in == (MAX_SIZE - 1)) ? 0 : in + 1; ++current_size; ++construct_count; @@ -138,7 +138,7 @@ namespace etl #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - new (&p_buffer[in]) T(); + ::new (&p_buffer[in]) T(); in = (in == (MAX_SIZE - 1)) ? 0 : in + 1; ++current_size; ++construct_count; diff --git a/src/iset.h b/src/iset.h index 5288c6be..d84b51ba 100644 --- a/src/iset.h +++ b/src/iset.h @@ -783,7 +783,7 @@ namespace etl Data_Node& allocate_data_node(value_type value) { Data_Node& node = *p_node_pool->allocate(); - new ((void*)&node.value) value_type(value); + ::new ((void*)&node.value) value_type(value); ++construct_count; return node; } diff --git a/src/istack.h b/src/istack.h index ff961f59..432fa615 100644 --- a/src/istack.h +++ b/src/istack.h @@ -90,7 +90,7 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif top_index = current_size++; - new (&p_buffer[top_index]) T(value); + ::new (&p_buffer[top_index]) T(value); ++construct_count; } @@ -107,7 +107,7 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif top_index = current_size++; - new (&p_buffer[top_index]) T(); + ::new (&p_buffer[top_index]) T(); ++construct_count; return p_buffer[top_index]; diff --git a/src/iunordered_map.h b/src/iunordered_map.h index 9f00fd3b..22127922 100644 --- a/src/iunordered_map.h +++ b/src/iunordered_map.h @@ -37,6 +37,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "type_traits.h" #include "parameter_type.h" #include "hash.h" @@ -648,7 +649,7 @@ namespace etl // Doesn't exist, so add a new one. // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key_value_pair) value_type(key, T()); + ::new (&node.key_value_pair) value_type(key, T()); ++construct_count; pbucket->insert_after(pbucket->before_begin(), node); @@ -736,7 +737,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_map_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_map_full)); @@ -778,7 +779,7 @@ namespace etl { // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key_value_pair) value_type(key_value_pair); + ::new (&node.key_value_pair) value_type(key_value_pair); ++construct_count; // Just add the pointer to the bucket; @@ -812,7 +813,7 @@ namespace etl { // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key_value_pair) value_type(key_value_pair); + ::new (&node.key_value_pair) value_type(key_value_pair); ++construct_count; // Add the node to the end of the bucket; diff --git a/src/iunordered_multimap.h b/src/iunordered_multimap.h index 4f136a4c..7319a624 100644 --- a/src/iunordered_multimap.h +++ b/src/iunordered_multimap.h @@ -37,6 +37,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "type_traits.h" #include "parameter_type.h" #include "hash.h" @@ -628,7 +629,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_multimap_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_multimap_full)); @@ -668,7 +669,7 @@ namespace etl { // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key_value_pair) value_type(key_value_pair); + ::new (&node.key_value_pair) value_type(key_value_pair); ++construct_count; // Just add the pointer to the bucket; @@ -698,7 +699,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key_value_pair) value_type(key_value_pair); + ::new (&node.key_value_pair) value_type(key_value_pair); ++construct_count; // Add the node to the end of the bucket; diff --git a/src/iunordered_multiset.h b/src/iunordered_multiset.h index fecab3a0..f1966559 100644 --- a/src/iunordered_multiset.h +++ b/src/iunordered_multiset.h @@ -37,6 +37,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "type_traits.h" #include "parameter_type.h" #include "hash.h" @@ -623,7 +624,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_multiset_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_multiset_full)); @@ -660,7 +661,7 @@ namespace etl { // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key) value_type(key); + ::new (&node.key) value_type(key); ++construct_count; // Just add the pointer to the bucket; @@ -691,7 +692,7 @@ namespace etl // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key) value_type(key); + ::new (&node.key) value_type(key); ++construct_count; // Add the node to the end of the bucket; diff --git a/src/iunordered_set.h b/src/iunordered_set.h index aaef8819..789375bb 100644 --- a/src/iunordered_set.h +++ b/src/iunordered_set.h @@ -37,6 +37,7 @@ SOFTWARE. #include #include +#include "platform.h" #include "type_traits.h" #include "parameter_type.h" #include "hash.h" @@ -623,7 +624,7 @@ namespace etl template void assign(TIterator first, TIterator last) { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(count >= 0, ETL_ERROR(unordered_set_iterator)); ETL_ASSERT(size_t(count) <= max_size() , ETL_ERROR(unordered_set_full)); @@ -660,7 +661,7 @@ namespace etl { // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key) value_type(key); + ::new (&node.key) value_type(key); ++construct_count; // Just add the pointer to the bucket; @@ -694,7 +695,7 @@ namespace etl { // Get a new node. node_t& node = *pnodepool->allocate(); - new (&node.key) value_type(key); + ::new (&node.key) value_type(key); ++construct_count; // Add the node to the end of the bucket; diff --git a/src/optional.h b/src/optional.h index d0787782..7b5a9e5c 100644 --- a/src/optional.h +++ b/src/optional.h @@ -31,6 +31,7 @@ SOFTWARE. #ifndef __ETL_OPTIONAL__ #define __ETL_OPTIONAL__ +#include "platform.h" #include "alignment.h" #include "type_traits.h" #include "exception.h" @@ -128,7 +129,7 @@ namespace etl { if (valid) { - new (storage.template get_address()) T(other.value()); + ::new (storage.template get_address()) T(other.value()); } } @@ -137,7 +138,7 @@ namespace etl //*************************************************************************** optional(const T& value) { - new (storage.template get_address()) T(value); + ::new (storage.template get_address()) T(value); valid = true; } @@ -186,7 +187,7 @@ namespace etl } else { - new (storage.template get_address()) T(other.value()); + ::new (storage.template get_address()) T(other.value()); valid = true; } } @@ -206,7 +207,7 @@ namespace etl } else { - new (storage.template get_address()) T(value); + ::new (storage.template get_address()) T(value); valid = true; } @@ -218,7 +219,7 @@ namespace etl //*************************************************************************** T* operator ->() { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -230,7 +231,7 @@ namespace etl //*************************************************************************** const T* operator ->() const { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -242,7 +243,7 @@ namespace etl //*************************************************************************** T& operator *() { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -254,7 +255,7 @@ namespace etl //*************************************************************************** const T& operator *() const { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -274,7 +275,7 @@ namespace etl //*************************************************************************** T& value() { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif @@ -286,7 +287,7 @@ namespace etl //*************************************************************************** const T& value() const { -#if defined(_DEBUG) || defined(DEBUG) +#if defined(ETL_DEBUG) ETL_ASSERT(valid, ETL_ERROR(optional_invalid)); #endif diff --git a/src/platform.h b/src/platform.h index 0616594c..6382b37c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -85,3 +85,6 @@ SOFTWARE. // Some targets do not support 8bit types. #define ETL_8BIT_SUPPORT (CHAR_BIT == 8) +#if defined(_DEBUG) || defined(DEBUG) + #define ETL_DEBUG +#endif \ No newline at end of file diff --git a/src/variant.h b/src/variant.h index 99641bbe..6b2931eb 100644 --- a/src/variant.h +++ b/src/variant.h @@ -711,7 +711,7 @@ namespace etl { STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); - new (static_cast(data)) T(value); + ::new (static_cast(data)) T(value); type_id = Type_Id_Lookup::type_id; } @@ -723,14 +723,14 @@ namespace etl { switch (other.type_id) { - case 0: new (static_cast(data)) T1(other.get()); break; - case 1: new (static_cast(data)) T2(other.get()); break; - case 2: new (static_cast(data)) T3(other.get()); break; - case 3: new (static_cast(data)) T4(other.get()); break; - case 4: new (static_cast(data)) T5(other.get()); break; - case 5: new (static_cast(data)) T6(other.get()); break; - case 6: new (static_cast(data)) T7(other.get()); break; - case 7: new (static_cast(data)) T8(other.get()); break; + case 0: ::new (static_cast(data)) T1(other.get()); break; + case 1: ::new (static_cast(data)) T2(other.get()); break; + case 2: ::new (static_cast(data)) T3(other.get()); break; + case 3: ::new (static_cast(data)) T4(other.get()); break; + case 4: ::new (static_cast(data)) T5(other.get()); break; + case 5: ::new (static_cast(data)) T6(other.get()); break; + case 6: ::new (static_cast(data)) T7(other.get()); break; + case 7: ::new (static_cast(data)) T8(other.get()); break; default: break; } @@ -747,7 +747,7 @@ namespace etl STATIC_ASSERT(Type_Is_Supported::value, "Unsupported type"); destruct_current(); - new (static_cast(data)) T(value); + ::new (static_cast(data)) T(value); type_id = Type_Id_Lookup::type_id; return *this; @@ -765,14 +765,14 @@ namespace etl switch (other.type_id) { - case 0: new (static_cast(data)) T1(other.get()); break; - case 1: new (static_cast(data)) T2(other.get()); break; - case 2: new (static_cast(data)) T3(other.get()); break; - case 3: new (static_cast(data)) T4(other.get()); break; - case 4: new (static_cast(data)) T5(other.get()); break; - case 5: new (static_cast(data)) T6(other.get()); break; - case 6: new (static_cast(data)) T7(other.get()); break; - case 7: new (static_cast(data)) T8(other.get()); break; + case 0: ::new (static_cast(data)) T1(other.get()); break; + case 1: ::new (static_cast(data)) T2(other.get()); break; + case 2: ::new (static_cast(data)) T3(other.get()); break; + case 3: ::new (static_cast(data)) T4(other.get()); break; + case 4: ::new (static_cast(data)) T5(other.get()); break; + case 5: ::new (static_cast(data)) T6(other.get()); break; + case 6: ::new (static_cast(data)) T7(other.get()); break; + case 7: ::new (static_cast(data)) T8(other.get()); break; default: break; } From 8fdea39e30f04dda7bd48d1abc99b10a628c00fb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 2 Mar 2017 19:30:43 +0000 Subject: [PATCH 161/168] Added 'typename' --- src/iterator.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/iterator.h b/src/iterator.h index b6d04c6e..e451c62b 100644 --- a/src/iterator.h +++ b/src/iterator.h @@ -43,31 +43,31 @@ namespace etl template struct is_input_iterator { - static const bool value = etl::is_same::iterator_category, std::input_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::input_iterator_tag>::value; }; template struct is_output_iterator { - static const bool value = etl::is_same::iterator_category, std::output_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::output_iterator_tag>::value; }; template struct is_forward_iterator { - static const bool value = etl::is_same::iterator_category, std::forward_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::forward_iterator_tag>::value; }; template struct is_bidirectional_iterator { - static const bool value = etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value; }; template struct is_random_iterator { - static const bool value = etl::is_same::iterator_category, std::random_access_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::random_access_iterator_tag>::value; }; template From 2f2a2350e493ba37f2d1950258e57952aef77aaa Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 3 Mar 2017 10:14:44 +0000 Subject: [PATCH 162/168] Removed git conflict marker --- src/algorithm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/algorithm.h b/src/algorithm.h index 73fb21c2..58e05eb1 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -695,7 +695,6 @@ namespace etl } return std::pair(destination_true, destination_false); ->>>>>>> origin/development } } From 8451bc1e888f09d2d7313168cfe5c2eeddbe2941 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 3 Mar 2017 10:24:02 +0000 Subject: [PATCH 163/168] Added dual input range versions transform algorithm. --- src/algorithm.h | 381 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 317 insertions(+), 64 deletions(-) diff --git a/src/algorithm.h b/src/algorithm.h index 58e05eb1..7698dee4 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -53,8 +53,11 @@ namespace etl /// ///\ingroup algorithm //*************************************************************************** - template - std::pair minmax_element(TIterator begin, TIterator end, TCompare compare) + template + std::pair minmax_element(TIterator begin, + TIterator end, + TCompare compare) { TIterator minimum = begin; TIterator maximum = begin; @@ -83,7 +86,8 @@ namespace etl /// //*************************************************************************** template - std::pair minmax_element(TIterator begin, TIterator end) + std::pair minmax_element(TIterator begin, + TIterator end) { typedef typename std::iterator_traits::value_type value_t; @@ -96,7 +100,8 @@ namespace etl /// //*************************************************************************** template - std::pair minmax(const T& a, const T& b) + std::pair minmax(const T& a, + const T& b) { return (b < a) ? std::pair(b, a) : std::pair(a, b); } @@ -106,8 +111,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - std::pair minmax(const T& a, const T& b, TCompare compare) + template + std::pair minmax(const T& a, + const T& b, + TCompare compare) { return compare(b, a) ? std::pair(b, a) : std::pair(a, b); } @@ -118,7 +126,8 @@ namespace etl /// //*************************************************************************** template - TIterator is_sorted_until(TIterator begin, TIterator end) + TIterator is_sorted_until(TIterator begin, + TIterator end) { if (begin != end) { @@ -143,8 +152,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - TIterator is_sorted_until(TIterator begin, TIterator end, TCompare compare) + template + TIterator is_sorted_until(TIterator begin, + TIterator end, + TCompare compare) { if (begin != end) { @@ -170,7 +182,8 @@ namespace etl /// //*************************************************************************** template - bool is_sorted(TIterator begin, TIterator end) + bool is_sorted(TIterator begin, + TIterator end) { return etl::is_sorted_until(begin, end) == end; } @@ -180,8 +193,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool is_sorted(TIterator begin, TIterator end, TCompare compare) + template + bool is_sorted(TIterator begin, + TIterator end, + TCompare compare) { return etl::is_sorted_until(begin, end, compare) == end; } @@ -197,11 +213,14 @@ namespace etl ///\param o_end End of the output range. ///\ingroup algorithm //*************************************************************************** - template + template typename etl::enable_if::value && etl::is_random_iterator::value, TOutputIterator>::type - copy(TInputIterator i_begin, TInputIterator i_end, - TOutputIterator o_begin, TOutputIterator o_end) + copy(TInputIterator i_begin, + TInputIterator i_end, + TOutputIterator o_begin, + TOutputIterator o_end) { size_t s_size = std::distance(i_begin, i_end); size_t d_size = std::distance(o_begin, o_end); @@ -221,11 +240,14 @@ namespace etl ///\param o_end End of the output range. ///\ingroup algorithm //*************************************************************************** - template + template typename etl::enable_if::value || !etl::is_random_iterator::value, TOutputIterator>::type - copy(TInputIterator i_begin, TInputIterator i_end, - TOutputIterator o_begin, TOutputIterator o_end) + copy(TInputIterator i_begin, + TInputIterator i_end, + TOutputIterator o_begin, + TOutputIterator o_end) { while ((i_begin != i_end) && (o_begin != o_end)) { @@ -240,8 +262,12 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - TOutputIterator copy_n(TInputIterator begin, Size count, TOutputIterator result) + template + TOutputIterator copy_n(TInputIterator begin, + TSize count, + TOutputIterator result) { return std::copy(begin, begin + count, result); } @@ -251,8 +277,13 @@ namespace etl /// A form of copy_n where the smallest of the two ranges is used. ///\ingroup algorithm //*************************************************************************** - template - TOutputIterator copy_n(TInputIterator i_begin, Size count, TOutputIterator o_begin, TOutputIterator o_end) + template + TOutputIterator copy_n(TInputIterator i_begin, + TSize count, + TOutputIterator o_begin, + TOutputIterator o_end) { return etl::copy(i_begin, i_begin + count, o_begin, o_end);; } @@ -262,8 +293,13 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - TOutputIterator copy_if(TIterator begin, TIterator end, TOutputIterator out, TUnaryPredicate predicate) + template + TOutputIterator copy_if(TIterator begin, + TIterator end, + TOutputIterator out, + TUnaryPredicate predicate) { while (begin != end) { @@ -284,9 +320,13 @@ namespace etl /// There is currently no STL equivelent. ///\ingroup algorithm //*************************************************************************** - template - TOutputIterator copy_if(TInputIterator i_begin, TInputIterator i_end, - TOutputIterator o_begin, TOutputIterator o_end, + template + TOutputIterator copy_if(TInputIterator i_begin, + TInputIterator i_end, + TOutputIterator o_begin, + TOutputIterator o_end, TUnaryPredicate predicate) { while ((i_begin != i_end) && (o_begin != o_end)) @@ -307,8 +347,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - TIterator find_if_not(TIterator begin, TIterator end, TUnaryPredicate predicate) + template + TIterator find_if_not(TIterator begin, + TIterator end, + TUnaryPredicate predicate) { while (begin != end) { @@ -328,8 +371,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool all_of(TIterator begin, TIterator end, TUnaryPredicate predicate) + template + bool all_of(TIterator begin, + TIterator end, + TUnaryPredicate predicate) { return etl::find_if_not(begin, end, predicate) == end; } @@ -339,8 +385,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool any_of(TIterator begin, TIterator end, TUnaryPredicate predicate) + template + bool any_of(TIterator begin, + TIterator end, + TUnaryPredicate predicate) { return std::find_if(begin, end, predicate) != end; } @@ -350,8 +399,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool none_of(TIterator begin, TIterator end, TUnaryPredicate predicate) + template + bool none_of(TIterator begin, + TIterator end, + TUnaryPredicate predicate) { return std::find_if(begin, end, predicate) == end; } @@ -361,8 +413,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2) + template + bool is_permutation(TIterator1 begin1, + TIterator1 end1, + TIterator2 begin2) { if (begin1 != end1) { @@ -392,8 +447,12 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TIterator2 end2) + template + bool is_permutation(TIterator1 begin1, + TIterator1 end1, + TIterator2 begin2, + TIterator2 end2) { if (begin1 != end1) { @@ -419,8 +478,13 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TBinaryPredicate predicate) + template + bool is_permutation(TIterator1 begin1, + TIterator1 end1, + TIterator2 begin2, + TBinaryPredicate predicate) { if (begin1 != end1) { @@ -450,8 +514,14 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool is_permutation(TIterator1 begin1, TIterator1 end1, TIterator2 begin2, TIterator2 end2, TBinaryPredicate predicate) + template + bool is_permutation(TIterator1 begin1, + TIterator1 end1, + TIterator2 begin2, + TIterator2 end2, + TBinaryPredicate predicate) { if (begin1 != end1) { @@ -477,8 +547,11 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template - bool is_partitioned(TIterator begin, TIterator end, TUnaryPredicate predicate) + template + bool is_partitioned(TIterator begin, + TIterator end, + TUnaryPredicate predicate) { while (begin != end) { @@ -504,8 +577,11 @@ namespace etl /// ///\ingroup algorithm //*************************************************************************** - template - TIterator partition_point(TIterator begin, TIterator end, TUnaryPredicate predicate) + template + TIterator partition_point(TIterator begin, + TIterator end, + TUnaryPredicate predicate) { while (begin != end) { @@ -526,7 +602,10 @@ namespace etl /// ///\ingroup algorithm //*************************************************************************** - template + template std::pair partition_copy(TSource begin, TSource end, TDestinationTrue destination_true, @@ -552,8 +631,13 @@ namespace etl /// Like std::for_each but applies a predicate before calling the function. ///\ingroup algorithm //*************************************************************************** - template - TUnaryFunction for_each_if(TIterator begin, const TIterator end, TUnaryFunction function, TUnaryPredicate predicate) + template + TUnaryFunction for_each_if(TIterator begin, + const TIterator end, + TUnaryFunction function, + TUnaryPredicate predicate) { while (begin != end) { @@ -574,7 +658,9 @@ namespace etl /// There is currently no STL equivalent. ///\ingroup algorithm //*************************************************************************** - template + template void transform(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, @@ -589,10 +675,14 @@ namespace etl //*************************************************************************** /// Transform 'n' items. + /// Random iterators. /// There is currently no STL equivalent. ///\ingroup algorithm //*************************************************************************** - template + template typename etl::enable_if::value, void>::type transform_n(TInputIterator i_begin, TSize n, @@ -603,11 +693,37 @@ namespace etl } //*************************************************************************** - /// Transform 'n' items. + /// Transform 'n' items from two ranges. + /// Random iterators. /// There is currently no STL equivalent. ///\ingroup algorithm //*************************************************************************** - template + template + typename etl::enable_if::value && + etl::is_random_iterator::value, void>::type + transform_n(TInputIterator1 i_begin1, + TInputIterator2 i_begin2, + TSize n, + TOutputIterator o_begin, + TBinaryFunction function) + { + std::transform(i_begin, i_begin + n, i_begin2, o_begin, function); + } + + //*************************************************************************** + /// Transform 'n' items. + /// Non-random iterators. + /// There is currently no STL equivalent. + ///\ingroup algorithm + //*************************************************************************** + template typename etl::enable_if::value, void>::type transform_n(TInputIterator i_begin, TSize n, @@ -621,14 +737,45 @@ namespace etl } } + //*************************************************************************** + /// Transform 'n' items from two ranges. + /// Non-random iterators. + /// There is currently no STL equivalent. + ///\ingroup algorithm + //*************************************************************************** + template + typename etl::enable_if::value || + !etl::is_random_iterator::value, void>::type + transform_n(TInputIterator1 i_begin1, + TInputIterator2 i_begin2, + TSize n, + TOutputIterator o_begin, + TBinaryFunction function) + { + while (n > 0) + { + *o_begin++ = function(*i_begin1++, *i_begin2++); + --n; + } + } + //*************************************************************************** /// Like std::transform but applies a predicate before calling the function. ///\ingroup algorithm //*************************************************************************** - template - TOutputIterator transform_if(TInputIterator i_begin, const TInputIterator i_end, - TOutputIterator o_begin, TUnaryFunction function, - TUnaryPredicate predicate) + template + TOutputIterator transform_if(TInputIterator i_begin, + const TInputIterator i_end, + TOutputIterator o_begin, + TUnaryFunction function, + TUnaryPredicate predicate) { while (i_begin != i_end) { @@ -643,16 +790,51 @@ namespace etl return o_begin; } + //*************************************************************************** + /// Like etl::transform_if but inputs from two ranges. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator transform_if(TInputIterator1 i_begin1, + const TInputIterator1 i_end1, + TInputIterator2 i_begin2, + TOutputIterator o_begin, + TBinaryFunction function, + TBinaryPredicate predicate) + { + while (i_begin1 != i_end1) + { + if (predicate(*i_begin1, *i_begin2)) + { + *o_begin++ = function(*i_begin1, *i_begin2); + } + + ++i_begin1; + ++i_begin2; + } + + return o_begin; + } + //*************************************************************************** /// Like std::transform but applies a predicate before calling the function. /// Returns when the first range end is reached. ///\ingroup algorithm //*************************************************************************** - template - TOutputIterator transform_if(TInputIterator i_begin, const TInputIterator i_end, - TOutputIterator o_begin, TOutputIterator o_end, - TUnaryFunction function, - TUnaryPredicate predicate) + template + TOutputIterator transform_if(TInputIterator i_begin, + const TInputIterator i_end, + TOutputIterator o_begin, + TOutputIterator o_end, + TUnaryFunction function, + TUnaryPredicate predicate) { while ((i_begin != i_end) && (o_begin != o_end)) { @@ -667,13 +849,47 @@ namespace etl return o_begin; } + //*************************************************************************** + /// Like etl::transform_if but inputs from two ranges. + /// Returns when the first range end is reached. + ///\ingroup algorithm + //*************************************************************************** + template + TOutputIterator transform_if(TInputIterator1 i_begin1, + const TInputIterator1 i_end1, + TInputIterator2 i_begin2, + const TInputIterator1 i_end2, + TOutputIterator o_begin, + const TInputIterator1 o_end, + TBinaryFunction function, + TBinaryPredicate predicate) + { + while ((i_begin1 != i_end1) && (i_begin2 != i_end2) && (o_begin != o_end)) + { + if (predicate(*i_begin1, *i_begin2)) + { + *o_begin++ = function(*i_begin1, *i_begin2); + } + + ++i_begin1; + ++i_begin2; + } + + return o_begin; + } + //*************************************************************************** /// Transforms the elements from the range (begin, end) to two different ranges /// depending on the value returned by the predicate.
///\ingroup algorithm //*************************************************************************** template + typename TUnaryFunctionTrue, typename TUnaryFunctionFalse, + typename TUnaryPredicate> std::pair partition_transform(TSource begin, TSource end, TDestinationTrue destination_true, @@ -698,5 +914,42 @@ namespace etl } } + //*************************************************************************** + /// Transforms the elements from the ranges (begin1, end1) & (begin2, end2) + /// to two different ranges depending on the value returned by the predicate. + ///\ingroup algorithm + //*************************************************************************** + template + std::pair partition_transform(TSource1 begin1, + TSource1 end1, + TSource2 begin2, + TDestinationTrue destination_true, + TDestinationFalse destination_false, + TBinaryFunctionTrue function_true, + TBinaryFunctionFalse function_false, + TBinaryPredicate predicate) + { + while (begin1 != end1) + { + if (predicate(*begin1, *begin2)) + { + *destination_true++ = function_true(*begin1++, *begin2++); + } + else + { + *destination_false++ = function_false(*begin1++, *begin2++); + } + } + + return std::pair(destination_true, destination_false); + } +} + #endif From bd738b0c2a0cdb765d5eedb00c1a9821e17c1414 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 3 Mar 2017 10:24:31 +0000 Subject: [PATCH 164/168] Experimental first draft of 'functors' header. --- src/functors.h | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/functors.h diff --git a/src/functors.h b/src/functors.h new file mode 100644 index 00000000..93e28340 --- /dev/null +++ b/src/functors.h @@ -0,0 +1,145 @@ +///\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. +******************************************************************************/ + +#ifndef __ETL_FUNCTORS__ +#define __ETL_FUNCTORS__ + +///\defgroup functors functors +/// A set of functors for use with for_each +///\ingroup utilities + +#include "type_traits.h" +#include "static_assert.h" + +namespace etl +{ + //*************************************************************************** + /// Finds the mean + ///\ingroup algorithm + //*************************************************************************** + template + class mean + { + public: + + mean() + : sum(TSum()), + count(0) + { + } + + mean(TSum initial_value) + : sum(initial_value()), + count(0) + { + } + + template + void operator()(TValue value) + { + sum += value; + ++count; + } + + template + typename etl::enable_if::value, TResult>::type + result() const + { + return TResult(sum) / TResult(count); + } + + template + typename etl::enable_if::value, TResult>::type + result() const + { + return TResult(sum / count); + } + + void reset() + { + sum = TSum(); + count = 0; + } + + private: + + TSum sum; + TCount count; + }; + + //*************************************************************************** + /// Finds the mean on a rolling basis. + /// Defaults to an initial value of TMean() and a ratio of 0.1 + ///\ingroup algorithm + //*************************************************************************** + template + class rolling_mean + { + public: + + STATIC_ASSERT(etl::is_floating_point::value, "TRatio must be a floating point type"); + + rolling_mean(TMean initial_value = TMean(), + TRatio ratio_ = TRatio(0.1) + : mean(initial_value), + ratio(ratio_) + { + } + + template + void operator()(TValue value) + { + mean -= (mean * ratio); + mean += (value * ratio); + } + + void set_ratio(TRatio ratio_) + { + ratio = ratio_; + } + + TMean result() const + { + return mean; + } + + void reset() + { + mean = TMean(); + } + + private: + + TMean mean; + }; +} + +#endif + From f09b7ccc374de88c71a1e8816d33ea66e9a27d9e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 2 Mar 2017 19:28:09 +0000 Subject: [PATCH 165/168] Added 'typename' --- src/iterator.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/iterator.h b/src/iterator.h index b6d04c6e..e451c62b 100644 --- a/src/iterator.h +++ b/src/iterator.h @@ -43,31 +43,31 @@ namespace etl template struct is_input_iterator { - static const bool value = etl::is_same::iterator_category, std::input_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::input_iterator_tag>::value; }; template struct is_output_iterator { - static const bool value = etl::is_same::iterator_category, std::output_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::output_iterator_tag>::value; }; template struct is_forward_iterator { - static const bool value = etl::is_same::iterator_category, std::forward_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::forward_iterator_tag>::value; }; template struct is_bidirectional_iterator { - static const bool value = etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value; }; template struct is_random_iterator { - static const bool value = etl::is_same::iterator_category, std::random_access_iterator_tag>::value; + static const bool value = etl::is_same::iterator_category, std::random_access_iterator_tag>::value; }; template From 4b84cc955ef3c38e62769e689b2451de6f95a6f7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Mar 2017 14:53:05 +0000 Subject: [PATCH 166/168] Changed internal operation to indirect access to improve insertion performance. --- src/flat_map.h | 27 ++- src/flat_multimap.h | 23 +- src/flat_multiset.h | 23 +- src/flat_set.h | 23 +- src/iflat_map.h | 378 +++++++++++++++++++++++++------ src/iflat_multimap.h | 357 ++++++++++++++++++++++++----- src/iflat_multiset.h | 327 ++++++++++++++++++++++---- src/iflat_set.h | 320 ++++++++++++++++++++++---- src/private/flat_map_base.h | 5 + src/private/flat_multimap_base.h | 5 + src/private/flat_multiset_base.h | 5 + src/private/flat_set_base.h | 6 +- test/test_flat_map.cpp | 100 ++++++-- test/test_flat_multimap.cpp | 151 +++++++----- test/test_flat_multiset.cpp | 126 +++++++---- test/test_flat_set.cpp | 154 ++++++++----- 16 files changed, 1625 insertions(+), 405 deletions(-) diff --git a/src/flat_map.h b/src/flat_map.h index f323a367..12cca227 100644 --- a/src/flat_map.h +++ b/src/flat_map.h @@ -37,18 +37,18 @@ SOFTWARE. #include "iflat_map.h" #include "vector.h" +#include "pool.h" //***************************************************************************** ///\defgroup flat_map flat_map /// A flat_map with the capacity defined at compile time. /// Has insertion of O(N) and flat_map of O(logN) -/// Duplicate entries and not allowed. +/// Duplicate entries are not allowed. ///\ingroup containers //***************************************************************************** namespace etl { - template > //*************************************************************************** /// A flat_map implementation that uses a fixed size buffer. ///\tparam TKey The key type. @@ -57,6 +57,7 @@ namespace etl ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. ///\ingroup flat_map //*************************************************************************** + template > class flat_map : public iflat_map { public: @@ -67,7 +68,7 @@ namespace etl /// Constructor. //************************************************************************* flat_map() - : iflat_map(buffer) + : iflat_map(lookup, storage) { } @@ -75,7 +76,7 @@ namespace etl /// Copy constructor. //************************************************************************* flat_map(const flat_map& other) - : iflat_map(buffer) + : iflat_map(lookup, storage) { iflat_map::assign(other.cbegin(), other.cend()); } @@ -88,11 +89,19 @@ namespace etl //************************************************************************* template flat_map(TIterator first, TIterator last) - : iflat_map(buffer) + : iflat_map(lookup, storage) { iflat_map::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~flat_map() + { + iflat_map::clear(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -108,7 +117,13 @@ namespace etl private: - etl::vector::value_type, MAX_SIZE> buffer; ///::value_type node_t; + + // The pool of nodes. + etl::pool storage; + + // The vector that stores pointers to the nodes. + etl::vector lookup; }; } diff --git a/src/flat_multimap.h b/src/flat_multimap.h index b0d3722b..603ff4b5 100644 --- a/src/flat_multimap.h +++ b/src/flat_multimap.h @@ -37,6 +37,7 @@ SOFTWARE. #include "iflat_multimap.h" #include "vector.h" +#include "pool.h" //***************************************************************************** ///\defgroup flat_multimap flat_multimap @@ -67,7 +68,7 @@ namespace etl /// Constructor. //************************************************************************* flat_multimap() - : iflat_multimap(buffer) + : iflat_multimap(lookup, storage) { } @@ -75,7 +76,7 @@ namespace etl /// Copy constructor. //************************************************************************* flat_multimap(const flat_multimap& other) - : iflat_multimap(buffer) + : iflat_multimap(lookup, storage) { iflat_multimap::assign(other.cbegin(), other.cend()); } @@ -88,11 +89,19 @@ namespace etl //************************************************************************* template flat_multimap(TIterator first, TIterator last) - : iflat_multimap(buffer) + : iflat_multimap(lookup, storage) { iflat_multimap::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~flat_multimap() + { + iflat_multimap::clear(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -108,7 +117,13 @@ namespace etl private: - etl::vector::value_type, MAX_SIZE> buffer; ///::value_type node_t; + + // The pool of nodes. + etl::pool storage; + + // The vector that stores pointers to the nodes. + etl::vector lookup; }; } diff --git a/src/flat_multiset.h b/src/flat_multiset.h index 3f5c47f9..be7a9273 100644 --- a/src/flat_multiset.h +++ b/src/flat_multiset.h @@ -37,6 +37,7 @@ SOFTWARE. #include "iflat_multiset.h" #include "vector.h" +#include "pool.h" //***************************************************************************** ///\defgroup flat_multiset flat_multiset @@ -66,7 +67,7 @@ namespace etl /// Constructor. //************************************************************************* flat_multiset() - : iflat_multiset(buffer) + : iflat_multiset(lookup, storage) { } @@ -74,7 +75,7 @@ namespace etl /// Copy constructor. //************************************************************************* flat_multiset(const flat_multiset& other) - : iflat_multiset(buffer) + : iflat_multiset(lookup, storage) { iflat_multiset::assign(other.cbegin(), other.cend()); } @@ -87,11 +88,19 @@ namespace etl //************************************************************************* template flat_multiset(TIterator first, TIterator last) - : iflat_multiset(buffer) + : iflat_multiset(lookup, storage) { iflat_multiset::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~flat_multiset() + { + iflat_multiset::clear(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -107,7 +116,13 @@ namespace etl private: - etl::vector buffer; ///::value_type node_t; + + // The pool of nodes. + etl::pool storage; + + // The vector that stores pointers to the nodes. + etl::vector lookup; }; } diff --git a/src/flat_set.h b/src/flat_set.h index 07ce888a..4a01b066 100644 --- a/src/flat_set.h +++ b/src/flat_set.h @@ -37,6 +37,7 @@ SOFTWARE. #include "iflat_set.h" #include "vector.h" +#include "pool.h" //***************************************************************************** ///\defgroup flat_set flat_set @@ -66,7 +67,7 @@ namespace etl /// Constructor. //************************************************************************* flat_set() - : iflat_set(buffer) + : iflat_set(lookup, storage) { } @@ -74,7 +75,7 @@ namespace etl /// Copy constructor. //************************************************************************* flat_set(const flat_set& other) - : iflat_set(buffer) + : iflat_set(lookup, storage) { iflat_set::assign(other.cbegin(), other.cend()); } @@ -87,11 +88,19 @@ namespace etl //************************************************************************* template flat_set(TIterator first, TIterator last) - : iflat_set(buffer) + : iflat_set(lookup, storage) { iflat_set::assign(first, last); } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~flat_set() + { + iflat_set::clear(); + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -107,7 +116,13 @@ namespace etl private: - etl::vector buffer; ///::value_type node_t; + + // The pool of nodes. + etl::pool storage; + + // The vector that stores pointers to the nodes. + etl::vector lookup; }; } diff --git a/src/iflat_map.h b/src/iflat_map.h index ded0c413..20dbed02 100644 --- a/src/iflat_map.h +++ b/src/iflat_map.h @@ -43,6 +43,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" #include "ivector.h" +#include "ipool.h" #include "error_handler.h" namespace etl @@ -61,22 +62,229 @@ namespace etl private: - typedef etl::ivector buffer_t; + typedef etl::ivector lookup_t; + typedef etl::ipool storage_t; public: - typedef TKey key_type; - typedef TMapped mapped_type; - typedef TKeyCompare key_compare; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef typename buffer_t::iterator iterator; - typedef typename buffer_t::const_iterator const_iterator; - typedef typename buffer_t::reverse_iterator reverse_iterator; - typedef typename buffer_t::const_reverse_iterator const_reverse_iterator; - typedef size_t size_type; + typedef TKey key_type; + typedef TMapped mapped_type; + typedef TKeyCompare key_compare; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + + //************************************************************************* + class iterator : public std::iterator + { + public: + + friend class iflat_map; + + iterator() + { + } + + iterator(typename lookup_t::iterator ilookup) + : ilookup(ilookup) + { + } + + iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + iterator& operator ++() + { + ++ilookup; + return *this; + } + + iterator operator ++(int) + { + iterator temp(*this); + ++ilookup; + return temp; + } + + iterator& operator --() + { + --ilookup; + return *this; + } + + iterator operator --(int) + { + iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return &(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const iterator& lhs, const iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const iterator& lhs, const iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::iterator ilookup; + }; + + //************************************************************************* + class const_iterator : public std::iterator + { + public: + + friend class iflat_map; + + const_iterator() + { + } + + const_iterator(typename lookup_t::const_iterator ilookup) + : ilookup(ilookup) + { + } + + const_iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator(const const_iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator =(const const_iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator ++() + { + ++ilookup; + return *this; + } + + const_iterator operator ++(int) + { + const_iterator temp(*this); + ++ilookup; + return temp; + } + + const_iterator& operator --() + { + --ilookup; + return *this; + } + + const_iterator operator --(int) + { + const_iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return etl::addressof(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::const_iterator ilookup; + }; + + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; typedef typename std::iterator_traits::difference_type difference_type; protected: @@ -111,7 +319,7 @@ namespace etl //********************************************************************* iterator begin() { - return buffer.begin(); + return iterator(lookup.begin()); } //********************************************************************* @@ -120,7 +328,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return buffer.begin(); + return const_iterator(lookup.begin()); } //********************************************************************* @@ -129,7 +337,7 @@ namespace etl //********************************************************************* iterator end() { - return buffer.end(); + return iterator(lookup.end()); } //********************************************************************* @@ -138,7 +346,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return buffer.end(); + return const_iterator(lookup.end()); } //********************************************************************* @@ -147,7 +355,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return buffer.cbegin(); + return const_iterator(lookup.cbegin()); } //********************************************************************* @@ -156,7 +364,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return buffer.cend(); + return const_iterator(lookup.cend()); } //********************************************************************* @@ -165,7 +373,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -174,7 +382,7 @@ namespace etl //********************************************************************* const_reverse_iterator rbegin() const { - return buffer.rbegin(); + return reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -183,7 +391,7 @@ namespace etl //********************************************************************* reverse_iterator rend() { - return buffer.rend(); + return reverse_iterator(lookup.rend()); } //********************************************************************* @@ -192,7 +400,7 @@ namespace etl //********************************************************************* const_reverse_iterator rend() const { - return buffer.rend(); + return const_reverse_iterator(lookup.rend()); } //********************************************************************* @@ -201,7 +409,7 @@ namespace etl //********************************************************************* const_reverse_iterator crbegin() const { - return buffer.crbegin(); + return const_reverse_iterator(lookup.crbegin()); } //********************************************************************* @@ -210,7 +418,7 @@ namespace etl //********************************************************************* const_reverse_iterator crend() const { - return buffer.crend(); + return const_reverse_iterator(lookup.crend()); } //********************************************************************* @@ -224,9 +432,9 @@ namespace etl if (i_element == end()) { - // Doesn't exist, so create a new one. - value_type value(key, mapped_type()); - i_element = insert(value).first; + std::pair result = insert_at(i_element, value_type(key, mapped_type())); + + i_element = result.first; } return i_element->second; @@ -255,7 +463,7 @@ namespace etl //********************************************************************* const mapped_type& at(key_value_parameter_t key) const { - typename buffer_t::const_iterator i_element = lower_bound(key); + typename const_iterator i_element = lower_bound(key); ETL_ASSERT(i_element != end(), ETL_ERROR(flat_map_out_of_bounds)); @@ -292,33 +500,9 @@ namespace etl //********************************************************************* std::pair insert(const value_type& value) { - std::pair result(end(), false); - iterator i_element = lower_bound(value.first); - if (i_element == end()) - { - // At the end. - ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_map_full)); - buffer.push_back(value); - result.first = end() - 1; - result.second = true; - } - else - { - // Not at the end. - // Existing element? - if (value.first != i_element->first) - { - // A new one. - ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_map_full)); - buffer.insert(i_element, value); - result.first = i_element; - result.second = true; - } - } - - return result; + return insert_at(i_element, value); } //********************************************************************* @@ -363,7 +547,10 @@ namespace etl } else { - buffer.erase(i_element); + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + lookup.erase(i_element.ilookup); + --construct_count; return 1; } } @@ -374,7 +561,10 @@ namespace etl //********************************************************************* void erase(iterator i_element) { - buffer.erase(i_element); + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + lookup.erase(i_element.ilookup); + --construct_count; } //********************************************************************* @@ -386,7 +576,17 @@ namespace etl //********************************************************************* void erase(iterator first, iterator last) { - buffer.erase(first, last); + iterator itr = first; + + while (itr != last) + { + itr->~value_type(); + storage.release(etl::addressof(*itr)); + ++itr; + --construct_count; + } + + lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* @@ -394,7 +594,7 @@ namespace etl //************************************************************************* void clear() { - buffer.clear(); + erase(begin(), end()); } //********************************************************************* @@ -538,7 +738,7 @@ namespace etl //************************************************************************* size_type size() const { - return buffer.size(); + return lookup.size(); } //************************************************************************* @@ -547,7 +747,7 @@ namespace etl //************************************************************************* bool empty() const { - return buffer.empty(); + return lookup.empty(); } //************************************************************************* @@ -556,7 +756,7 @@ namespace etl //************************************************************************* bool full() const { - return buffer.full(); + return lookup.full(); } //************************************************************************* @@ -565,7 +765,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return buffer.capacity(); + return lookup.capacity(); } //************************************************************************* @@ -574,7 +774,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return buffer.max_size(); + return lookup.max_size(); } //************************************************************************* @@ -583,7 +783,7 @@ namespace etl //************************************************************************* size_t available() const { - return buffer.available(); + return lookup.available(); } protected: @@ -591,17 +791,61 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iflat_map(buffer_t& buffer) - : buffer(buffer) + iflat_map(lookup_t& lookup_, storage_t& storage_) + : lookup(lookup_), + storage(storage_) { } private: + //********************************************************************* + /// Inserts a value to the flat_map. + ///\param i_element The place to insert. + ///\param value The value to insert. + //********************************************************************* + std::pair insert_at(iterator i_element, const value_type& value) + { + std::pair result(end(), false); + + if (i_element == end()) + { + // At the end. + ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full)); + + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.push_back(pvalue); + result.first = --end(); + result.second = true; + ++construct_count; + } + else + { + // Not at the end. + result.first = i_element; + + // Existing element? + if (value.first != i_element->first) + { + // A new one. + ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_map_full)); + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.insert(i_element.ilookup, pvalue); + result.second = true; + ++construct_count; + } + } + + return result; + } + // Disable copy construction. iflat_map(const iflat_map&); - buffer_t& buffer; + lookup_t& lookup; + storage_t& storage; }; //*************************************************************************** diff --git a/src/iflat_multimap.h b/src/iflat_multimap.h index 86728f0b..f16abda9 100644 --- a/src/iflat_multimap.h +++ b/src/iflat_multimap.h @@ -44,6 +44,7 @@ SOFTWARE. #include "parameter_type.h" #include "ivector.h" #include "error_handler.h" +#include "ipool.h" namespace etl { @@ -61,22 +62,229 @@ namespace etl private: - typedef etl::ivector buffer_t; + typedef etl::ivector lookup_t; + typedef etl::ipool storage_t; public: - typedef TKey key_type; - typedef TMapped mapped_type; - typedef TKeyCompare key_compare; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef typename buffer_t::iterator iterator; - typedef typename buffer_t::const_iterator const_iterator; - typedef typename buffer_t::reverse_iterator reverse_iterator; - typedef typename buffer_t::const_reverse_iterator const_reverse_iterator; - typedef size_t size_type; + typedef TKey key_type; + typedef TMapped mapped_type; + typedef TKeyCompare key_compare; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + + //************************************************************************* + class iterator : public std::iterator + { + public: + + friend class iflat_multimap; + + iterator() + { + } + + iterator(typename lookup_t::iterator ilookup) + : ilookup(ilookup) + { + } + + iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + iterator& operator ++() + { + ++ilookup; + return *this; + } + + iterator operator ++(int) + { + iterator temp(*this); + ++ilookup; + return temp; + } + + iterator& operator --() + { + --ilookup; + return *this; + } + + iterator operator --(int) + { + iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return &(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const iterator& lhs, const iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const iterator& lhs, const iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::iterator ilookup; + }; + + //************************************************************************* + class const_iterator : public std::iterator + { + public: + + friend class iflat_multimap; + + const_iterator() + { + } + + const_iterator(typename lookup_t::const_iterator ilookup) + : ilookup(ilookup) + { + } + + const_iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator(const const_iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator =(const const_iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator ++() + { + ++ilookup; + return *this; + } + + const_iterator operator ++(int) + { + const_iterator temp(*this); + ++ilookup; + return temp; + } + + const_iterator& operator --() + { + --ilookup; + return *this; + } + + const_iterator operator --(int) + { + const_iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return etl::addressof(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::const_iterator ilookup; + }; + + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; typedef typename std::iterator_traits::difference_type difference_type; protected: @@ -111,7 +319,7 @@ namespace etl //********************************************************************* iterator begin() { - return buffer.begin(); + return iterator(lookup.begin()); } //********************************************************************* @@ -120,7 +328,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return buffer.begin(); + return const_iterator(lookup.begin()); } //********************************************************************* @@ -129,7 +337,7 @@ namespace etl //********************************************************************* iterator end() { - return buffer.end(); + return iterator(lookup.end()); } //********************************************************************* @@ -138,7 +346,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return buffer.end(); + return const_iterator(lookup.end()); } //********************************************************************* @@ -147,7 +355,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return buffer.cbegin(); + return const_iterator(lookup.cbegin()); } //********************************************************************* @@ -156,7 +364,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return buffer.cend(); + return const_iterator(lookup.cend()); } //********************************************************************* @@ -165,7 +373,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -174,7 +382,7 @@ namespace etl //********************************************************************* const_reverse_iterator rbegin() const { - return buffer.rbegin(); + return const_reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -183,7 +391,7 @@ namespace etl //********************************************************************* reverse_iterator rend() { - return buffer.rend(); + return reverse_iterator(lookup.rend()); } //********************************************************************* @@ -192,7 +400,7 @@ namespace etl //********************************************************************* const_reverse_iterator rend() const { - return buffer.rend(); + return const_reverse_iterator(lookup.rend()); } //********************************************************************* @@ -201,7 +409,7 @@ namespace etl //********************************************************************* const_reverse_iterator crbegin() const { - return buffer.crbegin(); + return const_reverse_iterator(lookup.crbegin()); } //********************************************************************* @@ -210,7 +418,7 @@ namespace etl //********************************************************************* const_reverse_iterator crend() const { - return buffer.crend(); + return const_reverse_iterator(lookup.crend()); } //********************************************************************* @@ -243,28 +451,13 @@ namespace etl //********************************************************************* std::pair insert(const value_type& value) { - ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_multimap_full)); + ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_multimap_full)); - std::pair result(end(), false); +std::pair result(end(), false); iterator i_element = lower_bound(value.first); - if (i_element == end()) - { - // At the end. - buffer.push_back(value); - result.first = end() - 1; - result.second = true; - } - else - { - // Not at the end. - buffer.insert(i_element, value); - result.first = i_element; - result.second = true; - } - - return result; + return insert_at(i_element, value); } //********************************************************************* @@ -301,7 +494,7 @@ namespace etl //********************************************************************* size_t erase(key_value_parameter_t key) { - std::pair range = equal_range(key); + std::pair range = equal_range(key); if (range.first == end()) { @@ -309,8 +502,8 @@ namespace etl } else { - size_t count = std::distance(range.first, range.second); - erase(range.first, range.second); + size_t count = std::distance(range.first, range.second); + erase(range.first, range.second); return count; } } @@ -321,7 +514,10 @@ namespace etl //********************************************************************* void erase(iterator i_element) { - buffer.erase(i_element); + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + lookup.erase(i_element.ilookup); + --construct_count; } //********************************************************************* @@ -333,7 +529,17 @@ namespace etl //********************************************************************* void erase(iterator first, iterator last) { - buffer.erase(first, last); + iterator itr = first; + + while (itr != last) + { + itr->~value_type(); + storage.release(etl::addressof(*itr)); + ++itr; + --construct_count; + } + + lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* @@ -341,7 +547,7 @@ namespace etl //************************************************************************* void clear() { - buffer.clear(); + erase(begin(), end()); } //********************************************************************* @@ -487,7 +693,7 @@ namespace etl //************************************************************************* size_type size() const { - return buffer.size(); + return lookup.size(); } //************************************************************************* @@ -496,7 +702,7 @@ namespace etl //************************************************************************* bool empty() const { - return buffer.empty(); + return lookup.empty(); } //************************************************************************* @@ -505,7 +711,7 @@ namespace etl //************************************************************************* bool full() const { - return buffer.full(); + return lookup.full(); } //************************************************************************* @@ -514,7 +720,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return buffer.capacity(); + return lookup.capacity(); } //************************************************************************* @@ -523,7 +729,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return buffer.max_size(); + return lookup.max_size(); } //************************************************************************* @@ -532,7 +738,7 @@ namespace etl //************************************************************************* size_t available() const { - return buffer.available(); + return lookup.available(); } protected: @@ -540,17 +746,52 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iflat_multimap(buffer_t& buffer) - : buffer(buffer) + iflat_multimap(lookup_t& lookup_, storage_t& storage_) + : lookup(lookup_), + storage(storage_) { } private: + //********************************************************************* + /// Inserts a value to the flat_multimap. + ///\param i_element The place to insert. + ///\param value The value to insert. + //********************************************************************* + std::pair insert_at(iterator i_element, const value_type& value) + { + std::pair result(end(), false); + + if (i_element == end()) + { + // At the end. + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.push_back(pvalue); + result.first = --end(); + result.second = true; + } + else + { + // Not at the end. + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.insert(i_element.ilookup, pvalue); + result.first = i_element; + result.second = true; + } + + ++construct_count; + + return result; + } + // Disable copy construction. iflat_multimap(const iflat_multimap&); - buffer_t& buffer; + lookup_t& lookup; + storage_t& storage; }; //*************************************************************************** diff --git a/src/iflat_multiset.h b/src/iflat_multiset.h index 4a40ba7a..541e723a 100644 --- a/src/iflat_multiset.h +++ b/src/iflat_multiset.h @@ -44,6 +44,7 @@ SOFTWARE. #include "parameter_type.h" #include "ivector.h" #include "error_handler.h" +#include "ipool.h" namespace etl { @@ -55,26 +56,237 @@ namespace etl template > class iflat_multiset : public flat_multiset_base { + public: + + typedef T key_type; + typedef T value_type; + private: - typedef etl::ivector buffer_t; + typedef etl::ivector lookup_t; + typedef etl::ipool storage_t; public: - typedef T key_type; - typedef T value_type; - typedef TKeyCompare key_compare; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef typename buffer_t::iterator iterator; - typedef typename buffer_t::const_iterator const_iterator; - typedef typename buffer_t::reverse_iterator reverse_iterator; - typedef typename buffer_t::const_reverse_iterator const_reverse_iterator; - typedef size_t size_type; + typedef TKeyCompare key_compare; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + + //************************************************************************* + class iterator : public std::iterator + { + public: + + friend class iflat_multiset; + + iterator() + { + } + + iterator(typename lookup_t::iterator ilookup) + : ilookup(ilookup) + { + } + + iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + iterator& operator ++() + { + ++ilookup; + return *this; + } + + iterator operator ++(int) + { + iterator temp(*this); + ++ilookup; + return temp; + } + + iterator& operator --() + { + --ilookup; + return *this; + } + + iterator operator --(int) + { + iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return &(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const iterator& lhs, const iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const iterator& lhs, const iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::iterator ilookup; + }; + + //************************************************************************* + class const_iterator : public std::iterator + { + public: + + friend class iflat_multiset; + + const_iterator() + { + } + + const_iterator(typename lookup_t::const_iterator ilookup) + : ilookup(ilookup) + { + } + + const_iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator(const const_iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator =(const const_iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator ++() + { + ++ilookup; + return *this; + } + + const_iterator operator ++(int) + { + const_iterator temp(*this); + ++ilookup; + return temp; + } + + const_iterator& operator --() + { + --ilookup; + return *this; + } + + const_iterator operator --(int) + { + const_iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return etl::addressof(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::const_iterator ilookup; + }; + + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; typedef typename std::iterator_traits::difference_type difference_type; + protected: typedef typename parameter_type::type parameter_t; @@ -87,7 +299,7 @@ namespace etl //********************************************************************* iterator begin() { - return buffer.begin(); + return iterator(lookup.begin()); } //********************************************************************* @@ -96,7 +308,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return buffer.begin(); + return const_iterator(lookup.begin()); } //********************************************************************* @@ -105,7 +317,7 @@ namespace etl //********************************************************************* iterator end() { - return buffer.end(); + return iterator(lookup.end()); } //********************************************************************* @@ -114,7 +326,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return buffer.end(); + return const_iterator(lookup.end()); } //********************************************************************* @@ -123,7 +335,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return buffer.cbegin(); + return const_iterator(lookup.cbegin()); } //********************************************************************* @@ -132,7 +344,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return buffer.cend(); + return const_iterator(lookup.cend()); } //********************************************************************* @@ -141,7 +353,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -150,7 +362,7 @@ namespace etl //********************************************************************* const_reverse_iterator rbegin() const { - return buffer.rbegin(); + return const_reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -159,7 +371,7 @@ namespace etl //********************************************************************* reverse_iterator rend() { - return buffer.rend(); + return reverse_iterator(lookup.rend()); } //********************************************************************* @@ -168,7 +380,7 @@ namespace etl //********************************************************************* const_reverse_iterator rend() const { - return buffer.rend(); + return const_reverse_iterator(lookup.rend()); } //********************************************************************* @@ -177,7 +389,7 @@ namespace etl //********************************************************************* const_reverse_iterator crbegin() const { - return buffer.crbegin(); + return const_reverse_iterator(lookup.crbegin()); } //********************************************************************* @@ -186,7 +398,7 @@ namespace etl //********************************************************************* const_reverse_iterator crend() const { - return buffer.crend(); + return const_reverse_iterator(lookup.crend()); } //********************************************************************* @@ -221,25 +433,31 @@ namespace etl { std::pair result(end(), false); - ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_multiset_full)); + ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_multiset_full)); iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare()); if (i_element == end()) { // At the end. - buffer.push_back(value); - result.first = end() - 1; + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.push_back(pvalue); + result.first = --end(); result.second = true; } else { // Not at the end. - buffer.insert(i_element, value); + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.insert(i_element.ilookup, pvalue); result.first = i_element; result.second = true; } - + + ++construct_count; + return result; } @@ -277,7 +495,7 @@ namespace etl //********************************************************************* size_t erase(parameter_t key) { - std::pair range = equal_range(key); + std::pair range = equal_range(key); if (range.first == end()) { @@ -285,9 +503,9 @@ namespace etl } else { - size_t count = std::distance(range.first, range.second); - erase(range.first, range.second); - return count; + size_t count = std::distance(range.first, range.second); + erase(range.first, range.second); + return count; } } @@ -297,7 +515,10 @@ namespace etl //********************************************************************* void erase(iterator i_element) { - buffer.erase(i_element); + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + lookup.erase(i_element.ilookup); + --construct_count; } //********************************************************************* @@ -309,7 +530,17 @@ namespace etl //********************************************************************* void erase(iterator first, iterator last) { - buffer.erase(first, last); + iterator itr = first; + + while (itr != last) + { + itr->~value_type(); + storage.release(etl::addressof(*itr)); + ++itr; + --construct_count; + } + + lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* @@ -317,7 +548,7 @@ namespace etl //************************************************************************* void clear() { - buffer.clear(); + erase(begin(), end()); } //********************************************************************* @@ -377,7 +608,7 @@ namespace etl { std::pair range = equal_range(key); - return std::distance(range.first, range.second); + return std::distance(range.first, range.second); } //********************************************************************* @@ -459,7 +690,7 @@ namespace etl //************************************************************************* size_type size() const { - return buffer.size(); + return lookup.size(); } //************************************************************************* @@ -468,7 +699,7 @@ namespace etl //************************************************************************* bool empty() const { - return buffer.empty(); + return lookup.empty(); } //************************************************************************* @@ -477,7 +708,7 @@ namespace etl //************************************************************************* bool full() const { - return buffer.full(); + return lookup.full(); } //************************************************************************* @@ -486,7 +717,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return buffer.capacity(); + return lookup.capacity(); } //************************************************************************* @@ -495,7 +726,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return buffer.max_size(); + return lookup.max_size(); } //************************************************************************* @@ -504,7 +735,7 @@ namespace etl //************************************************************************* size_t available() const { - return buffer.available(); + return lookup.available(); } protected: @@ -512,8 +743,9 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iflat_multiset(buffer_t& buffer) - : buffer(buffer) + iflat_multiset(lookup_t& lookup_, storage_t& storage_) + : lookup(lookup_), + storage(storage_) { } @@ -522,7 +754,8 @@ namespace etl // Disable copy construction. iflat_multiset(const iflat_multiset&); - buffer_t& buffer; + lookup_t& lookup; + storage_t& storage; }; //*************************************************************************** diff --git a/src/iflat_set.h b/src/iflat_set.h index e692e143..c5cbaf78 100644 --- a/src/iflat_set.h +++ b/src/iflat_set.h @@ -43,6 +43,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" #include "ivector.h" +#include "ipool.h" #include "error_handler.h" namespace etl @@ -55,25 +56,230 @@ namespace etl template > class iflat_set : public flat_set_base { + public: + + typedef T key_type; + typedef T value_type; + typedef TKeyCompare key_compare; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef size_t size_type; + private: - typedef etl::ivector buffer_t; + typedef etl::ivector lookup_t; + typedef etl::ipool storage_t; public: - typedef T key_type; - typedef T value_type; - typedef TKeyCompare key_compare; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef typename buffer_t::iterator iterator; - typedef typename buffer_t::const_iterator const_iterator; - typedef typename buffer_t::reverse_iterator reverse_iterator; - typedef typename buffer_t::const_reverse_iterator const_reverse_iterator; - typedef size_t size_type; - typedef typename std::iterator_traits::difference_type difference_type; + //************************************************************************* + class iterator : public std::iterator + { + public: + + friend class iflat_set; + + iterator() + { + } + + iterator(typename lookup_t::iterator ilookup) + : ilookup(ilookup) + { + } + + iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + iterator& operator ++() + { + ++ilookup; + return *this; + } + + iterator operator ++(int) + { + iterator temp(*this); + ++ilookup; + return temp; + } + + iterator& operator --() + { + --ilookup; + return *this; + } + + iterator operator --(int) + { + iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return &(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const iterator& lhs, const iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const iterator& lhs, const iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::iterator ilookup; + }; + + //************************************************************************* + class const_iterator : public std::iterator + { + public: + + friend class iflat_set; + + const_iterator() + { + } + + const_iterator(typename lookup_t::const_iterator ilookup) + : ilookup(ilookup) + { + } + + const_iterator(const iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator(const const_iterator& other) + : ilookup(other.ilookup) + { + } + + const_iterator& operator =(const iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator =(const const_iterator& other) + { + ilookup = other.ilookup; + return *this; + } + + const_iterator& operator ++() + { + ++ilookup; + return *this; + } + + const_iterator operator ++(int) + { + const_iterator temp(*this); + ++ilookup; + return temp; + } + + const_iterator& operator --() + { + --ilookup; + return *this; + } + + const_iterator operator --(int) + { + const_iterator temp(*this); + --ilookup; + return temp; + } + + reference operator *() + { + return *(*ilookup); + } + + const_reference operator *() const + { + return *(*ilookup); + } + + pointer operator &() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator &() const + { + return etl::addressof(*(*ilookup)); + } + + pointer operator ->() + { + return etl::addressof(*(*ilookup)); + } + + const_pointer operator ->() const + { + return etl::addressof(*(*ilookup)); + } + + friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) + { + return lhs.ilookup == rhs.ilookup; + } + + friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typename lookup_t::const_iterator ilookup; + }; protected: @@ -81,13 +287,17 @@ namespace etl public: + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef typename std::iterator_traits::difference_type difference_type; + //********************************************************************* /// Returns an iterator to the beginning of the flat_set. ///\return An iterator to the beginning of the flat_set. //********************************************************************* iterator begin() { - return buffer.begin(); + return iterator(lookup.begin()); } //********************************************************************* @@ -96,7 +306,7 @@ namespace etl //********************************************************************* const_iterator begin() const { - return buffer.begin(); + return const_iterator(lookup.begin()); } //********************************************************************* @@ -105,7 +315,7 @@ namespace etl //********************************************************************* iterator end() { - return buffer.end(); + return iterator(lookup.end()); } //********************************************************************* @@ -114,7 +324,7 @@ namespace etl //********************************************************************* const_iterator end() const { - return buffer.end(); + return const_iterator(lookup.end()); } //********************************************************************* @@ -123,7 +333,7 @@ namespace etl //********************************************************************* const_iterator cbegin() const { - return buffer.cbegin(); + return const_iterator(lookup.cbegin()); } //********************************************************************* @@ -132,7 +342,7 @@ namespace etl //********************************************************************* const_iterator cend() const { - return buffer.cend(); + return const_iterator(lookup.cend()); } //********************************************************************* @@ -141,7 +351,7 @@ namespace etl //********************************************************************* reverse_iterator rbegin() { - return buffer.rbegin(); + return reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -150,7 +360,7 @@ namespace etl //********************************************************************* const_reverse_iterator rbegin() const { - return buffer.rbegin(); + return const_reverse_iterator(lookup.rbegin()); } //********************************************************************* @@ -159,7 +369,7 @@ namespace etl //********************************************************************* reverse_iterator rend() { - return buffer.rend(); + return reverse_iterator(lookup.rend()); } //********************************************************************* @@ -168,7 +378,7 @@ namespace etl //********************************************************************* const_reverse_iterator rend() const { - return buffer.rend(); + return const_reverse_iterator(lookup.rend()); } //********************************************************************* @@ -177,7 +387,7 @@ namespace etl //********************************************************************* const_reverse_iterator crbegin() const { - return buffer.crbegin(); + return const_reverse_iterator(lookup.crbegin()); } //********************************************************************* @@ -186,7 +396,7 @@ namespace etl //********************************************************************* const_reverse_iterator crend() const { - return buffer.crend(); + return const_reverse_iterator(lookup.crend()); } //********************************************************************* @@ -221,16 +431,19 @@ namespace etl { std::pair result(end(), false); - ETL_ASSERT(!buffer.full(), ETL_ERROR(flat_set_full)); + ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_set_full)); iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare()); if (i_element == end()) { // At the end. Doesn't exist. - buffer.push_back(value); - result.first = end() - 1; + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.push_back(pvalue); + result.first = --end(); result.second = true; + ++construct_count; } else { @@ -238,9 +451,12 @@ namespace etl // Does not exist already? if (*i_element != value) { - buffer.insert(i_element, value); + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(value); + lookup.insert(i_element.ilookup, pvalue); result.first = i_element; result.second = true; + ++construct_count; } else { @@ -294,7 +510,10 @@ namespace etl } else { - buffer.erase(i_element); + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + lookup.erase(i_element.ilookup); + --construct_count; return 1; } } @@ -305,7 +524,10 @@ namespace etl //********************************************************************* void erase(iterator i_element) { - buffer.erase(i_element); + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + lookup.erase(i_element.ilookup); + --construct_count; } //********************************************************************* @@ -317,7 +539,17 @@ namespace etl //********************************************************************* void erase(iterator first, iterator last) { - buffer.erase(first, last); + iterator itr = first; + + while (itr != last) + { + itr->~value_type(); + storage.release(etl::addressof(*itr)); + ++itr; + --construct_count; + } + + lookup.erase(first.ilookup, last.ilookup);; } //************************************************************************* @@ -325,7 +557,7 @@ namespace etl //************************************************************************* void clear() { - buffer.clear(); + erase(begin(), end()); } //********************************************************************* @@ -465,7 +697,7 @@ namespace etl //************************************************************************* size_type size() const { - return buffer.size(); + return lookup.size(); } //************************************************************************* @@ -474,7 +706,7 @@ namespace etl //************************************************************************* bool empty() const { - return buffer.empty(); + return lookup.empty(); } //************************************************************************* @@ -483,7 +715,7 @@ namespace etl //************************************************************************* bool full() const { - return buffer.full(); + return lookup.full(); } //************************************************************************* @@ -492,7 +724,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return buffer.capacity(); + return lookup.capacity(); } //************************************************************************* @@ -501,7 +733,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return buffer.max_size(); + return lookup.max_size(); } //************************************************************************* @@ -510,7 +742,7 @@ namespace etl //************************************************************************* size_t available() const { - return buffer.available(); + return lookup.available(); } protected: @@ -518,8 +750,9 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - iflat_set(buffer_t& buffer) - : buffer(buffer) + iflat_set(lookup_t& lookup_, storage_t& storage) + : lookup(lookup_), + storage(storage) { } @@ -528,7 +761,8 @@ namespace etl // Disable copy construction. iflat_set(const iflat_set&); - buffer_t& buffer; + lookup_t& lookup; + storage_t& storage; }; //*************************************************************************** diff --git a/src/private/flat_map_base.h b/src/private/flat_map_base.h index eb237767..420ad2a9 100644 --- a/src/private/flat_map_base.h +++ b/src/private/flat_map_base.h @@ -40,6 +40,7 @@ SOFTWARE. #include "../exception.h" #include "../ivector.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "2" @@ -97,6 +98,10 @@ namespace etl public: typedef size_t size_type; + + protected: + + etl::debug_count construct_count; ///< Internal debugging. }; } diff --git a/src/private/flat_multimap_base.h b/src/private/flat_multimap_base.h index b9c0fc2b..3b65031c 100644 --- a/src/private/flat_multimap_base.h +++ b/src/private/flat_multimap_base.h @@ -40,6 +40,7 @@ SOFTWARE. #include "../exception.h" #include "../ivector.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "3" @@ -83,6 +84,10 @@ namespace etl public: typedef size_t size_type; + + protected: + + etl::debug_count construct_count; }; } diff --git a/src/private/flat_multiset_base.h b/src/private/flat_multiset_base.h index 3bcd337e..b2408b15 100644 --- a/src/private/flat_multiset_base.h +++ b/src/private/flat_multiset_base.h @@ -40,6 +40,7 @@ SOFTWARE. #include "../exception.h" #include "../ivector.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "4" @@ -86,6 +87,10 @@ namespace etl protected: + protected: + + etl::debug_count construct_count; + //************************************************************************* /// Constructor. //************************************************************************* diff --git a/src/private/flat_set_base.h b/src/private/flat_set_base.h index d494cfb4..33deaf5a 100644 --- a/src/private/flat_set_base.h +++ b/src/private/flat_set_base.h @@ -38,8 +38,8 @@ SOFTWARE. #include #include "../exception.h" -#include "../ivector.h" #include "../error_handler.h" +#include "../debug_count.h" #undef ETL_FILE #define ETL_FILE "5" @@ -97,6 +97,10 @@ namespace etl public: typedef size_t size_type; + + protected: + + etl::debug_count construct_count; }; } diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index 37d3444a..42ddb365 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -36,12 +36,30 @@ SOFTWARE. #include #include +#include + #include "data.h" #include "../src/flat_map.h" namespace { + static const size_t SIZE = 10; + + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef std::pair ElementDC; + typedef std::pair ElementNDC; + + typedef etl::flat_map DataDC; + typedef etl::flat_map DataNDC; + typedef etl::iflat_map IDataDC; + typedef etl::iflat_map IDataNDC; + + typedef std::map Compare_DataDC; + typedef std::map Compare_DataNDC; + //************************************************************************* template bool Check_Equal(T1 begin1, T1 end1, T2 begin2) @@ -60,23 +78,40 @@ namespace return true; } + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataDC::iterator& itr) + { + os << itr->first; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataDC::const_iterator& itr) + { + os << itr->first; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr) + { + os << itr->first; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr) + { + os << itr->first; + + return os; + } + SUITE(test_flat_map) { - static const size_t SIZE = 10; - - typedef TestDataDC DC; - typedef TestDataNDC NDC; - - typedef std::pair ElementDC; - typedef std::pair ElementNDC; - - typedef etl::flat_map DataDC; - typedef etl::flat_map DataNDC; - typedef etl::iflat_map IDataNDC; - - typedef std::map Compare_DataDC; - typedef std::map Compare_DataNDC; - NDC N0 = NDC("A"); NDC N1 = NDC("B"); NDC N2 = NDC("C"); @@ -399,6 +434,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -407,16 +444,20 @@ namespace Compare_DataNDC compare_data; DataNDC data; - data.insert(DataNDC::value_type(0, N0)); + std::pair result; + + result = data.insert(std::make_pair(0, N0)); compare_data.insert(std::make_pair(0, N0)); bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); - + CHECK(isEqual); + CHECK(result.second); + CHECK(*result.first == std::make_pair(0, N0)); - data.insert(std::make_pair(2, N2)); + result = data.insert(std::make_pair(2, N2)); compare_data.insert(std::make_pair(2, N2)); isEqual = Check_Equal(data.begin(), @@ -424,8 +465,10 @@ namespace compare_data.begin()); CHECK(isEqual); + CHECK(result.second); + CHECK(*result.first == std::make_pair(2, N2)); - data.insert(std::make_pair(1, N1)); + result = data.insert(std::make_pair(1, N1)); compare_data.insert(std::make_pair(1, N1)); isEqual = Check_Equal(data.begin(), @@ -433,6 +476,10 @@ namespace compare_data.begin()); CHECK(isEqual); + CHECK(result.second); + CHECK(*result.first == std::make_pair(1, N1)); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -441,23 +488,30 @@ namespace Compare_DataNDC compare_data; DataNDC data; - data.insert(DataNDC::value_type(0, N0)); - compare_data.insert(std::make_pair(0, N0)); + std::pair result1; + std::pair result2; + + result1 = data.insert(DataNDC::value_type(0, N0)); + result2 = compare_data.insert(std::make_pair(0, N0)); bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); CHECK(isEqual); + CHECK(result1.second); + CHECK(*result1.first == std::make_pair(0, N0)); - data.insert(std::make_pair(0, N2)); - compare_data.insert(std::make_pair(0, N2)); + result1 = data.insert(std::make_pair(0, N2)); + result2 = compare_data.insert(std::make_pair(0, N2)); isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); CHECK(isEqual); + CHECK(!result1.second); + CHECK(*result1.first != std::make_pair(0, N2)); } //************************************************************************* diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index c0d6260a..339b80fd 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -42,67 +42,100 @@ SOFTWARE. namespace { - SUITE(test_flat_multimap) - { - static const size_t SIZE = 10; + static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; + typedef TestDataDC DC; + typedef TestDataNDC NDC; - typedef std::pair ElementDC; - typedef std::pair ElementNDC; + typedef std::pair ElementDC; + typedef std::pair ElementNDC; - typedef etl::flat_multimap DataDC; - typedef etl::flat_multimap DataNDC; - typedef etl::iflat_multimap IDataNDC; + typedef etl::flat_multimap DataDC; + typedef etl::flat_multimap DataNDC; + typedef etl::iflat_multimap IDataDC; + typedef etl::iflat_multimap IDataNDC; - typedef std::multimap Compare_DataDC; - typedef std::multimap Compare_DataNDC; + typedef std::multimap Compare_DataDC; + typedef std::multimap Compare_DataNDC; - NDC N0 = NDC("A"); - NDC N1 = NDC("B"); - NDC N2 = NDC("C"); - NDC N3 = NDC("D"); - NDC N4 = NDC("E"); - NDC N5 = NDC("F"); - NDC N6 = NDC("G"); - NDC N7 = NDC("H"); - NDC N8 = NDC("I"); - NDC N9 = NDC("J"); - NDC N10 = NDC("K"); - NDC N11 = NDC("L"); - NDC N12 = NDC("M"); - NDC N13 = NDC("N"); - NDC N14 = NDC("O"); - NDC N15 = NDC("P"); - NDC N16 = NDC("Q"); - NDC N17 = NDC("R"); - NDC N18 = NDC("S"); - NDC N19 = NDC("T"); + NDC N0 = NDC("A"); + NDC N1 = NDC("B"); + NDC N2 = NDC("C"); + NDC N3 = NDC("D"); + NDC N4 = NDC("E"); + NDC N5 = NDC("F"); + NDC N6 = NDC("G"); + NDC N7 = NDC("H"); + NDC N8 = NDC("I"); + NDC N9 = NDC("J"); + NDC N10 = NDC("K"); + NDC N11 = NDC("L"); + NDC N12 = NDC("M"); + NDC N13 = NDC("N"); + NDC N14 = NDC("O"); + NDC N15 = NDC("P"); + NDC N16 = NDC("Q"); + NDC N17 = NDC("R"); + NDC N18 = NDC("S"); + NDC N19 = NDC("T"); - std::vector initial_data; - std::vector excess_data; - std::vector different_data; + std::vector initial_data; + std::vector excess_data; + std::vector different_data; std::vector multi_data; - //************************************************************************* - template - bool Check_Equal(T1 begin1, T1 end1, T2 begin2) + //************************************************************************* + template + bool Check_Equal(T1 begin1, T1 end1, T2 begin2) + { + while (begin1 != end1) { - while (begin1 != end1) + if ((begin1->first != begin2->first) || (begin1->second != begin2->second)) { - if ((begin1->first != begin2->first) || (begin1->second != begin2->second)) - { - return false; - } - - ++begin1; - ++begin2; + return false; } - return true; + ++begin1; + ++begin2; } + return true; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataDC::iterator& itr) + { + os << itr->first; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataDC::const_iterator& itr) + { + os << itr->first; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr) + { + os << itr->first; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr) + { + os << itr->first; + + return os; + } + + SUITE(test_flat_multimap) + { //************************************************************************* struct SetupFixture { @@ -127,16 +160,16 @@ namespace ElementNDC(15, N15), ElementNDC(16, N16), ElementNDC(17, N17), ElementNDC(18, N18), ElementNDC(19, N19) }; - ElementNDC n4[] = - { - ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(1, N3), ElementNDC(3, N4), - ElementNDC(4, N5), ElementNDC(4, N6), ElementNDC(5, N7), ElementNDC(4, N8), ElementNDC(0, N9) - }; + ElementNDC n4[] = + { + ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(1, N3), ElementNDC(3, N4), + ElementNDC(4, N5), ElementNDC(4, N6), ElementNDC(5, N7), ElementNDC(4, N8), ElementNDC(0, N9) + }; initial_data.assign(std::begin(n), std::end(n)); excess_data.assign(std::begin(n2), std::end(n2)); different_data.assign(std::begin(n3), std::end(n3)); - multi_data.assign(std::begin(n4), std::end(n4)); + multi_data.assign(std::begin(n4), std::end(n4)); } }; @@ -263,6 +296,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -297,6 +332,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -331,6 +368,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -339,6 +378,8 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); CHECK_THROW(data.insert(std::make_pair(10, N10)), etl::flat_multimap_full); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -355,6 +396,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -363,6 +406,8 @@ namespace DataNDC data; CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::flat_multimap_full); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index 7d54bc6c..0e870cd0 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -42,49 +42,81 @@ SOFTWARE. namespace { + static const size_t SIZE = 10; + + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef etl::flat_multiset DataDC; + typedef etl::flat_multiset DataNDC; + typedef etl::iflat_multiset IDataNDC; + + typedef std::multiset Compare_DataDC; + typedef std::multiset Compare_DataNDC; + + NDC NX = NDC("@"); + NDC NY = NDC("["); + + NDC N0 = NDC("A"); + NDC N1 = NDC("B"); + NDC N2 = NDC("C"); + NDC N3 = NDC("D"); + NDC N4 = NDC("E"); + NDC N5 = NDC("F"); + NDC N6 = NDC("G"); + NDC N7 = NDC("H"); + NDC N8 = NDC("I"); + NDC N9 = NDC("J"); + NDC N10 = NDC("K"); + NDC N11 = NDC("L"); + NDC N12 = NDC("M"); + NDC N13 = NDC("N"); + NDC N14 = NDC("O"); + NDC N15 = NDC("P"); + NDC N16 = NDC("Q"); + NDC N17 = NDC("R"); + NDC N18 = NDC("S"); + NDC N19 = NDC("T"); + + std::vector initial_data; + std::vector excess_data; + std::vector different_data; + std::vector multi_data; + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataDC::iterator& itr) + { + os << itr->value; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataDC::const_iterator& itr) + { + os << itr->value; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr) + { + os << itr->value; + + return os; + } + + //************************************************************************* + std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr) + { + os << itr->value; + + return os; + } + SUITE(test_flat_multiset) { - static const size_t SIZE = 10; - - typedef TestDataDC DC; - typedef TestDataNDC NDC; - - typedef etl::flat_multiset DataDC; - typedef etl::flat_multiset DataNDC; - typedef etl::iflat_multiset IDataNDC; - - typedef std::multiset Compare_DataDC; - typedef std::multiset Compare_DataNDC; - - NDC NX = NDC("@"); - NDC NY = NDC("["); - - NDC N0 = NDC("A"); - NDC N1 = NDC("B"); - NDC N2 = NDC("C"); - NDC N3 = NDC("D"); - NDC N4 = NDC("E"); - NDC N5 = NDC("F"); - NDC N6 = NDC("G"); - NDC N7 = NDC("H"); - NDC N8 = NDC("I"); - NDC N9 = NDC("J"); - NDC N10 = NDC("K"); - NDC N11 = NDC("L"); - NDC N12 = NDC("M"); - NDC N13 = NDC("N"); - NDC N14 = NDC("O"); - NDC N15 = NDC("P"); - NDC N16 = NDC("Q"); - NDC N17 = NDC("R"); - NDC N18 = NDC("S"); - NDC N19 = NDC("T"); - - std::vector initial_data; - std::vector excess_data; - std::vector different_data; - std::vector multi_data; - //************************************************************************* struct SetupFixture { @@ -240,6 +272,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -274,6 +308,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -308,6 +344,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -316,6 +354,8 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); CHECK_THROW(data.insert(N10), etl::flat_multiset_full); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -332,6 +372,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -340,6 +382,8 @@ namespace DataNDC data; CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::flat_multiset_full); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index cab386c8..c770a1fa 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -40,50 +40,82 @@ SOFTWARE. #include "../src/flat_set.h" +static const size_t SIZE = 10; + +typedef TestDataDC DC; +typedef TestDataNDC NDC; + +typedef etl::flat_set DataDC; +typedef etl::flat_set DataNDC; +typedef etl::iflat_set IDataNDC; + +typedef std::set Compare_DataDC; +typedef std::set Compare_DataNDC; + +NDC NX = NDC("@"); +NDC NY = NDC("["); + +NDC N0 = NDC("A"); +NDC N1 = NDC("B"); +NDC N2 = NDC("C"); +NDC N3 = NDC("D"); +NDC N4 = NDC("E"); +NDC N5 = NDC("F"); +NDC N6 = NDC("G"); +NDC N7 = NDC("H"); +NDC N8 = NDC("I"); +NDC N9 = NDC("J"); +NDC N10 = NDC("K"); +NDC N11 = NDC("L"); +NDC N12 = NDC("M"); +NDC N13 = NDC("N"); +NDC N14 = NDC("O"); +NDC N15 = NDC("P"); +NDC N16 = NDC("Q"); +NDC N17 = NDC("R"); +NDC N18 = NDC("S"); +NDC N19 = NDC("T"); + +std::vector initial_data; +std::vector excess_data; +std::vector different_data; + +//************************************************************************* +std::ostream& operator <<(std::ostream& os, const DataDC::iterator& itr) +{ + os << itr->value; + + return os; +} + +//************************************************************************* +std::ostream& operator <<(std::ostream& os, const DataDC::const_iterator& itr) +{ + os << itr->value; + + return os; +} + +//************************************************************************* +std::ostream& operator <<(std::ostream& os, const DataNDC::iterator& itr) +{ + os << itr->value; + + return os; +} + +//************************************************************************* +std::ostream& operator <<(std::ostream& os, const DataNDC::const_iterator& itr) +{ + os << itr->value; + + return os; +} + namespace { SUITE(test_flat_set) { - static const size_t SIZE = 10; - - typedef TestDataDC DC; - typedef TestDataNDC NDC; - - typedef etl::flat_set DataDC; - typedef etl::flat_set DataNDC; - typedef etl::iflat_set IDataNDC; - - typedef std::set Compare_DataDC; - typedef std::set Compare_DataNDC; - - NDC NX = NDC("@"); - NDC NY = NDC("["); - - NDC N0 = NDC("A"); - NDC N1 = NDC("B"); - NDC N2 = NDC("C"); - NDC N3 = NDC("D"); - NDC N4 = NDC("E"); - NDC N5 = NDC("F"); - NDC N6 = NDC("G"); - NDC N7 = NDC("H"); - NDC N8 = NDC("I"); - NDC N9 = NDC("J"); - NDC N10 = NDC("K"); - NDC N11 = NDC("L"); - NDC N12 = NDC("M"); - NDC N13 = NDC("N"); - NDC N14 = NDC("O"); - NDC N15 = NDC("P"); - NDC N16 = NDC("Q"); - NDC N17 = NDC("R"); - NDC N18 = NDC("S"); - NDC N19 = NDC("T"); - - std::vector initial_data; - std::vector excess_data; - std::vector different_data; - //************************************************************************* struct SetupFixture { @@ -233,6 +265,8 @@ namespace compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -245,8 +279,8 @@ namespace compare_data.insert(N0); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); @@ -254,19 +288,23 @@ namespace compare_data.insert(N2); isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); data.insert(N1); compare_data.insert(N1); + std::vector test(data.begin(), data.end()); + isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -295,6 +333,8 @@ namespace compare_data.insert(N2); CHECK_EQUAL(compare_data.size(), data.size()); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -303,6 +343,8 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); CHECK_THROW(data.insert(N10), etl::flat_set_full); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -315,10 +357,12 @@ namespace compare_data.insert(initial_data.begin(), initial_data.end()); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -327,6 +371,8 @@ namespace DataNDC data; CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::flat_set_full); + + CHECK(std::is_sorted(data.begin(), data.end())); } //************************************************************************* @@ -344,8 +390,8 @@ namespace CHECK_EQUAL(count_compare, count); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -366,8 +412,8 @@ namespace data.erase(i_data); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -394,8 +440,8 @@ namespace data.erase(i_data, i_data_end); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); } From 656184001962685a47c08ca91f288827f598e64f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Mar 2017 19:30:36 +0000 Subject: [PATCH 167/168] Completed additional ETL extension algorithms --- src/algorithm.h | 65 +---------------------------------------- test/test_algorithm.cpp | 63 ++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 88 deletions(-) diff --git a/src/algorithm.h b/src/algorithm.h index 7698dee4..eeaa88a5 100644 --- a/src/algorithm.h +++ b/src/algorithm.h @@ -820,68 +820,6 @@ namespace etl return o_begin; } - //*************************************************************************** - /// Like std::transform but applies a predicate before calling the function. - /// Returns when the first range end is reached. - ///\ingroup algorithm - //*************************************************************************** - template - TOutputIterator transform_if(TInputIterator i_begin, - const TInputIterator i_end, - TOutputIterator o_begin, - TOutputIterator o_end, - TUnaryFunction function, - TUnaryPredicate predicate) - { - while ((i_begin != i_end) && (o_begin != o_end)) - { - if (predicate(*i_begin)) - { - *o_begin++ = function(*i_begin); - } - - ++i_begin; - } - - return o_begin; - } - - //*************************************************************************** - /// Like etl::transform_if but inputs from two ranges. - /// Returns when the first range end is reached. - ///\ingroup algorithm - //*************************************************************************** - template - TOutputIterator transform_if(TInputIterator1 i_begin1, - const TInputIterator1 i_end1, - TInputIterator2 i_begin2, - const TInputIterator1 i_end2, - TOutputIterator o_begin, - const TInputIterator1 o_end, - TBinaryFunction function, - TBinaryPredicate predicate) - { - while ((i_begin1 != i_end1) && (i_begin2 != i_end2) && (o_begin != o_end)) - { - if (predicate(*i_begin1, *i_begin2)) - { - *o_begin++ = function(*i_begin1, *i_begin2); - } - - ++i_begin1; - ++i_begin2; - } - - return o_begin; - } - //*************************************************************************** /// Transforms the elements from the range (begin, end) to two different ranges /// depending on the value returned by the predicate.
@@ -912,10 +850,9 @@ namespace etl return std::pair(destination_true, destination_false); } -} //*************************************************************************** - /// Transforms the elements from the ranges (begin1, end1) & (begin2, end2) + /// Transforms the elements from the ranges (begin1, end1) & (begin2) /// to two different ranges depending on the value returned by the predicate. ///\ingroup algorithm //*************************************************************************** diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 7284731b..7b95a89d 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -580,34 +580,22 @@ namespace } //========================================================================= - TEST(transform_if_4_parameter) + TEST(transform_if_2_input_ranges) { - int input[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; - int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - int compare1[] = { 2, 4, 6, 8, 0, 0, 0, 0, 0, 0 }; - int compare2[] = { 2, 4, 6, 0, 0, 0, 0, 0, 0, 0 }; + int input1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int input2[] = { 8, 7, 6, 5, 4, 10, 9, 3, 2, 1 }; + int output[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare[] = { 8, 12, 12, 60, 36, 0, 0, 0, 0, 0 }; - // Double everything and copy to output. - etl::transform_if(std::begin(input), - std::end(input), + // Multiply together everything where input1 is less than input2 and copy to output. + etl::transform_if(std::begin(input1), + std::end(input1), + std::begin(input2), std::begin(output), - std::begin(output) + (etl::size(output) / 2), - std::bind2nd(std::multiplies(), 2), - std::bind2nd(std::less(), 5)); + std::multiplies(), + std::less()); - bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare1)); - CHECK(is_same); - - std::fill(std::begin(output), std::end(output), 0); - - etl::transform_if(std::begin(input), - std::begin(input) + (etl::size(input) / 2), - std::begin(output), - std::end(output), - std::bind2nd(std::multiplies(), 2), - std::bind2nd(std::less(), 5)); - - is_same = std::equal(std::begin(output), std::end(output), std::begin(compare2)); + bool is_same = std::equal(std::begin(output), std::end(output), std::begin(compare)); CHECK(is_same); } @@ -636,5 +624,32 @@ namespace is_same = std::equal(std::begin(output_false), std::end(output_false), std::begin(compare_false)); CHECK(is_same); } + + //========================================================================= + TEST(partition_transform_2_input_ranges) + { + int input1[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 }; + int input2[] = { 8, 7, 6, 5, 4, 10, 9, 3, 2, 1 }; + int output_true[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int output_false[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int compare_true[] = { 8, 12, 12, 60, 36, 0, 0, 0, 0, 0 }; + int compare_false[] = { 15, 12, 8, 12, 10, 0, 0, 0, 0, 0 }; + + // If input1 < input2 multiply else add. + etl::partition_transform(std::begin(input1), + std::end(input1), + std::begin(input2), + std::begin(output_true), + std::begin(output_false), + std::multiplies(), + std::plus(), + std::less()); + + bool is_same = std::equal(std::begin(output_true), std::end(output_true), std::begin(compare_true)); + CHECK(is_same); + + is_same = std::equal(std::begin(output_false), std::end(output_false), std::begin(compare_false)); + CHECK(is_same); + } }; } From fdc73603e1e577e31c081c7586124fd8de5321b5 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 6 Mar 2017 13:29:42 +0000 Subject: [PATCH 168/168] Updated version to 9.1.0 --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index fbd7fbf0..cfc24522 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=Embedded Template Library -version=9.0.0 +version=9.1.0 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. paragraph=Requires some support from STL. See http://andybrown.me.uk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/ category=Other url=http://www.etlcpp.com/ -architectures=* +architectures=*