diff --git a/externals/coda-oss/.gitignore b/externals/coda-oss/.gitignore index d96301f3b..40c572955 100644 --- a/externals/coda-oss/.gitignore +++ b/externals/coda-oss/.gitignore @@ -1,52 +1,55 @@ -*.swp -*~ -*.pyc -__pycache__/ -# Build artifacts - -install/ -install-*/ -target/ - -# Conan -modules/drivers/**/build -test_package/build/ - -# CMake -_deps/ -*.cmake -CMakeCache.txt -CMakeFiles/ -*_config.h -Makefile -modules/**/Makefile -out/ - -# Waf -.waf-* -waf-* -.waf3-* -waf3-* -.lock-waf* -build/waf*/ - -# Eclipse -.project -.cproject - -# Drivers -modules/drivers/fftw/fftw-2.1.*/ -modules/drivers/jpeg/jpeg-9/ -modules/drivers/jpeg/jpeg-9d/ -modules/drivers/j2k/openjpeg/openjpeg-2.3.*_mod/ -modules/drivers/pcre/pcre2-10.*/ -modules/drivers/uuid/e2fsprogs-1.*-uuid/ -modules/drivers/xml/xerces/xerces-c-*/ -modules/drivers/zlib/zlib-1.2.*/ - -# VS -.vs/ -project.sln -.depproj/ - -CMakeSettings.json \ No newline at end of file +*.swp +*~ +*.pyc +__pycache__/ +# Build artifacts + +install/ +install-*/ +target/ + +# Conan +modules/drivers/**/build +test_package/build/ + +# CMake +_deps/ +*.cmake +CMakeCache.txt +CMakeFiles/ +*_config.h +Makefile +modules/**/Makefile +out/ + +# Waf +.waf-* +waf-* +.waf3-* +waf3-* +.lock-waf* +build/waf*/ + +# Eclipse +.project +.cproject + +# Drivers +modules/drivers/fftw/fftw-2.1.*/ +modules/drivers/jpeg/jpeg-9/ +modules/drivers/jpeg/jpeg-9d/ +modules/drivers/j2k/openjpeg/openjpeg-2.3.*_mod/ +modules/drivers/pcre/pcre2-10.*/ +modules/drivers/uuid/e2fsprogs-1.*-uuid/ +modules/drivers/xml/xerces/xerces-c-*/ +modules/drivers/zlib/zlib-1.2.*/ + +# VS +.vs/ +project.sln +.depproj/ +*.tlog +**/x64/ +*.vcxproj.user + +CMakeSettings.json diff --git a/externals/coda-oss/build/build.py b/externals/coda-oss/build/build.py index 25daa2215..a78599549 100644 --- a/externals/coda-oss/build/build.py +++ b/externals/coda-oss/build/build.py @@ -672,11 +672,11 @@ def getPlatform(pwd=None, default=None): for loc in locs: if not exists(loc): continue try: - out = subprocess.Popen('chmod +x %s' % loc, shell=True) + out = subprocess.Popen('chmod +x %s' % loc, shell=True, universal_newlines=True) out.close() except:{} try: - out = subprocess.Popen(loc, shell=True, stdout=PIPE).stdout + out = subprocess.Popen(loc, shell=True, stdout=subprocess.PIPE, universal_newlines=True).stdout platform = out.readline() platform = platform.strip('\n') out.close() @@ -1678,7 +1678,7 @@ def getSolarisFlags(compilerName): # If they don't, default to the old -xtarget flags # TODO: Is there a cleaner way to do this with check_cc() instead? bitFlag64 = '-xtarget=generic64' - (out, err) = subprocess.Popen([compilerName, '-flags'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + (out, err) = subprocess.Popen([compilerName, '-flags'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate() for line in out.split('\n'): if re.match(r'-m64.*', line): diff --git a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj new file mode 100644 index 000000000..af7e4000c --- /dev/null +++ b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj @@ -0,0 +1,504 @@ + + + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + + + + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + + + + + Create + Create + + + + + + + + + + + true + true + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + Win32Proj + {9997e895-5161-4ddf-8f3f-099894cb2f21} + codaoss + 10.0 + coda-oss-lite + + + + DynamicLibrary + true + v143 + + + DynamicLibrary + false + v143 + true + + + + + + + + + + + + + + + true + + + false + + + + EnableAllWarnings + true + _DEBUG;_LIB;%(PreprocessorDefinitions);CODA_OSS_EXPORTS;CODA_OSS_DLL + true + pch.h + cli\include\;coda_oss\include;config\include\;except\include\;gsl\include\;io\include\;math\include\;math.linear\include\;math.poly\include\;mem\include\;polygon\include\;std\include\;str\include\;sys\include\;types\include\;units\include\ + Use + pch.h + true + Guard + true + ProgramDatabase + + + + + true + + + + + Level3 + true + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions);CODA_OSS_EXPORTS;CODA_OSS_DLL + true + pch.h + cli\include\;coda_oss\include;config\include\;except\include\;gsl\include\;io\include\;math\include\;math.linear\include\;math.poly\include\;mem\include\;polygon\include\;std\include\;str\include\;sys\include\;types\include\;units\include\ + Use + pch.h + true + Guard + true + + + + + true + true + true + + + + + + \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters new file mode 100644 index 000000000..1125cbccc --- /dev/null +++ b/externals/coda-oss/modules/c++/coda-oss-lite.vcxproj.filters @@ -0,0 +1,1004 @@ + + + + + + + config + + + config + + + gsl + + + gsl + + + gsl + + + gsl + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + coda_oss + + + except + + + except + + + except + + + except + + + except + + + except + + + except + + + str + + + str + + + str + + + str + + + str + + + str + + + str + + + str + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + types + + + types + + + types + + + types + + + types + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + mem + + + math + + + math + + + math + + + math + + + math + + + units + + + units + + + units + + + math.linear + + + math.linear + + + math.linear + + + math.linear + + + math.linear + + + math.linear + + + math.poly + + + math.poly + + + math.poly + + + math.poly + + + math.poly + + + math.poly + + + math.poly + + + math.poly + + + polygon + + + polygon + + + polygon + + + config + + + include + + + cli + + + cli + + + cli + + + cli + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + + + + except + + + except + + + except + + + except + + + str + + + str + + + str + + + str + + + str + + + str + + + str + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + sys + + + types + + + types + + + mem + + + mem + + + math + + + math + + + math + + + math.linear + + + polygon + + + math\unittests + + + math\unittests + + + math\unittests + + + math\unittests + + + math\unittests + + + math\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + math.linear\unittests + + + str\unittests + + + str\unittests + + + units\unittests + + + mem\unittests + + + mem\unittests + + + mem\unittests + + + mem\unittests + + + mem\unittests + + + mem\unittests + + + mem\unittests + + + cli + + + cli + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + io + + + + + {89602880-5929-45e9-a603-d13f81972397} + + + {619ad1da-f21c-4027-9b5d-23f08225b96f} + + + {59f3d9a1-06d3-4779-aef2-cc55223c3017} + + + {3051f4b6-dad4-47ea-b4bd-d25d9e09f782} + + + {44a8dfa7-099c-4dd5-87b6-3b05ce13580b} + + + {d714ac63-ef19-4629-a13f-59b550604842} + + + {d8059280-e435-4365-be67-865195b9e813} + + + {3613caf2-18d1-4af7-bfa0-a3712a44da45} + + + {0e318d08-1ee3-4644-a299-a81e436c9a32} + + + {6d8f380f-54e3-4d0d-bd1a-a2edd0efbaa7} + + + {1bf84676-4c62-4e2b-b943-59bf82f89126} + + + {b3d7f0e3-2e9f-4a19-b181-27cace7536c0} + + + {15f9b62f-d17e-4d84-bc34-de6fd5fbcb33} + + + {f2544ccb-0933-44c7-af39-cd986982af3d} + + + {82d38fbe-b150-411a-8843-b584142c07ad} + + + {d17adbee-6720-4a93-b45f-2a05eb6a4620} + + + {4cee5537-9ac0-4bb8-9b9f-78aae69d0084} + + + {55522351-e752-4be8-9139-f7ac4b91a66d} + + + {6a70a638-d58c-4e34-87c1-6d1115690de8} + + + {9050a469-23a5-4da0-92b1-a07a8e52e9fc} + + + {de76f131-1cd6-4c3d-aa9c-37ca3b5079f0} + + + {cc681a99-da96-483e-a92a-eab0ea3a0ec0} + + + + + gsl + + + gsl + + + gsl + + + gsl + + + gsl + + + gsl + + + gsl + + + gsl + + + gsl + + + gsl + + + std + + + std + + + std + + + std + + + std + + + std + + + std + + + std + + + sys + + + \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h index 9374afd14..f1f8d72a8 100644 --- a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h +++ b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/CPlusPlus.h @@ -58,10 +58,6 @@ #endif #endif // CODA_OSS_cplusplus -#if CODA_OSS_cplusplus < 201103L -#error "Must compile with C++11 or greater." -#endif - // Define a few macros as that's less verbose than testing against a version number #define CODA_OSS_cpp11 (CODA_OSS_cplusplus >= 201103L) #define CODA_OSS_cpp14 (CODA_OSS_cplusplus >= 201402L) @@ -69,4 +65,8 @@ #define CODA_OSS_cpp20 (CODA_OSS_cplusplus >= 202002L) #define CODA_OSS_cpp23 0 +#if !CODA_OSS_cpp11 +#error "Must compile with C++11 or greater." +#endif + #endif // CODA_OSS_coda_oss_CPlusPlus_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/config/include/config/Exports.h b/externals/coda-oss/modules/c++/config/include/config/Exports.h new file mode 100644 index 000000000..6b77d9fd7 --- /dev/null +++ b/externals/coda-oss/modules/c++/config/include/config/Exports.h @@ -0,0 +1,54 @@ +#ifndef CODA_OSS_config_Exports_h_INCLUDED_ +#define CODA_OSS_config_Exports_h_INCLUDED_ +#pragma once + +#include "config/compiler_extensions.h" + +// Need to specify how this code will be consumed, either CODA_OSS_LIB (static library) +// or CODA_OSS_DLL (aka "shared" library). For DLLs, it needs to be set for BOTH +// "exporting" (building this code) and "importing" (consuming). +// +// Use Windows naming conventions (DLL, LIB) because this really only matters for _MSC_VER, see below. +#if !defined(CODA_OSS_LIB) && !defined(CODA_OSS_DLL) + #define CODA_OSS_LIB 1 + //#define CODA_OSS_DLL 1 +#endif +#if defined(CODA_OSS_LIB) && defined(CODA_OSS_DLL) + #error "Both CODA_OSS_LIB and CODA_OSS_DLL are #define'd'" +#endif +#if defined(CODA_OSS_EXPORTS) && defined(CODA_OSS_LIB) + #error "Can't export from a LIB'" +#endif + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the CODA_OSS_EXPORTS +// symbol defined on the command line. This symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// CODA_OSS_API functions as being imported from a DLL, whereas this DLL sees symbols +// defined with this macro as being exported. +// https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html +#ifdef CODA_OSS_EXPORTS + #define CODA_OSS_API CODA_OSS_library_export +#else + // Either building a static library (no CODA_OSS_EXPORTS) or + // importing (not building) a shared library. + + // We need to know whether we're consuming (importing) a DLL or static LIB + // The default is a static LIB as that's what existing code/builds expect. + #ifdef CODA_OSS_DLL + // Actually, it seems that the linker is able to figure this out from the .LIB, so + // there doesn't seem to be a need for __declspec(dllimport). Clients don't + // need to #define CODA_OSS_DLL ... ? Well, almost ... it looks + // like __declspec(dllimport) is needed to get virtual "inline"s (e.g., + // destructors) correct. + #define CODA_OSS_API CODA_OSS_library_import + #else + #define CODA_OSS_API /* "importing" a static LIB */ + #endif +#endif + +#if defined(_MSC_VER) +#pragma warning(disable: 4251) // '...' : class '...' needs to have dll-interface to be used by clients of struct '...' +#endif + +#endif // CODA_OSS_config_Exports_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/config/include/config/compiler_extensions.h b/externals/coda-oss/modules/c++/config/include/config/compiler_extensions.h index 774ff1d51..1ce9ac953 100644 --- a/externals/coda-oss/modules/c++/config/include/config/compiler_extensions.h +++ b/externals/coda-oss/modules/c++/config/include/config/compiler_extensions.h @@ -23,8 +23,6 @@ #define CODA_OSS_config_compiler_extentions_h_INCLUDED_ #pragma once -#include - #ifndef CODA_OSS_attribute_noinline_DEFINED_ #define CODA_OSS_attribute_noinline_DEFINED_ 1 @@ -144,4 +142,32 @@ } while (0); #endif +#if !defined(CODA_OSS_library_export) && !defined(CODA_OSS_library_import) + + #if defined(__GNUC__) // && HAVE_VISIBILITY + // https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html + #define CODA_OSS_library_export __attribute__((visibility("default"))) + + // For GCC, there's no difference in consuming ("importing") an .a or .so + #define CODA_OSS_library_import /* no __declspec(dllimport) for GCC */ + + #elif defined(_MSC_VER) // && (defined(_WINDLL) && !defined(_LIB)) + #define CODA_OSS_library_export __declspec(dllexport) + + // Actually, it seems that the linker is able to figure this out from the .LIB, + // so there doesn't seem to be a need for __declspec(dllimport). Clients don't + // need to #define NITRO_NITFCPP_DLL ... ? Well, almost ... it looks + // like __declspec(dllimport) is needed to get virtual "inline"s (e.g., + // destructors) correct. + #define CODA_OSS_library_import __declspec(dllimport) + + #else + // https://stackoverflow.com/a/2164853/8877 + #define CODA_OSS_library_export /* do nothing and hope for the best? */ + #define CODA_OSS_library_import /* do nothing and hope for the best? */ + #pragma warning Unknown dynamic link import semantics. + #endif + +#endif + #endif // CODA_OSS_config_compiler_extentions_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/except/include/except/Context.h b/externals/coda-oss/modules/c++/except/include/except/Context.h index bc397e302..c2e683016 100644 --- a/externals/coda-oss/modules/c++/except/include/except/Context.h +++ b/externals/coda-oss/modules/c++/except/include/except/Context.h @@ -27,7 +27,8 @@ #include #include -#include + +#include "config/Exports.h" /*! * \file @@ -44,7 +45,7 @@ namespace except * This class contains information such as the file, line, * function and time */ -struct Context final +struct CODA_OSS_API Context final { /*! * Constructor diff --git a/externals/coda-oss/modules/c++/except/include/except/Throwable.h b/externals/coda-oss/modules/c++/except/include/except/Throwable.h index d07d769b5..ac322a974 100644 --- a/externals/coda-oss/modules/c++/except/include/except/Throwable.h +++ b/externals/coda-oss/modules/c++/except/include/except/Throwable.h @@ -32,6 +32,8 @@ #include // std::accumulate #include +#include "config/Exports.h" +#include "config/compiler_extensions.h" #include "except/Trace.h" /*! @@ -52,7 +54,7 @@ namespace except */ class Throwable11; -class Throwable +class CODA_OSS_API Throwable { void doGetBacktrace(); template @@ -337,7 +339,6 @@ class Throwable11 : public std::exception mutable std::string mWhat; std::vector mBacktrace; }; - } #endif // CODA_OSS_except_Throwable_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/except/include/except/Trace.h b/externals/coda-oss/modules/c++/except/include/except/Trace.h index a7accbb2c..08f8baad7 100644 --- a/externals/coda-oss/modules/c++/except/include/except/Trace.h +++ b/externals/coda-oss/modules/c++/except/include/except/Trace.h @@ -40,7 +40,7 @@ namespace except * \class Trace * \brief Holds stack of context information */ -struct Trace final +struct CODA_OSS_API Trace final { /*! * Gets size of stack @@ -99,7 +99,7 @@ struct Trace final std::list mStack; }; -std::ostream& operator<<(std::ostream& os, const Trace& t); +CODA_OSS_API std::ostream& operator<<(std::ostream& os, const Trace& t); } #endif diff --git a/externals/coda-oss/modules/c++/framework.h b/externals/coda-oss/modules/c++/framework.h new file mode 100644 index 000000000..4b63b165b --- /dev/null +++ b/externals/coda-oss/modules/c++/framework.h @@ -0,0 +1,15 @@ +#pragma once + +#pragma warning(push) +#pragma warning(disable: 5039) // '...': pointer or reference to potentially throwing function passed to 'extern "C"' function under - EHc.Undefined behavior may occur if this function throws an exception. +#pragma warning(disable: 4514) // '...': unreferenced inline function has been removed +#pragma warning(disable: 4365) // '...': conversion from '...' to '...', signed/unsigned mismatch +#pragma warning(disable: 5204) // '...': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#define NOMINMAX // no min()/max() macros +#include +#include +#include +#pragma comment(lib, "Ws2_32") +#pragma warning(pop) diff --git a/externals/coda-oss/modules/c++/include/TestCase.h b/externals/coda-oss/modules/c++/include/TestCase.h index df87d7990..4d7461e0e 100644 --- a/externals/coda-oss/modules/c++/include/TestCase.h +++ b/externals/coda-oss/modules/c++/include/TestCase.h @@ -36,25 +36,71 @@ # define IS_NAN(X) X != X -namespace coda_oss { namespace test { +namespace test { inline void diePrintf(const char* format, const std::string& testName, const char* s) { sys::diePrintf(format, testName.c_str(), s); } +template +inline void diePrintf(const char* format, const std::string& testName, const TX& X) +{ + diePrintf(format, testName, str::toString(X).c_str()); +} inline void diePrintf(const char* format, const std::string& testName, const char* file, const char* func, int line) { sys::diePrintf(format, testName.c_str(), file, func, line); } +template +inline void diePrintf(const char* format, const std::string& testName, const char* file, const char* func, int line, + const TX& X) +{ + sys::diePrintf(format, testName.c_str(), file, func, line, + str::toString(X).c_str()); +} template inline void diePrintf(const char* format, const std::string& testName, const char* file, const char* func, int line, - TX1&& X1, TX2&& X2) + const TX1& X1, const TX2& X2) { sys::diePrintf(format, testName.c_str(), file, func, line, str::toString(X1).c_str(), str::toString(X2).c_str()); } +template +inline void diePrintf_eq(const std::string& testName, const char* file, const char* func, int line, + const TX1& X1, const TX2& X2) +{ + diePrintf("%s (%s,%s,%d): FAILED: Recv'd %s, Expected %s\n", testName, file, func, line, X1, X2); +} +#define CODA_OSS_test_diePrintf_eq_(X1, X2) test::diePrintf_eq(testName, __FILE__, SYS_FUNC, __LINE__, X1, X2) + +template +inline void diePrintf_eq_msg(const std::string& testName, const TMsg& msg, const char* file, int line, + const TX1& X1, const TX2& X2) +{ + sys::diePrintf("%s (%s,%d): FAILED (%s): Recv'd %s, Expected %s\n", testName.c_str(), file, line, (msg).c_str(), + str::toString((X1)).c_str(), str::toString((X2)).c_str()); +} +#define CODA_OSS_test_diePrintf_eq_msg_(msg, X1, X2) test::diePrintf_eq_msg(testName, msg, __FILE__, __LINE__, X1, X2) + +template +inline void diePrintf_ne(const std::string& testName, const char* file, const char* func, int line, + const TX1& X1, const TX2& X2) +{ + diePrintf("%s (%s,%s,%d): FAILED: Recv'd %s should not equal %s\n", testName, file, func, line, X1, X2); +} +#define CODA_OSS_test_diePrintf_not_eq_(X1, X2) test::diePrintf_ne(testName, __FILE__, SYS_FUNC, __LINE__, X1, X2) + +template +inline void diePrintf_ne_msg(const std::string& testName, const TMsg& msg, const char* file, int line, + const TX1& X1, const TX2& X2) +{ + sys::diePrintf("%s (%s,%d): FAILED (%s): Recv'd %s should not equal %s\n", testName.c_str(), file, line, (msg).c_str(), + str::toString((X1)).c_str(), str::toString((X2)).c_str()); +} +#define CODA_OSS_test_diePrintf_not_eq_msg_(msg, X1, X2) test::diePrintf_ne_msg(testName, msg, __FILE__, __LINE__, X1, X2) + template inline void check(TFunc f, const std::string& testName) { @@ -65,7 +111,7 @@ inline void check(TFunc f, const std::string& testName) } catch (const except::Throwable& ex) { - diePrintf("%s: FAILED: Exception thrown: %s\n", testName, ex.toString().c_str()); + diePrintf("%s: FAILED: Exception thrown: %s\n", testName, ex.toString()); } catch (const except::Throwable11& ex) { @@ -74,7 +120,7 @@ inline void check(TFunc f, const std::string& testName) } template -inline void assert_(TX&& X, const std::string& testName, const char* file, const char* func, int line) +inline void assert_(const TX& X, const std::string& testName, const char* file, const char* func, int line) { if (!X) { @@ -83,16 +129,24 @@ inline void assert_(TX&& X, const std::string& testName, const char* file, const } template -inline void assert_null(TX&& X, const std::string& testName, const char* file, const char* func, int line) +inline void assert_null(const TX& X, const std::string& testName, const char* file, const char* func, int line) { if ((X != nullptr) || (!(X == nullptr))) { diePrintf("%s (%s,%s,%d): FAILED: Value should be NULL\n", testName, file, func, line); } } +template +inline void assert_not_null(const TX& X, const std::string& testName, const char* file, const char* func, int line) +{ + if ((X == nullptr) || (!(X != nullptr))) + { + diePrintf("%s (%s,%s,%d): FAILED: Value should *not* be NULL\n", testName, file, func, line); + } +} template -inline void test_assert_false(TX&& X, const std::string& testName, const char* file, const char* func, int line) +inline void test_assert_false(const TX& X, const std::string& testName, const char* file, const char* func, int line) { if (X) { @@ -101,7 +155,7 @@ inline void test_assert_false(TX&& X, const std::string& testName, const char* } template -inline void test_assert_true(TX&& X, const std::string& testName, const char* file, const char* func, int line) +inline void test_assert_true(const TX& X, const std::string& testName, const char* file, const char* func, int line) { if (!X) { @@ -109,105 +163,37 @@ inline void test_assert_true(TX&& X, const std::string& testName, const char* f } } -// These cause warnings (or even errors, depending on compile settings) if the types have different signedness. -// assert_eq(v.size(), 1, ...); -/* -template -inline void assert_eq(TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, const char* func, int line) -{ - if ((X1 != X2) || (!(X1 == X2))) - { - diePrintf("%s (%s,%s,%d): FAILED: Recv'd %s, Expected %s\n", testName, file, func, line, X1, X2); - } -} -template -inline void assert_eq_msg(const std::string& msg, TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, int line) -{ - if ((X1 != X2) || (!(X1 == X2))) - { - die_printf("%s (%s,%d): FAILED (%s): Recv'd %s, Expected %s\n", testName.c_str(), file, line, - msg.c_str(), str::toString(X1).c_str(), str::toString(X2).c_str()); - } -} +// You might be tempted to write something like +// template +// inline void assert_eq(const TX1& X1, const TX2& X2, ...) {} +// A nice thought, but the compiler is able to do more implicit conversions when the code is "inline" +// if (!(X1 == X2)) { ... } +// behaves differently when it is in the functon (X1 and X2 are arguments). An easy example +// is std::vector::size() (size_t) compared to a literal 1 which is an "int" not "size_t". -template -inline void assert_not_eq(TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, const char* func, int line) -{ - if ((X1 == X2) || (!(X1 != X2))) - { - diePrintf("%s (%s,%s,%d): FAILED: Recv'd %s should not equal %s\n", testName, file, func, line, X1, X2); - } -} -*/ template -inline void assert_almost_eq_eps(TX1&& X1, TX2&& X2, TEPS&& EPS, +inline void assert_almost_eq_eps(const TX1& X1, const TX2& X2, const TEPS& EPS, const std::string& testName, const char* file, const char* func, int line) { const auto abs_difference = std::abs(X1 - X2); if (abs_difference > EPS || IS_NAN(abs_difference)) - { - diePrintf("%s (%s,%d): FAILED: Recv'd %s, Expected %s\n", testName, file, func, line, X1, X2); - } -} -template -inline void assert_almost_eq(TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, const char* func, int line) -{ - const auto abs_difference = std::abs(X1 - X2); - if (abs_difference > std::numeric_limits::epsilon() || IS_NAN(abs_difference)) { diePrintf("%s (%s,%s,%d): FAILED: Recv'd %s, Expected %s\n", testName, file, func, line, X1, X2); } } -/* -template -inline void assert_greater_eq(TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, const char* func, int line) -{ - if ((X1 < X2) || (!(X1 >= X2))) - { - diePrintf("%s (%s,%s,%d): FAILED: Value should be greater than or equal\n", testName, file, func, line); - } -} - -template -inline void assert_greater(TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, const char* func, int line) -{ - if ((X1 <= X2) || (!(X1 > X2))) - { - diePrintf("%s (%s,%s,%d): FAILED: Value should be greater than\n", testName, file, func, line); - } -} - template -inline void assert_lesser_eq(TX1&& X1, TX2&& X2, +inline void assert_almost_eq(const TX1& X1, const TX2& X2, const std::string& testName, const char* file, const char* func, int line) { - if ((X1 > X2) || (!(X1 <= X2))) - { - diePrintf("%s (%s,%s,%d): FAILED: Value should be less than or equal\n", testName, file, func, line); - } + const auto eps = std::numeric_limits::epsilon(); + assert_almost_eq_eps(X1, X2, eps, testName, file, func, line); } -template -inline void assert_lesser(TX1&& X1, TX2&& X2, - const std::string& testName, const char* file, const char* func, int line) -{ - if ((X1 >= X2) || (!(X1 < X2))) - { - diePrintf("%s (%s,%s,%d): FAILED: Value should be less than\n", testName, file, func, line); - } -} -*/ template -inline void fail(Tmsg&& msg, +inline void fail(const Tmsg& msg, const std::string& testName, const char* file, const char* func, int line) { - die_printf("%s (%s,%s,%d): FAILED: %s\n", testName.c_str(), file, func, line, str::toString(msg).c_str()); + diePrintf("%s (%s,%s,%d): FAILED: %s\n", testName, file, func, line, msg); } template @@ -277,32 +263,23 @@ inline int main(TFunc f) } return EXIT_FAILURE; } -}} -#define TEST_CHECK(X) coda_oss::test::check([&](const std::string& testName) { X(testName); }, #X) -#define TEST_ASSERT(X) coda_oss::test::assert_(X, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_NULL(X) coda_oss::test::assert_null(X, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_FALSE(X) coda_oss::test::test_assert_false(X, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_TRUE(X) coda_oss::test::test_assert_true(X, testName, __FILE__, SYS_FUNC, __LINE__) -/* -#define TEST_ASSERT_EQ(X1, X2) coda_oss::test::assert_eq(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_EQ_MSG(msg, X1, X2) coda_oss::test::assert_eq_msg(msg, X1, X2, testName, __FILE__, __LINE__) -#define TEST_ASSERT_NOT_EQ(X1, X2) coda_oss::test::assert_not_eq(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -*/ -#define TEST_ASSERT_ALMOST_EQ_EPS(X1, X2, EPS) coda_oss::test::assert_almost_eq_eps(X1, X2, EPS, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_ALMOST_EQ(X1, X2) coda_oss::test::assert_almost_eq(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -/* -#define TEST_ASSERT_GREATER_EQ(X1, X2) coda_oss::test::assert_greater_eq(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_GREATER(X1, X2) coda_oss::test::assert_greater(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_LESSER_EQ(X1, X2) coda_oss::test::assert_lesser_eq(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_ASSERT_LESSER(X1, X2) coda_oss::test::assert_lesser(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) -*/ -#define TEST_FAIL(msg) coda_oss::test::fail(msg, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_EXCEPTION(X) coda_oss::test::exception([&](){(X);}, testName, __FILE__, SYS_FUNC, __LINE__) -#define TEST_THROWS(X) coda_oss::test::throws([&](){(X);}, testName, __FILE__, SYS_FUNC, __LINE__) -# define TEST_SPECIFIC_EXCEPTION(X, Y) coda_oss::test::specific_exception([&](){(X);}, \ +} +#define TEST_CHECK(X) test::check([&](const std::string& testName) { X(testName); }, #X) +#define TEST_ASSERT(X) test::assert_(X, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_ASSERT_NULL(X) test::assert_null(X, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_ASSERT_NOT_NULL(X) test::assert_not_null(X, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_ASSERT_FALSE(X) test::test_assert_false(X, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_ASSERT_TRUE(X) test::test_assert_true(X, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_ASSERT_ALMOST_EQ_EPS(X1, X2, EPS) test::assert_almost_eq_eps(X1, X2, EPS, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_ASSERT_ALMOST_EQ(X1, X2) test::assert_almost_eq(X1, X2, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_FAIL(msg) test::fail(msg, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_EXCEPTION(X) test::exception([&](){(X);}, testName, __FILE__, SYS_FUNC, __LINE__) +#define TEST_THROWS(X) test::throws([&](){(X);}, testName, __FILE__, SYS_FUNC, __LINE__) +# define TEST_SPECIFIC_EXCEPTION(X, Y) test::specific_exception([&](){(X);}, \ "%s (%s,%s,%d): FAILED: Should have thrown exception: " # Y , testName, __FILE__, SYS_FUNC, __LINE__) # define TEST_CASE(X) void X(std::string testName) -#define TEST_MAIN(X) int main(int argc, char** argv) { return coda_oss::test::main([&](){X;}); } +#define TEST_MAIN(X) int main() { return test::main([&](){X;}); } +#define TEST_MAIN_ARGS(X) int main(int argc, char* argv[]) { return test::main([&](){X;}); } /* # define TEST_CHECK(X) try{ X(std::string(#X)); std::cerr << #X << ": PASSED" << std::endl; } \ catch(const except::Throwable& ex) { die_printf("%s: FAILED: Exception thrown: %s\n", std::string(#X).c_str(), ex.toString().c_str()); } \ @@ -312,18 +289,22 @@ inline int main(TFunc f) # define TEST_ASSERT_FALSE(X) if ((X)) { die_printf("%s (%s,%s,%d): FAILED: Value should evaluate to false\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } # define TEST_ASSERT_TRUE(X) if (!(X)) { die_printf("%s (%s,%s,%d): FAILED: Value should evaluate to true\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } */ -# define TEST_ASSERT_EQ(X1, X2) if ((X1) != (X2)) { die_printf("%s (%s,%s,%d): FAILED: Recv'd %s, Expected %s\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__, str::toString(X1).c_str(), str::toString(X2).c_str()); } -# define TEST_ASSERT_EQ_MSG(msg, X1, X2) if ((X1) != (X2)) die_printf("%s (%s,%d): FAILED (%s): Recv'd %s, Expected %s\n", testName.c_str(), __FILE__, __LINE__, (msg).c_str(), str::toString((X1)).c_str(), str::toString((X2)).c_str()); -# define TEST_ASSERT_NOT_EQ(X1, X2) if ((X1) == (X2)) { die_printf("%s (%s,%s,%d): FAILED: Recv'd %s should not equal %s\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__, str::toString(X1).c_str(), str::toString(X2).c_str()); } -# define TEST_ASSERT_NOT_EQ_MSG(msg, X1, X2) if ((X1) == (X2)) die_printf("%s (%s,%d): FAILED (%s): Recv'd %s should not equal %s\n", testName.c_str(), __FILE__, __LINE__, (msg).c_str(), str::toString((X1)).c_str(), str::toString((X2)).c_str()); -/* -# define TEST_ASSERT_ALMOST_EQ_EPS(X1, X2, EPS) if (std::abs((X1) - (X2)) > EPS || IS_NAN(std::abs((X1) - (X2)))) die_printf("%s (%s,%d): FAILED: Recv'd %s, Expected %s\n", testName.c_str(), __FILE__, __LINE__, str::toString((X1)).c_str(), str::toString((X2)).c_str()); -# define TEST_ASSERT_ALMOST_EQ(X1, X2) if (std::abs((X1) - (X2)) > std::numeric_limits::epsilon() || IS_NAN(std::abs((X1) - (X2)))) { die_printf("%s (%s,%s,%d): FAILED: Recv'd %s, Expected %s\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__, str::toString(X1).c_str(), str::toString(X2).c_str()); } -*/ -# define TEST_ASSERT_GREATER_EQ(X1, X2) if ((X1) < X2) { die_printf("%s (%s,%s,%d): FAILED: Value should be greater than or equal\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } -# define TEST_ASSERT_GREATER(X1, X2) if ((X1) <= X2) { die_printf("%s (%s,%s,%d): FAILED: Value should be greater than\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } -# define TEST_ASSERT_LESSER_EQ(X1, X2) if ((X1) > X2) { die_printf("%s (%s,%s,%d): FAILED: Value should be less than or equal\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } -# define TEST_ASSERT_LESSER(X1, X2) if ((X1) >= X2) { die_printf("%s (%s,%s,%d): FAILED: Value should be less than\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } +//#define CODA_OSS_test_eq_(X1, X2) (((X1) == (X2)) && ((X2) == (X1))) // X1 == X2 means X2 == X1 +#define CODA_OSS_test_eq_(X1, X2) ((X1) == (X2)) // above breaks CODA :-( +//#define CODA_OSS_test_ne_(X1, X2) (((X1) != (X2)) && ((X2) != (X1))) // X1 != X2 means X2 != X1 +#define CODA_OSS_test_ne_(X1, X2) ((X1) != (X2)) // above breaks CODA :-( +//#define CODA_OSS_test_ne(X1, X2) (CODA_OSS_test_ne_(X1, X2) && !CODA_OSS_test_eq_(X1, X2)) +#define CODA_OSS_test_ne(X1, X2) CODA_OSS_test_ne_(X1, X2) // above breaks CODA :-( +#define TEST_ASSERT_EQ(X1, X2) if (CODA_OSS_test_ne((X1), (X2))) { CODA_OSS_test_diePrintf_eq_(X1, X2); } +#define TEST_ASSERT_EQ_MSG(msg, X1, X2) if (CODA_OSS_test_ne((X1), (X2))) { CODA_OSS_test_diePrintf_eq_msg_(msg, X1, X2); } +//#define CODA_OSS_test_eq(X1, X2) (CODA_OSS_test_eq_(X1, X2) && !CODA_OSS_test_ne_(X1, X2)) +#define CODA_OSS_test_eq(X1, X2) CODA_OSS_test_eq_(X1, X2) // above breaks CODA :-( +#define TEST_ASSERT_NOT_EQ(X1, X2) if (CODA_OSS_test_eq((X1), (X2))) { CODA_OSS_test_diePrintf_not_eq_(X1, X2); } +#define TEST_ASSERT_NOT_EQ_MSG(msg, X1, X2) if (CODA_OSS_test_eq((X1), (X2))) { CODA_OSS_test_diePrintf_not_eq_msg_(msg, X1, X2); } +# define TEST_ASSERT_GREATER_EQ(X1, X2) if ((X1) < X2) { test::diePrintf("%s (%s,%s,%d): FAILED: Value should be greater than or equal\n", testName, __FILE__, SYS_FUNC, __LINE__); } +# define TEST_ASSERT_GREATER(X1, X2) if ((X1) <= X2) { test::diePrintf("%s (%s,%s,%d): FAILED: Value should be greater than\n", testName, __FILE__, SYS_FUNC, __LINE__); } +# define TEST_ASSERT_LESSER_EQ(X1, X2) if ((X1) > X2) { test::diePrintf("%s (%s,%s,%d): FAILED: Value should be less than or equal\n", testName, __FILE__, SYS_FUNC, __LINE__); } +# define TEST_ASSERT_LESSER(X1, X2) if ((X1) >= X2) { test::diePrintf("%s (%s,%s,%d): FAILED: Value should be less than\n", testName, __FILE__, SYS_FUNC, __LINE__); } /* # define TEST_FAIL(msg) die_printf("%s (%s,%s,%d): FAILED: %s\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__, str::toString(msg).c_str()); # define TEST_EXCEPTION(X) try{ (X); die_printf("%s (%s,%s,%d): FAILED: Should have thrown exception\n", testName.c_str(), __FILE__, SYS_FUNC, __LINE__); } catch (const except::Throwable&){} catch (const except::Throwable11&){} diff --git a/externals/coda-oss/modules/c++/io/source/ByteStream.cpp b/externals/coda-oss/modules/c++/io/source/ByteStream.cpp index 4f557e558..73d70457b 100644 --- a/externals/coda-oss/modules/c++/io/source/ByteStream.cpp +++ b/externals/coda-oss/modules/c++/io/source/ByteStream.cpp @@ -42,6 +42,7 @@ sys::Off_T io::ByteStream::seek(sys::Off_T offset, Whence whence) mPosition = mData.size() - offset; } break; + case CURRENT: default: mPosition += offset; break; diff --git a/externals/coda-oss/modules/c++/io/source/PipeStream.cpp b/externals/coda-oss/modules/c++/io/source/PipeStream.cpp index 2e178ce47..d25658380 100644 --- a/externals/coda-oss/modules/c++/io/source/PipeStream.cpp +++ b/externals/coda-oss/modules/c++/io/source/PipeStream.cpp @@ -20,6 +20,10 @@ * */ #include "io/PipeStream.h" +#undef min +#undef max + +#include "gsl/gsl.h" using namespace io; @@ -32,7 +36,7 @@ sys::SSize_T io::PipeStream::readImpl(void* buffer, size_t numBytes) size_t bytesLeft = numBytes; while (bytesLeft && !feof(pipe)) { - sys::SSize_T bytesRead = fread(cStr, 1, bytesLeft, pipe); + const auto bytesRead = fread(cStr, 1, bytesLeft, pipe); if (bytesRead > 0) { bytesLeft -= bytesRead; @@ -48,7 +52,7 @@ sys::SSize_T io::PipeStream::readImpl(void* buffer, size_t numBytes) if (bytesLeft == numBytes) return IS_EOF; - return numBytes - bytesLeft; + return gsl::narrow(numBytes - bytesLeft); } sys::SSize_T io::PipeStream::readln(sys::byte *cStr, @@ -61,7 +65,7 @@ sys::SSize_T io::PipeStream::readln(sys::byte *cStr, // get the next line or return null if (fgets(cStr, static_cast(strLenPlusNullByte), pipe) != NULL) { - return strlen(cStr); + return gsl::narrow(strlen(cStr)); } // throw if error reading stream @@ -79,30 +83,30 @@ sys::SSize_T io::PipeStream::streamTo(OutputStream& soi, { while (!feof(mExecPipe.getPipe())) { - sys::SSize_T bytesRead = read(mCharString.get(), mBufferSize); + const auto bytesRead = read(mCharString.get(), mBufferSize); if (bytesRead > 0) { - soi.write(mCharString.get(), bytesRead); + soi.write(mCharString.get(), gsl::narrow(bytesRead)); totalBytesRead += bytesRead; } } } else { - sys::Size_T bytesLeft = numBytes; + auto bytesLeft = gsl::narrow(numBytes); while (bytesLeft && !feof(mExecPipe.getPipe())) { // don't read more bytes than streaming forward or buff size - sys::SSize_T bytesRead = read(mCharString.get(), + const auto bytesRead = read(mCharString.get(), std::min(bytesLeft, mBufferSize)); if (bytesRead > 0) { - soi.write(mCharString.get(), bytesRead); + soi.write(mCharString.get(), gsl::narrow(bytesRead)); bytesLeft -= bytesRead; } } - totalBytesRead = numBytes - bytesLeft; + totalBytesRead = gsl::narrow(numBytes - bytesLeft); } // check if didn't read any bytes before end of file diff --git a/externals/coda-oss/modules/c++/math.linear/include/math/linear/Vector.h b/externals/coda-oss/modules/c++/math.linear/include/math/linear/Vector.h index 40bd8c8cd..06089d856 100644 --- a/externals/coda-oss/modules/c++/math.linear/include/math/linear/Vector.h +++ b/externals/coda-oss/modules/c++/math.linear/include/math/linear/Vector.h @@ -395,7 +395,7 @@ template class Vector * comparisons of types other than just Vectors * including fixed type VectorN and std::vector */ - template bool operator==(const Vector_T& v) const + template bool operator_eq(const Vector_T& v) const { size_t sz = v.size(); for (size_t i = 0; i < sz; ++i) @@ -405,12 +405,6 @@ template class Vector return true; } - //! Negate the equality operator - template bool operator!=(const Vector_T& v) const - { - return !(*this == v); - } - /*! * serialize out to a boost stream */ @@ -465,6 +459,17 @@ operator*(_T scalar, const Vector<_T>& v) return v * scalar; } +template +inline bool operator==(const Vector& lhs, const Vector_T& rhs) +{ + return lhs.operator_eq(rhs); +} +template +inline bool operator!=(const Vector& lhs, const Vector_T& rhs) +{ + return !(lhs == rhs); +} + /*! * Pretty(?)-print vector */ diff --git a/externals/coda-oss/modules/c++/math.linear/include/math/linear/VectorN.h b/externals/coda-oss/modules/c++/math.linear/include/math/linear/VectorN.h index 32b6fc8af..6e9b7c177 100644 --- a/externals/coda-oss/modules/c++/math.linear/include/math/linear/VectorN.h +++ b/externals/coda-oss/modules/c++/math.linear/include/math/linear/VectorN.h @@ -342,7 +342,7 @@ template class VectorN return v2; } - template bool operator==(const Vector_T& v) const + template bool operator_eq(const Vector_T& v) const { const auto sz = v.size(); for (size_t i = 0; i < sz; ++i) @@ -353,11 +353,6 @@ template class VectorN return true; } - template bool operator!=(const Vector_T& v) const - { - return !(*this == v); - } - }; template VectorN<3, _T> cross(const VectorN<3, _T>& u, @@ -402,6 +397,18 @@ template } return os; } + +template +inline bool operator==(const VectorN& lhs, const Vector_T& rhs) +{ + return lhs.operator_eq(rhs); +} +template +inline bool operator!=(const VectorN& lhs, const Vector_T& rhs) +{ + return !(lhs == rhs); +} + } // linear } // math diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_Vector.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_Vector.cpp index 9fc40954d..1a4df6d46 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_Vector.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_Vector.cpp @@ -2,12 +2,11 @@ #include "TestCase.h" #include "math/linear/Vector.h" -using namespace math::linear; -using namespace std; - TEST_CASE(testDefaultConstructor) { + using namespace math::linear; + Vector v; TEST_ASSERT_EQ(v.size(), static_cast(0)); } @@ -15,6 +14,8 @@ TEST_CASE(testDefaultConstructor) TEST_CASE(testScalarConstructor) { + using namespace math::linear; + Vector v(3, 42); TEST_ASSERT_EQ(v.size(), static_cast(3)); TEST_ASSERT_EQ(v[0], 42); @@ -26,6 +27,8 @@ TEST_CASE(testScalarConstructor) TEST_CASE(testRawConstructor) { + using namespace math::linear; + double raw[] = {1,2,3}; Vector v(3, raw); TEST_ASSERT_EQ(v.size(), static_cast(3)); @@ -37,6 +40,8 @@ TEST_CASE(testRawConstructor) TEST_CASE(testCopyConstructor) { + using namespace math::linear; + Vector vsrc(3); vsrc[0] = 1; vsrc[1] = 2; @@ -55,10 +60,9 @@ TEST_CASE(testCopyConstructor) TEST_CASE(testStdVectorConstructor) { - std::vector stdvec; - stdvec.push_back(10); - stdvec.push_back(11); - stdvec.push_back(12); + using namespace math::linear; + + std::vector stdvec{10, 11, 12}; Vector v(stdvec); TEST_ASSERT_EQ(v.size(), static_cast(3)); @@ -78,6 +82,8 @@ TEST_CASE(testStdVectorConstructor) TEST_CASE(testAssignmentOperator) { + using namespace math::linear; + Vector vsrc(2); vsrc[0] = 42; vsrc[1] = 99; @@ -92,6 +98,8 @@ TEST_CASE(testAssignmentOperator) TEST_CASE(testScalarAssignment) { + using namespace math::linear; + Vector v(5, 123.456); TEST_ASSERT_EQ(v.size(), static_cast(5)); for (int i = 0; i < 5; i++) @@ -105,10 +113,9 @@ TEST_CASE(testScalarAssignment) TEST_CASE(testStdVectorAssignment) { - std::vector stdvec; - stdvec.push_back(10); - stdvec.push_back(11); - stdvec.push_back(12); + using namespace math::linear; + + const std::vector stdvec{10, 11, 12}; Vector v(20, -1); v = stdvec; @@ -121,6 +128,8 @@ TEST_CASE(testStdVectorAssignment) TEST_CASE(testDotProduct) { + using namespace math::linear; + Vector vd1(5, 2); Vector vd2(5, 3); const double dotprod(vd1.dot(vd2)); @@ -142,10 +151,9 @@ TEST_CASE(testDotProduct) TEST_CASE(testNorm) { - std::vector stdvec; - stdvec.push_back(10); - stdvec.push_back(11); - stdvec.push_back(12); + using namespace math::linear; + + const std::vector stdvec{10, 11, 12}; Vector vnorm1(stdvec); const double norm(vnorm1.norm()); const double arg(10.*10 + 11.*11 + 12.*12); @@ -156,6 +164,8 @@ TEST_CASE(testNorm) TEST_CASE(testNormalize) { + using namespace math::linear; + Vector vnorm(4, 4.0); vnorm.normalize(); TEST_ASSERT_EQ(vnorm[0], 0.5); @@ -167,6 +177,8 @@ TEST_CASE(testNormalize) TEST_CASE(testScale) { + using namespace math::linear; + Vector vscale(2,4.0); vscale.scale(1.0 / 4.0); TEST_ASSERT_EQ(vscale[0], 1.0); @@ -175,6 +187,8 @@ TEST_CASE(testScale) TEST_CASE(testUnit) { + using namespace math::linear; + Vector v(4,4.0); Vector vunit = v.unit(); TEST_ASSERT_EQ(vunit[0], 0.5); @@ -185,6 +199,8 @@ TEST_CASE(testUnit) TEST_CASE(testOperatorPlusEquals) { + using namespace math::linear; + Vector v1(3, 1); Vector v2(3, -1); @@ -205,6 +221,8 @@ TEST_CASE(testOperatorPlusEquals) TEST_CASE(testOperatorPlus) { + using namespace math::linear; + Vector v1(3, 42); Vector v2(3, 11); Vector v3; @@ -231,6 +249,8 @@ TEST_CASE(testOperatorPlus) TEST_CASE(testOperatorMinusEquals) { + using namespace math::linear; + //TODO: Vector& operator-=(const Vector& v) Vector v1(5, 13); Vector v2(5, -5); @@ -247,6 +267,8 @@ TEST_CASE(testOperatorMinusEquals) TEST_CASE(testNegate) { + using namespace math::linear; + Vector X(3); Vector Y(3); X[0] = Y[2] = 1.; @@ -258,6 +280,8 @@ TEST_CASE(testNegate) TEST_CASE(testAdd) { + using namespace math::linear; + Vector v1(3, 2.4); Vector v2(3, 1.4); @@ -284,6 +308,8 @@ TEST_CASE(testAdd) TEST_CASE(testSubtract) { + using namespace math::linear; + Vector v1(3, 2.4); Vector v2(3, 1.4); @@ -310,6 +336,8 @@ TEST_CASE(testSubtract) TEST_CASE(testOperatorMinus) { + using namespace math::linear; + Vector v1(4), v2(4); for (int i = 0; i < 4; i++) { @@ -336,6 +364,8 @@ TEST_CASE(testOperatorMinus) TEST_CASE(testOperatorTimesEquals) { + using namespace math::linear; + Vector v1(4); for (int i = 0; i < 4; i++) v1[i] = i; @@ -356,6 +386,8 @@ TEST_CASE(testOperatorTimesEquals) TEST_CASE(testOperatorTimesEqualsScalar) { + using namespace math::linear; + Vector v1(5); for (int i = 0; i < 5; i++) v1[i] = i; @@ -369,6 +401,8 @@ TEST_CASE(testOperatorTimesEqualsScalar) TEST_CASE(testOperatorTimesScalar) { + using namespace math::linear; + Vector v1(5); for (int i = 0; i < 5; i++) v1[i] = i; @@ -383,6 +417,8 @@ TEST_CASE(testOperatorTimesScalar) TEST_CASE(testElementDivision) { + using namespace math::linear; + Vector numerator(3); numerator[0] = 0; numerator[1] = 1; @@ -402,6 +438,8 @@ TEST_CASE(testElementDivision) TEST_CASE(testOperatorTimes) { + using namespace math::linear; + Vector v1(4); Vector v2(4); for (int i = 0; i < 4; i++) @@ -417,6 +455,8 @@ TEST_CASE(testOperatorTimes) TEST_CASE(testOperatorDivide) { + using namespace math::linear; + Vector v1(4); Vector v2(4); for (int i = 0; i < 4; i++) @@ -430,11 +470,7 @@ TEST_CASE(testOperatorDivide) TEST_ASSERT_EQ(v3[i], i / (i + 2.)); } - - - -int main() -{ +TEST_MAIN( TEST_CHECK(testDefaultConstructor); TEST_CHECK(testScalarConstructor); TEST_CHECK(testRawConstructor); @@ -475,6 +511,4 @@ int main() //TODO: template math::linear::Vector<_T> operator*(const math::linear::Matrix2D<_T>& m, const math::linear::Vector<_T>& v) //TODO: template math::linear::Vector<_T> operator*(_T scalar, const math::linear::Vector<_T>& v) //TODO: template std::ostream& operator<<(std::ostream& os, const math::linear::Vector<_T>& v) - - return EXIT_SUCCESS; -} +) diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_VectorN.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_VectorN.cpp index 26bdc186c..148cd4c18 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_VectorN.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_VectorN.cpp @@ -33,12 +33,10 @@ #include "TestCase.h" #include "math/linear/VectorN.h" -using namespace math::linear; -using namespace std; - - TEST_CASE(testDefaultConstructor) { + using namespace math::linear; + // Solaris doesn't like arrays of zero size unless you use -features=zla, // so I've omitted this test. //VectorN<0, double> v0; @@ -54,6 +52,8 @@ TEST_CASE(testDefaultConstructor) TEST_CASE(testScalarConstructor) { + using namespace math::linear; + VectorN<3,double> v(42); TEST_ASSERT_EQ(v.size(), static_cast(3)); TEST_ASSERT_EQ(v[0], 42); @@ -64,6 +64,8 @@ TEST_CASE(testScalarConstructor) TEST_CASE(testRawConstructor) { + using namespace math::linear; + double raw[] = {1,2,3}; VectorN<3,double> v(raw); TEST_ASSERT_EQ(v.size(), static_cast(3)); @@ -75,6 +77,8 @@ TEST_CASE(testRawConstructor) TEST_CASE(testCopyConstructor) { + using namespace math::linear; + VectorN<3,double> vsrc; vsrc[0] = 1; vsrc[1] = 2; @@ -93,10 +97,9 @@ TEST_CASE(testCopyConstructor) TEST_CASE(testStdVectorConstructor) { - std::vector stdvec; - stdvec.push_back(10); - stdvec.push_back(11); - stdvec.push_back(12); + using namespace math::linear; + + std::vector stdvec{10, 11, 12}; VectorN<3,double> v(stdvec); TEST_ASSERT_EQ(v.size(), static_cast(3)); @@ -116,6 +119,8 @@ TEST_CASE(testStdVectorConstructor) TEST_CASE(testAssignmentOperator) { + using namespace math::linear; + VectorN<2,double> vsrc; vsrc[0] = 42; vsrc[1] = 99; @@ -129,6 +134,8 @@ TEST_CASE(testAssignmentOperator) TEST_CASE(testScalarAssignment) { + using namespace math::linear; + VectorN<5,double> v(123.456); TEST_ASSERT_EQ(v.size(), static_cast(5)); for (int i = 0; i < 5; i++) @@ -146,10 +153,9 @@ TEST_CASE(testScalarAssignment) TEST_CASE(testStdVectorAssignment) { - std::vector stdvec; - stdvec.push_back(10); - stdvec.push_back(11); - stdvec.push_back(12); + using namespace math::linear; + + const std::vector stdvec{10, 11, 12}; VectorN<3,double> v(-1); v = stdvec; @@ -162,6 +168,8 @@ TEST_CASE(testStdVectorAssignment) TEST_CASE(testDotProduct) { + using namespace math::linear; + VectorN<5,double> vd1(2); VectorN<5,double> vd2(3); const double dotprod(vd1.dot(vd2)); @@ -171,10 +179,10 @@ TEST_CASE(testDotProduct) TEST_CASE(testNorm) { - std::vector stdvec; - stdvec.push_back(10); - stdvec.push_back(11); - stdvec.push_back(12); + using namespace math::linear; + + const std::vector stdvec{10, 11, 12}; + VectorN<3,double> vnorm1(stdvec); const double norm(vnorm1.norm()); const double arg(10.*10 + 11.*11 + 12.*12); @@ -185,6 +193,8 @@ TEST_CASE(testNorm) TEST_CASE(testNormalize) { + using namespace math::linear; + VectorN<4,double> vnorm(4.0); vnorm.normalize(); TEST_ASSERT_EQ(vnorm[0], 0.5); @@ -196,6 +206,8 @@ TEST_CASE(testNormalize) TEST_CASE(testScale) { + using namespace math::linear; + VectorN<2,double> vscale(4.0); vscale.scale(1.0 / 4.0); TEST_ASSERT_EQ(vscale[0], 1.0); @@ -204,6 +216,8 @@ TEST_CASE(testScale) TEST_CASE(testUnit) { + using namespace math::linear; + VectorN<4,double> v(4.0); VectorN<4,double> vunit = v.unit(); TEST_ASSERT_EQ(v[0], 4.0); @@ -218,6 +232,8 @@ TEST_CASE(testUnit) TEST_CASE(testOperatorPlusEquals) { + using namespace math::linear; + VectorN<3,double> v1(1); VectorN<3,double> v2(-1); @@ -238,6 +254,8 @@ TEST_CASE(testOperatorPlusEquals) TEST_CASE(testOperatorPlus) { + using namespace math::linear; + VectorN<3,double> v1(42); VectorN<3,double> v2(11); VectorN<3,double> v3; @@ -264,6 +282,8 @@ TEST_CASE(testOperatorPlus) TEST_CASE(testOperatorMinusEquals) { + using namespace math::linear; + VectorN<5,double> v1(13); VectorN<5,double> v2(-5); @@ -279,6 +299,8 @@ TEST_CASE(testOperatorMinusEquals) TEST_CASE(testNegate) { + using namespace math::linear; + VectorN<3,double> X; VectorN<3,double> Y; X[0] = Y[2] = 1.; @@ -290,6 +312,8 @@ TEST_CASE(testNegate) TEST_CASE(testAdd) { + using namespace math::linear; + VectorN<3,double> v1(2.4); VectorN<3,double> v2(1.4); @@ -315,6 +339,8 @@ TEST_CASE(testAdd) TEST_CASE(testSubtract) { + using namespace math::linear; + VectorN<3,double> v1(2.4); VectorN<3,double> v2(1.4); @@ -340,6 +366,8 @@ TEST_CASE(testSubtract) TEST_CASE(testOperatorMinus) { + using namespace math::linear; + VectorN<4,double> v1; VectorN<4,double> v2; for (int i = 0; i < 4; i++) @@ -366,6 +394,8 @@ TEST_CASE(testOperatorMinus) TEST_CASE(testOperatorTimesEquals) { + using namespace math::linear; + VectorN<4,double> v1; for (int i = 0; i < 4; i++) v1[i] = i; @@ -384,6 +414,8 @@ TEST_CASE(testOperatorTimesEquals) TEST_CASE(testOperatorTimesEqualsScalar) { + using namespace math::linear; + VectorN<5,double> v1; for (int i = 0; i < 5; i++) v1[i] = i; @@ -397,6 +429,8 @@ TEST_CASE(testOperatorTimesEqualsScalar) TEST_CASE(testOperatorTimesScalar) { + using namespace math::linear; + VectorN<5,double> v1; for (int i = 0; i < 5; i++) v1[i] = i; @@ -411,6 +445,8 @@ TEST_CASE(testOperatorTimesScalar) TEST_CASE(testElementDivision) { + using namespace math::linear; + VectorN<3,double> numerator; numerator[0] = 0; numerator[1] = 1; @@ -429,6 +465,8 @@ TEST_CASE(testElementDivision) TEST_CASE(testOperatorTimes) { + using namespace math::linear; + VectorN<3,double> v1, v2; for (int i = 0; i < 3; i++) { @@ -444,6 +482,8 @@ TEST_CASE(testOperatorTimes) TEST_CASE(testOperatorDivide) { + using namespace math::linear; + VectorN<3,double> v1, v2; for (int i = 0; i < 3; i++) { @@ -456,9 +496,7 @@ TEST_CASE(testOperatorDivide) TEST_ASSERT_EQ(v3[i], (i + 1.) / (i + 2.)); } - -int main() -{ +TEST_MAIN( TEST_CHECK(testDefaultConstructor); TEST_CHECK(testScalarConstructor); TEST_CHECK(testRawConstructor); @@ -484,6 +522,4 @@ int main() TEST_CHECK(testElementDivision); TEST_CHECK(testOperatorTimes); TEST_CHECK(testOperatorDivide); - - return EXIT_SUCCESS; -} + ) diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_eigenvalue.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_eigenvalue.cpp index ca2454b20..8c0f294c9 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_eigenvalue.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_eigenvalue.cpp @@ -23,8 +23,6 @@ #include "TestCase.h" #include -namespace -{ typedef math::linear::Matrix2D Matrix; typedef math::linear::Vector Vector; typedef math::linear::Eigenvalue Eigenvalue; @@ -88,11 +86,8 @@ TEST_CASE(testSymmetric) } } } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testNonSymmetric); TEST_CHECK(testSymmetric); - return 0; -} + ) \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_inf_equality.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_inf_equality.cpp index f58d52dcc..47e225e51 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_inf_equality.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_inf_equality.cpp @@ -41,10 +41,9 @@ TEST_CASE(differentSignsNe) TEST_ASSERT(!math::linear::equals(std::numeric_limits::infinity(), -std::numeric_limits::infinity())); } -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(positiveInfinityEq); TEST_CHECK(negativeInfinityEq); TEST_CHECK(differentSignsNe); -} + ) diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_inverse.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_inverse.cpp index d4fd9999b..a56fe5ad1 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_inverse.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_inverse.cpp @@ -23,13 +23,9 @@ #include #include "TestCase.h" -namespace -{ -using math::linear::Matrix2D; - TEST_CASE(testLeftRealProperties) { - Matrix2D matrix(4, 2); + math::linear::Matrix2D matrix(4, 2); matrix(0, 0) = 2; matrix(0, 1) = 11.3; matrix(1, 0) = 1; @@ -38,7 +34,7 @@ TEST_CASE(testLeftRealProperties) matrix(2, 1) = 8; matrix(3, 0) = 1.1; matrix(3, 1) = 3.4; - const Matrix2D inverse = math::linear::leftInverse(matrix); + const auto inverse = math::linear::leftInverse(matrix); // Identities that should hold TEST_ASSERT_EQ(matrix, matrix * inverse * matrix); @@ -46,17 +42,17 @@ TEST_CASE(testLeftRealProperties) TEST_ASSERT_EQ(matrix, math::linear::rightInverse(inverse)); // We want this to be able to solve linear equations - Matrix2D xx(2, 1); + math::linear::Matrix2D xx(2, 1); xx(0, 0) = 1; xx(1, 0) = 5; - const Matrix2D yy = matrix * xx; + const auto yy = matrix * xx; TEST_ASSERT_EQ(inverse * yy, xx); } TEST_CASE(testRightRealProperties) { - Matrix2D matrix(4, 2); + math::linear::Matrix2D matrix(4, 2); matrix(0, 0) = 2; matrix(0, 1) = 11.3; matrix(1, 0) = 1; @@ -70,25 +66,22 @@ TEST_CASE(testRightRealProperties) matrix = matrix.transpose(); // Identities that should hold - const Matrix2D inverse = math::linear::rightInverse(matrix); + const auto inverse = math::linear::rightInverse(matrix); TEST_ASSERT_EQ(matrix, matrix * inverse * matrix); TEST_ASSERT_EQ(inverse, inverse * matrix * inverse); TEST_ASSERT_EQ(matrix, math::linear::leftInverse(inverse)); - Matrix2D xx(1, 2); + math::linear::Matrix2D xx(1, 2); xx(0, 0) = 1; xx(0, 1) = 5; // We want this to be able to solve linear equations - const Matrix2D yy = xx * matrix; + const auto yy = xx * matrix; TEST_ASSERT_EQ(yy * inverse, xx); } -} -int main(int /*argc*/, char** /*argv*/) -{ +TEST_MAIN( TEST_CHECK(testLeftRealProperties); TEST_CHECK(testRightRealProperties); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_lin.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_lin.cpp index 8dbabad5a..3dc706ea9 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_lin.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_lin.cpp @@ -33,19 +33,18 @@ line = result[1]; */ -using namespace math::linear; -typedef MatrixMxN<2, 2> Matrix2x2; -typedef MatrixMxN<3, 2> Matrix3x2; -typedef MatrixMxN<3, 3> Matrix3x3; -typedef MatrixMxN<4, 4> Matrix4x4; -typedef VectorN<3> Vector3; -typedef VectorN<2> Vector2; +typedef math::linear::MatrixMxN<2, 2> Matrix2x2; +typedef math::linear::MatrixMxN<3, 2> Matrix3x2; +typedef math::linear::MatrixMxN<3, 3> Matrix3x3; +typedef math::linear::MatrixMxN<4, 4> Matrix4x4; +typedef math::linear::VectorN<3> Vector3; +typedef math::linear::VectorN<2> Vector2; TEST_CASE(testEquality) { std::vector v1(3, 3); - Vector<> v2(3, 3); + math::linear::Vector<> v2(3, 3); Vector3 v3(3); if (v2 != v1) @@ -60,7 +59,7 @@ TEST_CASE(testEquality) TEST_CASE(testPtrAssign) { std::vector v1(3, 42); - Vector<> v2(v1.size(), &v1[0]); + math::linear::Vector<> v2(v1.size(), &v1[0]); Vector3 v3(&v1[0]); if (v2 != v1) @@ -71,7 +70,7 @@ TEST_CASE(testPtrAssign) TEST_CASE(testSTLVectorAssign) { std::vector v1(3, 42); - Vector<> v2(v1); + math::linear::Vector<> v2(v1); Vector3 v3(&v1[0]); if (v2 != v1) @@ -81,13 +80,13 @@ TEST_CASE(testSTLVectorAssign) TEST_CASE(testEmptyDim) { - Matrix2D AScale(3, 0); + math::linear::Matrix2D AScale(3, 0); } TEST_CASE(testPtrDecorator) { std::vector v1(9, 1); - Matrix2D AScale(3, 3, &v1[0], false); + math::linear::Matrix2D AScale(3, 3, &v1[0], false); AScale.scale(5); std::vector v5(9, 5); @@ -100,15 +99,15 @@ TEST_CASE(testPtrDecorator) TEST_CASE(testPtrAdopt) { // valgrind to ensure that we don't have a leak - Matrix2D AScale(3, 3, new double[9], true); + math::linear::Matrix2D AScale(3, 3, new double[9], true); } TEST_CASE(testArithmetic) { - Matrix2D A = identityMatrix(3); + auto A = math::linear::identityMatrix(3); Matrix3x3 A2( &(A.get())[0] ); - Vector x = constantVector(3, 1.2); + auto x = math::linear::constantVector(3, 1.2); x[2] = 2; Vector3 x2(x.matrix().row(0)); @@ -117,7 +116,7 @@ TEST_CASE(testArithmetic) TEST_ASSERT_EQ(x, x2); TEST_ASSERT_EQ(A2, A); - Vector b = A * x; + math::linear::Vector b = A * x; TEST_ASSERT_EQ(b, x); } @@ -130,7 +129,7 @@ TEST_CASE(testLinear) 0.547728758202852, -0.181368192064663, 0.816761156241381 }; - Matrix2D<> mx1(3, 3, q); + math::linear::Matrix2D<> mx1(3, 3, q); Matrix3x3 mx2(q); @@ -138,7 +137,7 @@ TEST_CASE(testLinear) Vector3 u1(mx2.row(0)); // This one doesnt know how big it is unless you tell it - Vector<> u2(3, mx1.row(0)); + math::linear::Vector<> u2(3, mx1.row(0)); TEST_ASSERT_EQ(u1, u2); // Notice that it doesnt matter which matrix the row came @@ -150,7 +149,7 @@ TEST_CASE(testLinear) Vector3 v1(mx1.row(1)); Vector3 w1 = mx2.row(2); - Vector3 w2 = cross(u1, v1); + Vector3 w2 = math::linear::cross(u1, v1); TEST_ASSERT_EQ(w2, w1); Vector3 w3 = u1.dot(v1); @@ -167,7 +166,7 @@ TEST_CASE(testNormalize) Vector3 v1(d); v1.normalize(); - Vector<> v2(3, d); + math::linear::Vector<> v2(3, d); v2.normalize(); @@ -181,8 +180,7 @@ TEST_CASE(testNormalize) TEST_ASSERT_ALMOST_EQ(v1[2], truth[2]); } -int main() -{ +TEST_MAIN( TEST_CHECK(testEquality); TEST_CHECK(testNormalize); TEST_CHECK(testPtrAssign); @@ -218,4 +216,4 @@ int main() std::cout << cross(v3, y) << std::endl; */ -} +) \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/math.linear/unittests/test_mx.cpp b/externals/coda-oss/modules/c++/math.linear/unittests/test_mx.cpp index 42461e71c..ca57f038a 100644 --- a/externals/coda-oss/modules/c++/math.linear/unittests/test_mx.cpp +++ b/externals/coda-oss/modules/c++/math.linear/unittests/test_mx.cpp @@ -22,13 +22,11 @@ #include #include "TestCase.h" -using namespace math::linear; - -typedef MatrixMxN<2, 2> Matrix2x2; -typedef MatrixMxN<3, 2> Matrix3x2; -typedef MatrixMxN<3, 3> Matrix3x3; -typedef MatrixMxN<4, 4> Matrix4x4; -typedef MatrixMxN<5, 5> Matrix5x5; +typedef math::linear::MatrixMxN<2, 2> Matrix2x2; +typedef math::linear::MatrixMxN<3, 2> Matrix3x2; +typedef math::linear::MatrixMxN<3, 3> Matrix3x3; +typedef math::linear::MatrixMxN<4, 4> Matrix4x4; +typedef math::linear::MatrixMxN<5, 5> Matrix5x5; #define foreach_ij(M, N) \ for (unsigned int i = 0; i < M; ++i) \ @@ -36,6 +34,8 @@ typedef MatrixMxN<5, 5> Matrix5x5; TEST_CASE(testIdentityMxN) { + using namespace math::linear; + Matrix3x3 A = identityMatrix<3, double>(); foreach_ij(3, 3) { @@ -67,6 +67,8 @@ TEST_CASE(testIdentityMxN) TEST_CASE(testScaleMultiplyMxN) { + using namespace math::linear; + Matrix3x3 A = identityMatrix<3, double>(); Matrix3x2 B = constantMatrix<3, 2, double>(1); @@ -83,6 +85,8 @@ TEST_CASE(testScaleMultiplyMxN) TEST_CASE(testNegateMxN) { + using namespace math::linear; + const Matrix3x3 A = identityMatrix<3, double>(); const Matrix3x3 B = -A; Matrix3x3 C = A; @@ -98,6 +102,8 @@ TEST_CASE(testNegateMxN) TEST_CASE(testNegate) { + using namespace math::linear; + const Matrix2D A = identityMatrix<3, double>(); const Matrix2D B = -A; Matrix2D C = A; @@ -113,6 +119,8 @@ TEST_CASE(testNegate) TEST_CASE(testInvert2x2Complex) { + using namespace math::linear; + std::complex q[4]; q[0] = std::complex(-0.326773864841957, -0.326773864841957); q[1] = std::complex( 0.945102555946311, 0.945102555946311); @@ -141,6 +149,8 @@ TEST_CASE(testInvert2x2Complex) } TEST_CASE(testInvert2x2) { + using namespace math::linear; + double q[] = { -0.326773864841957, 0.945102555946311, @@ -164,6 +174,8 @@ TEST_CASE(testInvert2x2) } TEST_CASE(testInvert3x3) { + using namespace math::linear; + double q[] = { -0.8335, -0.3467, 0.4302, @@ -193,6 +205,7 @@ TEST_CASE(testInvert3x3) TEST_CASE(testInvert4x4) { + using namespace math::linear; double q[] = { @@ -252,6 +265,8 @@ TEST_CASE(testInvert4x4) TEST_CASE(testOrthoTranspose5x5) { + using namespace math::linear; + double q[] = { 0.206598102328096, -0.258732861775711, -0.366144101439697, 0.808267284061313, 0.320962653355259, @@ -285,6 +300,8 @@ TEST_CASE(testOrthoTranspose5x5) TEST_CASE(testInvert5x5) { + using namespace math::linear; + double q[] = { -0.1, -0.0, 0.6, -0.3, 0.6, @@ -331,6 +348,8 @@ TEST_CASE(testInvert5x5) TEST_CASE(testSTLVectorAssign) { + using namespace math::linear; + std::vector v(9); for (unsigned int i = 0; i < 9; ++i) v[i] = 2 * (i+1); @@ -370,6 +389,8 @@ TEST_CASE(testSTLVectorAssign) TEST_CASE(testPtrAssign) { + using namespace math::linear; + double d[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18 }; Matrix2x2 A(d); @@ -406,6 +427,8 @@ TEST_CASE(testPtrAssign) TEST_CASE(testPermuteInvert2x2) { + using namespace math::linear; + std::vector p(2); p[0] = 1; p[1] = 0; @@ -437,6 +460,8 @@ TEST_CASE(testPermuteInvert2x2) TEST_CASE(testSetCols) { + using namespace math::linear; + MatrixMxN<3, 2> A(0.0); Matrix2D<> A2(3, 2); // Make it so each column vector has the same values @@ -458,6 +483,8 @@ TEST_CASE(testSetCols) TEST_CASE(testSetRows) { + using namespace math::linear; + MatrixMxN<3, 2> A; Matrix2D<> A2(3, 2); std::vector v(3, 0); @@ -483,6 +510,8 @@ TEST_CASE(testSetRows) } TEST_CASE(testGrabCols) { + using namespace math::linear; + MatrixMxN<3, 2> A; Matrix2D<> A2(3, 2); foreach_ij(3, 2) @@ -505,6 +534,8 @@ TEST_CASE(testGrabCols) TEST_CASE(testGrabRows) { + using namespace math::linear; + MatrixMxN<3, 2> A; Matrix2D<> A2(3, 2); foreach_ij(3, 2) @@ -530,6 +561,8 @@ TEST_CASE(testGrabRows) TEST_CASE(testArithmeticMxN) { + using namespace math::linear; + // 2 1 // 1 3 Matrix2x2 D(1); @@ -570,9 +603,7 @@ TEST_CASE(testArithmeticMxN) } -int main() -{ - +TEST_MAIN( TEST_CHECK(testIdentityMxN); TEST_CHECK(testScaleMultiplyMxN); TEST_CHECK(testSetRows); @@ -591,6 +622,4 @@ int main() TEST_CHECK(testOrthoTranspose5x5); TEST_CHECK(testNegateMxN); TEST_CHECK(testNegate); - - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/math/include/import/math.h b/externals/coda-oss/modules/c++/math/include/import/math.h new file mode 100644 index 000000000..841e943ef --- /dev/null +++ b/externals/coda-oss/modules/c++/math/include/import/math.h @@ -0,0 +1,33 @@ +/* ========================================================================= + * This file is part of math-c++ + * ========================================================================= + * + * (C) Copyright 2004 - 2014, MDA Information Systems LLC + * + * mem-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_math_import_h_INCLUDED_ +#define CODA_OSS_math_import_h_INCLUDED_ +#pragma once + +#include +#include +#include +#include +#include + +#endif // CODA_OSS_math_import_h_INCLUDED_ \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/math/include/math/Bessel.h b/externals/coda-oss/modules/c++/math/include/math/Bessel.h index c381cdb33..c7fb37cff 100644 --- a/externals/coda-oss/modules/c++/math/include/math/Bessel.h +++ b/externals/coda-oss/modules/c++/math/include/math/Bessel.h @@ -24,28 +24,31 @@ #define __MATH_BESSEL_H #include + +#include "config/Exports.h" + namespace math { /*! * Modified Bessel function of the first kind * This function wraps the following order-specific functions */ -double besselI(size_t order, double x); +CODA_OSS_API double besselI(size_t order, double x); /*! * Modified Bessel function of the first kind, order 0 */ -double besselIOrderZero(double x); +CODA_OSS_API double besselIOrderZero(double x); /*! * Modified Bessel function of the first kind, order 1 */ -double besselIOrderOne(double x); +CODA_OSS_API double besselIOrderOne(double x); /*! * Modified Bessel function of the first kind, order n > 1 */ -double besselIOrderN(size_t order, double x); +CODA_OSS_API double besselIOrderN(size_t order, double x); } #endif diff --git a/externals/coda-oss/modules/c++/math/include/math/Round.h b/externals/coda-oss/modules/c++/math/include/math/Round.h index ec207c7c1..d14151004 100644 --- a/externals/coda-oss/modules/c++/math/include/math/Round.h +++ b/externals/coda-oss/modules/c++/math/include/math/Round.h @@ -26,6 +26,8 @@ #include #include +#include "config/Exports.h" + namespace math { /*! @@ -78,7 +80,7 @@ template inline T round(T value, size_t fractionalDigits) * \return Result of division, rounded up * \throw if denominator is 0 */ -size_t ceilingDivide(size_t numerator, size_t denominator); +CODA_OSS_API size_t ceilingDivide(size_t numerator, size_t denominator); } #endif diff --git a/externals/coda-oss/modules/c++/math/include/math/Utilities.h b/externals/coda-oss/modules/c++/math/include/math/Utilities.h index 887ff64bb..df8c3be8d 100644 --- a/externals/coda-oss/modules/c++/math/include/math/Utilities.h +++ b/externals/coda-oss/modules/c++/math/include/math/Utilities.h @@ -25,10 +25,11 @@ #include #include -#include -#include #include +#include +#include "config/Exports.h" + namespace math { /*! @@ -64,9 +65,9 @@ template inline bool isNaN(T value) noexcept } // https://man7.org/linux/man-pages/man3/sincos.3.html -void SinCos(float angle, float& sin, float& cos) noexcept; -void SinCos(double angle, double& sin, double& cos) noexcept; -void SinCos(long double angle, long double& sin, long double& cos) noexcept; +CODA_OSS_API void SinCos(float angle, float& sin, float& cos) noexcept; +CODA_OSS_API void SinCos(double angle, double& sin, double& cos) noexcept; +CODA_OSS_API void SinCos(long double angle, long double& sin, long double& cos) noexcept; /* * Calculate the binomial coefficient @@ -76,7 +77,7 @@ void SinCos(long double angle, long double& sin, long double& cos) noexcept; * \param k number of outcomes * \return n choose k */ -sys::Uint64_T nChooseK(size_t n, size_t k); +CODA_OSS_API sys::Uint64_T nChooseK(size_t n, size_t k); } #endif diff --git a/externals/coda-oss/modules/c++/math/unittests/test_bessel_functions.cpp b/externals/coda-oss/modules/c++/math/unittests/test_bessel_functions.cpp index 3fc183ec1..d2aa4096a 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_bessel_functions.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_bessel_functions.cpp @@ -23,8 +23,6 @@ #include #include -namespace -{ TEST_CASE(orderZero) { TEST_ASSERT_ALMOST_EQ(math::besselI(0, 1), 1.266065878); @@ -45,13 +43,10 @@ TEST_CASE(orderFive) TEST_ASSERT_ALMOST_EQ(math::besselI(5, 0), 0); TEST_ASSERT_ALMOST_EQ(math::besselI(5, 1), 2.71463156e-4); } -} -int main(int /*argc*/, char** /*argv*/) -{ +TEST_MAIN( TEST_CHECK(orderZero); TEST_CHECK(orderOne); TEST_CHECK(orderFive); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/math/unittests/test_convex_hull.cpp b/externals/coda-oss/modules/c++/math/unittests/test_convex_hull.cpp index ee961e790..7a32f26f2 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_convex_hull.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_convex_hull.cpp @@ -24,8 +24,6 @@ #include #include "TestCase.h" -namespace -{ TEST_CASE(testConvexHull) { // Add in all the points @@ -76,10 +74,7 @@ TEST_CASE(testConvexHull) TEST_ASSERT_EQ(convexHull[ii].col, expectedConvexHull[ii].col); } } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testConvexHull); - return 0; -} +) \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/math/unittests/test_is_nan.cpp b/externals/coda-oss/modules/c++/math/unittests/test_is_nan.cpp index 23575d055..fd096716c 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_is_nan.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_is_nan.cpp @@ -24,8 +24,6 @@ #include #include -namespace -{ TEST_CASE(testIsNaNOnWeirdNumbers) { TEST_ASSERT(!math::isNaN(std::numeric_limits::infinity())); @@ -40,12 +38,9 @@ TEST_CASE(testNaNs) TEST_ASSERT(math::isNaN(std::numeric_limits::signaling_NaN())); } -} -int main() -{ +TEST_MAIN( TEST_CHECK(testIsNaNOnWeirdNumbers); TEST_CHECK(testNaNs); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/math/unittests/test_n_choose_k.cpp b/externals/coda-oss/modules/c++/math/unittests/test_n_choose_k.cpp index 478324f3e..c6259d87d 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_n_choose_k.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_n_choose_k.cpp @@ -23,8 +23,6 @@ #include #include -namespace -{ TEST_CASE(testNChooseK) { TEST_ASSERT_EQ(math::nChooseK(0, 0), static_cast(1)); @@ -46,12 +44,9 @@ TEST_CASE(testNLessThanK) } TEST_ASSERT(exceptionCaught); } -} -int main() -{ +TEST_MAIN( TEST_CHECK(testNChooseK); TEST_CHECK(testNLessThanK); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/math/unittests/test_round.cpp b/externals/coda-oss/modules/c++/math/unittests/test_round.cpp index f761634b8..1a30713f1 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_round.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_round.cpp @@ -27,8 +27,6 @@ #include #include -namespace -{ TEST_CASE(testFix) { float v1 = 12.3f; @@ -176,13 +174,10 @@ TEST_CASE(testCeilingDivide) size_t d3 = 0; TEST_THROWS(math::ceilingDivide(n3, d3)); } -} -int main() -{ +TEST_MAIN( TEST_CHECK(testFix); TEST_CHECK(testRound); TEST_CHECK(testRoundDigits); TEST_CHECK(testCeilingDivide); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp b/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp index a280b32de..51d7f510e 100644 --- a/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp +++ b/externals/coda-oss/modules/c++/math/unittests/test_sign.cpp @@ -24,8 +24,6 @@ #include #include -namespace -{ TEST_CASE(testZero) { TEST_ASSERT_EQ(math::sign(0), 0); @@ -44,13 +42,10 @@ TEST_CASE(testNegative) TEST_ASSERT_EQ(math::sign(-std::numeric_limits::epsilon()), -1); TEST_ASSERT_EQ(math::sign(-0.1), -1); } -} -int main(int /*argc*/, char** /*argv*/) -{ +TEST_MAIN( TEST_CHECK(testZero); TEST_CHECK(testPositive); TEST_CHECK(testNegative); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/include/mem/ScratchMemory.h b/externals/coda-oss/modules/c++/mem/include/mem/ScratchMemory.h index 2eb5c9113..1a89da787 100644 --- a/externals/coda-oss/modules/c++/mem/include/mem/ScratchMemory.h +++ b/externals/coda-oss/modules/c++/mem/include/mem/ScratchMemory.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace mem { @@ -46,7 +47,7 @@ namespace mem * The get method may be used afterwards to obtain pointers to the memory * segments. */ -class ScratchMemory +class CODA_OSS_API ScratchMemory { public: //! Default constructor @@ -161,7 +162,7 @@ class ScratchMemory ScratchMemory& operator=(const ScratchMemory&) = delete; private: - struct Segment + struct CODA_OSS_API Segment final { Segment(size_t numBytes, size_t numBuffers, size_t alignment, size_t offset); diff --git a/externals/coda-oss/modules/c++/mem/include/mem/SharedPtr.h b/externals/coda-oss/modules/c++/mem/include/mem/SharedPtr.h index f8254bbae..296de8d7b 100644 --- a/externals/coda-oss/modules/c++/mem/include/mem/SharedPtr.h +++ b/externals/coda-oss/modules/c++/mem/include/mem/SharedPtr.h @@ -26,8 +26,6 @@ #include -#include - // Adding a forward declaration here in order to have SWIG correctly generate // bindings for SharedPtr. // diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_Span.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_Span.cpp index 34f135b6c..119c5a65d 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_Span.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_Span.cpp @@ -29,14 +29,11 @@ #include "TestCase.h" -namespace -{ - - template static void testSpanBuffer_(const std::string& testName, const TContainer& ints, const TSpan& span) { + (void)testName; TEST_ASSERT_EQ(ints.size(), span.size()); TEST_ASSERT_EQ(ints.data(), span.data()); @@ -55,7 +52,7 @@ TEST_CASE(testSpanBuffer) { std::vector ints{1, 2, 3, 4, 5}; const coda_oss::span span(ints.data(), ints.size()); - testSpanBuffer_(testName, ints, span); + testSpanBuffer_("testSpanBuffer", ints, span); } } @@ -64,6 +61,7 @@ static void testSpanVector_(const std::string& testName, const TContainer& ints, const TSpan& span) { + (void)testName; TEST_ASSERT_EQ(ints.size(), span.size()); TEST_ASSERT_EQ(ints.data(), span.data()); @@ -79,7 +77,7 @@ TEST_CASE(testSpanVector) { std::vector ints{1, 2, 3, 4, 5}; const coda_oss::span span(ints.data(), ints.size()); - testSpanVector_(testName, ints, span); + testSpanVector_("testSpanVector", ints, span); } } @@ -95,12 +93,9 @@ TEST_CASE(testGslNarrow) TEST_THROWS(gsl::narrow(d)); } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testSpanBuffer); TEST_CHECK(testSpanVector); TEST_CHECK(testGslNarrow); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_scoped_cloneable_ptr.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_scoped_cloneable_ptr.cpp index d170074e1..cead2b360 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_scoped_cloneable_ptr.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_scoped_cloneable_ptr.cpp @@ -27,8 +27,6 @@ #include "TestCase.h" -namespace -{ struct Foo final { int val1 = 0; @@ -209,10 +207,8 @@ TEST_CASE(testEqualityOperator) TEST_ASSERT_FALSE(ptr1 != ptr2); } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testCopyConstructor); TEST_CHECK(testSharedCopyConstructor); TEST_CHECK(testAssignmentOperator); @@ -220,6 +216,4 @@ int main(int, char**) TEST_CHECK(testDestructor); TEST_CHECK(testSyntax); TEST_CHECK(testEqualityOperator); - - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_scoped_copyable_ptr.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_scoped_copyable_ptr.cpp index 46d663931..8fae1f608 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_scoped_copyable_ptr.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_scoped_copyable_ptr.cpp @@ -26,8 +26,6 @@ #include "TestCase.h" -namespace -{ struct Foo final { int val1 = 0; @@ -200,10 +198,8 @@ TEST_CASE(testEqualityOperator) TEST_ASSERT_FALSE(ptr1 != ptr2); } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testCopyConstructor); TEST_CHECK(testSharedCopyConstructor); TEST_CHECK(testAssignmentOperator); @@ -211,6 +207,4 @@ int main(int, char**) TEST_CHECK(testDestructor); TEST_CHECK(testSyntax); TEST_CHECK(testEqualityOperator); - - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_scratch_memory.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_scratch_memory.cpp index 1db04a7e0..421f4eb05 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_scratch_memory.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_scratch_memory.cpp @@ -30,8 +30,6 @@ #include #include "TestCase.h" -namespace -{ TEST_CASE(testReleaseSingleEndBuffer) { //A single release of the last element. Tests with different scratch templates. @@ -622,10 +620,8 @@ TEST_CASE(testScratchMemory) mem::BufferView invalidBuffer(NULL, buffer.size); TEST_EXCEPTION(scratch.setup(invalidBuffer)); } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testScratchMemory); TEST_CHECK(testReleaseSingleEndBuffer); TEST_CHECK(testReleaseMultipleEndBuffers); @@ -634,6 +630,4 @@ int main(int, char**) TEST_CHECK(testReleaseConcurrentKeys); TEST_CHECK(testReleaseConnectedKeys); TEST_CHECK(testGenerateBuffersForRelease); - - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_shared_ptr.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_shared_ptr.cpp index 77874fed3..866df1eb7 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_shared_ptr.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_shared_ptr.cpp @@ -20,13 +20,10 @@ * */ -#include #include #include "TestCase.h" -namespace -{ struct Foo { Foo(size_t val) : @@ -349,10 +346,8 @@ TEST_CASE(testStdSharedPtr) TEST_ASSERT_EQ(cpp11Function(fooLegacy), static_cast(123)); } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testNullCopying); TEST_CHECK(testAutoPtrConstructor); TEST_CHECK(testAutoPtrReset); @@ -361,6 +356,4 @@ int main(int, char**) TEST_CHECK(testSyntax); TEST_CHECK(testCasting); TEST_CHECK(testStdSharedPtr); - - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_unique_ptr.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_unique_ptr.cpp index a76349084..a43442c69 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_unique_ptr.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_unique_ptr.cpp @@ -22,13 +22,10 @@ #include -#include #include #include "TestCase.h" -namespace -{ struct Foo final { Foo() = default; @@ -77,7 +74,6 @@ TEST_CASE(test_make_unique) TEST_ASSERT_EQ(0, pFoos[122].mVal); } -#if CODA_OSS_lib_make_unique { auto fooCtor = std::make_unique(123); TEST_ASSERT_NOT_EQ(nullptr, fooCtor.get()); @@ -89,15 +85,9 @@ TEST_CASE(test_make_unique) TEST_ASSERT_EQ(0, pFoos[0].mVal); TEST_ASSERT_EQ(0, pFoos[122].mVal); } -#endif -} - } -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testStdUniquePtr); TEST_CHECK(test_make_unique); - - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mem/unittests/test_vector_pointers.cpp b/externals/coda-oss/modules/c++/mem/unittests/test_vector_pointers.cpp index 7631e5ec5..a4d5da5d1 100644 --- a/externals/coda-oss/modules/c++/mem/unittests/test_vector_pointers.cpp +++ b/externals/coda-oss/modules/c++/mem/unittests/test_vector_pointers.cpp @@ -24,9 +24,6 @@ #include "TestCase.h" -namespace -{ - TEST_CASE(testVecOfRawPointers) { mem::VectorOfPointers myVec; @@ -117,11 +114,8 @@ TEST_CASE(testVecOfSharedPointers) } } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testVecOfRawPointers); TEST_CHECK(testVecOfSharedPointers); - return 0; -} + ) diff --git a/externals/coda-oss/modules/c++/mt/include/mt/GenerationThreadPool.h b/externals/coda-oss/modules/c++/mt/include/mt/GenerationThreadPool.h index 0de601b13..c047110aa 100644 --- a/externals/coda-oss/modules/c++/mt/include/mt/GenerationThreadPool.h +++ b/externals/coda-oss/modules/c++/mt/include/mt/GenerationThreadPool.h @@ -32,6 +32,8 @@ #include "mt/BasicThreadPool.h" #include "mt/CPUAffinityInitializer.h" #include "mt/CPUAffinityThreadInitializer.h" +#include "mt/Runnable1D.h" + namespace mt { @@ -105,6 +107,35 @@ namespace mt waitGroup(); } + + /*! + * \brief Runs a given operation on a sequence of numbers in parallel + * + * \param numElements The number of elements to run - op will be called + * with 0 through numElements-1 + * \param op A function-like object taking a parameter of type + * size_t which will be called for each number in the + * given range + */ + template + void run1D(size_t numElements, const OpT& op) + { + std::vector runnables; + const ThreadPlanner planner(numElements, mNumThreads); + + size_t threadNum(0); + size_t startElement(0); + size_t numElementsThisThread(0); + while(planner.getThreadInfo(threadNum++, startElement, numElementsThisThread)) + { + runnables.push_back(new Runnable1D( + startElement, numElementsThisThread, op)); + } + addAndWaitGroup(runnables); + + } + + }; } #endif diff --git a/externals/coda-oss/modules/c++/pch.cpp b/externals/coda-oss/modules/c++/pch.cpp new file mode 100644 index 000000000..91c22df2a --- /dev/null +++ b/externals/coda-oss/modules/c++/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: source file corresponding to the pre-compiled header + +#include "pch.h" + +// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/externals/coda-oss/modules/c++/pch.h b/externals/coda-oss/modules/c++/pch.h new file mode 100644 index 000000000..c28fa07e2 --- /dev/null +++ b/externals/coda-oss/modules/c++/pch.h @@ -0,0 +1,57 @@ +// pch.h: This is a precompiled header file. +// Files listed below are compiled only once, improving build performance for future builds. +// This also affects IntelliSense performance, including code completion and many code browsing features. +// However, files listed here are ALL re-compiled if any one of them is updated between builds. +// Do not add files here that you will be updating frequently as this negates the performance advantage. + +#ifndef CODA_OSS_pch_h_INCLUDED_ +#define CODA_OSS_pch_h_INCLUDED_ + +#pragma warning(disable: 4820) // '...': '...' bytes padding added after data member '...' +#pragma warning(disable: 4710) // '...': function not inlined +#pragma warning(disable: 5045) // Compiler will insert Spectre mitigation for memory load if / Qspectre switch specified +#pragma warning(disable: 4668) // '...' is not defined as a preprocessor macro, replacing with '...' for '...' + +// add headers that you want to pre-compile here +#include "framework.h" + +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#pragma warning(disable: 4514) // '...': unreferenced inline function has been removed + +#endif //CODA_OSS_pch_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/std/include/std/bit b/externals/coda-oss/modules/c++/std/include/std/bit index ef4ad98f4..7ce052c0a 100644 --- a/externals/coda-oss/modules/c++/std/include/std/bit +++ b/externals/coda-oss/modules/c++/std/include/std/bit @@ -23,19 +23,20 @@ #pragma once // Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/bit.h" - #ifndef CODA_OSS_NO_std_endian - #define CODA_OSS_NO_std_endian 0 // enabled, unless explicitly disabled - #include "coda_oss/CPlusPlus.h" #if CODA_OSS_cpp17 // Some C++17 implementations have #if __has_include() // __has_include is C++17 #include - #undef CODA_OSS_NO_std_endian - #define CODA_OSS_NO_std_endian 1 // don't need our own + #define CODA_OSS_NO_std_endian 1 // provided by implementation, probably C++20 + #else + #include "coda_oss/bit.h" + #define CODA_OSS_NO_std_endian 0 // no , use our own #endif + #else + #include "coda_oss/bit.h" + #define CODA_OSS_NO_std_endian 0 // < C++17, use our own #endif #endif diff --git a/externals/coda-oss/modules/c++/std/include/std/cstddef b/externals/coda-oss/modules/c++/std/include/std/cstddef index c899d777e..694a46161 100644 --- a/externals/coda-oss/modules/c++/std/include/std/cstddef +++ b/externals/coda-oss/modules/c++/std/include/std/cstddef @@ -25,14 +25,13 @@ #include // Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/cstddef.h" - #ifndef CODA_OSS_NO_std_byte - #define CODA_OSS_NO_std_byte 0 // enabled, unless explicitly disabled - #if defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603L) // https://en.cppreference.com/w/cpp/utility/feature_test #undef CODA_OSS_NO_std_byte - #define CODA_OSS_NO_std_byte 1 // don't need our own + #define CODA_OSS_NO_std_byte 1 // provided by implementation, probably C++20 + #else + #include "coda_oss/cstddef.h" + #define CODA_OSS_NO_std_byte 0 // use our own #endif #endif diff --git a/externals/coda-oss/modules/c++/std/include/std/filesystem b/externals/coda-oss/modules/c++/std/include/std/filesystem index c3f9e1040..ec66c945f 100644 --- a/externals/coda-oss/modules/c++/std/include/std/filesystem +++ b/externals/coda-oss/modules/c++/std/include/std/filesystem @@ -23,19 +23,17 @@ #pragma once // Make it (too?) easy for clients to get our various std:: implementations -#include "sys/filesystem.h" - #ifndef CODA_OSS_NO_std_filesystem - #define CODA_OSS_NO_std_filesystem 0 // enabled, unless explicitly disabled - #include "coda_oss/CPlusPlus.h" #if CODA_OSS_cpp17 // Some versions of G++ say they're C++17 but don't have #if __has_include() // __has_include is C++17 #include - #undef CODA_OSS_NO_std_filesystem - #define CODA_OSS_NO_std_filesystem 1 // don't need our own + #define CODA_OSS_NO_std_filesystem 1 // part of C++17 #endif + #else + #include "sys/filesystem.h" + #define CODA_OSS_NO_std_filesystem 0 // use our own #endif #endif diff --git a/externals/coda-oss/modules/c++/std/include/std/memory b/externals/coda-oss/modules/c++/std/include/std/memory index 292dc4796..7415030be 100644 --- a/externals/coda-oss/modules/c++/std/include/std/memory +++ b/externals/coda-oss/modules/c++/std/include/std/memory @@ -25,14 +25,13 @@ #include // Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/memory.h" - #ifndef CODA_OSS_NO_std_make_unique - #define CODA_OSS_NO_std_make_unique 0 // enabled, unless explicitly disabled - - #if defined(__cpp_lib_make_unique) && (__cpp_lib_make_unique >= 201304L) // https://en.cppreference.com/w/cpp/utility/feature_test - #undef CODA_OSS_NO_std_make_unique - #define CODA_OSS_NO_std_make_unique 1 // don't need our own + #include "coda_oss/CPlusPlus.h" + #if CODA_OSS_cpp14 + #define CODA_OSS_NO_std_make_unique 1 // part of C++14 + #else + #include "coda_oss/memory.h" + #define CODA_OSS_NO_std_make_unique 0 // use our own #endif #endif diff --git a/externals/coda-oss/modules/c++/std/include/std/optional b/externals/coda-oss/modules/c++/std/include/std/optional index 57f9f5741..276cdee13 100644 --- a/externals/coda-oss/modules/c++/std/include/std/optional +++ b/externals/coda-oss/modules/c++/std/include/std/optional @@ -23,16 +23,14 @@ #pragma once // Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/optional.h" - #ifndef CODA_OSS_NO_std_optional - #define CODA_OSS_NO_std_optional 0 // enabled, unless explicitly disabled - #include "coda_oss/CPlusPlus.h" #if CODA_OSS_cpp17 #include - #undef CODA_OSS_NO_std_optional - #define CODA_OSS_NO_std_optional 1 // don't need our own + #define CODA_OSS_NO_std_optional 1 // part of C++17 + #else + #include "coda_oss/optional.h" + #define CODA_OSS_NO_std_optional 0 // use our own #endif #endif diff --git a/externals/coda-oss/modules/c++/std/include/std/span b/externals/coda-oss/modules/c++/std/include/std/span index 5433dcfc7..e85d7f716 100644 --- a/externals/coda-oss/modules/c++/std/include/std/span +++ b/externals/coda-oss/modules/c++/std/include/std/span @@ -23,16 +23,14 @@ #pragma once // Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/span.h" - #ifndef CODA_OSS_NO_std_span - #define CODA_OSS_NO_std_span 0 // enabled, unless explicitly disabled - #include "coda_oss/CPlusPlus.h" #if CODA_OSS_cpp20 #include - #undef CODA_OSS_NO_std_span - #define CODA_OSS_NO_std_span 1 // don't need our own + #define CODA_OSS_NO_std_span 1 // part of C++20 + #else + #include "coda_oss/span.h" + #define CODA_OSS_NO_std_span 0 // use our own #endif #endif diff --git a/externals/coda-oss/modules/c++/std/include/std/string b/externals/coda-oss/modules/c++/std/include/std/string index 92bb1ffb5..4af50dbd0 100644 --- a/externals/coda-oss/modules/c++/std/include/std/string +++ b/externals/coda-oss/modules/c++/std/include/std/string @@ -25,19 +25,18 @@ #include // Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/string.h" - #ifndef CODA_OSS_NO_std_u8string - #define CODA_OSS_NO_std_u8string 0 // enabled, unless explicitly disabled - - #if defined(__cpp_char8_t) && (__cpp_char8_t >= 201811L) // https://en.cppreference.com/w/cpp/feature_test - #undef CODA_OSS_NO_std_u8string - #define CODA_OSS_NO_std_u8string 1 // don't need our own + #include "coda_oss/CPlusPlus.h" + #if CODA_OSS_cpp17 + #define CODA_OSS_NO_std_u8string 1 // part of C++17 + #else + #include "coda_oss/string.h" + #define CODA_OSS_NO_std_u8string 0 // use our own #endif #endif -#include "config/compiler_extensions.h" #if !CODA_OSS_NO_std_u8string +#include "config/compiler_extensions.h" namespace std // This is slightly uncouth: we're not supposed to augment "std". { CODA_OSS_disable_warning_push 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 d2c329a55..519877b6e 100644 --- a/externals/coda-oss/modules/c++/std/include/std/type_traits +++ b/externals/coda-oss/modules/c++/std/include/std/type_traits @@ -22,17 +22,17 @@ #define CODA_OSS_std_type_traits_INCLUDED_ #pragma once -// Make it (too?) easy for clients to get our various std:: implementations -#include "coda_oss/type_traits.h" +#include +// Make it (too?) easy for clients to get our various std:: implementations #ifndef CODA_OSS_NO_is_trivially_copyable - #define CODA_OSS_NO_is_trivially_copyable 1 // *disabled*, unless explicitly enabled - // https://stackoverflow.com/a/31798726/8877 // workaround missing "is_trivially_copyable" in g++ < 5.0 #if defined(__GNUC__) && (__GNUC__ < 5) - #undef CODA_OSS_NO_is_trivially_copyable + #include "coda_oss/type_traits.h" #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 diff --git a/externals/coda-oss/modules/c++/str/include/str/Convert.h b/externals/coda-oss/modules/c++/str/include/str/Convert.h index 755490226..a09bf2aa4 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Convert.h +++ b/externals/coda-oss/modules/c++/str/include/str/Convert.h @@ -20,11 +20,10 @@ * */ -#ifndef __STR_CONVERT_H__ -#define __STR_CONVERT_H__ +#ifndef CODA_OSS_str_Convert_h_INCLUDED_ +#define CODA_OSS_str_Convert_h_INCLUDED_ #pragma once -#include #include #include #include @@ -36,8 +35,10 @@ #include #include +#include "config/Exports.h" #include "coda_oss/string.h" #include "coda_oss/optional.h" +#include "import/except.h" namespace str { @@ -59,10 +60,10 @@ std::string toString(const T& value) } template <> -std::string toString(const uint8_t& value); +CODA_OSS_API std::string toString(const uint8_t& value); template <> -std::string toString(const int8_t& value); +CODA_OSS_API std::string toString(const int8_t& value); template <> inline std::string toString(const std::nullptr_t&) @@ -71,7 +72,7 @@ inline std::string toString(const std::nullptr_t&) } template <> -std::string toString(const coda_oss::u8string&); +CODA_OSS_API std::string toString(const coda_oss::u8string&); template std::string toString(const coda_oss::optional& value) @@ -125,11 +126,11 @@ std::string toType(const std::string& s); /** * strtoll wrapper for msvc compatibility. */ -long long strtoll(const char* str, char** endptr, int base); +CODA_OSS_API long long strtoll(const char* str, char** endptr, int base); /** * strtoull wrapper for msvc compatibility. */ -unsigned long long strtoull(const char* str, char** endptr, int base); +CODA_OSS_API unsigned long long strtoull(const char* str, char** endptr, int base); /** * Convert a string containing a number in any base to a numerical type. @@ -239,4 +240,4 @@ T generic_cast(const std::string& value) } -#endif +#endif // CODA_OSS_str_Convert_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/str/include/str/EncodedString.h b/externals/coda-oss/modules/c++/str/include/str/EncodedString.h index c4f2c72f9..7e9c6f1b9 100644 --- a/externals/coda-oss/modules/c++/str/include/str/EncodedString.h +++ b/externals/coda-oss/modules/c++/str/include/str/EncodedString.h @@ -5,7 +5,7 @@ * (C) Copyright 2004 - 2014, MDA Information Systems LLC * (C) Copyright 2022, Maxar Technologies, Inc. * - * xml.lite-c++ is free software; you can redistribute it and/or modify + * str-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. @@ -28,6 +28,7 @@ #include #include +#include "config/Exports.h" #include "str/EncodedStringView.h" /*! @@ -45,7 +46,7 @@ namespace str { -class EncodedString final +class CODA_OSS_API EncodedString final { std::string s_; // We can do most everything through the view, so keep one around. @@ -66,19 +67,17 @@ class EncodedString final ~EncodedString() = default; EncodedString(const EncodedString&); EncodedString& operator=(const EncodedString&); - EncodedString(EncodedString&&) noexcept; - EncodedString& operator=(EncodedString&&) noexcept; + EncodedString(EncodedString&&); + EncodedString& operator=(EncodedString&&); - explicit EncodedString(const coda_oss::u8string& s); explicit EncodedString(coda_oss::u8string::const_pointer); + explicit EncodedString(const coda_oss::u8string& s); explicit EncodedString(const str::W1252string&); explicit EncodedString(str::W1252string::const_pointer); explicit EncodedString(const std::string&); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows explicit EncodedString(std::string::const_pointer); // Assume platform native encoding: UTF-8 on Linux, Windows-1252 on Windows explicit EncodedString(const std::u16string&); // converted to UTF-8 for storage - //explicit EncodedString(std::u16string::const_pointer); // no wcslen() for std::u16string::value_type explicit EncodedString(const std::u32string&); // converted to UTF-8 for storage - //explicit EncodedString(std::u32string::const_pointer); // no wcslen() for std::u32string::value_type explicit EncodedString(const std::wstring&); // Assume platform native encoding: UTF-32 on Linux, UTF-16 on Windows explicit EncodedString(std::wstring::const_pointer); // can call wcslen() @@ -87,10 +86,8 @@ class EncodedString final EncodedString& operator=(const EncodedStringView&); // Input is encoded as specified on all platforms. - static EncodedString fromUtf8(const std::string&); - static EncodedString fromWindows1252(const std::string&); - static EncodedString fromUtf16(const std::wstring&); // not currently implemetned, no need - static EncodedString fromUtf32(const std::wstring&); // not currently implemetned, no need + //static EncodedString fromUtf16(const std::wstring&); // not currently implemetned, no need + //static EncodedString fromUtf32(const std::wstring&); // not currently implemetned, no need // For "complex" operatations, use the view. const EncodedStringView& view() const diff --git a/externals/coda-oss/modules/c++/str/include/str/EncodedStringView.h b/externals/coda-oss/modules/c++/str/include/str/EncodedStringView.h index e75dd3287..14adb68e1 100644 --- a/externals/coda-oss/modules/c++/str/include/str/EncodedStringView.h +++ b/externals/coda-oss/modules/c++/str/include/str/EncodedStringView.h @@ -29,6 +29,7 @@ #include #include "coda_oss/span.h" +#include "config/Exports.h" #include "str/Encoding.h" /*! @@ -46,7 +47,7 @@ namespace str { class EncodedString; // forward -class EncodedStringView final +class CODA_OSS_API EncodedStringView final { // Since we only support two encodings--UTF-8 (native on Linux) and Windows-1252 // (native on Windows)--both of which are 8-bits, a simple "bool" flag will do. @@ -88,35 +89,6 @@ class EncodedStringView final // Can't "view" UTF-16 or UTF-32 data; we assume we're looking at an 8-bit encoding, // either UTF-8 or Windows-1252. - // Input is encoded as specified on all platforms. - template - static EncodedStringView create(const char* s) - { - using const_pointer = typename TBasicString::const_pointer; - return EncodedStringView(str::cast(s)); - } - template - static EncodedStringView create(const std::string& s) - { - return create(s.c_str()); - } - static EncodedStringView fromUtf8(const char* s) - { - return create(s); - } - static EncodedStringView fromUtf8(const std::string& s) - { - return create(s); - } - static EncodedStringView fromWindows1252(const char* s) - { - return create(s); - } - static EncodedStringView fromWindows1252(const std::string& s) - { - return create(s); - } - // Regardless of what string we're looking at, return a string in platform // native encoding: UTF-8 on Linux, Windows-1252 on Windows; this // might result in string conversion. diff --git a/externals/coda-oss/modules/c++/str/include/str/Encoding.h b/externals/coda-oss/modules/c++/str/include/str/Encoding.h index dcafa4711..0cace45b2 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Encoding.h +++ b/externals/coda-oss/modules/c++/str/include/str/Encoding.h @@ -35,6 +35,7 @@ #include "coda_oss/string.h" #include "gsl/gsl.h" +#include "config/Exports.h" // This can be useful for code that will compile on all platforms, but needs // different platform-specific behavior. This avoids the use of more #ifdefs @@ -70,10 +71,11 @@ inline TReturn cast(const TChar* s) static_assert(sizeof(*retval) == sizeof(*s), "sizeof(*TReturn) != sizeof(*TChar)"); return retval; } -template -inline TReturn c_str(const std::basic_string& s) +template +inline typename TBasicStringT::const_pointer c_str(const std::basic_string& s) { - return cast(s.c_str()); + using return_t = typename TBasicStringT::const_pointer; + return cast(s.c_str()); } // This is to make it difficult to get encodings mixed up; it's here (in a .h @@ -81,12 +83,12 @@ inline TReturn c_str(const std::basic_string& s) enum class Windows1252_T : unsigned char { }; // https://en.cppreference.com/w/cpp/language/types using W1252string = std::basic_string; // https://en.cppreference.com/w/cpp/string -coda_oss::u8string fromWindows1252(std::string::const_pointer, size_t); // std::string is Windows-1252 **ON ALL PLATFORMS** +CODA_OSS_API coda_oss::u8string fromWindows1252(std::string::const_pointer, size_t); // std::string is Windows-1252 **ON ALL PLATFORMS** inline coda_oss::u8string fromWindows1252(std::string::const_pointer s) { return fromWindows1252(s, gsl::narrow(strlen(s))); } -coda_oss::u8string fromUtf8(std::string::const_pointer, size_t); // std::string is UTF-8 **ON ALL PLATFORMS** +CODA_OSS_API coda_oss::u8string fromUtf8(std::string::const_pointer, size_t); // std::string is UTF-8 **ON ALL PLATFORMS** inline coda_oss::u8string fromUtf8(std::string::const_pointer s) { return fromUtf8(s, gsl::narrow(strlen(s))); @@ -108,23 +110,23 @@ static_assert(!std::is_same::value, "wchar_t should not be the // When the encoding is important, we want to "traffic" in coda_oss::u8string (UTF-8), not // str::W1252string (Windows-1252) or std::string (unknown). Make it easy to get those from other encodings. -coda_oss::u8string to_u8string(std::string::const_pointer, size_t); // std::string is Windows-1252 or UTF-8 depending on platform -coda_oss::u8string to_u8string(str::W1252string::const_pointer, size_t); +CODA_OSS_API coda_oss::u8string to_u8string(std::string::const_pointer, size_t); // std::string is Windows-1252 or UTF-8 depending on platform +CODA_OSS_API coda_oss::u8string to_u8string(str::W1252string::const_pointer, size_t); inline coda_oss::u8string to_u8string(coda_oss::u8string::const_pointer s, size_t sz) { return coda_oss::u8string(s, sz); } -coda_oss::u8string to_u8string(std::wstring::const_pointer, size_t); // std::wstring is UTF-16 or UTF-32 depending on platform +CODA_OSS_API coda_oss::u8string to_u8string(std::wstring::const_pointer, size_t); // std::wstring is UTF-16 or UTF-32 depending on platform // UTF-16 is typically uses on Windows (where it is std::wstring::value_type); // Linux preferred UTF-32. -coda_oss::u8string to_u8string(std::u16string::const_pointer, size_t); -std::u16string to_u16string(coda_oss::u8string::const_pointer, size_t); +CODA_OSS_API coda_oss::u8string to_u8string(std::u16string::const_pointer, size_t); +CODA_OSS_API std::u16string to_u16string(coda_oss::u8string::const_pointer, size_t); // UTF-32 is convenient because each code-point is a single 32-bit integer. // It's typically std::wstring::value_type on Linux, but NOT Windows. -coda_oss::u8string to_u8string(std::u32string::const_pointer, size_t); -std::u32string to_u32string(coda_oss::u8string::const_pointer, size_t); +CODA_OSS_API coda_oss::u8string to_u8string(std::u32string::const_pointer, size_t); +CODA_OSS_API std::u32string to_u32string(coda_oss::u8string::const_pointer, size_t); template inline coda_oss::u8string to_u8string(const std::basic_string& s) @@ -156,7 +158,7 @@ std::string& to_u8string(std::u32string::const_pointer, size_t, std::string&); / str::W1252string to_w1252string(std::string::const_pointer, size_t); // std::string is Windows-1252 or UTF-8 depending on platform str::W1252string to_w1252string(std::string::const_pointer, size_t, bool is_utf8 /* is 's' UTF-8? */); -str::W1252string to_w1252string(coda_oss::u8string::const_pointer, size_t); +CODA_OSS_API str::W1252string to_w1252string(coda_oss::u8string::const_pointer, size_t); inline str::W1252string to_w1252string(str::W1252string::const_pointer s, size_t sz) { return str::W1252string(s, sz); 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 73d55cb4c..5c612607e 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Manip.h +++ b/externals/coda-oss/modules/c++/str/include/str/Manip.h @@ -30,6 +30,7 @@ #include #include "config/compiler_extensions.h" +#include "config/Exports.h" #include "coda_oss/CPlusPlus.h" #include "str/Convert.h" @@ -66,9 +67,9 @@ inline const CharT* data(const std::basic_string& s) noexcept // to make * Trim the white space off the back and front of a string * @param s String to trim */ -void trim(std::string& s); -extern std::string strip(const std::string& s); -extern std::string& strip(std::string& s); +CODA_OSS_API void trim(std::string& s); +CODA_OSS_API std::string strip(const std::string& s); +CODA_OSS_API std::string& strip(std::string& s); /** * Checks the end of s with match @@ -76,8 +77,8 @@ extern std::string& strip(std::string& s); * @param match String to compare with * @return true if it matches, otherwise false */ -bool endsWith(const std::string& s, const std::string& match); -extern bool ends_with(const std::string& s, const std::string&) noexcept; +CODA_OSS_API bool endsWith(const std::string& s, const std::string& match); +CODA_OSS_API bool ends_with(const std::string& s, const std::string&) noexcept; /** * Checks the start of s with match @@ -85,8 +86,8 @@ extern bool ends_with(const std::string& s, const std::string&) noexcept; * @param s String to compare with * @return true if it matches, otherwise false */ -bool startsWith(const std::string& s, const std::string& match); -extern bool starts_with(const std::string& s, const std::string&) noexcept; +CODA_OSS_API bool startsWith(const std::string& s, const std::string& match); +CODA_OSS_API bool starts_with(const std::string& s, const std::string&) noexcept; /** @@ -100,7 +101,7 @@ extern bool starts_with(const std::string& s, const std::string&) noexcept; * @param start starting position to start search * @return position of first find, str.length() if not found */ -size_t replace(std::string& str, +CODA_OSS_API size_t replace(std::string& str, const std::string& search, const std::string& replace, size_t start = 0); @@ -112,56 +113,56 @@ size_t replace(std::string& str, * @param search String to search for * @param replace String to replace with */ -void replaceAll(std::string& string, +CODA_OSS_API void replaceAll(std::string& string, const std::string& search, const std::string& replace); /** * Returns true if the string contains the match */ -bool contains(const std::string& str, const std::string& match); +CODA_OSS_API bool contains(const std::string& str, const std::string& match); /** * Returns true if the string contains only letters. */ -bool isAlpha(const std::string& s); +CODA_OSS_API bool isAlpha(const std::string& s); /** * Returns true if the string contains only letters and spaces. */ -bool isAlphaSpace(const std::string& s); +CODA_OSS_API bool isAlphaSpace(const std::string& s); /** * Returns true if the string contains only digits. This does not include * decimal points. */ -bool isNumeric(const std::string& s); +CODA_OSS_API bool isNumeric(const std::string& s); /** * Returns true if the string contains only digits and spaces. */ -bool isNumericSpace(const std::string& s); +CODA_OSS_API bool isNumericSpace(const std::string& s); /** * Returns true if the string contains only whitespace characters (or empty). */ -bool isWhitespace(const std::string& s); +CODA_OSS_API bool isWhitespace(const std::string& s); /** * Returns true if the string contains only letters and digits. */ -bool isAlphanumeric(const std::string& s); +CODA_OSS_API bool isAlphanumeric(const std::string& s); /** * Returns true if the string contains only ASCII printable characters. */ -bool isAsciiPrintable(const std::string& s); +CODA_OSS_API bool isAsciiPrintable(const std::string& s); /** * Returns true if the string contains only the given allowed characters. */ -bool containsOnly(const std::string& s, const std::string& validChars); +CODA_OSS_API bool containsOnly(const std::string& s, const std::string& validChars); /** * Splits a string based on a splitter string. Similar to tokenization, except @@ -170,20 +171,20 @@ bool containsOnly(const std::string& s, const std::string& validChars); * @param splitter String to split upon * @return vector of strings */ -std::vector split(const std::string& s, +CODA_OSS_API std::vector split(const std::string& s, const std::string& splitter = " ", size_t maxSplit = std::string::npos); //! Uses std::transform to convert all chars to lower case //! Uses std::transform to convert all chars to upper case -void lower(std::string& s); -void upper(std::string& s); +CODA_OSS_API void lower(std::string& s); +CODA_OSS_API void upper(std::string& s); /*! * Replaces any characters that are invalid in XML (&, <, >, ', ") with their * escaped counterparts */ -void escapeForXML(std::string& str); +CODA_OSS_API void escapeForXML(std::string& str); template std::string join(const std::vector& toks, std::string with) diff --git a/externals/coda-oss/modules/c++/str/source/Convert.cpp b/externals/coda-oss/modules/c++/str/source/Convert.cpp index 2b763da65..fcf1b8d6a 100644 --- a/externals/coda-oss/modules/c++/str/source/Convert.cpp +++ b/externals/coda-oss/modules/c++/str/source/Convert.cpp @@ -98,15 +98,15 @@ unsigned long long str::strtoull(const char *str, char **endptr, int base) #endif } -template<> int str::getPrecision(const float& ) +template<> CODA_OSS_API int str::getPrecision(const float&) { return std::numeric_limits::max_digits10; } -template<> int str::getPrecision(const double& ) +template<> CODA_OSS_API int str::getPrecision(const double& ) { return std::numeric_limits::max_digits10; } -template<> int str::getPrecision(const long double& ) +template <> CODA_OSS_API int str::getPrecision(const long double&) { return std::numeric_limits::max_digits10; } diff --git a/externals/coda-oss/modules/c++/str/source/EncodedString.cpp b/externals/coda-oss/modules/c++/str/source/EncodedString.cpp index fdedd343a..8acbf1d27 100644 --- a/externals/coda-oss/modules/c++/str/source/EncodedString.cpp +++ b/externals/coda-oss/modules/c++/str/source/EncodedString.cpp @@ -21,29 +21,35 @@ * */ +#include + #include "str/EncodedString.h" void str::EncodedString::assign(coda_oss::u8string::const_pointer s) { + using char_t = std::remove_pointer::type; // avoid copy-paste error + using string_t = std::basic_string::type>; s_ = cast(s); // copy - v_ = EncodedStringView(c_str(s_)); // avoid copy-paste error + v_ = EncodedStringView(c_str(s_)); } void str::EncodedString::assign(str::W1252string::const_pointer s) { + using char_t = std::remove_pointer::type; // avoid copy-paste error + using string_t = std::basic_string::type>; s_ = cast(s); // copy - v_ = EncodedStringView(c_str(s_)); // avoid copy-paste error + v_ = EncodedStringView(c_str(s_)); // avoid copy-paste error } static str::EncodedStringView make_EncodedStringView(const std::string& s, bool isUtf8) { if (isUtf8) { - return str::EncodedStringView(str::c_str(s)); + return str::EncodedStringView(str::c_str(s)); } // not UTF-8, assume Windows-1252 - return str::EncodedStringView(str::c_str(s)); + return str::EncodedStringView(str::c_str(s)); } str::EncodedString::EncodedString(std::string::const_pointer s) : s_(s) /*copy*/, v_ (s_) { } @@ -103,7 +109,7 @@ str::EncodedString::EncodedString(const EncodedString& es) *this = es; } -str::EncodedString& str::EncodedString::operator=(EncodedString&& es) noexcept +str::EncodedString& str::EncodedString::operator=(EncodedString&& es) { if (this != &es) { @@ -112,16 +118,7 @@ str::EncodedString& str::EncodedString::operator=(EncodedString&& es) noexcept } return *this; } -str::EncodedString::EncodedString(EncodedString&& es) noexcept +str::EncodedString::EncodedString(EncodedString&& es) { *this = std::move(es); } - -str::EncodedString str::EncodedString::fromUtf8(const std::string& s) -{ - return str::EncodedStringView::fromUtf8(s); -} -str::EncodedString str::EncodedString::fromWindows1252(const std::string& s) -{ - return str::EncodedStringView::fromWindows1252(s); -} diff --git a/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp b/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp index abca1833f..b823158ca 100644 --- a/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp +++ b/externals/coda-oss/modules/c++/str/source/EncodedStringView.cpp @@ -44,7 +44,7 @@ inline coda_oss::span make_span(const CharT* s) template inline coda_oss::span make_span(const std::basic_string& s) { - return coda_oss::span(str::c_str(s), s.size()); + return coda_oss::span(str::c_str(s), s.size()); } str::EncodedStringView::EncodedStringView(std::string::const_pointer p) : mString(make_span(p)) { } diff --git a/externals/coda-oss/modules/c++/str/source/Encoding.cpp b/externals/coda-oss/modules/c++/str/source/Encoding.cpp index 1d29b1978..65c42a213 100644 --- a/externals/coda-oss/modules/c++/str/source/Encoding.cpp +++ b/externals/coda-oss/modules/c++/str/source/Encoding.cpp @@ -101,7 +101,7 @@ static std::map Windows1252_to_u inline void append(std::string& result, const coda_oss::u8string& utf8) { - result += str::c_str(utf8); + result += str::c_str(utf8); } inline void append(coda_oss::u8string& result, const coda_oss::u8string& utf8) { @@ -110,12 +110,12 @@ inline void append(coda_oss::u8string& result, const coda_oss::u8string& utf8) template inline void append(std::basic_string& result, const coda_oss::u8string& utf8) { - auto p = str::cast(utf8.c_str()); + auto p = str::c_str(utf8); utf8::utf8to16(p, p + utf8.size(), std::back_inserter(result)); } inline void append(std::u32string& result, const coda_oss::u8string& utf8) { - auto p = str::cast(utf8.c_str()); + auto p = str::c_str(utf8); utf8::utf8to32(p, p + utf8.size(), std::back_inserter(result)); } @@ -372,7 +372,7 @@ std::wstring str::details::to_wstring(std::string::const_pointer p, size_t sz, b #if !_WIN32 to_u32string(p, sz, is_utf8); // std::wstring is UTF-32 on Linux #endif - return str::c_str(s); // copy + return str::c_str(s); // copy } coda_oss::u8string str::to_u8string(std::wstring::const_pointer p_, size_t sz) // std::wstring is UTF-16 or UTF-32 depending on platform diff --git a/externals/coda-oss/modules/c++/str/unittests/test_base_convert.cpp b/externals/coda-oss/modules/c++/str/unittests/test_base_convert.cpp index bc5b5256b..6f528dfe1 100644 --- a/externals/coda-oss/modules/c++/str/unittests/test_base_convert.cpp +++ b/externals/coda-oss/modules/c++/str/unittests/test_base_convert.cpp @@ -30,25 +30,17 @@ #include #include +#include #include "TestCase.h" -inline std::string to_std_string(const coda_oss::u8string& value) +static std::string to_string(const coda_oss::u8string& value) { - return str::c_str(value); // copy + return str::c_str(value); // copy } -inline std::string to_std_string(const std::u32string& s) +static std::string to_string(const std::u32string& s) { - return to_std_string(str::to_u8string(s)); -} -template -void test_assert_eq(const std::string& testName, - const TActual& actual, const TExpected& expected) -{ - //TEST_ASSERT(actual == expected); - const auto actual_ = to_std_string(actual); - const auto expected_ = to_std_string(expected); - TEST_ASSERT_EQ(actual_, expected_); + return to_string(str::to_u8string(s)); } TEST_CASE(testConvert) @@ -106,7 +98,7 @@ TEST_CASE(test_string_to_u8string_ascii) const std::string input = "|\x00"; // ASCII, "|" const auto actual = fromWindows1252(input); const std::u8string expected{cast8('|')}; // '\x00' is the end of the string in C/C++ - test_assert_eq(testName, actual, expected); + TEST_ASSERT_EQ(actual, expected); } constexpr uint8_t start_of_heading = 0x01; constexpr uint8_t delete_character = 0x7f; @@ -115,9 +107,9 @@ TEST_CASE(test_string_to_u8string_ascii) const std::string input { '|', static_cast(ch), '|'}; const auto actual = fromWindows1252(input); const std::u8string expected8{cast8('|'), cast8(ch), cast8('|')}; - test_assert_eq(testName, actual, expected8); + TEST_ASSERT_EQ(actual, expected8); const std::u32string expected{cast32('|'), cast32(ch), cast32('|')}; - test_assert_eq(testName, actual, expected); + TEST_ASSERT_EQ(to_string(actual), to_string(expected)); } } @@ -128,17 +120,17 @@ TEST_CASE(test_string_to_u8string_windows_1252) const std::string input = "|\x80|"; // Windows-1252, "|�|" const auto actual = fromWindows1252(input); const std::u8string expected8{cast8('|'), cast8('\xE2'), cast8('\x82'), cast8('\xAC'), cast8('|')}; // UTF-8, "|�|" - test_assert_eq(testName, actual, expected8); + TEST_ASSERT_EQ(actual, expected8); const std::u32string expected{cast32('|'), 0x20AC, cast32('|')}; // UTF-32, "|�|" - test_assert_eq(testName, actual, expected); + TEST_ASSERT_EQ(to_string(actual), to_string(expected)); } { const std::string input = "|\x9F|"; // Windows-1252, "|�|" const auto actual = fromWindows1252(input); const std::u8string expected8{cast8('|'), cast8('\xC5'), cast8('\xB8'), cast8('|')}; // UTF-8, "|�|" - test_assert_eq(testName, actual, expected8); + TEST_ASSERT_EQ(actual, expected8); const std::u32string expected{cast32('|'), 0x0178, cast32('|')}; // UTF-32, "|�|" - test_assert_eq(testName, actual, expected); + TEST_ASSERT_EQ(to_string(actual), to_string(expected)); } { const std::vector undefined{ '\x81', '\x8d', '\x8f', '\x90', '\x9d' }; @@ -147,9 +139,9 @@ TEST_CASE(test_string_to_u8string_windows_1252) const std::string input{'|', ch, '|'}; const auto actual = fromWindows1252(input); static const std::u8string expected8{cast8('|'), cast8('\xEF'), cast8('\xBF'), cast8('\xBD'), cast8('|')}; // UTF-8, "||" - test_assert_eq(testName, actual, expected8); + TEST_ASSERT_EQ(actual, expected8); const std::u32string expected{cast32('|'), 0xfffd, cast32('|')}; // UTF-32, "||" - test_assert_eq(testName, actual, expected); + TEST_ASSERT_EQ(to_string(actual), to_string(expected)); } } { @@ -185,7 +177,7 @@ TEST_CASE(test_string_to_u8string_windows_1252) for (const auto& ch : windows1252_characters) { const std::string input_ { '|', static_cast(ch), '|'}; - const str::W1252string input(str::c_str(input_)); + const str::W1252string input(str::c_str(input_)); const auto actual = to_u8string(input); // No "expected" to test against as the UTF-8 values for these Windows-1252 characters @@ -214,10 +206,10 @@ TEST_CASE(test_string_to_u8string_iso8859_1) for (uint32_t ch = nobreak_space; ch <= latin_small_letter_y_with_diaeresis; ch++) // ISO8859-1 { const std::string input_ { '|', static_cast(ch), '|'}; - const str::W1252string input(str::c_str(input_)); + const str::W1252string input(str::c_str(input_)); const auto actual = to_u8string(input); const std::u32string expected{cast32('|'), cast32(ch), cast32('|')}; - test_assert_eq(testName, actual, expected); + TEST_ASSERT_EQ(to_string(actual), to_string(expected)); // Can't compare the values with == because TEST_ASSERT_EQ() // wants to do toString() and that doesn't work on Linux as the encoding @@ -234,6 +226,8 @@ TEST_CASE(test_string_to_u8string_iso8859_1) template static void test_change_case_(const std::string& testName, const TString& lower, const TString& upper) { + (void)testName; + auto s = upper; str::lower(s); TEST_ASSERT(s == lower); @@ -252,7 +246,7 @@ TEST_CASE(test_change_case) { const std::string ABC = "ABC"; const std::string abc = "abc"; - test_change_case_(testName, abc, ABC); + test_change_case_("test_change_case", abc, ABC); //const std::wstring ABC_w = L"ABC"; //const std::wstring abc_w = L"abc"; @@ -270,83 +264,92 @@ TEST_CASE(test_change_case) } // https://en.wikipedia.org/wiki/%C3%89#Character_mappings -static const auto classificationText_utf_8 = str::EncodedString::fromUtf8("NON CLASSIFI\xc3\x89 / UNCLASSIFIED"); // UTF-8 "NON CLASSIFI� / UNCLASSIFIED" -static const auto classificationText_iso8859_1 = str::EncodedString::fromWindows1252("NON CLASSIFI\xc9 / UNCLASSIFIED"); // ISO8859-1 "NON CLASSIFI� / UNCLASSIFIED" +static const str::EncodedString& classificationText_utf_8() +{ + static const str::EncodedString retval(str::cast("NON CLASSIFI\xc3\x89 / UNCLASSIFIED")); // UTF-8 "NON CLASSIFI� / UNCLASSIFIED" + return retval; + } +static const str::EncodedString& classificationText_iso8859_1() +{ + static const str::EncodedString retval(str::cast("NON CLASSIFI\xc9 / UNCLASSIFIED")); // ISO8859-1 "NON CLASSIFI� / UNCLASSIFIED" + return retval; + } // UTF-16 on Windows, UTF-32 on Linux -static const auto classificationText_wide_ = L"NON CLASSIFI\xc9 / UNCLASSIFIED"; // UTF-8 "NON CLASSIFI� / UNCLASSIFIED" -static const str::EncodedString classificationText_wide(classificationText_wide_); -static const auto classificationText_platform = - sys::Platform == sys::PlatformType::Linux ? classificationText_utf_8.native() : classificationText_iso8859_1.native(); +static const wchar_t* classificationText_wide_() { return L"NON CLASSIFI\xc9 / UNCLASSIFIED"; } // UTF-8 "NON CLASSIFI� / UNCLASSIFIED" +static str::EncodedString classificationText_wide() { return str::EncodedString(classificationText_wide_()); } +static std::string classificationText_platform() { return + sys::Platform == sys::PlatformType::Linux ? classificationText_utf_8().native() : classificationText_iso8859_1().native(); } TEST_CASE(test_u8string_to_string) { { - const auto utf8 = classificationText_utf_8.u8string(); + const auto utf8 = classificationText_utf_8().u8string(); const str::EncodedStringView utf8View(utf8); const auto actual = utf8View.native(); - TEST_ASSERT_EQ(classificationText_platform, actual); + TEST_ASSERT_EQ(classificationText_platform(), actual); } { - const auto utf8 = classificationText_iso8859_1.u8string(); + const auto utf8 = classificationText_iso8859_1().u8string(); const str::EncodedStringView utf8View(utf8); const auto actual = utf8View.native(); - TEST_ASSERT_EQ(classificationText_platform, actual); + TEST_ASSERT_EQ(classificationText_platform(), actual); } } TEST_CASE(test_u8string_to_u16string) { #if _WIN32 - const auto actual = classificationText_utf_8.u16string(); - const std::wstring s = str::c_str(actual); // Windows: std::wstring == std::u16string - TEST_ASSERT(classificationText_wide_ == s); // _EQ wants to do toString() + const auto actual = classificationText_utf_8().u16string(); + const std::wstring s = str::c_str(actual); // Windows: std::wstring == std::u16string + TEST_ASSERT(classificationText_wide_() == s); // _EQ wants to do toString() #endif - TEST_ASSERT_EQ(classificationText_wide, classificationText_utf_8); - TEST_ASSERT_EQ(classificationText_wide, classificationText_iso8859_1); + TEST_ASSERT_EQ(classificationText_wide(), classificationText_utf_8()); + TEST_ASSERT_EQ(classificationText_wide(), classificationText_iso8859_1()); - TEST_ASSERT(classificationText_wide.u16string() == classificationText_utf_8.u16string()); // _EQ wants to do toString() - TEST_ASSERT(classificationText_wide.u16string() == classificationText_iso8859_1.u16string()); // _EQ wants to do toString() + TEST_ASSERT(classificationText_wide().u16string() == classificationText_utf_8().u16string()); // _EQ wants to do toString() + TEST_ASSERT(classificationText_wide().u16string() == classificationText_iso8859_1().u16string()); // _EQ wants to do toString() } TEST_CASE(test_u8string_to_u32string) { #if !_WIN32 - const auto actual = classificationText_utf_8.u32string(); - const std::wstring s = str::c_str(actual); // Linux: std::wstring == std::u32string - TEST_ASSERT(classificationText_wide_ == s); // _EQ wants to do toString() + const auto actual = classificationText_utf_8().u32string(); + const std::wstring s = str::c_str(actual); // Linux: std::wstring == std::u32string + TEST_ASSERT(classificationText_wide_() == s); // _EQ wants to do toString() #endif - TEST_ASSERT_EQ(classificationText_wide, classificationText_utf_8); - TEST_ASSERT_EQ(classificationText_wide, classificationText_iso8859_1); + TEST_ASSERT_EQ(classificationText_wide(), classificationText_utf_8()); + TEST_ASSERT_EQ(classificationText_wide(), classificationText_iso8859_1()); - TEST_ASSERT(classificationText_wide.u32string() == classificationText_utf_8.u32string()); // _EQ wants to do toString() - TEST_ASSERT(classificationText_wide.u32string() == classificationText_iso8859_1.u32string()); // _EQ wants to do toString() + TEST_ASSERT(classificationText_wide().u32string() == classificationText_utf_8().u32string()); // _EQ wants to do toString() + TEST_ASSERT(classificationText_wide().u32string() == classificationText_iso8859_1().u32string()); // _EQ wants to do toString() } static void test_EncodedStringView_(const std::string& testName, const str::EncodedStringView& utf_8_view, const str::EncodedStringView& iso8859_1_view) { + (void)testName; TEST_ASSERT_EQ(iso8859_1_view, iso8859_1_view); TEST_ASSERT_EQ(utf_8_view, utf_8_view); TEST_ASSERT_EQ(iso8859_1_view, utf_8_view); TEST_ASSERT_EQ(utf_8_view, iso8859_1_view); TEST_ASSERT_EQ(iso8859_1_view.native(), utf_8_view.native()); - const auto native = classificationText_platform; + const auto native = classificationText_platform(); TEST_ASSERT_EQ(iso8859_1_view.native(), native); TEST_ASSERT_EQ(utf_8_view.native(), native); - TEST_ASSERT(utf_8_view == classificationText_utf_8); - TEST_ASSERT_EQ(utf_8_view, classificationText_utf_8); - TEST_ASSERT(iso8859_1_view == classificationText_utf_8); - TEST_ASSERT_EQ(iso8859_1_view, classificationText_utf_8); + TEST_ASSERT(utf_8_view == classificationText_utf_8()); + TEST_ASSERT_EQ(utf_8_view, classificationText_utf_8()); + TEST_ASSERT(iso8859_1_view == classificationText_utf_8()); + TEST_ASSERT_EQ(iso8859_1_view, classificationText_utf_8()); TEST_ASSERT(iso8859_1_view.u8string() == utf_8_view.u8string()); std::string utf8; - TEST_ASSERT_EQ(utf_8_view.toUtf8(utf8), str::EncodedString::details::string(classificationText_utf_8)); + TEST_ASSERT_EQ(utf_8_view.toUtf8(utf8), str::EncodedString::details::string(classificationText_utf_8())); utf8.clear(); - TEST_ASSERT_EQ(iso8859_1_view.toUtf8(utf8), str::EncodedString::details::string(classificationText_utf_8)); + TEST_ASSERT_EQ(iso8859_1_view.toUtf8(utf8), str::EncodedString::details::string(classificationText_utf_8())); } TEST_CASE(test_EncodedStringView) { @@ -355,29 +358,29 @@ TEST_CASE(test_EncodedStringView) copy = esv; // assignment { - auto utf_8_view(classificationText_utf_8.view()); - auto iso8859_1_view(classificationText_iso8859_1.view()); - test_EncodedStringView_(testName, utf_8_view, iso8859_1_view); + auto utf_8_view(classificationText_utf_8().view()); + auto iso8859_1_view(classificationText_iso8859_1().view()); + test_EncodedStringView_("test_EncodedStringView", utf_8_view, iso8859_1_view); - utf_8_view = classificationText_iso8859_1.view(); - iso8859_1_view = classificationText_utf_8.view(); - test_EncodedStringView_(testName, utf_8_view, iso8859_1_view); + utf_8_view = classificationText_iso8859_1().view(); + iso8859_1_view = classificationText_utf_8().view(); + test_EncodedStringView_("test_EncodedStringView", utf_8_view, iso8859_1_view); } { - auto utf_8_view = classificationText_utf_8.view(); - auto iso8859_1_view = classificationText_iso8859_1.view(); - test_EncodedStringView_(testName, utf_8_view, iso8859_1_view); + auto utf_8_view = classificationText_utf_8().view(); + auto iso8859_1_view = classificationText_iso8859_1().view(); + test_EncodedStringView_("test_EncodedStringView", utf_8_view, iso8859_1_view); - utf_8_view = classificationText_iso8859_1.view(); - iso8859_1_view = classificationText_utf_8.view(); - test_EncodedStringView_(testName, utf_8_view, iso8859_1_view); + utf_8_view = classificationText_iso8859_1().view(); + iso8859_1_view = classificationText_utf_8().view(); + test_EncodedStringView_("test_EncodedStringView", utf_8_view, iso8859_1_view); } { str::EncodedStringView utf_8_view; - utf_8_view = classificationText_iso8859_1.view(); + utf_8_view = classificationText_iso8859_1().view(); str::EncodedStringView iso8859_1_view; - iso8859_1_view = classificationText_utf_8.view(); - test_EncodedStringView_(testName, utf_8_view, iso8859_1_view); + iso8859_1_view = classificationText_utf_8().view(); + test_EncodedStringView_("test_EncodedStringView", utf_8_view, iso8859_1_view); } } @@ -409,9 +412,7 @@ TEST_CASE(test_EncodedString) str::EncodedString es3(std::move(abc)); // move constructor TEST_ASSERT_EQ(es3.native(), "abc"); } - -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testConvert); TEST_CHECK(testBadConvert); TEST_CHECK(testEightBitIntToString); @@ -425,4 +426,4 @@ int main(int, char**) TEST_CHECK(test_u8string_to_u32string); TEST_CHECK(test_EncodedStringView); TEST_CHECK(test_EncodedString); -} + ) \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/str/unittests/test_str.cpp b/externals/coda-oss/modules/c++/str/unittests/test_str.cpp index b18eaa561..edd6cf122 100644 --- a/externals/coda-oss/modules/c++/str/unittests/test_str.cpp +++ b/externals/coda-oss/modules/c++/str/unittests/test_str.cpp @@ -26,8 +26,11 @@ #include #include "TestCase.h" -namespace +inline std::string to_string(const std::string& value) { + return value; +} + TEST_CASE(testTrim) { std::string s = " test "; @@ -218,10 +221,8 @@ TEST_CASE(testEscapeForXMLKitchenSink) str::escapeForXML(message); TEST_ASSERT_EQ(message, expectedMessage); } -} -int main(int, char**) -{ +TEST_MAIN( TEST_CHECK(testTrim); TEST_CHECK(testStrip); TEST_CHECK(testData); @@ -243,5 +244,4 @@ int main(int, char**) TEST_CHECK(testRoundDouble); TEST_CHECK(testEscapeForXMLNoReplace); TEST_CHECK(testEscapeForXMLKitchenSink); - return 0; -} + ) \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/sys/include/sys/Conf.h b/externals/coda-oss/modules/c++/sys/include/sys/Conf.h index 601dc632c..b093cdf24 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/Conf.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/Conf.h @@ -34,8 +34,8 @@ #define CODA_OSS_POSIX2001_SOURCE CODA_OSS_POSIX_SOURCE && (_POSIX_C_SOURCE >= 200112L) #define CODA_OSS_POSIX2008_SOURCE CODA_OSS_POSIX2001_SOURCE && (_POSIX_C_SOURCE >= 200809L) -#include #include +#include #include #include diff --git a/externals/coda-oss/modules/c++/sys/include/sys/DateTime.h b/externals/coda-oss/modules/c++/sys/include/sys/DateTime.h index 93b22d7a1..38b7424a7 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/DateTime.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/DateTime.h @@ -30,13 +30,15 @@ #include +#include "config/Exports.h" + namespace sys { /*! * Representation of a date/time structure. */ -class DateTime +class CODA_OSS_API DateTime { protected: int mYear = 0; diff --git a/externals/coda-oss/modules/c++/sys/include/sys/LocalDateTime.h b/externals/coda-oss/modules/c++/sys/include/sys/LocalDateTime.h index 84d1959df..212de18eb 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/LocalDateTime.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/LocalDateTime.h @@ -24,6 +24,7 @@ #ifndef __SYS_LOCAL_DATE_TIME_H__ #define __SYS_LOCAL_DATE_TIME_H__ +#include "config/Exports.h" #include namespace sys @@ -32,7 +33,7 @@ namespace sys /*! * Representation of a local date/time structure. */ -class LocalDateTime : public DateTime +class CODA_OSS_API LocalDateTime : public DateTime { protected: int mDST; diff --git a/externals/coda-oss/modules/c++/sys/include/sys/sys_filesystem.h b/externals/coda-oss/modules/c++/sys/include/sys/sys_filesystem.h index e58f33c6d..a878492ec 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/sys_filesystem.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/sys_filesystem.h @@ -35,6 +35,7 @@ #include "sys/CPlusPlus.h" #include "coda_oss/namespace_.h" // get something in the "coda_oss" namespace +#include "config/Exports.h" namespace sys // should be in coda_oss/, but implementation needs sys::Path { @@ -59,7 +60,7 @@ namespace filesystem // not "Filesystem", make it easy to use code in other name }; // http://en.cppreference.com/w/cpp/filesystem/path -struct path final // N.B. this is an INCOMPLETE and NON-STANDARD implementation! +struct CODA_OSS_API path final // N.B. this is an INCOMPLETE and NON-STANDARD implementation! { // character type used by the native encoding of the filesystem: char on POSIX, wchar_t on Windows #ifdef _WIN32 @@ -104,15 +105,15 @@ struct path final // N.B. this is an INCOMPLETE and NON-STANDARD implementation! bool is_absolute() const; // http://en.cppreference.com/w/cpp/filesystem/path/is_absrel bool is_relative() const; // http://en.cppreference.com/w/cpp/filesystem/path/is_absrel - friend bool operator==(const path& lhs, const path& rhs) noexcept // https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp + CODA_OSS_API friend bool operator==(const path& lhs, const path& rhs) noexcept // https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp { return details::Equals(lhs, rhs); } - friend bool operator!=(const path& lhs, const path& rhs) noexcept // https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp + CODA_OSS_API friend bool operator!=(const path& lhs, const path& rhs) noexcept // https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp { return !(lhs == rhs); } - friend std::ostream& operator<<(std::ostream& os, const path& p) // https://en.cppreference.com/w/cpp/filesystem/path/operator_ltltgtgt + CODA_OSS_API friend std::ostream& operator<<(std::ostream& os, const path& p) // https://en.cppreference.com/w/cpp/filesystem/path/operator_ltltgtgt { return details::Ostream(os, p); } @@ -122,18 +123,18 @@ struct path final // N.B. this is an INCOMPLETE and NON-STANDARD implementation! static string_type to_native(const std::string& s); }; -path operator/(const path& lhs, const path& rhs); // http://en.cppreference.com/w/cpp/filesystem/path/operator_slash +CODA_OSS_API path operator/(const path& lhs, const path& rhs); // http://en.cppreference.com/w/cpp/filesystem/path/operator_slash -path absolute(const path&); // http://en.cppreference.com/w/cpp/filesystem/absolute -bool create_directory(const path&); // https://en.cppreference.com/w/cpp/filesystem/create_directory -path current_path(); // https://en.cppreference.com/w/cpp/filesystem/current_path -bool remove(const path& p); // https://en.cppreference.com/w/cpp/filesystem/remove -path temp_directory_path(); // https://en.cppreference.com/w/cpp/filesystem/temp_directory_path +CODA_OSS_API path absolute(const path&); // http://en.cppreference.com/w/cpp/filesystem/absolute +CODA_OSS_API bool create_directory(const path&); // https://en.cppreference.com/w/cpp/filesystem/create_directory +CODA_OSS_API path current_path(); // https://en.cppreference.com/w/cpp/filesystem/current_path +CODA_OSS_API bool remove(const path& p); // https://en.cppreference.com/w/cpp/filesystem/remove +CODA_OSS_API path temp_directory_path(); // https://en.cppreference.com/w/cpp/filesystem/temp_directory_path -bool is_regular_file(const path& p); // https://en.cppreference.com/w/cpp/filesystem/is_regular_file -bool is_directory(const path& p); // https://en.cppreference.com/w/cpp/filesystem/is_directory -bool exists(const path& p); // https://en.cppreference.com/w/cpp/filesystem/exists -std::uintmax_t file_size(const path& p); // https://en.cppreference.com/w/cpp/filesystem/file_size +CODA_OSS_API bool is_regular_file(const path& p); // https://en.cppreference.com/w/cpp/filesystem/is_regular_file +CODA_OSS_API bool is_directory(const path& p); // https://en.cppreference.com/w/cpp/filesystem/is_directory +CODA_OSS_API bool exists(const path& p); // https://en.cppreference.com/w/cpp/filesystem/exists +CODA_OSS_API std::uintmax_t file_size(const path& p); // https://en.cppreference.com/w/cpp/filesystem/file_size } } diff --git a/externals/coda-oss/modules/c++/sys/source/DateTime.cpp b/externals/coda-oss/modules/c++/sys/source/DateTime.cpp index d616cc103..8bd971ad8 100644 --- a/externals/coda-oss/modules/c++/sys/source/DateTime.cpp +++ b/externals/coda-oss/modules/c++/sys/source/DateTime.cpp @@ -28,7 +28,6 @@ #include #include -#include #include "except/Exception.h" #include "sys/Conf.h" #include "str/Convert.h" diff --git a/externals/coda-oss/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp b/externals/coda-oss/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp index 49d591380..1c88df2cc 100644 --- a/externals/coda-oss/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp +++ b/externals/coda-oss/modules/c++/sys/source/ScopedCPUAffinityUnix.cpp @@ -20,8 +20,6 @@ * */ -#include "config/coda_oss_config.h" - #if !(defined(WIN32) || defined(_WIN32)) #include diff --git a/externals/coda-oss/modules/c++/units/unittests/test_units.cpp b/externals/coda-oss/modules/c++/units/unittests/test_units.cpp index f48fbf138..cd8dd3d46 100644 --- a/externals/coda-oss/modules/c++/units/unittests/test_units.cpp +++ b/externals/coda-oss/modules/c++/units/unittests/test_units.cpp @@ -24,16 +24,15 @@ #include #include -namespace -{ template static void test_degrees_(const std::string& testName) { + (void)testName; T sin, cos; constexpr units::Degrees degrees_180 = 180; SinCos(degrees_180, sin, cos); - TEST_ASSERT_ALMOST_EQ(0.0, sin); - TEST_ASSERT_ALMOST_EQ(-1.0, cos); + TEST_ASSERT_ALMOST_EQ(static_cast(0.0), sin); + TEST_ASSERT_ALMOST_EQ(static_cast(-1.0), cos); } TEST_CASE(test_degrees) { @@ -55,9 +54,9 @@ TEST_CASE(test_degrees) TEST_ASSERT_ALMOST_EQ(0.0, cos(degrees_270)); TEST_ASSERT_ALMOST_EQ(1.0, cos(degrees_360)); - test_degrees_(testName); - test_degrees_(testName); - test_degrees_(testName); + test_degrees_("test_degrees"); + test_degrees_("test_degrees"); + test_degrees_("test_degrees"); } TEST_CASE(test_lengths) @@ -86,12 +85,8 @@ TEST_CASE(test_lengths) } } -} - -int main(int /*argc*/, char** /*argv*/) -{ +TEST_MAIN( TEST_CHECK(test_degrees); TEST_CHECK(test_lengths); - return 0; -} +) diff --git a/externals/coda-oss/modules/c++/xml.lite/source/Element.cpp b/externals/coda-oss/modules/c++/xml.lite/source/Element.cpp index 00cdf59f5..f40c5c245 100644 --- a/externals/coda-oss/modules/c++/xml.lite/source/Element.cpp +++ b/externals/coda-oss/modules/c++/xml.lite/source/Element.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include constexpr auto PlatformEncoding = sys::Platform == sys::PlatformType::Windows @@ -286,11 +287,11 @@ void xml::lite::Element::getCharacterData(coda_oss::u8string& result) const str::EncodedStringView view; if (encoding == xml::lite::StringEncoding::Utf8) { - view = str::EncodedStringView::fromUtf8(mCharacterData); + view = str::c_str(mCharacterData); } else if (encoding == xml::lite::StringEncoding::Windows1252) { - view = str::EncodedStringView::fromWindows1252(mCharacterData); + view = str::c_str(mCharacterData); } else { @@ -307,13 +308,13 @@ static void writeCharacterData(io::OutputStream& stream, if (encoding == xml::lite::StringEncoding::Windows1252) { // need to convert before writing - const auto view = str::EncodedStringView::fromWindows1252(characterData); + const str::EncodedStringView view(str::c_str(characterData)); stream.write(view.u8string()); } else if (encoding == xml::lite::StringEncoding::Utf8) { // already in UTF-8, no converstion necessary - auto pUtf8 = str::c_str(characterData); + auto pUtf8 = str::c_str(characterData); stream.write(pUtf8, characterData.length()); // call UTF-8 overload } else @@ -544,7 +545,7 @@ void xml::lite::Element::setCharacterData(const std::string& characters, StringE } void xml::lite::Element::setCharacterData(const coda_oss::u8string& characters) { - setCharacterData(str::c_str(characters), StringEncoding::Utf8); + setCharacterData(str::c_str(characters), StringEncoding::Utf8); } xml::lite::Element& xml::lite::add(const QName& qname, diff --git a/externals/coda-oss/modules/c++/xml.lite/unittests/test_xmlparser.cpp b/externals/coda-oss/modules/c++/xml.lite/unittests/test_xmlparser.cpp index e8774f77a..b1ac11ad3 100644 --- a/externals/coda-oss/modules/c++/xml.lite/unittests/test_xmlparser.cpp +++ b/externals/coda-oss/modules/c++/xml.lite/unittests/test_xmlparser.cpp @@ -37,16 +37,16 @@ static const std::string text("TEXT"); static const std::string strXml = "" + text + ""; -static const auto iso88591Text = str::EncodedString::fromWindows1252("T\xc9XT"); // ISO8859-1, "T�XT" +static const str::EncodedString iso88591Text(str::cast("T\xc9XT")); // ISO8859-1, "T�XT" static const auto iso88591Text1252 = str::EncodedStringView::details::w1252string(iso88591Text.view()); -static const auto pIso88591Text_ = str::c_str(iso88591Text1252); +static const auto pIso88591Text_ = str::c_str(iso88591Text1252); -static const auto utf8Text = str::EncodedString::fromUtf8("T\xc3\x89XT"); // UTF-8, "T�XT" +static const str::EncodedString utf8Text(str::cast("T\xc3\x89XT")); // UTF-8, "T�XT" static const auto utf8Text8 = utf8Text.u8string(); -static const auto pUtf8Text_ = str::c_str(utf8Text8); +static const auto pUtf8Text_ = str::c_str(utf8Text8); static const auto strUtf8Xml8 = str::fromUtf8("") + utf8Text8 + str::fromUtf8(""); -static const std::string strUtf8Xml = str::c_str(strUtf8Xml8); +static const std::string strUtf8Xml = str::c_str(strUtf8Xml8); constexpr auto PlatformEncoding = xml::lite::PlatformEncoding; static const std::string platfromText_ = PlatformEncoding == xml::lite::StringEncoding::Utf8 ? pUtf8Text_ : pIso88591Text_; @@ -399,7 +399,7 @@ TEST_CASE(testReadEmbeddedXml) const auto characterData = classificationXML.getCharacterData(); TEST_ASSERT_EQ(characterData, classificationText_platform); - const auto expectedCharDataView = str::EncodedStringView::create(classificationText_utf_8); + const str::EncodedStringView expectedCharDataView(str::c_str(classificationText_utf_8)); std::u8string u8_characterData; classificationXML.getCharacterData(u8_characterData); TEST_ASSERT_EQ(u8_characterData, expectedCharDataView); diff --git a/externals/coda-oss/modules/python/config/source/config.i b/externals/coda-oss/modules/python/config/source/config.i index 4fe662de4..2719b12c4 100644 --- a/externals/coda-oss/modules/python/config/source/config.i +++ b/externals/coda-oss/modules/python/config/source/config.i @@ -2,3 +2,11 @@ #define static_assert(...) // SWIG <= 3.0.12 cannot handle static_assert #define final // SWIG (as of 4.0.2) does not understand "final" + +// Turn off exports with SWIG. Use the compiler-specific macros (rather than a project-specifc name) +// so that this works in all projects +#define __attribute__(...) // __GNUC__ +#define __declspec(...) // _MSC_VER +#define CODA_OSS_library_export +#define CODA_OSS_library_import +#define CODA_OSS_API // ... well, except that it doesn't :-( diff --git a/modules/c++/nitf/unittests/test_j2k_loading++.cpp b/modules/c++/nitf/unittests/test_j2k_loading++.cpp index 308e175c6..efaadf17d 100644 --- a/modules/c++/nitf/unittests/test_j2k_loading++.cpp +++ b/modules/c++/nitf/unittests/test_j2k_loading++.cpp @@ -374,7 +374,7 @@ TEST_CASE(test_j2k_compress_raw_image) //} } -TEST_MAIN((void)argc; (void) argv; +TEST_MAIN( TEST_CHECK(test_j2k_loading); TEST_CHECK(test_j2k_nitf); TEST_CHECK(test_j2k_nitf_read_region);