From 08481bf2b328620c9698ccaa4cd84942993af33a Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 13 Jun 2023 16:19:30 -0400 Subject: [PATCH] Squashed 'externals/nitro/' changes from 3822f6ef3..d74a68191 d74a68191 Merge branch 'main' into cpp17 b12caf2fc latest from CODA-OSS (#556) 0cd432624 use sys::make_span (#555) f5223165c Merge commit '63bc647787ac53602074aeeedd3565522ea7b170' into cpp17 63bc64778 Squashed 'externals/coda-oss/' changes from d95aa8dd3b..113db4a49d 1ab864800 latest from coda-oss fc16938bc merge develop/sync_externals e4b454976 Merge branch 'main' into cpp17 05dae18a3 patch to build other projects git-subtree-dir: externals/nitro git-subtree-split: d74a6819149f37d8bbbbfc9f040197e3bcc94e88 --- externals/coda-oss/UnitTest/UnitTest.vcxproj | 6 + .../UnitTest/UnitTest.vcxproj.filters | 3 + externals/coda-oss/UnitTest/pch.h | 1 + externals/coda-oss/UnitTest/types.cpp | 4 + .../modules/c++/coda-oss-lite.vcxproj | 5 +- .../modules/c++/coda-oss-lite.vcxproj.filters | 9 +- .../c++/coda_oss/include/coda_oss/cstddef.h | 10 +- .../c++/coda_oss/include/coda_oss/memory.h | 67 -------- .../coda_oss/include/coda_oss/type_traits.h | 2 - .../modules/c++/mem/include/mem/AutoPtr.h | 1 - .../modules/c++/mem/include/mem/ScopedPtr.h | 20 ++- .../c++/mem/include/mem/SharedPtrCpp11.h | 3 +- .../modules/c++/std/include/import/cpp14.h | 3 +- .../modules/c++/std/include/std/cstddef | 5 +- .../modules/c++/std/include/std/memory | 20 +-- .../modules/c++/std/include/std/optional | 5 +- .../modules/c++/std/include/std/type_traits | 21 +-- .../modules/c++/str/include/str/Manip.h | 3 - .../c++/str/source/EncodedStringView.cpp | 1 - .../coda-oss/modules/c++/str/source/Manip.cpp | 2 + .../c++/sys/include/sys/ByteSwapValue.h | 2 - .../coda-oss/modules/c++/types/CMakeLists.txt | 2 +- .../modules/c++/types/include/types/complex.h | 145 ++++++++++++++++++ .../c++/types/unittests/test_complex.cpp | 56 +++++++ externals/coda-oss/modules/c++/types/wscript | 2 +- .../c++/xml.lite/include/xml/lite/Document.h | 3 +- .../include/xml/lite/MinidomHandler.h | 3 +- .../include/nitf/DecompressionInterface.hpp | 4 +- .../c++/nitf/include/nitf/FieldDescriptor.hpp | 7 +- .../c++/nitf/include/nitf/NITFBufferList.hpp | 2 +- .../c++/nitf/include/nitf/SegmentSource.hpp | 4 +- modules/c++/nitf/include/nitf/coda-oss.hpp | 2 + modules/c++/nitf/source/ByteProvider.cpp | 2 +- modules/c++/nitf/source/J2KCompressor.cpp | 11 +- modules/c++/nitf/source/J2KReader.cpp | 4 +- modules/c++/nitf/source/J2KWriter.cpp | 2 +- modules/c++/nitf/source/SegmentSource.cpp | 10 +- .../c++/nitf/unittests/test_j2k_loading++.cpp | 10 +- 38 files changed, 278 insertions(+), 184 deletions(-) delete mode 100644 externals/coda-oss/modules/c++/coda_oss/include/coda_oss/memory.h create mode 100644 externals/coda-oss/modules/c++/types/include/types/complex.h create mode 100644 externals/coda-oss/modules/c++/types/unittests/test_complex.cpp diff --git a/externals/coda-oss/UnitTest/UnitTest.vcxproj b/externals/coda-oss/UnitTest/UnitTest.vcxproj index e6dd924ee7..53ad1802e3 100644 --- a/externals/coda-oss/UnitTest/UnitTest.vcxproj +++ b/externals/coda-oss/UnitTest/UnitTest.vcxproj @@ -71,6 +71,7 @@ true true /Zc:__cplusplus %(AdditionalOptions) + stdcpp17 Windows @@ -96,6 +97,7 @@ true true /Zc:__cplusplus %(AdditionalOptions) + stdcpp17 Windows @@ -321,6 +323,10 @@ true true + + true + true + true true diff --git a/externals/coda-oss/UnitTest/UnitTest.vcxproj.filters b/externals/coda-oss/UnitTest/UnitTest.vcxproj.filters index 37d7c36cf4..fd73449870 100644 --- a/externals/coda-oss/UnitTest/UnitTest.vcxproj.filters +++ b/externals/coda-oss/UnitTest/UnitTest.vcxproj.filters @@ -222,6 +222,9 @@ mt + + types + diff --git a/externals/coda-oss/UnitTest/pch.h b/externals/coda-oss/UnitTest/pch.h index ecbdb7c880..26d745b783 100644 --- a/externals/coda-oss/UnitTest/pch.h +++ b/externals/coda-oss/UnitTest/pch.h @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include diff --git a/externals/coda-oss/UnitTest/types.cpp b/externals/coda-oss/UnitTest/types.cpp index 1384c00b78..3d03155b3f 100644 --- a/externals/coda-oss/UnitTest/types.cpp +++ b/externals/coda-oss/UnitTest/types.cpp @@ -15,4 +15,8 @@ TEST_CLASS(test_range_list){ public: #include "types/unittests/test_range_list.cpp" }; +TEST_CLASS(test_complex){ public: +#include "types/unittests/test_complex.cpp" +}; + } \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj index 2baf272d84..7e132aa6f7 100644 --- a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj +++ b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj @@ -19,10 +19,8 @@ - - @@ -257,6 +255,7 @@ + @@ -472,6 +471,7 @@ true /Zc:__cplusplus %(AdditionalOptions) true + stdcpp17 @@ -498,6 +498,7 @@ true true /Zc:__cplusplus %(AdditionalOptions) + stdcpp17 diff --git a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters index 1e84491f23..428dcd63a5 100644 --- a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters +++ b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters @@ -30,18 +30,12 @@ coda_oss - - coda_oss - coda_oss coda_oss - - coda_oss - coda_oss @@ -750,6 +744,9 @@ sys + + types + diff --git a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h index d9320e054b..68a7ad5dce 100644 --- a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h +++ b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h @@ -18,23 +18,15 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_coda_oss_cstddef_h_INCLUDED_ #define CODA_OSS_coda_oss_cstddef_h_INCLUDED_ -#pragma once - -#include #include -#include - -// Need a fairly decent C++ compiler to use the real GSL. This brings in more than -// we really need for span (e.g., gsl::narrow()), but it keeps things simple. -#include "gsl/gsl.h" // not gsl/byte; need #pragma here to turn off warnings namespace coda_oss { using byte = std::byte; } -static_assert(!std::is_same::value, "'coda_oss::byte' should be a unique type."); #endif // CODA_OSS_coda_oss_cstddef_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/memory.h b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/memory.h deleted file mode 100644 index a546428fb9..0000000000 --- a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/memory.h +++ /dev/null @@ -1,67 +0,0 @@ -/* ========================================================================= - * This file is part of coda_oss-c++ - * ========================================================================= - * - * (C) Copyright 2004 - 2018, MDA Information Systems LLC - * (C) Copyright 2022, Maxar Technologies, Inc. - * - * coda_oss-c++ is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; If not, - * see . - * - */ - -#ifndef CODA_OSS_coda_oss_memory_h_INCLUDED_ -#define CODA_OSS_coda_oss_memory_h_INCLUDED_ -#pragma once - -#include -#include -#include - -#include "config/compiler_extensions.h" - -#include "coda_oss/namespace_.h" -namespace coda_oss -{ -// C++11 inadvertently ommitted make_unique; provide it here. (Swiped from .) -template ::value, int>::type = 0> -std::unique_ptr make_unique(TArgs&&... args) -{ - CODA_OSS_disable_warning_push - #if _MSC_VER - #pragma warning(disable: 26409) // Avoid calling new and delete explicitly, use std::make_unique instead (r .11). - #endif - return std::unique_ptr(new T(std::forward(args)...)); - CODA_OSS_disable_warning_pop -} - -template ::value && std::extent::value == 0, int>::type = 0> -std::unique_ptr make_unique(size_t size) -{ - using element_t = typename std::remove_extent::type; - - CODA_OSS_disable_warning_push - #if _MSC_VER - #pragma warning(disable: 26409) // Avoid calling new and delete explicitly, use std::make_unique instead (r .11). - #endif - return std::unique_ptr(new element_t[size]()); - CODA_OSS_disable_warning_pop -} - -template ::value != 0, int>::type = 0> -void make_unique(TArgs&&...) = delete; - -} // namespace coda_oss - -#endif // CODA_OSS_coda_oss_memory_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/type_traits.h b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/type_traits.h index 5c92c1d321..a5a3df63a7 100644 --- a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/type_traits.h +++ b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/type_traits.h @@ -24,8 +24,6 @@ #include -#include "CPlusPlus.h" - #include "coda_oss/namespace_.h" namespace coda_oss { diff --git a/externals/coda-oss/modules/c++/mem/include/mem/AutoPtr.h b/externals/coda-oss/modules/c++/mem/include/mem/AutoPtr.h index 0061b47262..ee3eba6010 100644 --- a/externals/coda-oss/modules/c++/mem/include/mem/AutoPtr.h +++ b/externals/coda-oss/modules/c++/mem/include/mem/AutoPtr.h @@ -27,7 +27,6 @@ #include -#include "coda_oss/memory.h" #include "mem/SharedPtr.h" namespace mem diff --git a/externals/coda-oss/modules/c++/mem/include/mem/ScopedPtr.h b/externals/coda-oss/modules/c++/mem/include/mem/ScopedPtr.h index 11a57072b6..8b1c1d0753 100644 --- a/externals/coda-oss/modules/c++/mem/include/mem/ScopedPtr.h +++ b/externals/coda-oss/modules/c++/mem/include/mem/ScopedPtr.h @@ -21,9 +21,11 @@ * */ +#pragma once #ifndef CODA_OSS_mem_ScopedPtr_h_INCLUDED_ #define CODA_OSS_mem_ScopedPtr_h_INCLUDED_ -#pragma once + +#include #include #include @@ -110,15 +112,13 @@ class ScopedPtr auto rhs_ptr = rhs.get(); if (ptr == nullptr && rhs_ptr == nullptr) { - return true; + return true; // both NULL: equal } - if (ptr == nullptr || rhs_ptr == nullptr) { - return false; + return false; // either NULL, but not both (above): not equal } - - return *ptr == *rhs_ptr; + return *ptr == *rhs_ptr; // compare the (non-NULL) objects } bool operator!=(const ScopedPtr& rhs) const noexcept @@ -138,12 +138,16 @@ class ScopedPtr T& operator*() const { - return *get(); + auto ptr = get(); + assert(ptr != nullptr); + return *ptr; } T* operator->() const noexcept { - return get(); + auto ptr = get(); + assert(ptr != nullptr); + return ptr; } void reset(T* ptr = nullptr) diff --git a/externals/coda-oss/modules/c++/mem/include/mem/SharedPtrCpp11.h b/externals/coda-oss/modules/c++/mem/include/mem/SharedPtrCpp11.h index 867634180f..619d7b045e 100644 --- a/externals/coda-oss/modules/c++/mem/include/mem/SharedPtrCpp11.h +++ b/externals/coda-oss/modules/c++/mem/include/mem/SharedPtrCpp11.h @@ -20,14 +20,13 @@ * */ +#pragma once #ifndef CODA_OSS_mem_SharedPtrCpp11_h_INCLUDED_ #define CODA_OSS_mem_SharedPtrCpp11_h_INCLUDED_ -#pragma once #include #include -#include "coda_oss/memory.h" #include "sys/CPlusPlus.h" namespace mem diff --git a/externals/coda-oss/modules/c++/std/include/import/cpp14.h b/externals/coda-oss/modules/c++/std/include/import/cpp14.h index f91af67f17..1bc2640a5f 100644 --- a/externals/coda-oss/modules/c++/std/include/import/cpp14.h +++ b/externals/coda-oss/modules/c++/std/include/import/cpp14.h @@ -21,10 +21,9 @@ * */ - +#pragma once #ifndef CODA_OSS_import_cpp14_h_INCLUDED_ #define CODA_OSS_import_cpp14_h_INCLUDED_ -#pragma once // Common C++14 headers #include diff --git a/externals/coda-oss/modules/c++/std/include/std/cstddef b/externals/coda-oss/modules/c++/std/include/std/cstddef index 5411edfdd0..794d21efb6 100644 --- a/externals/coda-oss/modules/c++/std/include/std/cstddef +++ b/externals/coda-oss/modules/c++/std/include/std/cstddef @@ -18,11 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_cstddef_INCLUDED_ #define CODA_OSS_std_cstddef_INCLUDED_ -#pragma once -#include "coda_oss/CPlusPlus.h" -#include "coda_oss/cstddef.h" +#include #endif // CODA_OSS_std_cstddef_INCLUDED_ \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/std/include/std/memory b/externals/coda-oss/modules/c++/std/include/std/memory index 192f67094b..4cbd01d7cb 100644 --- a/externals/coda-oss/modules/c++/std/include/std/memory +++ b/externals/coda-oss/modules/c++/std/include/std/memory @@ -18,28 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_memory_INCLUDED_ #define CODA_OSS_std_memory_INCLUDED_ -#pragma once #include -#include "coda_oss/memory.h" -#include "coda_oss/CPlusPlus.h" - -// Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_std_make_unique - #if CODA_OSS_cpp14 - #define CODA_OSS_NO_std_make_unique 1 // part of C++14 - #else - #define CODA_OSS_NO_std_make_unique 0 // use our own - #endif -#endif - -#if !CODA_OSS_NO_std_make_unique -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ - using coda_oss::make_unique; -} -#endif // !CODA_OSS_NO_std_make_unique #endif // CODA_OSS_std_memory_INCLUDED_ \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/std/include/std/optional b/externals/coda-oss/modules/c++/std/include/std/optional index fb7122b8af..54345783f6 100644 --- a/externals/coda-oss/modules/c++/std/include/std/optional +++ b/externals/coda-oss/modules/c++/std/include/std/optional @@ -18,11 +18,10 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_optional_INCLUDED_ #define CODA_OSS_std_optional_INCLUDED_ -#pragma once -#include "coda_oss/CPlusPlus.h" -#include "coda_oss/optional.h" +#include #endif // CODA_OSS_std_optional_INCLUDED_ \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/std/include/std/type_traits b/externals/coda-oss/modules/c++/std/include/std/type_traits index 1aba653f96..cbcd0bfd8a 100644 --- a/externals/coda-oss/modules/c++/std/include/std/type_traits +++ b/externals/coda-oss/modules/c++/std/include/std/type_traits @@ -18,30 +18,11 @@ * License along with this program; If not, http://www.gnu.org/licenses/. * */ +#pragma once #ifndef CODA_OSS_std_type_traits_INCLUDED_ #define CODA_OSS_std_type_traits_INCLUDED_ -#pragma once #include -#include "coda_oss/type_traits.h" - -// Make it (too?) easy for clients to get our various std:: implementations -#ifndef CODA_OSS_NO_is_trivially_copyable - // https://stackoverflow.com/a/31798726/8877 - // workaround missing "is_trivially_copyable" in g++ < 5.0 - #if defined(__GNUC__) && (__GNUC__ < 5) - #define CODA_OSS_NO_is_trivially_copyable 0 // *need* our own - #else - #define CODA_OSS_NO_is_trivially_copyable 1 // *disabled*, unless explicitly enabled - #endif -#endif - -#if !CODA_OSS_NO_is_trivially_copyable -namespace std // This is slightly uncouth: we're not supposed to augment "std". -{ - using coda_oss::is_trivially_copyable; -} -#endif // CODA_OSS_NO_is_trivially_copyable #endif // CODA_OSS_std_type_traits_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/str/include/str/Manip.h b/externals/coda-oss/modules/c++/str/include/str/Manip.h index 0e942d91e5..ee95a4663a 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Manip.h +++ b/externals/coda-oss/modules/c++/str/include/str/Manip.h @@ -199,9 +199,6 @@ inline std::string join(const std::vector& toks, const std::string& with) // CASE INSENSTIVE string comparision routines. // Short names w/o a "case insenstive" indicator would seem OK as // normal (i.e., case sensitive) comparisons will use `==` and `!=` operators. -// -// Note that calling ne() directly can be faster than !eq() because the -// comparison can stop as soon as a mis-match is found. CODA_OSS_API bool eq(const std::string& lhs, const std::string& rhs) noexcept; CODA_OSS_API bool ne(const std::string& lhs, const std::string& rhs) noexcept; diff --git a/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp b/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp index a80340a88d..385293601e 100644 --- a/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp +++ b/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp @@ -27,7 +27,6 @@ #include #include -#include "coda_oss/memory.h" #include "coda_oss/span.h" #include "str/Convert.h" diff --git a/externals/coda-oss/modules/c++/str/source/Manip.cpp b/externals/coda-oss/modules/c++/str/source/Manip.cpp index 33cbb47c12..9efdac7166 100644 --- a/externals/coda-oss/modules/c++/str/source/Manip.cpp +++ b/externals/coda-oss/modules/c++/str/source/Manip.cpp @@ -312,6 +312,8 @@ void escapeForXML(std::string& str) // https://en.cppreference.com/w/cpp/string/char_traits class ci_char_traits final : public std::char_traits { + // Use our own routine rather than strcasecmp() so that the same + // toupperCheck() is used as when calling upper(). static auto to_upper(char ch) noexcept { return toupperCheck(ch); diff --git a/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h b/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h index c36c4428e4..4bc9132a3e 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h @@ -62,13 +62,11 @@ namespace sys template inline auto as_bytes(const T& v) noexcept { - static_assert(!std::is_compound::value, "T cannot be a 'struct'"); return sys::as_bytes(&v, 1); } template inline auto as_writable_bytes(T& v) noexcept { - static_assert(!std::is_compound::value, "T cannot be a 'struct'"); return sys::as_writable_bytes(&v, 1); } diff --git a/externals/coda-oss/modules/c++/types/CMakeLists.txt b/externals/coda-oss/modules/c++/types/CMakeLists.txt index 4663df35e9..d1accfb2eb 100644 --- a/externals/coda-oss/modules/c++/types/CMakeLists.txt +++ b/externals/coda-oss/modules/c++/types/CMakeLists.txt @@ -2,7 +2,7 @@ set(MODULE_NAME types) coda_add_module(${MODULE_NAME} VERSION 1.0 - DEPS gsl-c++) + DEPS coda_oss-c++ config-c++ gsl-c++ coda_oss-c++) coda_add_tests( MODULE_NAME ${MODULE_NAME} diff --git a/externals/coda-oss/modules/c++/types/include/types/complex.h b/externals/coda-oss/modules/c++/types/include/types/complex.h new file mode 100644 index 0000000000..f6051594c7 --- /dev/null +++ b/externals/coda-oss/modules/c++/types/include/types/complex.h @@ -0,0 +1,145 @@ +/* ========================================================================= + * This file is part of types-c++ + * ========================================================================= + * + * (C) Copyright 2004 - 2014, MDA Information Systems LLC + * (C) Copyright 2023, Maxar Technologies, Inc. + * + * types-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, + * see . + * + */ + +#pragma once +#ifndef CODA_OSS_types_complex_h_INCLUDED_ +#define CODA_OSS_types_complex_h_INCLUDED_ + +#include + +// TODO: remove this once TIntergers are switched to types::details::complex +// '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. +#ifndef _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING +#define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING +#endif + +#include +#include + +#include "config/disable_compiler_warnings.h" +#include "coda_oss/CPlusPlus.h" + +namespace types +{ +namespace details +{ +/*! + * \class complex + * \brief Our own implementation of std::complex for SIX and friends. + * + * `std::complex` is no longer valid C++; provide a (partial) work-around. + * See https://en.cppreference.com/w/cpp/numeric/complex for detals. + * + * SIX (and others) mostly use `std::complex` as a + * convenient package for two values; very little "complex math" is done + * using integers. + */ +template +struct complex final +{ + using value_type = T; + static_assert(!std::is_floating_point::value, "Use std::complex for floating-point."); + static_assert(std::is_signed::value, "T should be a signed integer."); + + complex(value_type re = 0, value_type im = 0) : z{re, im} {} + complex(const complex&) = default; + complex& operator=(const complex&) = default; + complex(complex&&) = default; + complex& operator=(complex&&) = default; + ~complex() = default; + + // If someone already has a std::complex, is there any harm in creating ours? + complex(const std::complex& z_) : complex(z_.real(), z_.imag()) {} + + value_type real() const + { + return z[0]; + } + void real(value_type value) + { + z[0] = value; + } + + value_type imag() const + { + return z[1]; + } + void imag(value_type value) + { + z[1] = value; + } + +private: + value_type z[2]{0, 0}; +}; + +CODA_OSS_disable_warning_push +#ifdef _MSC_VER +#pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. +#endif + +template +inline const std::complex& cast(const complex& z) +{ + // Getting different results with GCC vs MSVC :-( So just use + // std::complex Assume by the time we're actually using C++23 with a + // compiler that enforces this restriction, "something" will be different. + const void* const pZ_ = &z; + return *static_cast*>(pZ_); +} + +CODA_OSS_disable_warning_pop + +// https://en.cppreference.com/w/cpp/numeric/complex/abs +template +inline auto abs(const complex& z) +{ + return abs(cast(z)); +} + +} + +//// Have the compiler pick between std::complex and details::complex +//template +//using complex = std::conditional_t::value, std::complex, details::complex>; +//static_assert(std::is_same, complex>::value, "should be details::complex"); +template +using complex = std::complex; + +static_assert(std::is_same, complex>::value, "should be std::complex"); +static_assert(sizeof(std::complex) == sizeof(complex), "sizeof(sizeof(std::complex) != sizeof(complex)"); + +// Convenient aliases +using zfloat = complex; // std::complex +using zdouble = complex; // std::complex +//using zlong_double = complex; // std::complex + +// Intentionally using somewhat cumbersome names +// TODO: switch TIntergers to types::details::complex +using zint8_t = complex; // details:complex +using zint16_t = complex; // details:complex +using zint32_t = complex; // details::complex +using zint64_t = complex; // details::complex +} + +#endif // CODA_OSS_types_complex_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp b/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp new file mode 100644 index 0000000000..6410e48f30 --- /dev/null +++ b/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp @@ -0,0 +1,56 @@ +/* ========================================================================= + * This file is part of types-c++ + * ========================================================================= + * + * (C) Copyright 2004 - 2017, MDA Information Systems LLC + * + * types-c++ is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; If not, + * see . + * + */ + +#include "TestCase.h" + +#include + +TEST_CASE(TestCxShort_abs) +{ + constexpr auto real = 123; + constexpr auto imag = -321; + + CODA_OSS_disable_warning_push + #ifdef _MSC_VER + #pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. + #endif + const std::complex cx_short(real, imag); + CODA_OSS_disable_warning_pop + const auto expected = abs(cx_short); + + CODA_OSS_disable_warning_push + #ifdef _MSC_VER + #pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. + #endif + const types::zint16_t types_zint16(cx_short); + CODA_OSS_disable_warning_pop + auto actual = abs(types_zint16); + TEST_ASSERT_EQ(actual, expected); + + const types::complex types_cx_int16(cx_short); + actual = abs(types_cx_int16); + TEST_ASSERT_EQ(actual, expected); +} + +TEST_MAIN( + TEST_CHECK(TestCxShort_abs); + ) diff --git a/externals/coda-oss/modules/c++/types/wscript b/externals/coda-oss/modules/c++/types/wscript index c5134be79b..67379c3bb5 100644 --- a/externals/coda-oss/modules/c++/types/wscript +++ b/externals/coda-oss/modules/c++/types/wscript @@ -1,6 +1,6 @@ NAME = 'types' VERSION = '1.0' -MODULE_DEPS = 'gsl' +MODULE_DEPS = 'coda_oss config gsl coda_oss' UNITTEST_DEPS = 'sys' options = configure = distclean = lambda p: None diff --git a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Document.h b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Document.h index 1d53fdbab2..76ab1dd13a 100644 --- a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Document.h +++ b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Document.h @@ -39,9 +39,8 @@ #include #include -#include +#include #include "coda_oss/string.h" -#include "coda_oss/memory.h" #include "xml/lite/Element.h" #include "xml/lite/QName.h" diff --git a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h index 9ff2089bb9..e8d9e25678 100644 --- a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h +++ b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/MinidomHandler.h @@ -46,9 +46,8 @@ */ #include -#include +#include #include "coda_oss/string.h" -#include "coda_oss/memory.h" #include "str/EncodedString.h" #include "str/EncodedStringView.h" diff --git a/modules/c++/nitf/include/nitf/DecompressionInterface.hpp b/modules/c++/nitf/include/nitf/DecompressionInterface.hpp index 14a75889a7..e7d99487d2 100644 --- a/modules/c++/nitf/include/nitf/DecompressionInterface.hpp +++ b/modules/c++/nitf/include/nitf/DecompressionInterface.hpp @@ -121,7 +121,7 @@ struct DecompressionInterface final * \class Compressor * \brief This is the c++ interface for nitf_CompressionControl */ -struct Decompressor final +struct Decompressor { Decompressor() = default; virtual ~Decompressor() {} @@ -145,4 +145,4 @@ struct Decompressor final } -#endif \ No newline at end of file +#endif diff --git a/modules/c++/nitf/include/nitf/FieldDescriptor.hpp b/modules/c++/nitf/include/nitf/FieldDescriptor.hpp index 1ce6ccedb4..e2d088c5c0 100644 --- a/modules/c++/nitf/include/nitf/FieldDescriptor.hpp +++ b/modules/c++/nitf/include/nitf/FieldDescriptor.hpp @@ -21,15 +21,17 @@ * */ +#pragma once #ifndef NITRO_nitf_FieldDescriptor_hpp_INCLUDED_ #define NITRO_nitf_FieldDescriptor_hpp_INCLUDED_ -#pragma once #include #include #include #include +#include + #include "nitf/FieldDescriptor.h" #include "nitf/Field.hpp" #include "nitf/Object.hpp" @@ -84,8 +86,7 @@ namespace nitf template inline std::vector getFieldDescriptors(const nitf_StructFieldDescriptor(&descriptors)[N]) { - // constexpr auto extent = std::extent::value; - const std::span s(descriptors, N); + const auto s = sys::make_span(descriptors, N); return getFieldDescriptors(s); } } diff --git a/modules/c++/nitf/include/nitf/NITFBufferList.hpp b/modules/c++/nitf/include/nitf/NITFBufferList.hpp index 806559dc12..e03c6c707f 100644 --- a/modules/c++/nitf/include/nitf/NITFBufferList.hpp +++ b/modules/c++/nitf/include/nitf/NITFBufferList.hpp @@ -61,7 +61,7 @@ struct NITRO_NITFCPP_API NITFBuffer std::span getBytes() const noexcept { - return std::span(static_cast(mData), mNumBytes); + return sys::make_span(static_cast(mData), mNumBytes); } }; diff --git a/modules/c++/nitf/include/nitf/SegmentSource.hpp b/modules/c++/nitf/include/nitf/SegmentSource.hpp index 4e6357bc89..3a53c3c255 100644 --- a/modules/c++/nitf/include/nitf/SegmentSource.hpp +++ b/modules/c++/nitf/include/nitf/SegmentSource.hpp @@ -74,9 +74,9 @@ struct NITRO_NITFCPP_API SegmentMemorySource : public SegmentSource SegmentMemorySource(const sys::byte* data, nitf::Off size, nitf::Off start, int byteSkip, bool copyData); - SegmentMemorySource(const std::span& data, nitf::Off start, + SegmentMemorySource(std::span data, nitf::Off start, int byteSkip, bool copyData); - SegmentMemorySource(const std::span& data, nitf::Off start, + SegmentMemorySource(std::span data, nitf::Off start, int byteSkip, bool copyData); SegmentMemorySource(const std::vector& data, nitf::Off start, int byteSkip, bool copyData); diff --git a/modules/c++/nitf/include/nitf/coda-oss.hpp b/modules/c++/nitf/include/nitf/coda-oss.hpp index 9a4dbe7640..bb4e9720ff 100644 --- a/modules/c++/nitf/include/nitf/coda-oss.hpp +++ b/modules/c++/nitf/include/nitf/coda-oss.hpp @@ -73,6 +73,8 @@ #include #include +#include + #if _MSC_VER #pragma warning(pop) #endif // _MSC_VER diff --git a/modules/c++/nitf/source/ByteProvider.cpp b/modules/c++/nitf/source/ByteProvider.cpp index 5d1f564b7a..c908b2a8c5 100644 --- a/modules/c++/nitf/source/ByteProvider.cpp +++ b/modules/c++/nitf/source/ByteProvider.cpp @@ -634,7 +634,7 @@ void ByteProvider::getBytes(const void* imageData, static std::span make_span(const std::vector& v) noexcept { const void* const pData = v.data(); - return std::span(static_cast(pData), v.size()); + return sys::make_span(static_cast(pData), v.size()); } void nitf::ByteProvider::getFileHeader(std::span& result) const noexcept diff --git a/modules/c++/nitf/source/J2KCompressor.cpp b/modules/c++/nitf/source/J2KCompressor.cpp index b648f76c84..98648338e3 100644 --- a/modules/c++/nitf/source/J2KCompressor.cpp +++ b/modules/c++/nitf/source/J2KCompressor.cpp @@ -309,7 +309,7 @@ class TileWriter final for (size_t row = 0; row < resizedTileDims.row; ++row) { const auto srcTileRowStart = tileData + row * tileDims.col; - const std::span src(srcTileRowStart, resizedTileDims.col); + const auto src = sys::make_span(srcTileRowStart, resizedTileDims.col); // partialTileBuffer.data() + row * resizedTileDims.col auto dest = partialTileBuffer.begin(); @@ -390,7 +390,7 @@ class CodestreamOp final mCompressionParams(compressionParams) { mImageBlock.resize(mCompressionParams.getTileDims().area()); - mpImageBlock = std::span(mImageBlock.data(), mImageBlock.size()); + mpImageBlock = sys::make_span(mImageBlock); } CodestreamOp(const CodestreamOp&) = delete; CodestreamOp& operator=(const CodestreamOp&) = delete; @@ -509,8 +509,7 @@ void j2k::Compressor::compress( std::vector& bytesPerTile) const { compressedData.resize(getMaxBytesRequiredToCompress()); - const auto compressedDataView = compress(rawImageData, - std::span(compressedData.data(), compressedData.size()), bytesPerTile); + const auto compressedDataView = compress(rawImageData, sys::make_span(compressedData), bytesPerTile); compressedData.resize(compressedDataView.size()); } @@ -531,7 +530,7 @@ void j2k::Compressor::compressTile( { compressedTile.resize(getMaxBytesRequiredToCompress(1)); std::vector bytesPerTile; - std::span compressedView(compressedTile.data(), compressedTile.size()); + auto compressedView = sys::make_span(compressedTile); compressedView = compressTileSubrange(rawImageData, types::Range(tileIndex, 1), compressedView, bytesPerTile); compressedTile.resize(compressedView.size()); @@ -668,7 +667,7 @@ std::span j2k::Compressor::compressTileSubrange( dest += numBytesThisTile; } - return std::span(compressedData.data(), numBytesWritten); + return sys::make_span(compressedData.data(), numBytesWritten); } diff --git a/modules/c++/nitf/source/J2KReader.cpp b/modules/c++/nitf/source/J2KReader.cpp index 0b2a151e02..647c41b675 100644 --- a/modules/c++/nitf/source/J2KReader.cpp +++ b/modules/c++/nitf/source/J2KReader.cpp @@ -50,12 +50,12 @@ std::span j2k::Reader::readRegion(uint32_t x0, uint32_t y0, uint32_t x1 uint8_t* pBuf = nullptr; const auto bufSize = impl_.callNativeOrThrow(j2k_Reader_readRegion, x0, y0, x1, y1, &pBuf); buf = make_Buffer(pBuf); // turn over ownership (and test our utility routine) - return std::span(buf.get(), bufSize); + return sys::make_span(buf.get(), bufSize); } std::span j2k::Reader::readRegion(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf) { // "buf" is already allocated, maybe from a previous call auto buf_ = buf.data(); const auto bufSize = impl_.callNativeOrThrow(j2k_Reader_readRegion, x0, y0, x1, y1, &buf_); - return std::span(buf_, bufSize); // "bufSize" may have changed + return sys::make_span(buf_, bufSize); // "bufSize" may have changed } \ No newline at end of file diff --git a/modules/c++/nitf/source/J2KWriter.cpp b/modules/c++/nitf/source/J2KWriter.cpp index 31f7219542..afceb6109e 100644 --- a/modules/c++/nitf/source/J2KWriter.cpp +++ b/modules/c++/nitf/source/J2KWriter.cpp @@ -77,6 +77,6 @@ void j2k::WriteTiler::setTile(uint32_t tileX, uint32_t tileY, uint32_t i) const auto offset_ = index * tileSize_ * bytes * numComponents_; const auto offset = gsl::narrow(offset_); - const std::span buf(buf_.data() + offset, tileSize_); + const auto buf = sys::make_span(buf_.data() + offset, tileSize_); writer_.setTile(tileX, tileY, buf); } \ No newline at end of file diff --git a/modules/c++/nitf/source/SegmentSource.cpp b/modules/c++/nitf/source/SegmentSource.cpp index f74d7a7dc0..3a46778905 100644 --- a/modules/c++/nitf/source/SegmentSource.cpp +++ b/modules/c++/nitf/source/SegmentSource.cpp @@ -41,18 +41,18 @@ SegmentMemorySource::SegmentMemorySource(const std::string& data, : SegmentMemorySource(data.c_str(), gsl::narrow(data.size()), start, byteSkip, copyData) { } -SegmentMemorySource::SegmentMemorySource(const std::span& data, nitf::Off start, +SegmentMemorySource::SegmentMemorySource(std::span data, nitf::Off start, int byteSkip, bool copyData) : SegmentMemorySource(data.data(), gsl::narrow(data.size()), start, byteSkip, copyData) { } -static const sys::byte* data(const std::span& data) noexcept +static const sys::byte* data(std::span data) noexcept { const void* pData = data.data(); return static_cast(pData); } -SegmentMemorySource::SegmentMemorySource(const std::span& s, nitf::Off start, +SegmentMemorySource::SegmentMemorySource(std::span s, nitf::Off start, int byteSkip, bool copyData) : SegmentMemorySource(data(s), gsl::narrow(s.size()), start, byteSkip, copyData) { @@ -60,13 +60,13 @@ SegmentMemorySource::SegmentMemorySource(const std::span& s, ni SegmentMemorySource::SegmentMemorySource(const std::vector& data, nitf::Off start, int byteSkip, bool copyData) - : SegmentMemorySource(std::span(data.data(), data.size()), start, byteSkip, copyData) + : SegmentMemorySource(sys::make_span(data), start, byteSkip, copyData) { } SegmentMemorySource::SegmentMemorySource(const std::vector& data, nitf::Off start, int byteSkip, bool copyData) - : SegmentMemorySource(std::span(data.data(), data.size()), start, byteSkip, copyData) + : SegmentMemorySource(sys::make_span(data), start, byteSkip, copyData) { } } diff --git a/modules/c++/nitf/unittests/test_j2k_loading++.cpp b/modules/c++/nitf/unittests/test_j2k_loading++.cpp index aa92ef0760..11cd4bceab 100644 --- a/modules/c++/nitf/unittests/test_j2k_loading++.cpp +++ b/modules/c++/nitf/unittests/test_j2k_loading++.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -270,7 +271,7 @@ void test_j2k_nitf_read_region_(const path& fname) const auto height = container.getHeight(); const auto result_ = j2kReader.readRegion(0, 0, width, height, buf); - const std::span result(result_.data(), result_.size()); + const auto result = sys::make_const_span(result_); const auto namePrefix = str::format("image-%d", (i + 1)); // TODO: Update write to only output tiles in read region @@ -351,9 +352,8 @@ TEST_CASE(test_j2k_compress_raw_image) // Read in the raw data from the input SIO types::RowCol rawDims; std::vector rawImage_; - const sys::filesystem::path inPathname_ = inPathname.string(); - sio::lite::readSIO(inPathname_, rawDims, rawImage_); - const std::span rawImage(rawImage_.data(), rawImage_.size()); + sio::lite::readSIO(inPathname, rawDims, rawImage_); + const auto rawImage = sys::make_span(rawImage_); const auto& tileDims = rawDims; const size_t numThreads = sys::OS().getNumCPUs() - 1; @@ -363,7 +363,7 @@ TEST_CASE(test_j2k_compress_raw_image) std::vector compressedImage_; std::vector bytesPerBlock; compressor.compress(rawImage, compressedImage_, bytesPerBlock); - const std::span compressedImage(compressedImage_.data(), compressedImage_.size()); + const auto compressedImage = sys::make_span(compressedImage_); const auto sumCompressedBytes = std::accumulate(bytesPerBlock.begin(), bytesPerBlock.end(), gsl::narrow(0)); TEST_ASSERT_EQ(sumCompressedBytes, compressedImage.size()); // "Size of compressed image does not match sum of bytes per block"