From fb189e5a2522ff774a33ec82cbd616d23fc53c1c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 17 Jul 2015 13:00:25 +0100 Subject: [PATCH 01/14] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c7c1908..b2759607 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,18 @@ The library is intended for any compiler that supports C++ 03. **Main features:** + - Cross platform. This library is not specific to any processor type. - No dynamic memory allocation. - - A set of fixed capacity containers. (stack, queue, list, forward_list, vector, deque) + - Very little use of virtual functions. + - A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector) + - As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly - Templated compile time constants. - Templated design pattern base classes (Visitor, Observer) - Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.) - Smart enumerations - 8, 16, 32 & 64 bit CRC calculations + - Checksums & hash functions - Many utilities for template support. - Variants (a type that can store many types in a type-safe interface) - - Optional exceptions on errors. + - Choice of exceptions or error handler. From 14101031da17b0ac071be9aee56e280490107fbd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 17 Jul 2015 13:01:30 +0100 Subject: [PATCH 02/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b2759607..648d7510 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ The library is intended for any compiler that supports C++ 03. **Main features:** - Cross platform. This library is not specific to any processor type. - - No dynamic memory allocation. - - Very little use of virtual functions. + - No dynamic memory allocation. (No heap required) + - Very little use of virtual functions. (Keeps the vtable count low) - A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector) - As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly - Templated compile time constants. From 5505395eb6461a8ead42baa0e89de79b3dd4217a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 17 Jul 2015 13:01:57 +0100 Subject: [PATCH 03/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 648d7510..9d38c804 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The library is intended for any compiler that supports C++ 03. - Cross platform. This library is not specific to any processor type. - No dynamic memory allocation. (No heap required) - - Very little use of virtual functions. (Keeps the vtable count low) + - Very little use of virtual functions. (Keeps the vtable sizes low) - A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector) - As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly - Templated compile time constants. From 4fa6c72a1c7787ecbc471784c27050630b2765d5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 17 Jul 2015 13:03:28 +0100 Subject: [PATCH 04/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d38c804..422a91e3 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ The library is intended for any compiler that supports C++ 03. - No dynamic memory allocation. (No heap required) - Very little use of virtual functions. (Keeps the vtable sizes low) - A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector) - - As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly + - Cache friendlly containers, as the storage for each of the container types is allocated as a contiguous block - Templated compile time constants. - Templated design pattern base classes (Visitor, Observer) - Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.) From ad01ec664c991af0fcec8389362871aed85b449d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 17 Jul 2015 13:04:41 +0100 Subject: [PATCH 05/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 422a91e3..e4d5a010 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Embedded Template Library (ETL) **Motivation** -C++ is a great language to use for embedded applications and templates are a powerful aspect. The standard library can offer a great deal of well tested functionality, but there are some parts of the standard library that do not fit well with deterministic behaviour and limited resource requirements. These limitations usually preclude the use of dynamically allocated memory and open ended sized containers. +C++ is a great language to use for embedded applications and templates are a powerful aspect. The standard library can offer a great deal of well tested functionality, but there are some parts of the standard library that do not fit well with deterministic behaviour and limited resource requirements. These limitations usually preclude the use of dynamically allocated memory and containers with open ended sizes. What is needed is a template library where the user can declare the size, or maximum size of any object upfront. Most embedded compilers do not currently support the standard beyond C++ 03, therefore excluding the programmer from using the enhanced features of the later library. From 13c024bd9c8175899dd97265706a45c55dc54f2a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 13 Aug 2015 10:38:12 +0100 Subject: [PATCH 06/14] Changed 2nd exists2 to exists3 in exists() --- bloom_filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bloom_filter.h b/bloom_filter.h index b430f8a8..b25f075e 100644 --- a/bloom_filter.h +++ b/bloom_filter.h @@ -132,7 +132,7 @@ namespace etl // Do we have a third hash? if (!etl::is_same::value) { - exists2 = flags[get_hash(key)]; + exists3 = flags[get_hash(key)]; } return exists1 && exists2 && exists3; From 779e313e11a339205bb9e158b48436a793c9d1d7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 19 Aug 2015 14:36:18 +0100 Subject: [PATCH 07/14] Added raise_error free function that will either throw the error (if ETL_THROW_EXCEPTIONS is defined) or call error_handler::error. --- error_handler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/error_handler.h b/error_handler.h index 4fd697d5..e4050391 100644 --- a/error_handler.h +++ b/error_handler.h @@ -78,6 +78,21 @@ namespace etl static ifunction* p_ifunction; }; + + //*************************************************************************** + /// Raise an error. + /// If ETL_THROW_EXCEPTIONS is defined then the error is thrown, otherwise + /// the error handler is called. + ///\ingroup error_handler + //*************************************************************************** + inline void raise_error(const exception& e) + { +#ifdef ETL_THROW_EXCEPTIONS + throw e; +#else + error_handler::error(e); +#endif + } } #endif From 4d475bb086354dab0b644a1da4e5da2f1528982d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 13 Sep 2015 21:17:40 +0100 Subject: [PATCH 08/14] Fixed serious error where etl::vector would always allocate N^2 storage instead of N. --- vector.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vector.h b/vector.h index 4575fdeb..fd679dee 100644 --- a/vector.h +++ b/vector.h @@ -64,7 +64,7 @@ namespace etl /// Constructor. //************************************************************************* vector() - : ivector(reinterpret_cast(&buffer[0]), MAX_SIZE) + : ivector(reinterpret_cast(&buffer), MAX_SIZE) { } @@ -73,7 +73,7 @@ namespace etl ///\param initialSize The initial size of the vector. //************************************************************************* explicit vector(size_t initialSize) - : ivector(reinterpret_cast(&buffer[0]), MAX_SIZE) + : ivector(reinterpret_cast(&buffer), MAX_SIZE) { ivector::resize(initialSize); } @@ -84,7 +84,7 @@ namespace etl ///\param value The value to fill the vector with. //************************************************************************* vector(size_t initialSize, typename ivector::parameter_t value) - : ivector(reinterpret_cast(&buffer[0]), MAX_SIZE) + : ivector(reinterpret_cast(&buffer), MAX_SIZE) { ivector::resize(initialSize, value); } @@ -97,7 +97,7 @@ namespace etl //************************************************************************* template vector(TIterator first, TIterator last) - : ivector(reinterpret_cast(&buffer[0]), MAX_SIZE) + : ivector(reinterpret_cast(&buffer), MAX_SIZE) { ivector::assign(first, last); } @@ -117,7 +117,7 @@ namespace etl private: - typename etl::aligned_storage::value>::type buffer[MAX_SIZE]; + typename etl::aligned_storage::value>::type buffer; }; } From a283db52647988a2b8423c6c8024fb80d9e0a800 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 26 Sep 2015 09:45:43 +0100 Subject: [PATCH 09/14] Changed to use iterator_traits for difference type. --- algorithm.h | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/algorithm.h b/algorithm.h index 25770cca..2a455b15 100644 --- a/algorithm.h +++ b/algorithm.h @@ -65,7 +65,7 @@ namespace etl { maximum = begin; } - + ++begin; } @@ -83,14 +83,14 @@ namespace etl typedef typename std::iterator_traits::value_type value_t; return etl::minmax_element(begin, end, std::less()); - } - + } + //*************************************************************************** /// minmax ///\ingroup algorithm /// //*************************************************************************** - template + template std::pair minmax(const T& a, const T& b) { return (b < a) ? std::pair(b, a) : std::pair(a, b); @@ -101,7 +101,7 @@ namespace etl ///\ingroup algorithm /// //*************************************************************************** - template + template std::pair minmax(const T& a, const T& b, TCompare compare) { return compare(b, a) ? std::pair(b, a) : std::pair(a, b); @@ -115,17 +115,17 @@ namespace etl template TIterator is_sorted_until(TIterator begin, TIterator end) { - if (begin != end) + if (begin != end) { TIterator next = begin; - while (++next != end) + while (++next != end) { if (*next < *begin) { return next; } - + ++begin; } } @@ -139,19 +139,19 @@ namespace etl /// //*************************************************************************** template - TIterator is_sorted_until(TIterator begin, TIterator end, TCompare compare) + TIterator is_sorted_until(TIterator begin, TIterator end, TCompare compare) { - if (begin != end) + if (begin != end) { TIterator next = begin; - while (++next != end) + while (++next != end) { if (compare(*next, *begin)) { return next; } - + ++begin; } } @@ -214,7 +214,7 @@ namespace etl { *out++ = *begin; } - + ++begin; } @@ -274,7 +274,7 @@ namespace etl { return std::find_if(begin, end, predicate) == end; } - + //*************************************************************************** /// is_permutation ///\ingroup algorithm @@ -289,11 +289,11 @@ namespace etl std::advance(end2, std::distance(begin1, end1)); - for (TIterator1 i = begin1; i != end1; ++i) + for (TIterator1 i = begin1; i != end1; ++i) { if (i == std::find(begin1, i, *i)) { - size_t n = std::count(begin2, end2, *i); + std::iterator_traits::difference_type n = std::count(begin2, end2, *i); if (n == 0 || std::count(i, end1, *i) != n) { @@ -305,7 +305,7 @@ namespace etl return true; } - + //*************************************************************************** /// is_permutation ///\ingroup algorithm @@ -316,11 +316,11 @@ namespace etl { if (begin1 != end1) { - for (TIterator1 i = begin1; i != end1; ++i) + for (TIterator1 i = begin1; i != end1; ++i) { if (i == std::find(begin1, i, *i)) { - size_t n = std::count(begin2, end2, *i); + std::iterator_traits::difference_type n = std::count(begin2, end2, *i); if (n == 0 || std::count(i, end1, *i) != n) { @@ -331,7 +331,7 @@ namespace etl } return true; - } + } //*************************************************************************** /// is_permutation @@ -347,11 +347,11 @@ namespace etl std::advance(end2, std::distance(begin1, end1)); - for (TIterator1 i = begin1; i != end1; ++i) + for (TIterator1 i = begin1; i != end1; ++i) { if (i == std::find_if(begin1, i, std::bind1st(predicate, *i))) { - size_t n = std::count(begin2, end2, *i); + std::iterator_traits::difference_type n = std::count(begin2, end2, *i); if (n == 0 || std::count(i, end1, *i) != n) { @@ -374,11 +374,11 @@ namespace etl { if (begin1 != end1) { - for (TIterator1 i = begin1; i != end1; ++i) + for (TIterator1 i = begin1; i != end1; ++i) { if (i == std::find_if(begin1, i, std::bind1st(predicate, *i))) { - size_t n = std::count(begin2, end2, *i); + std::iterator_traits::difference_type n = std::count(begin2, end2, *i); if (n == 0 || std::count(i, end1, *i) != n) { @@ -414,7 +414,7 @@ namespace etl return false; } } - + return true; } @@ -447,9 +447,9 @@ namespace etl //*************************************************************************** template std::pair partition_copy(TSource begin, - TSource end, + TSource end, TDestinationTrue destination_true, - TDestinationFalse destination_false, + TDestinationFalse destination_false, TUnaryPredicate predicate) { while (begin != end) From 723962de231a91df196006a935b3e26b9b3bc3bd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Sep 2015 10:14:42 +0100 Subject: [PATCH 10/14] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e4d5a010..379a60bc 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,4 @@ The library is intended for any compiler that supports C++ 03. - Variants (a type that can store many types in a type-safe interface) - Choice of exceptions or error handler. +See (http://www.etlcpp.com) for up-to-date information. From f357a582e7b2c5d0f753408b0a89a884d0507ad8 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Tue, 6 Oct 2015 22:23:32 +0100 Subject: [PATCH 11/14] Enum type - fix doc to_string references --- enum_type.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/enum_type.h b/enum_type.h index d241a48d..b57ed2a5 100644 --- a/enum_type.h +++ b/enum_type.h @@ -69,15 +69,15 @@ SOFTWARE. /// /// direction = value; // **** Compilation error **** /// -/// std::cout << "Direction = " << direction.to_string(); // Prints "Direction = North" +/// 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 to_string() function will return a "?". This will also be the case for any +/// 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 member functions and the first section of the 'to_string' function. +// The declaration of the member functions and the first section of the 'c_str' function. //***************************************************************************** #define DECLARE_ENUM_TYPE(TypeName, ValueType) \ typedef ValueType value_type; \ @@ -95,14 +95,14 @@ SOFTWARE. { //***************************************************************************** -// A case in the 'to_string' function's switch statement. +// A case in the 'c_str' function's switch statement. //***************************************************************************** #define ENUM_TYPE(value, name) \ case value: \ return name; \ //***************************************************************************** -// The final section of the 'to_string' function and the value declaration. +// The final section of the 'c_str' function and the value declaration. //***************************************************************************** #define END_ENUM_TYPE \ default: \ From 0c1ba31fe877afc2ad05c5c729449d7ad3769b23 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 11 Dec 2015 09:06:58 +0000 Subject: [PATCH 12/14] Update README.md Modified main features --- README.md | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 379a60bc..9ed78ce6 100644 --- a/README.md +++ b/README.md @@ -25,19 +25,20 @@ The library is intended for any compiler that supports C++ 03. **Main features:** - - Cross platform. This library is not specific to any processor type. - - No dynamic memory allocation. (No heap required) - - Very little use of virtual functions. (Keeps the vtable sizes low) - - A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector) - - Cache friendlly containers, as the storage for each of the container types is allocated as a contiguous block - - Templated compile time constants. - - Templated design pattern base classes (Visitor, Observer) - - Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.) - - Smart enumerations - - 8, 16, 32 & 64 bit CRC calculations - - Checksums & hash functions - - Many utilities for template support. - - Variants (a type that can store many types in a type-safe interface) - - Choice of exceptions or error handler. +- No dynamic memory allocation +- No RTTI required +- Very little use of virtual functions. They are used only when they are absolutely necessary for the required functionality +- A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector, map, set, etc.) +- As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly +- Templated compile time constants +- Templated design pattern base classes (Visitor, Observer) +- Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.) +- Smart enumerations +- 8, 16, 32 & 64 bit CRC calculations +- Checksums & hash functions +- Variants (a type that can store many types in a type-safe interface) +- Choice of asserts, exceptions, error handler or no checks on errors +- Many utilities for template support. + See (http://www.etlcpp.com) for up-to-date information. From 43806c9a9cc1ca8c38a3e07f5313150b99a6bbdf Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 14 Jan 2016 17:34:08 +0000 Subject: [PATCH 13/14] Fixed missing copy constructor. --- test/test_vector.cpp | 11 +++++++++++ vector.h | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/test/test_vector.cpp b/test/test_vector.cpp index d5feb40a..cbe94355 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -139,6 +139,17 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor) + { + Data data(initial_data.begin(), initial_data.end()); + Data data2(data); + CHECK(data2 == data); + + data2[2] = -1; + CHECK(data2 != data); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { diff --git a/vector.h b/vector.h index 9043e874..77fdfb4c 100644 --- a/vector.h +++ b/vector.h @@ -103,6 +103,15 @@ namespace etl ivector::assign(first, last); } + //************************************************************************* + /// Copy constructor. + //************************************************************************* + vector(const vector& other) + : ivector(reinterpret_cast(&buffer), MAX_SIZE) + { + ivector::assign(other.begin(), other.end()); + } + //************************************************************************* /// Assignment operator. //************************************************************************* From 2906824184d40d69274916751758b3898bb53d3c Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 22 Jan 2016 11:10:22 +0000 Subject: [PATCH 14/14] Removed basic_intrusive_forward_list --- basic_intrusive_forward_list.h | 600 --------------------- basic_intrusive_forward_list_node.h | 51 -- test/codeblocks/ETL.cbp | 2 - test/test_basic_intrusive_forward_list.cpp | 591 -------------------- test/vs2015/etl.vcxproj | 3 - test/vs2015/etl.vcxproj.filters | 9 - 6 files changed, 1256 deletions(-) delete mode 100644 basic_intrusive_forward_list.h delete mode 100644 basic_intrusive_forward_list_node.h delete mode 100644 test/test_basic_intrusive_forward_list.cpp diff --git a/basic_intrusive_forward_list.h b/basic_intrusive_forward_list.h deleted file mode 100644 index 94d5b0d1..00000000 --- a/basic_intrusive_forward_list.h +++ /dev/null @@ -1,600 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2015 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -//***************************************************************************** -// This forward list is intended for internal library use. -// It may be used as a very low cost intrusive forward list. -// Elements in the list are accessed as basic_intrusive_forward_list_node. -// Code using this list will be required to cast to the real data type. -// etl::basic_intrusive_forward_list will throw no exceptions or errors. -//***************************************************************************** - -#ifndef __ETL_BASIC_INTRUSIVE_FORWARD_LIST__ -#define __ETL_BASIC_INTRUSIVE_FORWARD_LIST__ - -#include -#include - -#include "nullptr.h" -#include "type_traits.h" -#include "basic_intrusive_forward_list_node.h" -#include "error_handler.h" - -namespace etl -{ - //*************************************************************************** - /// Exception for the intrusive_forward_list. - ///\ingroup intrusive_forward_list - //*************************************************************************** - class basic_intrusive_forward_list_exception : public exception - { - public: - - basic_intrusive_forward_list_exception(string_type what, string_type file_name, numeric_type line_number) - : exception(what, file_name, line_number) - { - } - }; - - //*************************************************************************** - /// Empty exception for the intrusive_forward_list. - ///\ingroup intrusive_forward_list - //*************************************************************************** - class basic_intrusive_forward_list_empty : public basic_intrusive_forward_list_exception - { - public: - - basic_intrusive_forward_list_empty(string_type file_name, numeric_type line_number) - : basic_intrusive_forward_list_exception(ETL_ERROR_TEXT("basic_intrusive_forward_list:empty", ETL_FILE"A"), file_name, line_number) - { - } - }; - - //*************************************************************************** - /// An intrusive forward list. - ///\ingroup basic_intrusive_forward_list - //*************************************************************************** - class basic_intrusive_forward_list - { - public: - - // Node typedef. - typedef basic_intrusive_forward_list_node node_t; - - // STL style typedefs. - typedef node_t value_type; - typedef node_t* pointer; - typedef const node_t* const_pointer; - typedef node_t& reference; - typedef const node_t& const_reference; - typedef size_t size_type; - - public: - - //************************************************************************* - /// iterator. - //************************************************************************* - class iterator : public std::iterator - { - public: - - friend class basic_intrusive_forward_list; - - iterator() - : p_node(nullptr) - { - } - - iterator(node_t& node) - : p_node(&node) - { - } - - iterator(const iterator& other) - : p_node(other.p_node) - { - } - - iterator& operator ++() - { - p_node = p_node->bifln_next; - return *this; - } - - iterator operator ++(int) - { - iterator temp(*this); - p_node = p_node->bifln_next; - return temp; - } - - iterator operator =(const iterator& other) - { - p_node = other.p_node; - return *this; - } - - reference operator *() - { - return *p_node; - } - - const_reference operator *() const - { - return *p_node; - } - - pointer operator &() - { - return p_node; - } - - const_pointer operator &() const - { - return p_node; - } - - pointer operator ->() - { - return p_node; - } - - const_pointer operator ->() const - { - return p_node; - } - - friend bool operator == (const iterator& lhs, const iterator& rhs) - { - return lhs.p_node == rhs.p_node; - } - - friend bool operator != (const iterator& lhs, const iterator& rhs) - { - return !(lhs == rhs); - } - - template - T& ref_cast() - { - return static_cast(*p_node); - } - - template - const T& ref_cast() const - { - return static_cast(*p_node); - } - - private: - - node_t* p_node; - }; - - //************************************************************************* - /// const_iterator - //************************************************************************* - class const_iterator : public std::iterator - { - public: - - friend class basic_intrusive_forward_list; - - const_iterator() - : p_node(nullptr) - { - } - - const_iterator(node_t& node) - : p_node(&node) - { - } - - const_iterator(const node_t& node) - : p_node(&node) - { - } - - const_iterator(const basic_intrusive_forward_list::iterator& other) - : p_node(other.p_node) - { - } - - const_iterator(const const_iterator& other) - : p_node(other.p_node) - { - } - - const_iterator& operator ++() - { - p_node = p_node->bifln_next; - return *this; - } - - const_iterator operator ++(int) - { - const_iterator temp(*this); - p_node = p_node->bifln_next; - return temp; - } - - const_iterator operator =(const const_iterator& other) - { - p_node = other.p_node; - return *this; - } - - const_reference operator *() const - { - return *p_node; - } - - const_pointer operator &() const - { - return p_node; - } - - const_pointer operator ->() const - { - return p_node; - } - - friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) - { - return lhs.p_node == rhs.p_node; - } - - friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) - { - return !(lhs == rhs); - } - - template - const T& ref_cast() const - { - return static_cast(*p_node); - } - - private: - - const node_t* p_node; - }; - - typedef std::iterator_traits::difference_type difference_type; - - //************************************************************************* - /// Constructor. - //************************************************************************* - basic_intrusive_forward_list() - { - initialise(); - } - - //************************************************************************* - /// Constructor from range - //************************************************************************* - template - basic_intrusive_forward_list(TIterator first, TIterator last) - { - assign(first, last); - } - - //************************************************************************* - /// Gets the beginning of the basic_intrusive_forward_list. - //************************************************************************* - iterator begin() - { - return iterator(get_head()); - } - - //************************************************************************* - /// Gets the beginning of the basic_intrusive_forward_list. - //************************************************************************* - const_iterator begin() const - { - return const_iterator(get_head()); - } - - //************************************************************************* - /// Gets before the beginning of the basic_intrusive_forward_list. - //************************************************************************* - iterator before_begin() - { - return iterator(start_node); - } - - //************************************************************************* - /// Gets before the beginning of the basic_intrusive_forward_list. - //************************************************************************* - const_iterator before_begin() const - { - return const_iterator(start_node); - } - - //************************************************************************* - /// Gets the beginning of the basic_intrusive_forward_list. - //************************************************************************* - const_iterator cbegin() const - { - return const_iterator(get_head()); - } - - //************************************************************************* - /// Gets the end of the basic_intrusive_forward_list. - //************************************************************************* - iterator end() - { - return iterator(); - } - - //************************************************************************* - /// Gets the end of the basic_intrusive_forward_list. - //************************************************************************* - const_iterator end() const - { - return const_iterator(); - } - - //************************************************************************* - /// Gets the end of the basic_intrusive_forward_list. - //************************************************************************* - const_iterator cend() const - { - return const_iterator(); - } - - //************************************************************************* - /// Clears the basic_intrusive_forward_list. - //************************************************************************* - void clear() - { - initialise(); - } - - //************************************************************************* - /// Gets a reference to the first element. - //************************************************************************* - template - T& front() - { - return static_cast(get_head()); - } - - //************************************************************************* - /// Gets a const reference to the first element. - //************************************************************************* - template - const_reference front() const - { - return static_cast(get_head()); - } - - //************************************************************************* - /// Assigns a range of values to the basic_intrusive_forward_list. - //************************************************************************* - template - void assign(TIterator first, TIterator last) - { - initialise(); - - node_t* p_last_node = &start_node; - - // Add all of the elements. - while (first != last) - { - node_t& node = *first++; - join(p_last_node, &node); - join(&node, nullptr); - p_last_node = &node; - } - } - - //************************************************************************* - /// Pushes a value to the front of the basic_intrusive_forward_list. - //************************************************************************* - void push_front(node_t& value) - { - insert_node_after(start_node, value); - } - - //************************************************************************* - /// Removes a value from the front of the basic_intrusive_forward_list. - //************************************************************************* - void pop_front() - { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(!empty(), ETL_ERROR(basic_intrusive_forward_list_empty)); -#endif - remove_node_after(start_node); - } - - //************************************************************************* - /// Reverses the basic_intrusive_forward_list. - //************************************************************************* - void reverse() - { - if ((start_node.bifln_next == nullptr) || (start_node.bifln_next->bifln_next == nullptr)) - { - return; - } - - node_t* first = nullptr; // To keep first node - node_t* second = start_node.bifln_next; // To keep second node - node_t* track = start_node.bifln_next; // Track the list - - while (track != NULL) - { - track = track->bifln_next; // Track point to next node; - second->bifln_next = first; // Second node point to first - first = second; // Move first node to next - second = track; // Move second node to next - } - - join(&start_node, first); - } - - //************************************************************************* - /// Inserts a value to the basic_intrusive_forward_list after the specified position. - //************************************************************************* - iterator insert_after(iterator position, node_t& value) - { - insert_node_after(*position.p_node, value); - - return iterator(value); - } - - //************************************************************************* - /// Inserts a range of values to the basic_intrusive_forward_list after the specified position. - //************************************************************************* - template - void insert_after(iterator position, TIterator first, TIterator last) - { - while (first != last) - { - // Set up the next free node. - insert_node_after(*position.p_node, *first++); - ++position; - } - } - - //************************************************************************* - /// Erases the value at the specified position. - //************************************************************************* - iterator erase_after(iterator position) - { - iterator next(position); - ++next; - ++next; - - remove_node_after(*position.p_node); - - return next; - } - - //************************************************************************* - /// Erases a range of elements. - //************************************************************************* - iterator erase_after(iterator first, iterator last) - { - node_t* p_first = first.p_node; - node_t* p_last = last.p_node; - node_t* p_next = p_first->bifln_next; - - // Join the ends. - join(p_first, p_last); - - p_first = p_next; - - // Erase the ones in between. - while (p_first != p_last) - { - p_next = p_first->bifln_next; // Remember the next node. - p_first = p_next; // Move to the next node. - } - - return last; - } - - //************************************************************************* - /// Returns true if the list has no elements. - //************************************************************************* - bool empty() const - { - return start_node.bifln_next == nullptr; - } - - private: - - node_t start_node; ///< The node that acts as the basic_intrusive_forward_list start. - - //************************************************************************* - /// Join two nodes. - //************************************************************************* - void join(node_t* left, node_t* right) - { - left->bifln_next = right; - } - - //************************************************************************* - /// Insert a node. - //************************************************************************* - void insert_node_after(node_t& position, node_t& node) - { - // Connect to the basic_intrusive_forward_list. - join(&node, position.bifln_next); - join(&position, &node); - } - - //************************************************************************* - /// Remove a node. - //************************************************************************* - void remove_node_after(node_t& node) - { - // The node to erase. - node_t* p_node = node.bifln_next; - - if (p_node != nullptr) - { - // Disconnect the node from the basic_intrusive_forward_list. - join(&node, p_node->bifln_next); - } - } - - //************************************************************************* - /// Get the head node. - //************************************************************************* - node_t& get_head() - { - return *start_node.bifln_next; - } - - //************************************************************************* - /// Get the head node. - //************************************************************************* - const node_t& get_head() const - { - return *start_node.bifln_next; - } - - //************************************************************************* - /// Initialise the basic_intrusive_forward_list. - //************************************************************************* - void initialise() - { - start_node.bifln_next = nullptr; - } - - // Disabled. - basic_intrusive_forward_list(const basic_intrusive_forward_list& other); - basic_intrusive_forward_list& operator = (const basic_intrusive_forward_list& rhs); - }; -} - -#endif diff --git a/basic_intrusive_forward_list_node.h b/basic_intrusive_forward_list_node.h deleted file mode 100644 index a3728b40..00000000 --- a/basic_intrusive_forward_list_node.h +++ /dev/null @@ -1,51 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2015 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef __ETL_BASIC_INTRUSIVE_FORWARD_LIST_NODE__ -#define __ETL_BASIC_INTRUSIVE_FORWARD_LIST_NODE__ - -namespace etl -{ - //*************************************************************************** - /// The node element in the basic_intrusive_forward_list. - /// Derive intrusive node data elements from this. - //*************************************************************************** - struct basic_intrusive_forward_list_node - { - basic_intrusive_forward_list_node() - : bifln_next(nullptr) - { - } - - basic_intrusive_forward_list_node* bifln_next; - }; -} - -#endif diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index f22f7e44..acd558bb 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -127,8 +127,6 @@ - - diff --git a/test/test_basic_intrusive_forward_list.cpp b/test/test_basic_intrusive_forward_list.cpp deleted file mode 100644 index feb04f12..00000000 --- a/test/test_basic_intrusive_forward_list.cpp +++ /dev/null @@ -1,591 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -http://www.etlcpp.com - -Copyright(c) 2015 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include -#include "ExtraCheckMacros.h" - -#include "data.h" - -#include "../basic_intrusive_forward_list.h" - -#include -#include -#include -#include -#include -#include - -typedef TestDataDC ItemDC; -typedef TestDataNDC ItemNDC; - -namespace -{ - class ItemDCNode : public etl::basic_intrusive_forward_list_node - { - public: - - ItemDCNode(const std::string& text) - : data(text) - { - } - - ItemDC data; - }; - - class ItemNDCNode : public etl::basic_intrusive_forward_list_node - { - public: - - ItemNDCNode(const std::string& text) - : data(text) - { - } - - bool operator <(const ItemNDCNode& other) const - { - return data < other.data; - } - - ItemNDC 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; - } - - std::ostream& operator << (std::ostream& os, const ItemNDCNode& node) - { - os << node.data; - return os; - } - - struct CompareItemNDCNode - { - bool operator ()(const ItemNDCNode& lhs, const ItemNDCNode& rhs) const - { - return lhs.data < rhs.data; - } - }; - - struct EqualItemNDCNode - { - bool operator ()(const ItemNDCNode& lhs, const ItemNDCNode& rhs) const - { - return lhs.data == rhs.data; - } - }; -} - -namespace -{ - SUITE(test_forward_list) - { - typedef etl::basic_intrusive_forward_list DataDC; - typedef etl::basic_intrusive_forward_list DataNDC; - - typedef std::vector InitialDataNDC; - - InitialDataNDC unsorted_data; - InitialDataNDC sorted_data; - InitialDataNDC non_unique_data; - InitialDataNDC unique_data; - InitialDataNDC small_data; - - bool are_equal; - - //************************************************************************* - struct SetupFixture - { - SetupFixture() - { - unsorted_data = { ItemNDCNode("1"), ItemNDCNode("0"), ItemNDCNode("3"), ItemNDCNode("2"), ItemNDCNode("5"), ItemNDCNode("4"), ItemNDCNode("7"), ItemNDCNode("6"), ItemNDCNode("9"), ItemNDCNode("8") }; - sorted_data = { ItemNDCNode("0"), ItemNDCNode("1"), ItemNDCNode("2"), ItemNDCNode("3"), ItemNDCNode("4"), ItemNDCNode("5"), ItemNDCNode("6"), ItemNDCNode("7"), ItemNDCNode("8"), ItemNDCNode("9") }; - non_unique_data = { ItemNDCNode("0"), ItemNDCNode("0"), ItemNDCNode("1"), ItemNDCNode("1"), ItemNDCNode("2"), ItemNDCNode("3"), ItemNDCNode("3"), ItemNDCNode("3"), ItemNDCNode("4"), ItemNDCNode("5") }; - unique_data = { ItemNDCNode("0"), ItemNDCNode("1"), ItemNDCNode("2"), ItemNDCNode("3"), ItemNDCNode("4"), ItemNDCNode("5") }; - small_data = { ItemNDCNode("0"), ItemNDCNode("1"), ItemNDCNode("2"), ItemNDCNode("3"), ItemNDCNode("4"), ItemNDCNode("5") }; - } - }; - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_default_constructor) - { - DataNDC data; - DataNDC data1; - - CHECK(data.empty()); - CHECK(data1.empty()); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_range) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - - CHECK(!data.empty()); - } - - ////************************************************************************* - TEST_FIXTURE(SetupFixture, test_begin_end_empty) - { - DataNDC data; - - CHECK(data.begin() == data.end()); - } - - ////************************************************************************* - TEST_FIXTURE(SetupFixture, test_iterator) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - - InitialDataNDC::iterator isorted = sorted_data.begin(); - DataNDC::iterator idata = data.begin(); - - while (isorted != sorted_data.end()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *isorted; - CHECK(are_equal); - ++idata; - ++isorted; - } - } - - ////************************************************************************* - TEST_FIXTURE(SetupFixture, test_const_iterator) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - - InitialDataNDC::const_iterator isorted = sorted_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (isorted != sorted_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *isorted; - CHECK(are_equal); - ++idata; - ++isorted; - } - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_clear) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - data.clear(); - - CHECK(data.empty()); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_range) - { - DataNDC data; - - // Do it twice. We should only get one copy. - data.assign(sorted_data.begin(), sorted_data.end()); - data.assign(sorted_data.begin(), sorted_data.end()); - - InitialDataNDC::const_iterator isorted = sorted_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (isorted != sorted_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *isorted; - CHECK(are_equal); - ++idata; - ++isorted; - } - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_after_position_value) - { - ItemNDCNode INSERT_VALUE1 = ItemNDCNode("1"); - ItemNDCNode INSERT_VALUE2 = ItemNDCNode("2"); - - std::vector compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC data(sorted_data.begin(), sorted_data.end()); - - size_t offset = 2; - - DataNDC::iterator i_data = data.begin(); - std::advance(i_data, offset); - - std::vector::iterator i_compare_data = compare_data.begin(); - std::advance(i_compare_data, offset + 1); - - data.insert_after(i_data, INSERT_VALUE1); - compare_data.insert(i_compare_data, INSERT_VALUE1); - - InitialDataNDC::const_iterator icompare = compare_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_after_range) - { - std::vector test1 = { ItemNDCNode("0"), ItemNDCNode("1"), ItemNDCNode("2"), ItemNDCNode("3"), ItemNDCNode("4") }; - std::vector test2 = { ItemNDCNode("5"), ItemNDCNode("6"), ItemNDCNode("7"), ItemNDCNode("8"), ItemNDCNode("9") }; - std::vector compare(test2); - compare.insert(compare.end(), test1.begin(), test1.end()); - - size_t final_size = test1.size() + test2.size(); - - DataNDC data(test1.begin(), test1.end()); - - data.insert_after(data.before_begin(), test2.begin(), test2.end()); - - InitialDataNDC::const_iterator icompare = compare.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (icompare != compare.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(final_size, std::distance(data.begin(), data.end())); - - compare.assign(test1.begin(), test1.end()); - data.assign(test1.begin(), test1.end()); - - std::vector::iterator icd = compare.begin(); - DataNDC::iterator id = data.begin(); - - std::advance(icd, 4); - std::advance(id, 3); - - compare.insert(icd, test2.begin(), test2.end()); - data.insert_after(id, test2.begin(), test2.end()); - - icompare = compare.cbegin(); - idata = data.cbegin(); - - while (icompare != compare.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(final_size, std::distance(data.begin(), data.end())); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_push_front) - { - std::list compare_data; - DataNDC data; - - ItemNDCNode node1("1"); - ItemNDCNode node2("2"); - ItemNDCNode node3("3"); - ItemNDCNode node4("4"); - 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); - - data.push_front(node1); - data.push_front(node2); - data.push_front(node3); - data.push_front(node4); - data.push_front(node5); - data.push_front(node6); - - std::list::const_iterator icompare = compare_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - CHECK_EQUAL(6, std::distance(data.begin(), data.end())); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_push_front_pop_front) - { - DataNDC data; - - ItemNDCNode node1("1"); - ItemNDCNode node2("2"); - ItemNDCNode node3("3"); - ItemNDCNode node4("4"); - ItemNDCNode node5("5"); - ItemNDCNode node6("6"); - - data.push_front(node1); - data.push_front(node2); - data.push_front(node3); - data.push_front(node4); - data.push_front(node5); - data.push_front(node6); - - CHECK_EQUAL(6, std::distance(data.begin(), data.end())); - CHECK(!data.empty()); - - data.pop_front(); - data.pop_front(); - data.pop_front(); - data.pop_front(); - data.pop_front(); - - CHECK_EQUAL(1, std::distance(data.begin(), data.end())); - CHECK(!data.empty()); - - data.pop_front(); - - CHECK_EQUAL(0, std::distance(data.begin(), data.end())); - CHECK(data.empty()); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_after_single) - { - std::vector compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC data(sorted_data.begin(), sorted_data.end()); - - DataNDC::iterator i_data = data.begin(); - std::advance(i_data, 2); - - std::vector::iterator i_compare_data = compare_data.begin(); - std::advance(i_compare_data, 3); - - i_compare_data = compare_data.erase(i_compare_data); - i_data = data.erase_after(i_data); - - std::vector::const_iterator icompare = compare_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK(*i_compare_data == i_data.ref_cast()); - - i_compare_data = compare_data.erase(compare_data.begin() + 1); - i_data = data.erase_after(data.begin()); - - icompare = compare_data.cbegin(); - idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); - - // Move to the last value and erase. - i_compare_data = compare_data.begin() + 1; - i_compare_data = compare_data.erase(i_compare_data); - - i_data = data.begin(); - i_data = data.erase_after(i_data); - - icompare = compare_data.cbegin(); - idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_after_range) - { - std::vector compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC data(sorted_data.begin(), sorted_data.end()); - - DataNDC::iterator i_data_1 = data.begin(); - std::advance(i_data_1, 2); - - DataNDC::iterator i_data_2 = data.begin(); - std::advance(i_data_2, 5); - - std::vector::iterator i_compare_data_1 = compare_data.begin(); - std::advance(i_compare_data_1, 3); - - std::vector::iterator i_compare_data_2 = compare_data.begin(); - std::advance(i_compare_data_2, 5); - - std::vector::iterator i_compare_result = compare_data.erase(i_compare_data_1, i_compare_data_2); - - DataNDC::iterator i_result = data.erase_after(i_data_1, i_data_2); - - CHECK_EQUAL(*i_compare_result, i_result.ref_cast()); - - std::vector::const_iterator icompare = compare_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_after_range_end) - { - std::vector compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC data(sorted_data.begin(), sorted_data.end()); - - DataNDC::iterator i_data = data.begin(); - std::advance(i_data, 4); - - std::vector::iterator i_compare_data = compare_data.begin(); - std::advance(i_compare_data, 5); - - std::vector::iterator i_compare_result = compare_data.erase(i_compare_data, compare_data.end()); - - DataNDC::iterator i_result = data.erase_after(i_data, data.end()); - - CHECK(i_result == data.end()); - - std::vector::const_iterator icompare = compare_data.cbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); - - icompare = compare_data.cbegin(); - idata = data.cbegin(); - - while (icompare != compare_data.cend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *icompare; - CHECK(are_equal); - ++idata; - ++icompare; - } - - CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_after_all) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - - data.erase_after(data.before_begin(), data.end()); - - CHECK(data.empty()); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_front) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - - CHECK_EQUAL(sorted_data.front(), data.front()); - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_reverse) - { - DataNDC data(sorted_data.begin(), sorted_data.end()); - data.reverse(); - - InitialDataNDC::const_reverse_iterator isorted = sorted_data.crbegin(); - DataNDC::const_iterator idata = data.cbegin(); - - while (isorted != sorted_data.crend()) - { - const ItemNDCNode& item = idata.ref_cast(); - are_equal = item == *isorted; - CHECK(are_equal); - ++idata; - ++isorted; - } - } - }; -} diff --git a/test/vs2015/etl.vcxproj b/test/vs2015/etl.vcxproj index f798f135..05227085 100644 --- a/test/vs2015/etl.vcxproj +++ b/test/vs2015/etl.vcxproj @@ -157,8 +157,6 @@ - - @@ -307,7 +305,6 @@ ../../../unittest-cpp false - diff --git a/test/vs2015/etl.vcxproj.filters b/test/vs2015/etl.vcxproj.filters index bb93b7ec..d1fd4d1b 100644 --- a/test/vs2015/etl.vcxproj.filters +++ b/test/vs2015/etl.vcxproj.filters @@ -393,12 +393,6 @@ ETL\Containers - - ETL\Containers - - - ETL\Containers - ETL\Private @@ -713,9 +707,6 @@ Source Files - - Source Files - Source Files