From 6e34e8717e92a7ec5053c72df86e98a24db3bb2a Mon Sep 17 00:00:00 2001 From: "J. Daniel Smith" Date: Thu, 15 Jun 2023 16:10:34 -0400 Subject: [PATCH] latest from CODA-OSS (#664) * latest from CODA-OSS and NITRO * Squashed 'externals/coda-oss/' changes from e87c32b4d..f4d42005f f4d42005f fix build error in NITRO ff11a5557 keep using std::complex for now (#682) c88b9c053 types::complex (#681) d1244a080 don't need our own make_unique in C++14 (#680) aeec0131c assert()s for mem::CopyablePtr (#679) 72b0ebd60 add types::complex_short (#678) 932130a58 patch to build other projects c00c1f203 coda-oss release 2023-06-06 (#677) ef54bbcd5 remove more compiler warnings (#676) dadfc5ce6 distinguish between byte-swapping a buffer and single value (#674) 90187f6cd more xml.lite tweaks for SIDD-3.0/ISM (#675) eb9960772 stronger type-checking for byteSwap() (#673) ff4f820ed xml.lite tweaks to support SIDD 3.0 ISM (#672) b1de8c0e5 std::byte should be a unique type (#671) c05bf9a02 allow enums to be byte-swapped too 1f9fd88d6 remove spurious 47684c45b byteSwap now uses byte buffers (#670) cbc659db2 add swapBytes() utility from SIX (#669) 891481b64 simplify byte-swapping (#668) 540ae763e more byteSwap() tweaks 0774c03c4 threaded byteSwap() (#667) d156370d3 swapping a single-byte value makes no sense c120e3255 be sure parameter is used to avoid compiler warning e85ec9331 --output-on-failure for CTest (#666) e80376197 turn off "there is no warning number" warning c5f0a5d15 A C-string may not be NULL-terminated (#665) 0c5eb29ae use platform-specific routines for byteSwap() (#664) 0b7d581fa remove transform_async() (#663) f6489b6be Merge branch 'main' into feature/xml.lite_tweaks 836c426a2 use function-pointers so that isConsoleOutput is only checked once 56e3c45b1 move depthPrint() functionality into non-member function in preparation for future changes ddcd26d97 Merge branch 'main' into feature/xml.lite_tweaks 69cc0e506 use the more rigorous create_and_check_datatype() 9efb87558 Merge branch 'main' into feature/hdf5 4d2f2f417 more HighFive unittests (#662) 14191a844 HighFive::create_datatype() goes from C++ to HighFive 98583473f utility routines to read string attributes 1fa75ce81 use the C API to read a string attribute 71e7b69f5 still can't figure out how to read a string attribute :-( e96f37a69 test reading the file attributes a25244519 getAttribute() unittest 8f12a3000 getDataType() unittest 857ff0af3 HighFive utility routines (#661) 1d687db57 writeDataSet() utility overload 106aa6894 sigh ... H5Easy::dump() fill fails on Windows/WAF :-( 2641b60b2 Merge branch 'main' into feature/hdf5 35c19e7e8 change actions to @v3 (#660) 212bbd3a3 works on local machine, but not build server ... ? 7125118b0 dump of 1D vector doesn't work :-( c704db435 sigh ... WAF build still failing :-( 01aae4616 does dump() of a 1D vector work? 76a53c813 comment-out H5 writing :-( 0f0e19aff test_highfive_dump() cb8f73795 trying to get highfive_dump() unittest working w/Windows-WAF 6584a264a does test_highfive_create() work? cde6147ce tweak HighFive wrappers (#659) 316566854 Revert "trying HighFive "write" unittests again" a9ec24ca4 trying HighFive "write" unittests again 585ad49a5 tweak names of utility routines 4c91a4d97 make it easier to read a std::vector and std::vecotr 0217ffa26 readDataSet() now works for 1D data 95e8973f2 trying to get hdf5::lite::load() working 4d294611d "const" correctness 5e6305c3f fix load_complex() 4a134dc5f start work on utility routines to read complex data from HDF5 9d76a7f41 Merge branch 'main' into feature/hdf5 8f9667a24 whitepsace ebd3fc99e Merge branch 'main' into feature/hdf5 40091b069 comment-out writing tests for now ... need to figure our WAF bulid failure 935aa3459 be sure the dataset has real data 114b9bf33 update release notes bd9c0b26c tweak HighFive utility routines acda1ef57 turn off diagnostics around expected failures 22a748840 readDataSet() utility routine for HighFive bd88a8c25 HighFive writeDataSet() utility to work with our SpanRC 6142f5b33 use HighFive routines to write a HDF5 file 5bbf1abaf Use HiveFive routines to get info about the file 84fbc8378 duplicate unittests with H5Easy f1f054c03 Merge branch 'main' into feature/hdf5 9b63ca470 fix directory names f6f826689 fix directory names 7aeb82c33 Merge branch 'main' into feature/hdf5 d028baaeb hook up HighFive header-only library (#653) 3083b0a31 Revert "HighFive 2.6.2" 246985a7f Revert ""build" HighFive HDF5 library" a8b75a586 Revert "turn off HighFive Boost support" ec68d5f83 Revert "Add HighFive unittests" f1f85b9e7 Revert "get test_high_five_base more-or-less compiling" 5ea634ee1 Revert "more work on getting HighFive unittests to build" ecc45433c more work on getting HighFive unittests to build bb194788a get test_high_five_base more-or-less compiling d42bde000 Add HighFive unittests ddc86bb32 turn off HighFive Boost support b255122d4 "build" HighFive HDF5 library 396cc3ef2 HighFive 2.6.2 5e5f9d9c0 Merge branch 'main' into feature/hdf5 ee938b4a5 changes from SIX bb764df90 Merge branch 'main' into feature/xml.lite_tweaks de2a24380 make derived classes 'final' if possible 14e19bcd2 Change xml lite function to virtual (#645) 8f42ac8e9 Merge branch 'main' into feature/xml.lite_tweaks 18ad90645 hdf5Write unittest 3462e1179 createFile() and writeFile() overloads ecee81d53 fix typos 197eecfa6 sketch-out hdf5::lite::writeFile() bd2311795 use SpanRC for writeFile(), not yet implemented ea9af7510 simple SpanRC to hold a 2D-size and pointer 027c19ee8 createFile() unittest 1f9d07ecb hook up createFile() 8c7e4473f start hooking up HDF5 writing 146e0bea3 Merge branch 'main' into feature/hdf5 88ca9fcb7 Merge branch 'main' into feature/hdf5 42b604b46 Squashed commit of the following: 10ee602c2 Merge branch 'main' into feature/hdf5 67aa42b69 restore changes from "main" 8bbfcbfbf unittests can be simplified to match fewer "view" classes 126bb802e Merge branch 'main' into feature/hdf5 3f8ba7a42 again, don't need a class just to convert from std::vector<> to std::span<> 24c2b489c Squashed commit of the following: 2703c119d Squashed commit of the following: 9d5228a2b don't need an entire class just to convert a std::vector<> into std::span<> 51bc931dc Merge branch 'main' into feature/hdf5 a84f25816 Squashed commit of the following: c4d2ed696 add missing #include guards, fix type in existing #include guard d541525a0 use a single ComplexViewConstIterator for all views 86e6a459f CODA_OSS_disable_warning causes GCC errors :-( 5d4b9c2cb only need an custom iterator for ComplexSpansView d9f0fb128 hook up iterators b9329e4db initial pass at a ComplexViewConstIterator 635238873 remove compiler warning about unused "constexpr" variables b39f6096f use the casing from H5 to make copy/pasting code slightly easier 0887b13eb Merge branch 'main' into feature/hdf5 bd07df1ca Consistent casing for Dataset, Datatype, Dataspace 7acd30ee2 tweak hdf5.lite dependencies 38ab914df Jupyter notebook for creating H5 files 95a040e0b _small.h5 is now (correctly) FLOAT32 107e7c487 make a simple values() member function to avoid template magic e1feca919 use TEST_SPECIFIC_EXCEPTION macro instead of try/catch 738333688 readDatasetT() now throws for the wrong buffer type 6b2cc2529 Merge branch 'feature/hdf5' of github.com:mdaus/coda-oss into feature/hdf5 310f8fd3d can't get template magic right for copy_axis() 86b306d59 stepping through copy ctors in the debugger is annoying f243e92d6 trying to make wrong type of buffer fail 2b10d9652 read in new sample file a28e59d8c help the compiler with type deduction 49bf5e9bc nested_complex_float_data_small.h5 e029325fc utility routines to "deconstruct" and array of std::complex dede3bd39 Merge branch 'main' into feature/hdf5 904b1ef5e tweak class names, make_() and copy() utility routines 8237b9efb make it harder to pass the wrong types to ComplexViews 4d9aeda2c ComplexArrayView and ComplexParallelView utility classes f5e367dfa test std::span> a4a2844f2 read in the nested "i" and "r" data 115615265 sample file has subgroups 8e1b7869a Merge branch 'feature/hdf5' of github.com:mdaus/coda-oss into feature/hdf5 9f4232a1d update sample H5 file 8c55db73a walk through HDF5 sub-groups 7775ed9c4 Update 123_barfoo_catdog_cx.h5 677975d7c Matlab code to create sample H5 file a0e7dfe07 Update test_hdf5info.cpp 0b67e1602 pass __FILE__ and __LINE__ from calling site for a more accurate exception message 86a677321 skeleton for more sample data 85f79b099 Merge branch 'main' into feature/hdf5 18088e942 Merge branch 'main' into feature/hdf5 3a1d17692 Merge branch 'main' into feature/hdf5 1755c69d7 Merge branch 'main' into feature/hdf5 9ad015432 No more "11" suffix on exception names c20d96251 Squashed commit of the following: c88cee999 other values to be filled-in bca4a4ecd incorporation NamedObject from HDF5 docs 61fa68f72 groupInfo() 460e7d766 datasetInfo() 14eb9b764 start filling in DatasetInfo afe5f1c3a start to fill in DatasetInfo 77a968c72 start filling in GroupInfo d81bcdfd9 openGroup() to open groups (loc) a0cd29469 comment-out "dataset" unittest for now 86e006024 begin filling in FileInfo 366dda6ab a return_type_of utility is needed to deduce the return type e21928263 explicitly pass return type to template 4937ccd11 template to reduce boilerplate when calling try_catch_H5Exceptions b3b5ebde7 use new exception utility routines ea1c03ef0 put exception handling/conversion in a utility routine 819a99d39 utility routine for exception handling 6f34eea97 put utilities in a separate file for easier reuse fcbde4f24 break utility routines into smaller pieces for easier reuse 52358ea8a WIN32 no longer automatically defined? 5a4286472 Revert "build HDF5 with C89" 680e599e9 build HDF5 with C89 a87a07121 Merge branch 'main' into feature/hdf5 8447c1a90 Revert "sym-links instead of copying files" db3b5e12b Merge branch 'main' into feature/xml.lite_tweaks fb60b5696 Merge branch 'main' into feature/hdf5 5110a5cc8 Comments about _u and _q 1a937d32c Merge branch 'main' into feature/xml.lite_tweaks fa06f04d7 get ready for hdf5.lite enhancdements b040c7c43 sym-links instead of copying files aa431bb47 use _u for xml::lite::Uri 3d0c6d58c fix case-sensitive #include filename 93dcd0e52 operator() for getElementByName() 75a93af85 more operator[] overloads to make attribute management easier 4ab8216f8 user-defined string literals to remove some noise around xml::lite::QName f82f0b0fc Merge branch 'main' into feature/xml.lite_tweaks ae30e3644 Merge branch 'feature/xml.lite_tweaks' of github.com:mdaus/coda-oss into feature/xml.lite_tweaks ffdd9beb0 simplify attribute creation 9bf5414f5 simplify attribute creation 82d7a4e95 SWIG gets confused about namespaces 7a61d0741 fix bug on Element ctor uncovered by unittest fdd7e58c1 QName is also in the xerces namespace which confuses SWIG bindings a325b7053 operator+=() overload for addChild daf30e6c0 Merge branch 'feature/xml.lite_tweaks' of github.com:mdaus/coda-oss into feature/xml.lite_tweaks b887d2b47 provide overloads for Element& rather than creating new "reference" types 1fa6bba38 rename test_xmleasy.cpp 7c8c9e0f1 += overload 850da6f63 overload for std::string 4547fc5a7 use UIT-8 strings for characterData 4723462a3 convenient addChild() overloads e48720753 copy over ElementReference from xml.easy a4ca30a0d Merge branch 'main' into feature/xml.lite_tweaks 6ae9f0b71 Revert "check-in of new xml.easy (to move code between computers)" f7466a6d7 Revert "simple routines for single element" a5490230d Revert "make some operators simplier ways of calling functions" c9a25630a Revert "get document creation working" 8af8710b0 Revert "free functions instead of member functions" 16c3847cb Revert "ElementReference distinct from Element" 7d68e156f Revert "ElementMutableReference" 00eb2a282 Merge branch 'main' into feature/xml.lite_tweaks a42969c1f ElementMutableReference a20ae9355 ElementReference distinct from Element 14eeeea0b free functions instead of member functions 4aae014b3 get document creation working 883569269 make some operators simplier ways of calling functions 053bd1212 simple routines for single element 8bf701a2e check-in of new xml.easy (to move code between computers) 41f959051 unittests for creating XML documents from scratch 9752d50ae Merge branch 'main' into feature/xml.lite_tweaks 1531d5709 by default, don't validate strings passed to Uri() 46d13d4bf Merge branch 'master' into feature/xml.lite_tweaks 39b547d32 remove more vestiges of Expat and LibXML ec8274d52 remove LibXML and Expat as they're no longer used/supported. 20eeefeef Merge branch 'master' into feature/xml.lite_tweaks 95074b9b1 update for newer Intel compiler 7024f71e1 Merge branch 'master' into feature/xml.lite_tweaks 57b1cbc83 Merge branch 'master' into feature/xml.lite_tweaks 4b67561c3 remove validate() overload that nobody is using fa15f1e5d Squashed commit of the following: 1484a9090 test the new validate() API 470da70fb hookup StringStreamT routines 2cddf2504 begin hooking up validate() overloads 1b5d910f3 overload validate() for UTF-8 and Windows-1252 03309b8c9 Squashed commit of the following: b72c6c5bf older compiler doesn't like our make_unique af8f00307 validate UTF-8 XML on Linux 211188613 unit-test for LEGACY XML validation 3c1169d2b Squashed commit of the following: 3afff19ca std::filesystem::path for FileInputStreamOS 908d452f8 WIP: validate all of our sample XML files 00f9bb16b validate against a XML schema 243d8c356 Merge branch 'master' into feature/xml.lite_tweaks 2815d707d fix to work with SWIG bindings. :-( 460862132 trying (again) to remove vestiages of old code e3c83a858 Revert "new code should use UTF-8" 811207c92 new code should use UTF-8 0ffd835f9 Squashed commit of the following: 1e7e03ded Merge branch 'master' into feature/xml.lite_tweaks c1d806aff Merge branch 'master' into feature/xml.lite_tweaks 850d3c811 str::strip() that can be easier to use than str::trim() 580ba9c8c explicitly =delete move 2b39831a8 Squashed commit of the following: 39eebdc23 Merge branch 'master' into feature/xml.lite_tweaks 9adf86cba force calling new UTF-8 write() routines ea61b6204 Merge branch 'master' into feature/xml.lite_tweaks 8a34583fa overload to take schemaPaths as filesystem::path 8671b442f parse XML embedded in a binary file ec4a902f1 updates from xerces.lite 80dc4d963 updates from xerces.lite 549766d6c Attributes::contains() no longer catches an exception 8a645ceac need "sys/" when building in other environments 36af08269 super-simple URI validation 78ef28a3e SWIG bindings are a PITA! :-( e9cba8491 SWIG needs help with Uri 8a8d8dc07 another routines used by pre-build SWIG bindings 818e1ec5d pre-build SWIG bindings use getElementByTagName() member function 067cac5d8 old compiler gets confused on unadorned QName ba92c0ae7 more use of Uri and QName 446c7d17a use QName in new code d6f8b0c83 more direct use of QName 90fff1c73 use xml::lite::QName instead of tuple 646cbb5ed more direct use of QName and Uri ba589ea3b make QName more robust bab0ee8b5 createElement() -> addNewElement() e3a145747 grab changes from six-library 32285e95c Merge branch 'master' into feature/xml.lite_tweaks 9f79f0bf6 Merge branch 'master' into feature/xml.lite_tweaks a12bbc32c make it easier to create new Elements with a value fc9967f98 make it easy for callers to addChild() keep a reference to the Element 4627766b7 be sure test_xmlparser works in "externals" of other projects bf2276396 "private" is part of the name-mangling fad92bcc8 making sure copy-ctor is implemented f90fdcead consolidate common XML test code 9fc53f2d5 use str:: utility for casting 6da6f794b still trying to find the right macro for SWIG 0c1b86c56 still trying to fix SWIG fdc6fc9bd trying to fix SWIG build error 7835e8c27 SWIG needs copy-ctor 585695942 disable copy/assignment for Element, it's probably almost always wrong 391fed613 fix double-delete caused by copying 61790fe69 retry parsing XML with Windows-1252 if first parse() fails 63cffac59 change string_encoding to match coda-oss style of PascalCase 010479bbe read an XML file we know is wrongly encoded as Windows-1252 9a0505062 more references instead of pointers 2d44b6951 Reading Windows-1252 w/o "encoding" fails 63dc7b076 read Windows-1252 too c9434c9cb test as UIT-8 too f310ccf0c get reading from UTF-8 XML working on Windows 1fa39c2be get testReadUtf8XmlFile working on Linux 1a83cd815 sys::Path is too much trouble right now ed60aa22c unit-test to read XML from a file a9336db7c Squashed commit of the following: 0825beb0d Merge branch 'master' into feature/xml.lite_tweaks c618489be Merge branch 'master' into feature/xml.lite_tweaks e8e4b8fe1 determine string_encoding based on platform 1f43bcfc2 create a new Element by using the platform to determine "characterData" encoding 961bef66b Merge branch 'master' into feature/xml.lite_tweaks e9798a5cb fix static_assert() 6f7772874 Merge branch 'master' into feature/xml.lite_tweaks b98d4f5a9 Merge branch 'master' into feature/xml.lite_tweaks 1b5abba2a The (old) version of SWIG we're using doesn't like certain C++11 features. 53bdeabaf Merge branch 'master' into feature/xml.lite_tweaks 60cf8ae80 "" doesn't work with decltype() in older C++ 97e72477a reduce getValue() overloads by making "key" a template argument 5e6373e55 reduce code duplication f9e7cfeee provide castValue instead of getValue(T&) cbd0bd8f2 castValue throws instead of returning a bool like getValue(T&) 87c7514fc Merge branch 'master' into feature/xml.lite_tweaks 10cc61223 make getElement*() consistent for zero or >1 results f5b137e3c Merge branch 'master' into feature/xml.lite_tweaks 1765efc62 allow clients to specify toType() and toString() for getValue() and setValue() df8b746e1 allow clients to specify their own toType/toString routines 66702726a Merge branch 'master' into feature/xml.lite_tweaks 6956311f1 Merge branch 'master' into feature/xml.lite_tweaks d505f3593 Merge branch 'master' into feature/xml.lite_tweaks fbd106115 catch a BadCastException and return false from getValue() 3a78377b5 use a template to reduce duplicated code 0ad4b8606 Merge branch 'master' into feature/xml.lite_tweaks a848aa3a2 get & set the characer data as a type f3ee1ee12 utility routines to set an attribute value 595227683 templates to get an attribute value convert to a specific type 06639227b miised a change in last commit 1aa458ef8 add getValue() overloads that return true/false rather than throwing faa6d3075 added getElementByTagName() overloads as that's a very common use-case git-subtree-dir: externals/coda-oss git-subtree-split: f4d42005fa477ae59da193422aa2cb14b877cf0c * Squashed 'externals/nitro/' changes from c8ecbe9ae..3f01809fa 3f01809fa latest from coda-oss (#557) 471fb3fc1 Update test_j2k_loading++.cpp b12caf2fc latest from CODA-OSS (#556) 0cd432624 use sys::make_span (#555) 05dae18a3 patch to build other projects 8f974e995 NITRO-2.11.3 (#554) 870aa6afd update to coda-oss 2023-06-05 (#553) 2fd7a0bfa latest from coda-oss (#552) 0eecce004 invoke() utility to reduce code duplication (#550) 59fb02fe9 latest from coda-oss (#551) 9fbf2b7b8 Fill out adapter free block which is used for nitf decompression (#549) 089ba0b5b latest from coda-oss 3b52f0025 latest from coda-oss (#547) 90c6263e2 latest from coda-oss (#544) 90d513ac5 latest from coda-oss (#543) git-subtree-dir: externals/nitro git-subtree-split: 3f01809fae7d471aa0f1594fc5eec1e3111cd710 * latest from CODA-OSS and NITRO * latest from CODA-OSS * Squashed 'externals/coda-oss/' changes from f4d42005f..704d6867f 704d6867f beef-up our complex type (#687) 47c1c1cd6 check is_absolute() for URLs (#686) c042373e1 be sure our Path::isAbolute() matches std::filesystem::path::absolute() (#684) ad10286bc volatile is about "special" memory, not threading (#685) git-subtree-dir: externals/coda-oss git-subtree-split: 704d6867f959f60e3e62c44681a3fb1f7abc99bf --- .../c++/mt/tests/ThreadGroupAffinityTest.cpp | 6 +- .../coda-oss/modules/c++/str/CMakeLists.txt | 2 +- .../modules/c++/str/include/str/Convert.h | 22 ++- .../modules/c++/str/unittests/test_str.cpp | 88 +++++++++ externals/coda-oss/modules/c++/str/wscript | 2 +- .../coda-oss/modules/c++/sys/source/Path.cpp | 12 +- .../modules/c++/sys/unittests/test_path.cpp | 59 ++++++ .../coda-oss/modules/c++/types/CMakeLists.txt | 2 +- .../modules/c++/types/include/types/complex.h | 175 ++++++++++++------ .../c++/types/unittests/test_complex.cpp | 2 +- externals/coda-oss/modules/c++/types/wscript | 2 +- 11 files changed, 303 insertions(+), 69 deletions(-) diff --git a/externals/coda-oss/modules/c++/mt/tests/ThreadGroupAffinityTest.cpp b/externals/coda-oss/modules/c++/mt/tests/ThreadGroupAffinityTest.cpp index 32d3c63c01..57f3e3f688 100644 --- a/externals/coda-oss/modules/c++/mt/tests/ThreadGroupAffinityTest.cpp +++ b/externals/coda-oss/modules/c++/mt/tests/ThreadGroupAffinityTest.cpp @@ -20,6 +20,8 @@ * */ +#include + #if !defined(__APPLE_CC__) && (defined(__linux) || defined(__linux__)) #include @@ -64,8 +66,8 @@ class MyRunTask : public Runnable // assigned to for (size_t trials = 0; trials < 10; ++trials) { - volatile size_t count = 10000000000; - volatile size_t sum = 0; + constexpr size_t count = 10000000000; + std::atomic sum{0}; for (size_t ii = 0; ii < count; ++ii) { sum++; diff --git a/externals/coda-oss/modules/c++/str/CMakeLists.txt b/externals/coda-oss/modules/c++/str/CMakeLists.txt index 0228ccda72..de3d531b7d 100644 --- a/externals/coda-oss/modules/c++/str/CMakeLists.txt +++ b/externals/coda-oss/modules/c++/str/CMakeLists.txt @@ -3,7 +3,7 @@ set(MODULE_NAME str) coda_add_module( ${MODULE_NAME} VERSION 1.0 - DEPS except-c++ coda_oss-c++) + DEPS types-c++ except-c++ coda_oss-c++) coda_add_tests( MODULE_NAME ${MODULE_NAME} 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 dd32bd5ea3..3adda99b4a 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Convert.h +++ b/externals/coda-oss/modules/c++/str/include/str/Convert.h @@ -20,12 +20,11 @@ * */ +#pragma once #ifndef CODA_OSS_str_Convert_h_INCLUDED_ #define CODA_OSS_str_Convert_h_INCLUDED_ -#pragma once #include -#include #include #include #include @@ -34,20 +33,22 @@ #include #include #include +#include #include "config/Exports.h" #include "coda_oss/string.h" #include "coda_oss/optional.h" #include "coda_oss/cstddef.h" +#include "types/complex.h" #include "import/except.h" namespace str { -template -int getPrecision(const T& type); - -template -int getPrecision(const std::complex& type); +template int getPrecision(const T& type); +template int getPrecision(const std::complex&); +#if CODA_OSS_types_unique_zinteger +template int getPrecision(const types::zinteger&); +#endif namespace details { @@ -334,6 +335,13 @@ int getPrecision(const std::complex& type) { return getPrecision(type.real()); } +#if CODA_OSS_types_unique_zinteger +template +int getPrecision(const types::zinteger& type) +{ + return getPrecision(type.real()); +} +#endif template <> int getPrecision(const float& type); 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 49e4a4894a..0c5af2ff6a 100644 --- a/externals/coda-oss/modules/c++/str/unittests/test_str.cpp +++ b/externals/coda-oss/modules/c++/str/unittests/test_str.cpp @@ -22,8 +22,10 @@ #include // std::ignore +#include #include #include + #include "TestCase.h" inline std::string to_string(const std::string& value) @@ -225,6 +227,88 @@ TEST_CASE(testEscapeForXMLKitchenSink) TEST_ASSERT_EQ(message, expectedMessage); } +TEST_CASE(test_toStringComplexFloat) +{ + const std::string expected("(1,-2)"); + + const std::complex std_cx_float(1.0f, -2.0f); + auto actual = str::toString(std_cx_float); + TEST_ASSERT_EQ(actual, expected); + + const types::zreal types_cx_float(1.0f, -2.0f); + actual = str::toString(types_cx_float); + TEST_ASSERT_EQ(actual, expected); + + const types::zfloat zfloat(1.0f, -2.0f); + actual = str::toString(zfloat); + TEST_ASSERT_EQ(actual, expected); +} +TEST_CASE(test_toTypeComplexFloat) +{ + const std::string strValue("(1,-2)"); + + auto actual = str::toType>(strValue); + auto strActual = str::toString(actual); + TEST_ASSERT_EQ(strActual, strValue); + + actual = str::toType>(strValue); + strActual = str::toString(actual); + TEST_ASSERT_EQ(strActual, strValue); + + actual = str::toType(strValue); + strActual = str::toString(actual); + TEST_ASSERT_EQ(strActual, strValue); +} + +TEST_CASE(test_toStringComplexShort) +{ + const std::string expected("(1,-2)"); + + CODA_OSS_disable_warning_push + #if _MSC_VER + #pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning + #endif + const std::complex std_cx_short(1, -2); + CODA_OSS_disable_warning_pop + auto actual = str::toString(std_cx_short); + TEST_ASSERT_EQ(actual, expected); + + const types::zinteger types_cx_short(std_cx_short); // "copy constructor" or overload + actual = str::toString(types_cx_short); + TEST_ASSERT_EQ(actual, expected); + + const types::zint16_t zint16(1, -2); + actual = str::toString(zint16); + TEST_ASSERT_EQ(actual, expected); +} +TEST_CASE(test_toTypeComplexShort) +{ + const std::string strValue("(1,-2)"); + + CODA_OSS_disable_warning_push + #if _MSC_VER + #pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning + #endif + const auto cx_actual = str::toType>(strValue); + CODA_OSS_disable_warning_pop + auto strActual = str::toString(cx_actual); + TEST_ASSERT_EQ(strActual, strValue); + + CODA_OSS_disable_warning_push + #if _MSC_VER + #pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning + #endif + auto zactual = str::toType>(strValue); + CODA_OSS_disable_warning_pop + strActual = str::toString(zactual); + TEST_ASSERT_EQ(strActual, strValue); + + zactual = str::toType(strValue); + strActual = str::toString(zactual); + TEST_ASSERT_EQ(strActual, strValue); +} + + TEST_MAIN( TEST_CHECK(testTrim); TEST_CHECK(testData); @@ -247,4 +331,8 @@ TEST_MAIN( TEST_CHECK(testRoundDouble); TEST_CHECK(testEscapeForXMLNoReplace); TEST_CHECK(testEscapeForXMLKitchenSink); + TEST_CHECK(test_toStringComplexFloat); + TEST_CHECK(test_toTypeComplexFloat); + TEST_CHECK(test_toStringComplexShort); + TEST_CHECK(test_toTypeComplexShort); ) \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/str/wscript b/externals/coda-oss/modules/c++/str/wscript index 8cefbb5f76..d50988cfdc 100644 --- a/externals/coda-oss/modules/c++/str/wscript +++ b/externals/coda-oss/modules/c++/str/wscript @@ -1,6 +1,6 @@ NAME = 'str' VERSION = '1.0' -MODULE_DEPS = 'except coda_oss' +MODULE_DEPS = 'types except coda_oss' UNITTEST_DEPS = 'sys std' options = configure = distclean = lambda p: None diff --git a/externals/coda-oss/modules/c++/sys/source/Path.cpp b/externals/coda-oss/modules/c++/sys/source/Path.cpp index c466438543..b775585af2 100644 --- a/externals/coda-oss/modules/c++/sys/source/Path.cpp +++ b/externals/coda-oss/modules/c++/sys/source/Path.cpp @@ -178,7 +178,17 @@ std::string Path::absolutePath(const std::string& path) bool Path::isAbsolutePath(const std::string& path) { #ifdef _WIN32 - return !Path::splitDrive(path).first.empty(); + const auto split = Path::splitDrive(path); + const auto drive = split.first; + + // a URL such as "http://example.com" should NOT be an absolute path + // according to std::filesystem::path::is_absolute(). + if (drive.length() > 2) // "C:" + { + return false; // drive letters are single characters, e.g., "C:\Windows" + } + + return !drive.empty(); #else return (!path.empty() && path[0] == Path::delimiter()[0]); #endif diff --git a/externals/coda-oss/modules/c++/sys/unittests/test_path.cpp b/externals/coda-oss/modules/c++/sys/unittests/test_path.cpp index ab838d0275..a444b9c656 100644 --- a/externals/coda-oss/modules/c++/sys/unittests/test_path.cpp +++ b/externals/coda-oss/modules/c++/sys/unittests/test_path.cpp @@ -21,6 +21,8 @@ * */ +#include + #include #include "TestCase.h" @@ -81,6 +83,62 @@ TEST_CASE(testPathMerge) TEST_ASSERT_EQ(result, path); } +TEST_CASE(test_std_filesystem_is_absolute) +{ + std::filesystem::path path +#ifdef _WIN32 + (R"(c:\a\b\c)"); +#else + ("/a/b/c"); +#endif + TEST_ASSERT_TRUE(path.is_absolute()); + path = +#ifdef _WIN32 + R"(a\b\c)"; +#else + "a/b/c"; +#endif + TEST_ASSERT_FALSE(path.is_absolute()); + TEST_ASSERT_TRUE(path.is_relative()); + + const std::filesystem::path slash("/"); + // https://en.cppreference.com/w/cpp/filesystem/path/is_absrel + // "The path "/" is absolute on a POSIX OS, but is relative on Windows." +#ifdef _WIN32 + TEST_ASSERT_TRUE(slash.is_relative()); + TEST_ASSERT_FALSE(slash.is_absolute()); +#else + TEST_ASSERT_TRUE(slash.is_absolute()); + TEST_ASSERT_FALSE(slash.is_relative()); +#endif + + std::filesystem::path url("x://example.com"); // 1 letter +#ifdef _WIN32 + TEST_ASSERT_TRUE(url.is_absolute()); // looks like a drive letter on Windows + TEST_ASSERT_FALSE(url.is_relative()); +#else + TEST_ASSERT_FALSE(url.is_absolute()); + TEST_ASSERT_TRUE(url.is_relative()); +#endif + + url = "s3://example.com"; // 2 letters + TEST_ASSERT_FALSE(url.is_absolute()); + TEST_ASSERT_TRUE(url.is_relative()); // Should this be false? + + url = "ftp://example.com"; // 3 letters + TEST_ASSERT_FALSE(url.is_absolute()); + + url = "http://example.com"; // 4 letters + TEST_ASSERT_FALSE(url.is_absolute()); + + url = "https://example.com"; // 5 letters + TEST_ASSERT_FALSE(url.is_absolute()); + + url = "mailto:nobody@example.com"; // 6 letters + TEST_ASSERT_FALSE(url.is_absolute()); + TEST_ASSERT_TRUE(url.is_relative()); // Should this be false? +} + TEST_CASE(testExpandEnvTilde) { auto path = sys::Path::expandEnvironmentVariables("~"); @@ -322,6 +380,7 @@ TEST_CASE(testModifyVar2) TEST_MAIN( TEST_CHECK(testPathMerge); + TEST_CHECK(test_std_filesystem_is_absolute); TEST_CHECK(testExpandEnvTilde); TEST_CHECK(testExpandEnv); TEST_CHECK(testExpandEnvTildePath); diff --git a/externals/coda-oss/modules/c++/types/CMakeLists.txt b/externals/coda-oss/modules/c++/types/CMakeLists.txt index d1accfb2eb..00881001ca 100644 --- a/externals/coda-oss/modules/c++/types/CMakeLists.txt +++ b/externals/coda-oss/modules/c++/types/CMakeLists.txt @@ -2,7 +2,7 @@ set(MODULE_NAME types) coda_add_module(${MODULE_NAME} VERSION 1.0 - DEPS coda_oss-c++ config-c++ gsl-c++ coda_oss-c++) + DEPS coda_oss-c++ config-c++ gsl-c++) coda_add_tests( MODULE_NAME ${MODULE_NAME} diff --git a/externals/coda-oss/modules/c++/types/include/types/complex.h b/externals/coda-oss/modules/c++/types/include/types/complex.h index f6051594c7..95e6132d3a 100644 --- a/externals/coda-oss/modules/c++/types/include/types/complex.h +++ b/externals/coda-oss/modules/c++/types/include/types/complex.h @@ -27,49 +27,41 @@ #include -// TODO: remove this once TIntergers are switched to types::details::complex -// '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. -#ifndef _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING -#define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING -#endif - #include #include +#include #include "config/disable_compiler_warnings.h" #include "coda_oss/CPlusPlus.h" namespace types { -namespace details -{ /*! - * \class complex + * \class zintegerT * \brief Our own implementation of std::complex for SIX and friends. * - * `std::complex` is no longer valid C++; provide a (partial) work-around. - * See https://en.cppreference.com/w/cpp/numeric/complex for detals. - * - * SIX (and others) mostly use `std::complex` as a - * convenient package for two values; very little "complex math" is done - * using integers. + * `std::complex` is no longer valid C++; provide a (partial) work-around. + * See https://en.cppreference.com/w/cpp/numeric/complex for details. + * + * SIX (and others) mostly use `std::complex` as a convenient + * package for two values; very little "complex math" is done using integers. */ -template -struct complex final +template +struct zintegerT final { using value_type = T; static_assert(!std::is_floating_point::value, "Use std::complex for floating-point."); static_assert(std::is_signed::value, "T should be a signed integer."); - complex(value_type re = 0, value_type im = 0) : z{re, im} {} - complex(const complex&) = default; - complex& operator=(const complex&) = default; - complex(complex&&) = default; - complex& operator=(complex&&) = default; - ~complex() = default; + zintegerT(value_type re = 0, value_type im = 0) : z{re, im} { } + zintegerT(const zintegerT&) = default; + zintegerT& operator=(const zintegerT&) = default; + zintegerT(zintegerT&&) = default; + zintegerT& operator=(zintegerT&&) = default; + ~zintegerT() = default; - // If someone already has a std::complex, is there any harm in creating ours? - complex(const std::complex& z_) : complex(z_.real(), z_.imag()) {} + // If someone already has a std::complex, is there any harm in creating ours? + zintegerT(const std::complex& z_) : zintegerT(z_.real(), z_.imag()) { } value_type real() const { @@ -95,51 +87,126 @@ struct complex final CODA_OSS_disable_warning_push #ifdef _MSC_VER -#pragma warning(disable: 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. +#pragma warning(disable : 4996) // '...': warning STL4037: The effect of instantiating the template std::complex for any type other than float, double, or long double is unspecified. You can define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING to suppress this warning. #endif - -template -inline const std::complex& cast(const complex& z) +// Getting different results with GCC vs MSVC :-( So just use +// std::complex Assume by the time we're actually using C++23 with a +// compiler that enforces this restriction, "something" will be different. +template +inline const std::complex& cast(const zintegerT& z) { - // Getting different results with GCC vs MSVC :-( So just use - // std::complex Assume by the time we're actually using C++23 with a - // compiler that enforces this restriction, "something" will be different. const void* const pZ_ = &z; return *static_cast*>(pZ_); } - +template +inline std::complex& cast(zintegerT& z) +{ + void* const pZ_ = &z; + return *static_cast*>(pZ_); +} CODA_OSS_disable_warning_pop -// https://en.cppreference.com/w/cpp/numeric/complex/abs -template -inline auto abs(const complex& z) +// https://en.cppreference.com/w/cpp/numeric/complex/operator_ltltgtgt +template +inline auto& operator<<(std::basic_ostream& o, const zintegerT& z) { - return abs(cast(z)); + return o << cast(z); +} +template +inline auto& operator>>(std::basic_istream& o, zintegerT& z) +{ + return o >> cast(z); } +// https://en.cppreference.com/w/cpp/numeric/complex/operator_cmp +template +inline bool operator==(const zintegerT& lhs, const zintegerT& rhs) +{ + return (lhs.real() == rhs.real()) && (lhs.imag() == rhs.imag()); +} +template +inline bool operator!=(const zintegerT& lhs, const zintegerT& rhs) +{ + return !(lhs == rhs); } -//// Have the compiler pick between std::complex and details::complex -//template -//using complex = std::conditional_t::value, std::complex, details::complex>; -//static_assert(std::is_same, complex>::value, "should be details::complex"); +// Keep functions like abs() to a minimum; complex math probably shouldn't be done with integers. +template +inline auto abs(const zintegerT& z) // https://en.cppreference.com/w/cpp/numeric/complex/abs +{ + return abs(cast(z)); +} + +// Control whether zinteger is std::complex or details::zintegerT. +// If it is std::complex, then a types::zinteger overload normally can't be +// used as it will be the same as std::complex +#ifdef CODA_OSS_types_FORCE_unique_zinteger // bypass checks below +#define CODA_OSS_types_unique_zinteger 1 +#endif +#ifdef CODA_OSS_types_NO_unique_zinteger +#ifdef CODA_OSS_types_unique_zinteger +#error "CODA_OSS_types_unique_zinteger already #define'd" +#endif +#define CODA_OSS_types_unique_zinteger 0 +#endif + +#ifndef CODA_OSS_types_unique_zinteger +// If the warning about using std::complex has been turned off, we might +// as well use std:complex. +#ifdef _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING +#define CODA_OSS_types_unique_zinteger 0 +#endif +#endif + +#ifndef CODA_OSS_types_unique_zinteger +#define CODA_OSS_types_unique_zinteger 1 +#endif + +template +#if CODA_OSS_types_unique_zinteger +using zinteger = zintegerT; +#else +using zinteger = std::complex; +#endif + +namespace details +{ +// Explicit specializations so that clients can't do zreal +template struct zreal; +template<> struct zreal final +{ + using type = std::complex; +}; +template<> struct zreal final +{ + using type = std::complex; +}; +template<> struct zreal final +{ + using type = std::complex; +}; +} // namespace details template -using complex = std::complex; +using zreal = typename details::zreal::type; -static_assert(std::is_same, complex>::value, "should be std::complex"); -static_assert(sizeof(std::complex) == sizeof(complex), "sizeof(sizeof(std::complex) != sizeof(complex)"); +// This might be more trouble than it's worth: there really isn't that much code +// that is generic for both integer and real complex types; recall that the primary +// use of `std::integer` is a "convenient package" for two values. +// +//Have the compiler pick between std::complex and details::complex +//template +//using complex = std::conditional_t::value, zreal_t, zinteger_t>; +static_assert(sizeof(std::complex) == sizeof(zintegerT), "sizeof(sizeof(std::complex) != sizeof(zintegerT)"); +static_assert(std::is_same, zreal>::value, "should be std::complex"); // Convenient aliases -using zfloat = complex; // std::complex -using zdouble = complex; // std::complex -//using zlong_double = complex; // std::complex - -// Intentionally using somewhat cumbersome names -// TODO: switch TIntergers to types::details::complex -using zint8_t = complex; // details:complex -using zint16_t = complex; // details:complex -using zint32_t = complex; // details::complex -using zint64_t = complex; // details::complex +using zfloat = zreal; // std::complex +using zdouble = zreal; // std::complex +//using zlong_double = zreal_t; // std::complex +using zint8_t = zinteger; // details:complex +using zint16_t = zinteger; // details:complex +using zint32_t = zinteger; // details::complex +using zint64_t = zinteger; // details::complex } #endif // CODA_OSS_types_complex_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp b/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp index 6410e48f30..a16fc758b2 100644 --- a/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp +++ b/externals/coda-oss/modules/c++/types/unittests/test_complex.cpp @@ -46,7 +46,7 @@ TEST_CASE(TestCxShort_abs) auto actual = abs(types_zint16); TEST_ASSERT_EQ(actual, expected); - const types::complex types_cx_int16(cx_short); + const types::zinteger types_cx_int16(cx_short); actual = abs(types_cx_int16); TEST_ASSERT_EQ(actual, expected); } diff --git a/externals/coda-oss/modules/c++/types/wscript b/externals/coda-oss/modules/c++/types/wscript index 67379c3bb5..eb974e3b81 100644 --- a/externals/coda-oss/modules/c++/types/wscript +++ b/externals/coda-oss/modules/c++/types/wscript @@ -1,6 +1,6 @@ NAME = 'types' VERSION = '1.0' -MODULE_DEPS = 'coda_oss config gsl coda_oss' +MODULE_DEPS = 'coda_oss config gsl' UNITTEST_DEPS = 'sys' options = configure = distclean = lambda p: None