diff --git a/src/basic_string.h b/src/basic_string.h index 0cb56f2c..36045b0a 100644 --- a/src/basic_string.h +++ b/src/basic_string.h @@ -1890,6 +1890,13 @@ namespace etl return *this; } +#ifdef ETL_ISTRING_REPAIR_ENABLE + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + virtual void repair() = 0; +#endif + protected: //********************************************************************* @@ -1910,6 +1917,14 @@ namespace etl p_buffer[0] = 0; } + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair(T* p_buffer_) + { + p_buffer = p_buffer_; + } + private: //************************************************************************* diff --git a/src/cstring.h b/src/cstring.h index 66d97f42..9686c211 100644 --- a/src/cstring.h +++ b/src/cstring.h @@ -73,7 +73,6 @@ namespace etl string(const etl::string& other) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - istring::initialise(); istring::assign(other.begin(), other.end()); } @@ -91,7 +90,6 @@ namespace etl // 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); } @@ -102,7 +100,6 @@ namespace etl string(const value_type* text) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - istring::initialise(); istring::assign(text, text + etl::char_traits::length(text)); } @@ -114,7 +111,6 @@ namespace etl string(const value_type* text, size_t count) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - istring::initialise(); istring::assign(text, text + count); } @@ -177,6 +173,14 @@ namespace etl return *this; } + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() + { + etl::istring::repair(buffer); + } + private: value_type buffer[MAX_SIZE + 1]; diff --git a/src/deque.h b/src/deque.h index 7ac9d71e..03f8c71e 100644 --- a/src/deque.h +++ b/src/deque.h @@ -113,6 +113,20 @@ namespace etl } }; + //*************************************************************************** + ///\ingroup vector + /// Deque incompatible type exception. + //*************************************************************************** + class deque_incompatible_type : public deque_exception + { + public: + + deque_incompatible_type(string_type file_name, numeric_type line_number) + : deque_exception(ETL_ERROR_TEXT("deque:type", ETL_FILE"D"), file_name, line_number) + { + } + }; + //*************************************************************************** /// The base class for all templated deque types. ///\ingroup deque @@ -1358,6 +1372,13 @@ namespace etl return *this; } +#ifdef ETL_IDEQUE_REPAIR_ENABLE + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + virtual void repair() = 0; +#endif + protected: //************************************************************************* @@ -1380,7 +1401,18 @@ namespace etl } _begin = iterator(0, *this, p_buffer); - _end = iterator(0, *this, p_buffer); + _end = iterator(0, *this, p_buffer); + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair(pointer p_buffer_) + { + p_buffer = p_buffer_; + + _begin = iterator(_begin.index, *this, p_buffer); + _end = iterator(_end.index, *this, p_buffer); } iterator _begin; ///Iterator to the _begin item in the deque. @@ -1613,6 +1645,18 @@ namespace etl return *this; } + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() + { +#ifdef ETL_C11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + ETL_ASSERT(std::is_trivially_copyable::value, ETL_ERROR(etl::deque_incompatible_type)); +#endif + + etl::ideque::repair(reinterpret_cast(&buffer[0])); + } + private: /// The uninitialised buffer of T used in the deque. diff --git a/src/platform.h b/src/platform.h index 7887f354..a9c3efee 100644 --- a/src/platform.h +++ b/src/platform.h @@ -89,6 +89,11 @@ SOFTWARE. #define ETL_C11_TYPE_TRAITS_SUPPORTED #endif +#if (defined(ETL_COMPILER_MICROSOFT) && (_MSC_VER >= 1600)) || \ + (defined(ETL_COMPILER_GCC) && (__cplusplus >= 201402L)) +#define ETL_C11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED +#endif + // Some targets do not support 8bit types. #define ETL_8BIT_SUPPORT (CHAR_BIT == 8) diff --git a/src/private/pvoidvector.h b/src/private/pvoidvector.h index d34e447f..f81c228d 100644 --- a/src/private/pvoidvector.h +++ b/src/private/pvoidvector.h @@ -569,7 +569,7 @@ namespace etl //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* - void fixup(void** p_buffer_) + void repair(void** p_buffer_) { uintptr_t length = p_end - p_buffer; diff --git a/src/private/vector_base.h b/src/private/vector_base.h index ed408926..b39f8dfe 100644 --- a/src/private/vector_base.h +++ b/src/private/vector_base.h @@ -101,6 +101,20 @@ namespace etl } }; + //*************************************************************************** + ///\ingroup vector + /// Vector incompatible type exception. + //*************************************************************************** + class vector_incompatible_type : public vector_exception + { + public: + + vector_incompatible_type(string_type file_name, numeric_type line_number) + : vector_exception(ETL_ERROR_TEXT("vector:type", ETL_FILE"D"), file_name, line_number) + { + } + }; + //*************************************************************************** ///\ingroup vector /// The base class for all templated vector types. diff --git a/src/u16string.h b/src/u16string.h index 55a39084..2e760996 100644 --- a/src/u16string.h +++ b/src/u16string.h @@ -177,6 +177,14 @@ namespace etl return *this; } + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() + { + etl::iu16string::repair(buffer); + } + private: value_type buffer[MAX_SIZE + 1]; diff --git a/src/u32string.h b/src/u32string.h index 6d16f36c..877c7a0d 100644 --- a/src/u32string.h +++ b/src/u32string.h @@ -177,6 +177,14 @@ namespace etl return *this; } + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() + { + etl::iu32string::repair(buffer); + } + private: value_type buffer[MAX_SIZE + 1]; diff --git a/src/vector.h b/src/vector.h index 24f77d16..38e438ef 100644 --- a/src/vector.h +++ b/src/vector.h @@ -224,7 +224,7 @@ namespace etl ///\param value The value to fill new elements with. Default = default constructed value. //********************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type resize(size_t new_size, T value) { ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); @@ -258,7 +258,7 @@ namespace etl ///\param value The value to fill new elements with. Default = default constructed value. //********************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type resize(size_t new_size, T value) { ETL_ASSERT(new_size <= MAX_SIZE, ETL_ERROR(vector_full)); @@ -399,6 +399,8 @@ namespace etl template void assign(TIterator first, TIterator last) { + STATIC_ASSERT((etl::is_same::type, typename etl::remove_cv::value_type>::type>::value), "Iterator type does not match container type"); + #if defined(ETL_DEBUG) difference_type count = std::distance(first, last); ETL_ASSERT(static_cast(count) <= MAX_SIZE, ETL_ERROR(vector_full)); @@ -510,7 +512,7 @@ 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((size() + n) <= MAX_SIZE, ETL_ERROR(vector_full)); @@ -530,7 +532,7 @@ 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((size() + n) <= MAX_SIZE, ETL_ERROR(vector_full)); @@ -598,7 +600,7 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type insert(iterator position, TIterator first, TIterator last) { size_t count = std::distance(first, last); @@ -628,7 +630,7 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type insert(iterator position, TIterator first, TIterator last) { size_t count = std::distance(first, last); @@ -711,7 +713,7 @@ namespace etl ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* template - typename etl::enable_if::value, iterator>::type + typename etl::enable_if::value, iterator>::type erase(iterator first, iterator last) { if (first == begin() && last == end()) @@ -738,7 +740,7 @@ namespace etl ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* template - typename etl::enable_if::value, iterator>::type + typename etl::enable_if::value, iterator>::type erase(iterator first, iterator last) { if (first == begin() && last == end()) @@ -811,6 +813,13 @@ namespace etl return max_size() - size(); } +#ifdef ETL_IVECTOR_REPAIR_ENABLE + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + virtual void repair() = 0; +#endif + protected: //********************************************************************* @@ -840,7 +849,7 @@ namespace etl //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* - void fixup(T* p_buffer_) + void repair(T* p_buffer_) { uintptr_t length = p_end - p_buffer; p_buffer = p_buffer_; @@ -1065,13 +1074,13 @@ namespace etl //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* - void fixup() + void repair() { - #ifdef ETL_C11_TYPE_TRAITS_SUPPORTED - ETL_STATIC_ASSERT(std::is_trivially_copyable::value, "The stored type is not compatible with a low level copy"); + #ifdef ETL_C11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + ETL_ASSERT(std::is_trivially_copyable::value, ETL_ERROR(etl::vector_incompatible_type)); #endif - etl::ivector::fixup(buffer); + etl::ivector::repair(buffer); } private: @@ -1162,9 +1171,9 @@ namespace etl //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* - void fixup() + void repair() { - etl::ivector::fixup(buffer); + etl::ivector::repair(buffer); } private: diff --git a/src/wstring.h b/src/wstring.h index 0f015e00..4434f1c2 100644 --- a/src/wstring.h +++ b/src/wstring.h @@ -178,6 +178,14 @@ namespace etl return *this; } + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() + { + etl::iwstring::repair(buffer); + } + private: value_type buffer[MAX_SIZE + 1]; diff --git a/test/codeblocks/ETL.depend b/test/codeblocks/ETL.depend index f3bcb39a..1b401b1f 100644 --- a/test/codeblocks/ETL.depend +++ b/test/codeblocks/ETL.depend @@ -3289,7 +3289,7 @@ "CurrentTest.h" "ReportAssertImpl.h" -1494283539 source:d:\users\john\documents\programming\github\etl\test\test_algorithm.cpp +1497706369 source:d:\users\john\documents\programming\github\etl\test\test_algorithm.cpp "UnitTest++.h" "algorithm.h" "container.h" @@ -3315,7 +3315,7 @@ -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_alignment.cpp +1496992773 source:d:\users\john\documents\programming\github\etl\test\test_alignment.cpp "UnitTest++.h" "alignment.h" "type_traits.h" @@ -3423,7 +3423,7 @@ "exception.h" "error_handler.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_bitset.cpp +1497690249 source:d:\users\john\documents\programming\github\etl\test\test_bitset.cpp "UnitTest++.h" @@ -3538,7 +3538,7 @@ "static_assert.h" "exception.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_deque.cpp +1497708284 source:d:\users\john\documents\programming\github\etl\test\test_deque.cpp "UnitTest++.h" "ExtraCheckMacros.h" "deque.h" @@ -3548,6 +3548,7 @@ + 1494277861 d:\users\john\documents\programming\github\etl\test\extracheckmacros.h "../unittest-cpp/UnitTest++/HelperMacros.h" @@ -3582,7 +3583,7 @@ "exception.h" -1488104217 d:\users\john\documents\programming\github\etl\test\data.h +1497685058 d:\users\john\documents\programming\github\etl\test\data.h 1494277861 source:d:\users\john\documents\programming\github\etl\test\test_endian.cpp @@ -3612,7 +3613,7 @@ "exception.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_flat_map.cpp +1497306512 source:d:\users\john\documents\programming\github\etl\test\test_flat_map.cpp "UnitTest++.h" @@ -3726,7 +3727,7 @@ 1482623723 v_1.h" -1494283539 source:d:\users\john\documents\programming\github\etl\test\test_forward_list.cpp +1497685058 source:d:\users\john\documents\programming\github\etl\test\test_forward_list.cpp "UnitTest++.h" "ExtraCheckMacros.h" "data.h" @@ -3783,7 +3784,7 @@ 1479511692 nction.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_functional.cpp +1497685058 source:d:\users\john\documents\programming\github\etl\test\test_functional.cpp "UnitTest++.h" "functional.h" @@ -3843,7 +3844,7 @@ 1450265856 d:\users\john\documents\programming\github\etl\largest.h "type_traits.h" -1494283539 source:d:\users\john\documents\programming\github\etl\test\test_list.cpp +1497685059 source:d:\users\john\documents\programming\github\etl\test\test_list.cpp "UnitTest++.h" "ExtraCheckMacros.h" "list.h" @@ -3968,11 +3969,12 @@ "exception.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_vector.cpp +1497712887 source:d:\users\john\documents\programming\github\etl\test\test_vector.cpp "UnitTest++.h" + "vector.h" 1479511692 ctor.h" @@ -5230,7 +5232,7 @@ 1452516033 /home/jwellbelove/Programming/etl/visitor.h -1494283539 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_forward_list.cpp +1497685059 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_forward_list.cpp "UnitTest++.h" "ExtraCheckMacros.h" "data.h" @@ -5309,7 +5311,7 @@ "iterator.h" "type_traits.h" -1494277861 d:\users\john\documents\programming\github\etl\src\type_traits.h +1497689716 d:\users\john\documents\programming\github\etl\src\type_traits.h "platform.h" "nullptr.h" @@ -5318,7 +5320,7 @@ -1492164295 d:\users\john\documents\programming\github\etl\src\alignment.h +1496993010 d:\users\john\documents\programming\github\etl\src\alignment.h "type_traits.h" "static_assert.h" @@ -5326,7 +5328,7 @@ 1482948766 d:\users\john\documents\programming\github\etl\src\static_assert.h "platform.h" -1494277860 d:\users\john\documents\programming\github\etl\src\array.h +1497306512 d:\users\john\documents\programming\github\etl\src\array.h @@ -5370,7 +5372,7 @@ "integral_limits.h" -1494277860 d:\users\john\documents\programming\github\etl\src\bitset.h +1497685058 d:\users\john\documents\programming\github\etl\src\bitset.h @@ -5480,7 +5482,7 @@ "static_assert.h" "exception.h" -1494277860 d:\users\john\documents\programming\github\etl\src\deque.h +1497708272 d:\users\john\documents\programming\github\etl\src\deque.h @@ -5512,22 +5514,9 @@ 1482948766 d:\users\john\documents\programming\github\etl\src\fixed_iterator.h -1494277860 d:\users\john\documents\programming\github\etl\src\flat_map.h - - - - - - - "platform.h" - "vector.h" +1497712590 d:\users\john\documents\programming\github\etl\src\flat_map.h + "reference_flat_map.h" "pool.h" - "exception.h" - "vector.h" - "error_handler.h" - "debug_count.h" - "type_traits.h" - "parameter_type.h" 1482748252 d:\users\john\documents\programming\github\etl\src\iflat_map.h @@ -5562,13 +5551,14 @@ 1482748239 vectorpointer.h" -1494277860 d:\users\john\documents\programming\github\etl\src\private\vector_base.h +1497705958 d:\users\john\documents\programming\github\etl\src\private\vector_base.h "../exception.h" "../error_handler.h" "../debug_count.h" -1494277861 d:\users\john\documents\programming\github\etl\src\vector.h +1497712492 d:\users\john\documents\programming\github\etl\src\vector.h + @@ -5624,7 +5614,7 @@ "../ivector.h" "../error_handler.h" -1494277860 d:\users\john\documents\programming\github\etl\src\forward_list.h +1497685058 d:\users\john\documents\programming\github\etl\src\forward_list.h @@ -5680,7 +5670,7 @@ "../exception.h" "../error_handler.h" -1479515290 d:\users\john\documents\programming\github\etl\src\functional.h +1494763312 d:\users\john\documents\programming\github\etl\src\functional.h 1482948766 d:\users\john\documents\programming\github\etl\src\hash.h @@ -5691,7 +5681,7 @@ 1479515290 d:\users\john\documents\programming\github\etl\src\instance_count.h -1488104217 d:\users\john\documents\programming\github\etl\src\intrusive_forward_list.h +1497685058 d:\users\john\documents\programming\github\etl\src\intrusive_forward_list.h "platform.h" @@ -5715,7 +5705,7 @@ "exception.h" "error_handler.h" -1494277860 d:\users\john\documents\programming\github\etl\src\io_port.h +1497308571 d:\users\john\documents\programming\github\etl\src\io_port.h "nullptr.h" @@ -5724,7 +5714,7 @@ 1485905321 d:\users\john\documents\programming\github\etl\src\largest.h "type_traits.h" -1494277860 d:\users\john\documents\programming\github\etl\src\list.h +1497685058 d:\users\john\documents\programming\github\etl\src\list.h @@ -5757,7 +5747,7 @@ "../exception.h" "../error_handler.h" -1494277860 d:\users\john\documents\programming\github\etl\src\map.h +1497306512 d:\users\john\documents\programming\github\etl\src\map.h @@ -5835,7 +5825,7 @@ "../exception.h" "../error_handler.h" -1494277861 d:\users\john\documents\programming\github\etl\src\set.h +1497685058 d:\users\john\documents\programming\github\etl\src\set.h @@ -5908,7 +5898,7 @@ 1482624915 ordered_map.h" -1494277861 d:\users\john\documents\programming\github\etl\src\unordered_map.h +1497306512 d:\users\john\documents\programming\github\etl\src\unordered_map.h @@ -5961,7 +5951,7 @@ 1479515291 d:\users\john\documents\programming\github\etl\src\visitor.h -1494277860 d:\users\john\documents\programming\github\etl\src\platform.h +1497712972 d:\users\john\documents\programming\github\etl\src\platform.h @@ -5997,7 +5987,7 @@ 1479511691 at_multimap.h" -1494277860 d:\users\john\documents\programming\github\etl\src\flat_multimap.h +1497306512 d:\users\john\documents\programming\github\etl\src\flat_multimap.h @@ -6087,7 +6077,7 @@ 1482358550 trusive_links.h" -1494283539 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_list.cpp +1497685059 source:d:\users\john\documents\programming\github\etl\test\test_intrusive_list.cpp "UnitTest++.h" "ExtraCheckMacros.h" "data.h" @@ -6098,7 +6088,7 @@ -1488104217 d:\users\john\documents\programming\github\etl\src\intrusive_list.h +1497685058 d:\users\john\documents\programming\github\etl\src\intrusive_list.h "platform.h" @@ -6144,7 +6134,7 @@ 1479511692 ltimap.h" -1494277860 d:\users\john\documents\programming\github\etl\src\multimap.h +1497306512 d:\users\john\documents\programming\github\etl\src\multimap.h @@ -6189,7 +6179,7 @@ 1479511692 ltiset.h" -1494277860 d:\users\john\documents\programming\github\etl\src\multiset.h +1497306512 d:\users\john\documents\programming\github\etl\src\multiset.h @@ -6301,7 +6291,7 @@ 1482625301 ordered_multimap.h" -1494277861 d:\users\john\documents\programming\github\etl\src\unordered_multimap.h +1497306512 d:\users\john\documents\programming\github\etl\src\unordered_multimap.h @@ -6354,7 +6344,7 @@ "unordered_multiset.h" "checksum.h" -1494277861 d:\users\john\documents\programming\github\etl\src\unordered_multiset.h +1497306512 d:\users\john\documents\programming\github\etl\src\unordered_multiset.h @@ -6404,7 +6394,7 @@ "unordered_set.h" "checksum.h" -1494277861 d:\users\john\documents\programming\github\etl\src\unordered_set.h +1497306512 d:\users\john\documents\programming\github\etl\src\unordered_set.h @@ -6480,7 +6470,7 @@ 1482079098 or.h" -1494277861 d:\users\john\documents\programming\github\etl\src\private\pvoidvector.h +1497685165 d:\users\john\documents\programming\github\etl\src\private\pvoidvector.h @@ -6530,7 +6520,7 @@ "error_handler.h" "intrusive_links.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_string_char.cpp +1497705758 source:d:\users\john\documents\programming\github\etl\test\test_string_char.cpp "UnitTest++.h" @@ -6539,12 +6529,12 @@ 1482181573 tring.h" -1494277860 d:\users\john\documents\programming\github\etl\src\cstring.h +1497690092 d:\users\john\documents\programming\github\etl\src\cstring.h "platform.h" "basic_string.h" "hash.h" -1494277860 d:\users\john\documents\programming\github\etl\src\basic_string.h +1497702020 d:\users\john\documents\programming\github\etl\src\basic_string.h @@ -6583,7 +6573,7 @@ "../exception.h" "../error_handler.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_string_u16.cpp +1497705758 source:d:\users\john\documents\programming\github\etl\test\test_string_u16.cpp "UnitTest++.h" @@ -6592,12 +6582,12 @@ 1482099557 6string.h" -1482948766 d:\users\john\documents\programming\github\etl\src\u16string.h +1497690510 d:\users\john\documents\programming\github\etl\src\u16string.h "platform.h" "basic_string.h" "hash.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_string_u32.cpp +1497705758 source:d:\users\john\documents\programming\github\etl\test\test_string_u32.cpp "UnitTest++.h" @@ -6606,19 +6596,19 @@ 1482099666 2string.h" -1482948766 d:\users\john\documents\programming\github\etl\src\u32string.h +1497690510 d:\users\john\documents\programming\github\etl\src\u32string.h "platform.h" "basic_string.h" "hash.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_string_wchar_t.cpp +1497705758 source:d:\users\john\documents\programming\github\etl\test\test_string_wchar_t.cpp "UnitTest++.h" "wstring.h" -1482948766 d:\users\john\documents\programming\github\etl\src\wstring.h +1497690510 d:\users\john\documents\programming\github\etl\src\wstring.h "platform.h" "basic_string.h" "hash.h" @@ -6641,11 +6631,12 @@ 1482948766 d:\users\john\documents\programming\github\etl\src\utility.h "type_traits.h" -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_vector_pointer.cpp +1497712935 source:d:\users\john\documents\programming\github\etl\test\test_vector_pointer.cpp "UnitTest++.h" + "vector.h" 1482076051 source:/mnt/hgfs/Programming/GitHub/unittest-cpp/UnitTest++/RequiredCheckException.cpp @@ -7862,7 +7853,7 @@ "type_traits.h" -1488104217 d:\users\john\documents\programming\github\etl\src\memory.h +1497689774 d:\users\john\documents\programming\github\etl\src\memory.h "type_traits.h" @@ -7981,7 +7972,7 @@ -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_random.cpp +1497684591 source:d:\users\john\documents\programming\github\etl\test\test_random.cpp "UnitTest++.h" "random.h" @@ -7989,7 +7980,7 @@ -1494277861 source:d:\users\john\documents\programming\github\etl\test\test_vector_non_trivial.cpp +1497685854 source:d:\users\john\documents\programming\github\etl\test\test_vector_non_trivial.cpp "UnitTest++.h" @@ -8173,7 +8164,7 @@ "HelperMacros.h" -1494362778 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_map.cpp +1497308006 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_map.cpp "UnitTest++.h" @@ -8186,13 +8177,18 @@ "data.h" "reference_flat_map.h" -1494362778 d:\users\john\documents\programming\github\etl\src\reference_flat_map.h +1497308006 d:\users\john\documents\programming\github\etl\src\reference_flat_map.h - "exception.h" + "platform.h" "vector.h" "error_handler.h" + "debug_count.h" + "type_traits.h" + "parameter_type.h" + "exception.h" + "static_assert.h" -1494362778 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_multimap.cpp +1494363271 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_multimap.cpp "UnitTest++.h" @@ -8204,14 +8200,14 @@ "data.h" "reference_flat_multimap.h" -1494362778 d:\users\john\documents\programming\github\etl\src\reference_flat_multimap.h +1497685058 d:\users\john\documents\programming\github\etl\src\reference_flat_multimap.h "exception.h" "error_handler.h" "debug_count.h" "vector.h" -1494362778 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_multiset.cpp +1494363271 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_multiset.cpp "UnitTest++.h" @@ -8223,7 +8219,7 @@ "data.h" "reference_flat_multiset.h" -1494362778 d:\users\john\documents\programming\github\etl\src\reference_flat_multiset.h +1494363271 d:\users\john\documents\programming\github\etl\src\reference_flat_multiset.h @@ -8236,7 +8232,7 @@ "error_handler.h" "exception.h" -1494362778 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_set.cpp +1494363271 source:d:\users\john\documents\programming\github\etl\test\test_reference_flat_set.cpp "UnitTest++.h" @@ -8248,7 +8244,7 @@ "data.h" "reference_flat_set.h" -1494362778 d:\users\john\documents\programming\github\etl\src\reference_flat_set.h +1494363271 d:\users\john\documents\programming\github\etl\src\reference_flat_set.h diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index c0d3ac7a..542b69b9 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -2,19 +2,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + + + + + + + + + + + @@ -22,9 +97,89 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -37,64 +192,14 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -102,74 +207,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 12465f81..7ef3373f 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -38,6 +38,7 @@ SOFTWARE. #include #include #include +#include namespace { @@ -48,6 +49,8 @@ namespace typedef TestDataDC DC; typedef TestDataNDC NDC; + typedef etl::deque DataInt; + typedef etl::ideque IDataInt; typedef etl::deque DataDC; typedef etl::deque DataNDC; typedef etl::ideque IDataNDC; @@ -82,6 +85,9 @@ namespace std::vector initial_data_small = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; std::vector insert_data = { N10, N11, N12, N13, N14 }; 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") }; + std::vector int_data1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; + std::vector int_data2 = { 15, 16, 17, 18 }; + //************************************************************************* TEST(test_constructor) @@ -1514,5 +1520,81 @@ namespace CHECK(data.rbegin() == data.rend()); CHECK(data.crbegin() == data.crend()); } + + //************************************************************************* + TEST(test_memcpy_repair) + { + DataInt data(int_data1.begin(), int_data1.end()); + data.pop_front(); + data.pop_front(); + data.pop_front(); + data.pop_front(); + data.insert(data.end(), int_data2.begin(), int_data2.end()); + + char buffer[sizeof(DataInt)]; + + memcpy(&buffer, &data, sizeof(data)); + + DataInt& rdata(*reinterpret_cast(buffer)); + rdata.repair(); + + // Check that the memcpy'd vector is the same. + CHECK_EQUAL(data.size(), rdata.size()); + CHECK(!rdata.empty()); + CHECK(rdata.full()); + + bool is_equal = std::equal(rdata.begin(), + rdata.end(), + data.begin()); + + CHECK(is_equal); + + // Modify the original and check that the memcpy'd vector is not the same. + std::reverse(data.begin(), data.end()); + + is_equal = std::equal(rdata.begin(), + rdata.end(), + data.begin()); + + CHECK(!is_equal); + } + + //************************************************************************* + TEST(test_memcpy_repair_virtual) + { + DataInt data(int_data1.begin(), int_data1.end()); + data.pop_front(); + data.pop_front(); + data.pop_front(); + data.pop_front(); + data.insert(data.end(), int_data2.begin(), int_data2.end()); + + char buffer[sizeof(DataInt)]; + + memcpy(&buffer, &data, sizeof(data)); + + IDataInt& idata(*reinterpret_cast(buffer)); + idata.repair(); + + // Check that the memcpy'd vector is the same. + CHECK_EQUAL(data.size(), idata.size()); + CHECK(!idata.empty()); + CHECK(idata.full()); + + bool is_equal = std::equal(idata.begin(), + idata.end(), + data.begin()); + + CHECK(is_equal); + + // Modify the original and check that the memcpy'd vector is not the same. + std::reverse(data.begin(), data.end()); + + is_equal = std::equal(idata.begin(), + idata.end(), + data.begin()); + + CHECK(!is_equal); + } }; } diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 29851334..5b311949 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -3019,7 +3019,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_memcpy) + TEST_FIXTURE(SetupFixture, test_memcpy_repair) { Text text; @@ -3029,14 +3029,42 @@ namespace memcpy(&buffer, &text, sizeof(text)); - Text& text2(*reinterpret_cast(buffer)); - text2.repair(); + Text& rtext(*reinterpret_cast(buffer)); + rtext.repair(); - bool is_equal = Equal(text, text2); + CHECK(!rtext.empty()); + CHECK(!rtext.full()); + + bool is_equal = Equal(text, rtext); CHECK(is_equal); - text = "GHIJKL"; - is_equal = Equal(text, text2); + text = STR("GHIJKL"); + is_equal = Equal(text, rtext); + CHECK(!is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + IText& itext(*reinterpret_cast(buffer)); + itext.repair(); + + CHECK(!itext.empty()); + CHECK(!itext.full()); + + bool is_equal = Equal(text, itext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, itext); CHECK(!is_equal); } }; diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index cd1fe7ff..73afca91 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -3017,5 +3017,55 @@ namespace CHECK_EQUAL(position1, position2); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + Text& rtext(*reinterpret_cast(buffer)); + rtext.repair(); + + CHECK(!rtext.empty()); + CHECK(!rtext.full()); + + bool is_equal = Equal(text, rtext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, rtext); + CHECK(!is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + IText& itext(*reinterpret_cast(buffer)); + itext.repair(); + + CHECK(!itext.empty()); + CHECK(!itext.full()); + + bool is_equal = Equal(text, itext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, itext); + CHECK(!is_equal); + } }; } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 165a0743..a49aae22 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -3017,5 +3017,55 @@ namespace CHECK_EQUAL(position1, position2); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + Text& rtext(*reinterpret_cast(buffer)); + rtext.repair(); + + CHECK(!rtext.empty()); + CHECK(!rtext.full()); + + bool is_equal = Equal(text, rtext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, rtext); + CHECK(!is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + IText& itext(*reinterpret_cast(buffer)); + itext.repair(); + + CHECK(!itext.empty()); + CHECK(!itext.full()); + + bool is_equal = Equal(text, itext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, itext); + CHECK(!is_equal); + } }; } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 61604113..f19decae 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -3017,6 +3017,56 @@ namespace CHECK_EQUAL(position1, position2); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + Text& rtext(*reinterpret_cast(buffer)); + rtext.repair(); + + CHECK(!rtext.empty()); + CHECK(!rtext.full()); + + bool is_equal = Equal(text, rtext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, rtext); + CHECK(!is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) + { + Text text; + + text.assign(STR("ABCDEF")); + + char buffer[sizeof(Text)]; + + memcpy(&buffer, &text, sizeof(text)); + + IText& itext(*reinterpret_cast(buffer)); + itext.repair(); + + CHECK(!itext.empty()); + CHECK(!itext.full()); + + bool is_equal = Equal(text, itext); + CHECK(is_equal); + + text = STR("GHIJKL"); + is_equal = Equal(text, itext); + CHECK(!is_equal); + } }; } diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 4a692376..11c1f954 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -31,11 +31,12 @@ SOFTWARE. #include #include #include +#include #include "vector.h" namespace -{ +{ SUITE(test_vector) { static const size_t SIZE = 10; @@ -146,7 +147,7 @@ namespace Data data(initial_data.begin(), initial_data.end()); Data data2(data); CHECK(data2 == data); - + data2[2] = -1; CHECK(data2 != data); } @@ -624,7 +625,7 @@ namespace const size_t INITIAL_SIZE = 5; const size_t INSERT_SIZE = 3; const int INITIAL_VALUE = 11; - + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { Compare_Data compare_data; @@ -718,7 +719,7 @@ namespace 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); @@ -762,7 +763,7 @@ namespace CHECK(is_equal); } - + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -955,5 +956,71 @@ namespace const Data initial2(initial_data.begin(), initial_data.end()); CHECK((initial >= initial2) == (initial_data >= initial_data)); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair) + { + Data data(initial_data.begin(), initial_data.end()); + + char buffer[sizeof(Data)]; + + memcpy(&buffer, &data, sizeof(data)); + + Data& rdata(*reinterpret_cast(buffer)); + rdata.repair(); + + // Check that the memcpy'd vector is the same. + CHECK_EQUAL(data.size(), rdata.size()); + CHECK(!rdata.empty()); + CHECK(rdata.full()); + + bool is_equal = std::equal(rdata.begin(), + rdata.end(), + data.begin()); + + CHECK(is_equal); + + // Modify the original and check that the memcpy'd vector is not the same. + std::reverse(data.begin(), data.end()); + + is_equal = std::equal(rdata.begin(), + rdata.end(), + data.begin()); + + CHECK(!is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual) + { + Data data(initial_data.begin(), initial_data.end()); + + char buffer[sizeof(Data)]; + + memcpy(&buffer, &data, sizeof(data)); + + IData& idata(*reinterpret_cast(buffer)); + idata.repair(); + + // Check that the memcpy'd vector is the same. + CHECK_EQUAL(data.size(), idata.size()); + CHECK(!idata.empty()); + CHECK(idata.full()); + + bool is_equal = std::equal(idata.begin(), + idata.end(), + data.begin()); + + CHECK(is_equal); + + // Modify the original and check that the memcpy'd vector is not the same. + std::reverse(data.begin(), data.end()); + + is_equal = std::equal(idata.begin(), + idata.end(), + data.begin()); + + CHECK(!is_equal); + } }; } diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index 5f08cbe5..232faa21 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -31,11 +31,12 @@ SOFTWARE. #include #include #include +#include #include "vector.h" namespace -{ +{ SUITE(test_vector_pointer) { static const size_t SIZE = 10; @@ -159,7 +160,7 @@ namespace Data data(initial_data.begin(), initial_data.end()); Data data2(data); CHECK(data2 == data); - + data2[2] = nullptr; CHECK(data2 != data); } @@ -612,7 +613,7 @@ namespace const size_t INITIAL_SIZE = 5; const size_t INSERT_SIZE = 3; int INITIAL_VALUE = 11; - + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { Compare_Data compare_data; @@ -700,7 +701,7 @@ namespace 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); @@ -740,7 +741,7 @@ namespace CHECK(is_equal); } - + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -933,5 +934,38 @@ namespace const Data initial2(initial_data.begin(), initial_data.end()); CHECK((initial >= initial2) == (initial_data >= initial_data)); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_memcpy_repair) + { + Data data(initial_data.begin(), initial_data.end()); + + char buffer[sizeof(Data)]; + + memcpy(&buffer, &data, sizeof(data)); + + Data& rdata(*reinterpret_cast(buffer)); + rdata.repair(); + + // Check that the memcpy'd vector is the same. + CHECK_EQUAL(data.size(), rdata.size()); + CHECK(!rdata.empty()); + CHECK(rdata.full()); + + bool is_equal = std::equal(rdata.begin(), + rdata.end(), + data.begin()); + + CHECK(is_equal); + + // Modify the original and check that the memcpy'd vector is not the same. + std::reverse(data.begin(), data.end()); + + is_equal = std::equal(rdata.begin(), + rdata.end(), + data.begin()); + + CHECK(!is_equal); + } }; } diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index d38c27c9..6015dc55 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -72,7 +72,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;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_IVECTOR_REPAIR_ENABLE;ETL_ISTRING_REPAIR_ENABLE;ETL_IDEQUE_REPAIR_ENABLE;ETL_IN_UNIT_TEST;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions) ../../unittest-cpp/UnitTest++/;../../src @@ -91,7 +91,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;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_IN_UNIT_TEST;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions) ../../unittest-cpp/UnitTest++/;../../src diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 6be3e083..f2bf51fa 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -37,6 +37,9 @@ {7028012c-30c4-4993-b2d9-3b1521a610ae} + + {5de50c3d-4679-4eb3-9b76-e43e1aad6a66} + @@ -336,12 +339,6 @@ ETL\Utilities - - ETL\Patterns - - - ETL\Patterns - ETL\Containers @@ -441,6 +438,12 @@ Header Files + + Header Files + + + Header Files + @@ -773,7 +776,7 @@ Resource Files - ETL\Patterns + Source Files