diff --git a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h index e6e19a8ad..c8c51ed42 100644 --- a/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h +++ b/externals/coda-oss/modules/c++/coda_oss/include/coda_oss/cstddef.h @@ -22,7 +22,10 @@ #define CODA_OSS_coda_oss_cstddef_h_INCLUDED_ #pragma once +#include + #include +#include // Need a fairly decent C++ compiler to use the real GSL. This brings in more than // we really need for span (e.g., gsl::narrow()), but it keeps things simple. @@ -37,5 +40,6 @@ namespace coda_oss enum class byte : unsigned char {}; #endif // GSL_BYTE_H } +static_assert(!std::is_same::value, "'coda_oss::byte' should be a unique type."); #endif // CODA_OSS_coda_oss_cstddef_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/std/include/std/cstddef b/externals/coda-oss/modules/c++/std/include/std/cstddef index 56700ec71..10ba7deac 100644 --- a/externals/coda-oss/modules/c++/std/include/std/cstddef +++ b/externals/coda-oss/modules/c++/std/include/std/cstddef @@ -22,7 +22,10 @@ #define CODA_OSS_std_cstddef_INCLUDED_ #pragma once +#include + #include +#include #include "coda_oss/cstddef.h" #include "coda_oss/CPlusPlus.h" @@ -41,6 +44,7 @@ namespace std // This is slightly uncouth: we're not supposed to augment "std". { using coda_oss::byte; } +static_assert(!std::is_same::value, "'std::byte' should be a unique type."); #endif // !CODA_OSS_NO_std_byte #endif // CODA_OSS_std_cstddef_INCLUDED_ \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/sys/include/sys/AbstractOS.h b/externals/coda-oss/modules/c++/sys/include/sys/AbstractOS.h index 158bce489..3c8a6b0e6 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/AbstractOS.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/AbstractOS.h @@ -99,6 +99,11 @@ struct CODA_OSS_API AbstractOS const std::string& fragment = "", const std::string& extension = "", bool recursive = true) const; + std::vector search( + const std::vector& searchPaths, + const std::string& fragment = "", + const std::string& extension = "", + bool recursive = true) const; /*! * Does this path exist? diff --git a/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h b/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h index f333cb3f8..57cffe3f3 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/ByteSwapValue.h @@ -127,7 +127,7 @@ namespace sys // * `struct`s have padding that should be ignored. // * each individual member of a `struct` should be byte-swaped // * byte-swaped `float` or `double` bits are nonsense - return !std::is_compound::value; + return (std::is_integral::value || std::is_enum::value) || !std::is_compound::value; } } diff --git a/externals/coda-oss/modules/c++/sys/source/AbstractOS.cpp b/externals/coda-oss/modules/c++/sys/source/AbstractOS.cpp index 549415680..ede2d6cce 100644 --- a/externals/coda-oss/modules/c++/sys/source/AbstractOS.cpp +++ b/externals/coda-oss/modules/c++/sys/source/AbstractOS.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -83,6 +85,31 @@ AbstractOS::search(const std::vector& searchPaths, return elementsFound; } +inline auto convert(const std::vector& paths) +{ + std::vector retval; + std::transform(paths.begin(), paths.end(), std::back_inserter(retval), + [](const fs::path& p) { return p.string(); }); + return retval; +} +inline auto convert(const std::vector& paths) +{ + std::vector retval; + std::transform(paths.begin(), paths.end(), std::back_inserter(retval), + [](const auto& p) { return p; }); + return retval; +} + +std::vector AbstractOS::search( + const std::vector& searchPaths, + const std::string& fragment, + const std::string& extension, + bool recursive) const +{ + const auto results = search(convert(searchPaths), fragment, extension, recursive); + return convert(results); +} + void AbstractOS::remove(const std::string& path) const { if (isDirectory(path)) diff --git a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Attributes.h b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Attributes.h index 8b354844b..b8823164d 100644 --- a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Attributes.h +++ b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/Attributes.h @@ -217,6 +217,10 @@ struct Attributes final { return static_cast(size()); } + bool empty() const + { + return mAttributes.empty(); + } /*! * Look up an attribute's local name by index. @@ -396,6 +400,16 @@ struct Attributes final { mAttributes.clear(); } + + auto begin() const + { + return mAttributes.begin(); + } + auto end() const + { + return mAttributes.end(); + } + private: //! Underlying representation Attributes_T mAttributes; diff --git a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h index 8942aaf57..3cdde6884 100644 --- a/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h +++ b/externals/coda-oss/modules/c++/xml.lite/include/xml/lite/ValidatorXerces.h @@ -137,6 +137,9 @@ class ValidatorXerces : public ValidatorInterface bool validate(const coda_oss::u8string&, const std::string& xmlID, std::vector&) const override; bool validate(const str::W1252string&, const std::string& xmlID, std::vector&) const override; + // Search each directory for XSD files + static std::vector loadSchemas(const std::vector& schemaPaths, bool recursive=true); + private: bool validate_(const coda_oss::u8string& xml, const std::string& xmlID, diff --git a/externals/coda-oss/modules/c++/xml.lite/source/ValidatorXerces.cpp b/externals/coda-oss/modules/c++/xml.lite/source/ValidatorXerces.cpp index 7657e7b8a..7e794d4e4 100644 --- a/externals/coda-oss/modules/c++/xml.lite/source/ValidatorXerces.cpp +++ b/externals/coda-oss/modules/c++/xml.lite/source/ValidatorXerces.cpp @@ -26,6 +26,7 @@ #include #include #include +#include // std::ignore #include #include @@ -89,6 +90,14 @@ inline std::vector convert(const std::vector& schemaPaths [](const fs::path& p) { return p.string(); }); return retval; } +inline auto convert(const std::vector& paths) +{ + std::vector retval; + std::transform(paths.begin(), paths.end(), std::back_inserter(retval), + [](const auto& p) { return p; }); + return retval; +} + ValidatorXerces::ValidatorXerces( const std::vector& schemaPaths, logging::Logger* log, @@ -154,19 +163,18 @@ ValidatorXerces::ValidatorXerces( // load our schemas -- // search each directory for schemas - sys::OS os; - std::vector schemas = - os.search(schemaPaths, "", ".xsd", recursive); + const auto schemas = loadSchemas(convert(schemaPaths), recursive); // add the schema to the validator - for (size_t i = 0; i < schemas.size(); ++i) + // add the schema to the validator + for (auto&& schema : schemas) { - if (!mValidator->loadGrammar(schemas[i].c_str(), + if (!mValidator->loadGrammar(schema.c_str(), xercesc::Grammar::SchemaGrammarType, true)) { std::ostringstream oss; - oss << "Error: Failure to load schema " << schemas[i]; + oss << "Error: Failure to load schema " << schema; log->warn(Ctxt(oss.str())); } } @@ -175,6 +183,14 @@ ValidatorXerces::ValidatorXerces( mSchemaPool->lockPool(); } +std::vector ValidatorXerces::loadSchemas(const std::vector& schemaPaths, bool recursive) +{ + // load our schemas -- + // search each directory for schemas + sys::OS os; + return os.search(schemaPaths, "", ".xsd", recursive); +} + // From config.h.in: Define to the 16 bit type used to represent Xerces UTF-16 characters // On Windows, this needs to be wchar_t so that various "wide character" Win32 APIs can be called. static_assert(sizeof(XMLCh) == 2, "XMLCh should be two bytes for UTF-16."); diff --git a/externals/nitro/modules/c++/nitf/include/nitf/DecompressionInterface.hpp b/externals/nitro/modules/c++/nitf/include/nitf/DecompressionInterface.hpp index 55e815b04..14a75889a 100644 --- a/externals/nitro/modules/c++/nitf/include/nitf/DecompressionInterface.hpp +++ b/externals/nitro/modules/c++/nitf/include/nitf/DecompressionInterface.hpp @@ -24,6 +24,8 @@ #define __NITF_DECOMPRESSION_INTERFACE_HPP__ #pragma once +#include + #include #include #include @@ -87,10 +89,8 @@ namespace nitf * during decompression, and gives a c++ api for getting * things done. */ -class DecompressionInterface +struct DecompressionInterface final { -public: - //! These are canned methods which turn around // and call the nitf_DecompressionControl of your choice static NITF_BOOL adapterStart(nitf_DecompressionControl* object, @@ -121,7 +121,7 @@ class DecompressionInterface * \class Compressor * \brief This is the c++ interface for nitf_CompressionControl */ -struct Decompressor +struct Decompressor final { Decompressor() = default; virtual ~Decompressor() {} diff --git a/externals/nitro/modules/c++/nitf/source/DecompressionInterface.cpp b/externals/nitro/modules/c++/nitf/source/DecompressionInterface.cpp index d91bebe96..06328eef4 100644 --- a/externals/nitro/modules/c++/nitf/source/DecompressionInterface.cpp +++ b/externals/nitro/modules/c++/nitf/source/DecompressionInterface.cpp @@ -26,6 +26,35 @@ using namespace nitf; +template +static inline auto invoke(nitf_Error* error, const char* file, int line, const char* func, + TReturn catch_return, TFunction f) +{ + try + { + return f(); + } + catch (const except::Exception& ex) + { + Utils::error_init(error, ex.getMessage(), file, line, func, NRT_ERR_DECOMPRESSION); + } + catch (const std::exception& ex) + { + Utils::error_init(error, ex, file, line, func, NRT_ERR_DECOMPRESSION); + } + catch (...) + { + nrt_Error_init(error, "Unknown error", file, line, func, NRT_ERR_DECOMPRESSION); + } + + return catch_return; +} + +// Ensure the return type is deduced correctly. NRT_SUCCESS/NRT_FAILURE +// is `int`, not `NITF_BOOL`. +constexpr NITF_BOOL nrt_success = NRT_SUCCESS; +constexpr NITF_BOOL nrt_failure = NRT_FAILURE; + NITF_BOOL DecompressionInterface::adapterStart( nitf_DecompressionControl* object, nitf_IOInterface* io, @@ -35,7 +64,7 @@ NITF_BOOL DecompressionInterface::adapterStart( uint64_t* blockMask, nitf_Error* error) { - try + return invoke(error, NRT_CTXT, nrt_failure, [&]() { nitf::IOInterface ioInter(io); ioInter.setManaged(true); @@ -46,26 +75,8 @@ NITF_BOOL DecompressionInterface::adapterStart( fileLength, blockInfo, blockMask); - return NRT_SUCCESS; - } - catch (const except::Exception& ex) - { - Utils::error_init(error, ex.getMessage(), NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return NRT_FAILURE; - } - catch (const std::exception& ex) - { - Utils::error_init(error, ex, NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return NRT_FAILURE; - } - catch (...) - { - nrt_Error_init(error, "Unknown error", NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return NRT_FAILURE; - } + return nrt_success; + }); } uint8_t* DecompressionInterface::adapterReadBlock( @@ -74,29 +85,24 @@ uint8_t* DecompressionInterface::adapterReadBlock( uint64_t* blockSize, nitf_Error* error) { - try - { + const auto f = [&]() { return static_cast(object)->readBlock(blockNumber, blockSize); - } - catch (const except::Exception& ex) - { - Utils::error_init(error, ex.getMessage(), NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return nullptr; - } - catch (const std::exception& ex) - { - Utils::error_init(error, ex, NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return nullptr; - } - catch (...) + }; + using retval_t = decltype(f()); + return invoke(error, NRT_CTXT, static_cast(nullptr), f); +} + +NITF_BOOL DecompressionInterface::adapterFreeBlock( + nitf_DecompressionControl* object, + uint8_t* block, + nitf_Error* error) +{ + return invoke(error, NRT_CTXT, nrt_failure, [&]() { - nrt_Error_init(error, "Unknown error", NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return nullptr; - } + static_cast(object)->freeBlock(block); + return nrt_success; + }); } NITF_BOOL DecompressionInterface::adapterFreeBlock( @@ -104,29 +110,11 @@ NITF_BOOL DecompressionInterface::adapterFreeBlock( std::byte* block, nitf_Error* error) { - try + return invoke(error, NRT_CTXT, nrt_failure, [&]() { static_cast(object)->freeBlock(block); - return NRT_SUCCESS; - } - catch (const except::Exception& ex) - { - Utils::error_init(error, ex.getMessage(), NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return NRT_FAILURE; - } - catch (const std::exception& ex) - { - Utils::error_init(error, ex, NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return NRT_FAILURE; - } - catch (...) - { - nrt_Error_init(error, "Unknown error", NRT_CTXT, - NRT_ERR_DECOMPRESSION); - return NRT_FAILURE; - } + return nrt_success; + }); } void DecompressionInterface::adapterDestroy(