From 877ef005eafd49af38c032db8274858cd97496a3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 15 Aug 2025 18:04:50 +0100 Subject: [PATCH] Fixed file Id error Updated CMakeLists.txt for tests and syntax checks --- include/etl/file_error_numbers.h | 1 + include/etl/not_null.h | 51 ++++++++++++++++++------------ test/CMakeLists.txt | 2 ++ test/syntax_check/CMakeLists.txt | 1 + test/syntax_check/not_null.h.t.cpp | 29 +++++++++++++++++ test/vs2022/etl.vcxproj | 18 +++++++++++ test/vs2022/etl.vcxproj.filters | 18 ++--------- 7 files changed, 84 insertions(+), 36 deletions(-) create mode 100644 test/syntax_check/not_null.h.t.cpp diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 5404828a..51a009e7 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -107,4 +107,5 @@ SOFTWARE. #define ETL_UNALIGNED_TYPE_FILE_ID "74" #define ETL_SPAN_FILE_ID "75" #define ETL_ALGORITHM_FILE_ID "76" +#define ETL_NOT_NULL_FILE_ID "77" #endif diff --git a/include/etl/not_null.h b/include/etl/not_null.h index 54a4f565..0387a35c 100644 --- a/include/etl/not_null.h +++ b/include/etl/not_null.h @@ -82,11 +82,17 @@ namespace etl { public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + //********************************* /// Constructs a not_null from a pointer. /// Asserts if the pointer is null. //********************************* - explicit not_null(T* ptr_) + explicit not_null(pointer ptr_) : ptr(ptr_) { ETL_ASSERT(ptr_ != ETL_NULLPTR, ETL_ERROR(not_null_contains_null)); @@ -114,7 +120,7 @@ namespace etl /// Assignment from a pointer. /// Asserts if the pointer is null. //********************************* - not_null& operator =(T* rhs) + not_null& operator =(pointer rhs) { ETL_ASSERT_OR_RETURN_VALUE(rhs != ETL_NULLPTR, ETL_ERROR(not_null_contains_null), *this); @@ -126,15 +132,15 @@ namespace etl //********************************* /// Gets the underlying pointer. //********************************* - T* get() const + pointer get() const { return ptr; } //********************************* - /// Implicit conversion to T*. + /// Implicit conversion to pointer. //********************************* - operator T*() const + operator pointer() const { return ptr; } @@ -142,7 +148,7 @@ namespace etl //********************************* /// Dereference operator. //********************************* - T& operator*() const + reference operator*() const { return *ptr; } @@ -150,7 +156,7 @@ namespace etl //********************************* /// Arrow operator. //********************************* - T* operator->() const + pointer operator->() const { return ptr; } @@ -158,7 +164,7 @@ namespace etl private: /// The underlying pointer. - T* ptr; + pointer ptr; }; //*************************************************************************** @@ -166,15 +172,19 @@ namespace etl // A container for unique_ptr that are not allowed to be null. //*************************************************************************** template - class not_null> + class not_null > { - private: - - // The unique_ptr type. - typedef etl::unique_ptr unique_ptr_type; - public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + + typedef etl::unique_ptr unique_ptr_type; + +#if ETL_USING_CPP11 //********************************* /// Constructs a not_null from a unique_ptr. /// Asserts if the unique_ptr is null. @@ -185,7 +195,6 @@ namespace etl ETL_ASSERT(u_ptr.get() != ETL_NULLPTR, ETL_ERROR(not_null_contains_null)); } -#if ETL_USING_CPP11 //********************************* /// Constructs a not_null from a unique_ptr. //********************************* @@ -219,17 +228,17 @@ namespace etl #endif //********************************* - /// Gets the underlying unique_ptr. + /// Gets the underlying ptr. //********************************* - T* get() const + pointer get() const { return u_ptr.get(); } //********************************* - /// Implicit conversion to T*. + /// Implicit conversion to pointer. //********************************* - operator T*() const + operator pointer() const { return u_ptr.get(); } @@ -237,7 +246,7 @@ namespace etl //********************************* /// Dereference operator. //********************************* - T& operator*() const + reference operator*() const { return *u_ptr; } @@ -245,7 +254,7 @@ namespace etl //********************************* /// Arrow operator. //********************************* - T* operator->() const + pointer operator->() const { return u_ptr.get(); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a60856f7..5b3564f1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -229,6 +229,8 @@ add_executable(etl_tests test_multi_span.cpp test_multi_vector.cpp test_murmur3.cpp + test_not_null_pointer.cpp + test_not_null_unique_pointer.cpp test_nth_type.cpp test_numeric.cpp test_observer.cpp diff --git a/test/syntax_check/CMakeLists.txt b/test/syntax_check/CMakeLists.txt index eb0deadf..e664a3a2 100644 --- a/test/syntax_check/CMakeLists.txt +++ b/test/syntax_check/CMakeLists.txt @@ -246,6 +246,7 @@ target_sources(tests PRIVATE murmur3.h.t.cpp mutex.h.t.cpp negative.h.t.cpp + not_null.h.t.cpp nth_type.h.t.cpp nullptr.h.t.cpp null_type.h.t.cpp diff --git a/test/syntax_check/not_null.h.t.cpp b/test/syntax_check/not_null.h.t.cpp new file mode 100644 index 00000000..8f44b76c --- /dev/null +++ b/test/syntax_check/not_null.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 13d90f26..6ae0e148 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -7462,6 +7462,24 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 281ff201..5c6910c2 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -196,27 +196,12 @@ {8a3300fa-c2cd-44dd-8582-692f97ec4dc0} - - {ca522a34-8cf0-4f64-8ca1-33f52f65a9a7} - - - {ba2bf848-6023-4906-a0d4-14a4c8fba0e5} - - - {527f4d9a-8968-4352-8cdf-f6ccc391dcf9} - - - {57b110fa-b3d8-4cc4-9619-ca510a29c213} - {5b76fd56-eb83-489f-b9a6-798c07c5fa76} {a05ae045-3218-4ca2-9f25-08cc977898df} - - {3336d15c-7c22-4df0-a6b2-1eb605099a1a} - {c75cedd3-8b6c-4662-b965-aecbe7fd5d1c} @@ -3707,6 +3692,9 @@ Tests\Misc + + Tests\Syntax Checks\Source +