diff --git a/externals/coda-oss/modules/c++/cli/include/cli/Results.h b/externals/coda-oss/modules/c++/cli/include/cli/Results.h index 1a74cc7aab..bd293cf695 100644 --- a/externals/coda-oss/modules/c++/cli/include/cli/Results.h +++ b/externals/coda-oss/modules/c++/cli/include/cli/Results.h @@ -25,6 +25,9 @@ #define CODA_OSS_cli_Results_h_INCLUDED_ #include +#include +#include +#include #include "sys/Conf.h" @@ -33,10 +36,9 @@ namespace cli { -class Results +class Results final { -protected: - typedef std::map ValueStorage_T; + typedef std::map> ValueStorage_T; typedef ValueStorage_T::iterator ValueIter_T; typedef ValueStorage_T::const_iterator ConstValueIter_T; typedef std::map ResultsStorage_T; @@ -44,13 +46,15 @@ class Results typedef ResultsStorage_T::const_iterator ConstResultsIter_T; public: - Results() - { - } + Results() = default; ~Results() { destroy(); } + Results(const Results&) = delete; + Results& operator=(const Results&) = delete; + Results(Results&&) = default; + Results& operator=(Results&&) = default; bool hasValue(const std::string& key) const { @@ -62,20 +66,30 @@ class Results return mResults.find(key) != mResults.end(); } - cli::Value* operator[](const std::string& key) const + const cli::Value* operator[](const std::string& key) const { return getValue(key); } - cli::Value* getValue(const std::string& key) const + const cli::Value* getValue(const std::string& key) const { - ConstValueIter_T p = mValues.find(key); + auto const p = mValues.find(key); if (p == mValues.end()) { const std::string errorMessage = "No argument named " + key; throw except::NoSuchKeyException(Ctxt(errorMessage)); } - return p->second; + return p->second.get(); + } + cli::Value* getValue(const std::string& key) + { + auto const p = mValues.find(key); + if (p == mValues.end()) + { + const std::string errorMessage = "No argument named " + key; + throw except::NoSuchKeyException(Ctxt(errorMessage)); + } + return p->second.get(); } template @@ -100,15 +114,22 @@ class Results return p->second; } - void put(const std::string& key, cli::Value *value) + void put(const std::string& key, std::unique_ptr value) + { + if (hasValue(key) && (getValue(key) == value.get())) + { + return; + } + mValues[key] = std::move(value); + } + void put(const std::string& key, cli::Value* value) { - if (hasValue(key)) + cli::Value* pExistingValue = hasValue(key) ? getValue(key) : nullptr; + if ((pExistingValue == nullptr) || (pExistingValue != value)) { - cli::Value* existing = getValue(key); - if (existing != value) - delete getValue(key); + // Either 1) we didn't already have a value or 2) the existing value is different + put(key, std::unique_ptr(value)); } - mValues[key] = value; } void put(const std::string& key, cli::Results *args) @@ -122,26 +143,21 @@ class Results mResults[key] = args; } - typedef ValueStorage_T::iterator iterator; - typedef ValueStorage_T::const_iterator const_iterator; + auto begin() { return mValues.begin(); } + auto begin() const { return mValues.begin(); } + auto end() { return mValues.end(); } + auto end() const { return mValues.end(); } - iterator begin() { return mValues.begin(); } - const_iterator begin() const { return mValues.begin(); } - iterator end() { return mValues.end(); } - const_iterator end() const { return mValues.end(); } - -protected: +private: ValueStorage_T mValues; ResultsStorage_T mResults; void destroy() { - for (ValueIter_T it = mValues.begin(), end = mValues.end(); it != end; ++it) - delete it->second; + mValues.clear(); for (ResultsIter_T it = mResults.begin(), end = mResults.end(); it != end; ++it) delete it->second; - mValues.clear(); mResults.clear(); } }; diff --git a/externals/coda-oss/modules/c++/cli/include/cli/Value.h b/externals/coda-oss/modules/c++/cli/include/cli/Value.h index 571565cab5..49f1125ebd 100644 --- a/externals/coda-oss/modules/c++/cli/include/cli/Value.h +++ b/externals/coda-oss/modules/c++/cli/include/cli/Value.h @@ -26,6 +26,7 @@ #include #include +#include #include #include "sys/Conf.h" @@ -38,12 +39,9 @@ namespace cli * The Value class provides access to one or more actual values. * It provides index-based access to parameters. */ -class CODA_OSS_API Value +struct CODA_OSS_API Value final { -public: - Value() - { - } + Value() = default; template explicit Value(std::vector value) @@ -57,12 +55,6 @@ class CODA_OSS_API Value set(value); } - template - Value(T* value, size_t size, bool own = false) - { - set(value, size, own); - } - ~Value() { cleanup(); @@ -75,17 +67,6 @@ class CODA_OSS_API Value mValues.push_back(str::toString(value)); } - template - void set(T* value, size_t size, bool own = false) - { - cleanup(); - mValues.reserve(size); - for (size_t i = 0; i < size; ++i) - add(value[i]); - if (own) - delete[] value; - } - template void setContainer(const std::vector& c) { @@ -106,7 +87,7 @@ class CODA_OSS_API Value { if (index >= mValues.size()) throw except::IndexOutOfRangeException( - Ctxt(FmtX("Invalid index: %d", index))); + Ctxt(str::Format("Invalid index: %d", index))); return str::toType(mValues[index]); } diff --git a/externals/coda-oss/modules/c++/cli/source/Argument.cpp b/externals/coda-oss/modules/c++/cli/source/Argument.cpp index 01b2563233..8b924f30a7 100644 --- a/externals/coda-oss/modules/c++/cli/source/Argument.cpp +++ b/externals/coda-oss/modules/c++/cli/source/Argument.cpp @@ -54,7 +54,7 @@ cli::Argument::~Argument() cli::Argument* cli::Argument::addFlag(const std::string& flag) { char p = mParser->mPrefixChar; - std::string p2 = FmtX("%c%c", p, p); + std::string p2 = str::Format("%c%c", p, p); if (flag.size() > 2 && str::startsWith(flag, p2) && flag[2] != p) mLongFlags.push_back(validateFlag(flag.substr(2))); else if (flag.size() > 1 && flag[0] == p && flag[1] != p) diff --git a/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp b/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp index e7763e4aae..367ff9edce 100644 --- a/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp +++ b/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp @@ -28,10 +28,11 @@ #include #include +#include namespace { -static const size_t MAX_ARG_LINE_LENGTH = 21; +constexpr size_t MAX_ARG_LINE_LENGTH = 21; bool containsOnly(const std::string& str, const std::map& flags) @@ -284,6 +285,20 @@ cli::Results* cli::ArgumentParser::parse(const std::vector& args) return parse("cli::ArgumentParser::parse" /*program*/, args).release(); // provide a "meaningful" default program name } } + +static auto put(cli::Results& currentResults, const std::string& argVar, + cli::Value* v, std::unique_ptr&& v_) +{ + if (v == v_.get()) // no existing value, using the newly created std::unique_ptr + { + currentResults.put(argVar, std::move(v_)); + } + else + { + currentResults.put(argVar, v); // already had a value, just update + } +} + std::unique_ptr cli::ArgumentParser::parse(const std::string& program, const std::vector& args) { if (!program.empty()) @@ -318,7 +333,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog std::map& flagMap = (subOption ? shortOptionsFlags : shortFlags); if (flagMap.find(op) != flagMap.end()) - parseError(FmtX("Conflicting option: %c%s", mPrefixChar, op)); + parseError(str::Format("Conflicting option: %c%s", mPrefixChar, op)); flagMap[op] = arg; } for (std::vector::const_iterator it = @@ -328,7 +343,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog std::map& flagMap = (subOption ? longOptionsFlags : longFlags); if (flagMap.find(op) != flagMap.end()) - parseError(FmtX("Conflicting option: %c%c%s", mPrefixChar, mPrefixChar, op)); + parseError(str::Format("Conflicting option: %c%c%s", mPrefixChar, mPrefixChar, op)); flagMap[op] = arg; } } @@ -457,7 +472,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } else { - throw except::Exception(Ctxt(FmtX("Invalid option: [%s]", argStr))); + throw except::Exception(Ctxt(str::Format("Invalid option: [%s]", argStr))); } } } @@ -498,7 +513,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } else { - throw except::Exception(Ctxt(FmtX("Invalid option: [%s]", argStr))); + throw except::Exception(Ctxt(str::Format("Invalid option: [%s]", argStr))); } } @@ -513,9 +528,8 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog { case cli::STORE: { - cli::Value* v = currentResults->hasValue(argVar) - ? currentResults->getValue(argVar) - : new cli::Value; + auto v_ = std::make_unique(); + auto v = currentResults->hasValue(argVar) ? currentResults->getValue(argVar) : v_.get(); int maxArgs = arg->getMaxArgs(); // risky, I know... bool added = false; @@ -545,16 +559,16 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } if (!added) - parseError(FmtX("option requires value or has exceeded its max: [%s]", argVar)); + parseError(str::Format("option requires value or has exceeded its max: [%s]", argVar)); - currentResults->put(argVar, v); + put(*currentResults, argVar, v, std::move(v_)); break; } case cli::STORE_TRUE: - currentResults->put(argVar, new cli::Value(true)); + currentResults->put(argVar, std::make_unique(true)); break; case cli::STORE_FALSE: - currentResults->put(argVar, new cli::Value(false)); + currentResults->put(argVar, std::make_unique(false)); break; case cli::STORE_CONST: { @@ -565,10 +579,10 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog case cli::SUB_OPTIONS: { if (optionsStr.empty()) - parseError(FmtX("invalid sub option: [%s]", argVar.c_str())); - cli::Value* v = currentResults->hasValue(optionsStr) - ? currentResults->getValue(optionsStr) - : new cli::Value; + parseError(str::Format("invalid sub option: [%s]", argVar.c_str())); + + auto v_ = std::make_unique(); + auto v = currentResults->hasValue(optionsStr) ? currentResults->getValue(optionsStr) : v_.get(); if (i < s - 1) { std::string nextArg = explodedArgs[i + 1]; @@ -589,7 +603,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog // this indicates the sub op is a bool v->add(true); } - currentResults->put(optionsStr, v); + put(*currentResults, optionsStr, v, std::move(v_)); break; } case cli::VERSION: @@ -601,24 +615,22 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog { // it's a positional argument cli::Value* lastPosVal = nullptr; - for (std::vector::iterator it = - positionalArgs.begin(); it != positionalArgs.end(); ++it) + for (auto&& posArg : positionalArgs) { - cli::Argument *posArg = *it; std::string argVar = posArg->getVariable(); int maxArgs = posArg->getMaxArgs(); if (currentResults->hasValue(argVar)) { - cli::Value *posVal = lastPosVal - = currentResults->getValue(argVar); - if (static_cast(posVal->size()) >= maxArgs) + lastPosVal = currentResults->getValue(argVar); + if (gsl::narrow(lastPosVal->size()) >= maxArgs) continue; break; } else if (maxArgs != 0) { - lastPosVal = new cli::Value; - currentResults->put(argVar, lastPosVal); + auto lastPosVal_ = std::make_unique(); + lastPosVal = lastPosVal_.get(); + currentResults->put(argVar, std::move(lastPosVal_)); break; } } @@ -651,12 +663,11 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog if (defaultVal != nullptr) results->put(argVar, defaultVal->clone()); else if (arg->getAction() == cli::STORE_FALSE) - results->put(argVar, new cli::Value(true)); + results->put(argVar, std::make_unique(true)); else if (arg->getAction() == cli::STORE_TRUE) - results->put(argVar, new cli::Value(false)); + results->put(argVar, std::make_unique(false)); else if (arg->isRequired()) - parseError(FmtX("missing required argument: [%s]", - argVar.c_str())); + parseError(str::Format("missing required argument: [%s]", argVar)); } @@ -670,9 +681,9 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog if (arg->isRequired() || numGiven > 0) { if (minArgs > 0 && numGiven < static_cast(minArgs)) - parseError(FmtX("not enough arguments, %d required: [%s]", minArgs, argId)); + parseError(str::Format("not enough arguments, %d required: [%s]", minArgs, argId)); if (maxArgs >= 0 && numGiven > static_cast(maxArgs)) - parseError(FmtX("too many arguments, %d supported: [%s]", maxArgs, argId)); + parseError(str::Format("too many arguments, %d supported: [%s]", maxArgs, argId)); } @@ -682,7 +693,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog if (numGiven > 0 && !choices.empty()) { bool isValid = false; - cli::Value *vals = results->getValue(argVar); + auto vals = results->getValue(argVar); for (size_t ii = 0; ii < numGiven; ++ii) { @@ -695,7 +706,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } if (!isValid) { - parseError(FmtX("invalid option for [%s]", argVar.c_str())); + parseError(str::Format("invalid option for [%s]", argVar.c_str())); } } } diff --git a/externals/coda-oss/modules/c++/cli/unittests/test_cli.cpp b/externals/coda-oss/modules/c++/cli/unittests/test_cli.cpp index ade63b34ac..d8d1578ff9 100644 --- a/externals/coda-oss/modules/c++/cli/unittests/test_cli.cpp +++ b/externals/coda-oss/modules/c++/cli/unittests/test_cli.cpp @@ -160,7 +160,7 @@ TEST_CASE(testIterate) std::unique_ptr results(parser.parse(str::split("-v -c config.xml"))); std::vector keys; - for(cli::Results::const_iterator it = results->begin(); it != results->end(); ++it) + for(auto it = results->begin(); it != results->end(); ++it) keys.push_back(it->first); TEST_ASSERT_EQ(std::ssize(keys), 2); // std::map returns keys in alphabetical order... @@ -186,14 +186,9 @@ TEST_CASE(testRequiredThrows) parser.addArgument("-c --config", "Specify a config file", cli::STORE) ->setRequired(true); - // The exceptions leak memory which causes an ASAN diagnostic on Linux. - #if CODA_OSS_POSIX_SOURCE && __SANITIZE_ADDRESS__ - TEST_SUCCESS; - #else const std::string program(testName); TEST_EXCEPTION(parser.parse(program, str::split(""))); TEST_EXCEPTION(parser.parse(program, str::split("-c"))); - #endif } TEST_CASE(testUnknownArgumentsOptions) diff --git a/externals/coda-oss/modules/c++/io/source/FileInputStreamIOS.cpp b/externals/coda-oss/modules/c++/io/source/FileInputStreamIOS.cpp index e1585d16ba..5ff403893d 100644 --- a/externals/coda-oss/modules/c++/io/source/FileInputStreamIOS.cpp +++ b/externals/coda-oss/modules/c++/io/source/FileInputStreamIOS.cpp @@ -91,7 +91,7 @@ void io::FileInputStreamIOS::open(const char *file, mFStream.open(file, mode); if (!isOpen()) throw except::IOException(Ctxt( - FmtX( + str::Format( "File %s could not be opened for reading", file) ) diff --git a/externals/coda-oss/modules/c++/io/source/FileUtils.cpp b/externals/coda-oss/modules/c++/io/source/FileUtils.cpp index 9de78af1f1..5c61540576 100644 --- a/externals/coda-oss/modules/c++/io/source/FileUtils.cpp +++ b/externals/coda-oss/modules/c++/io/source/FileUtils.cpp @@ -133,7 +133,7 @@ std::string io::FileUtils::createFile(std::string dirname, sys::OS os; if (!os.exists(dirname)) - throw except::IOException(Ctxt(FmtX("Directory does not exist: %s", + throw except::IOException(Ctxt(str::Format("Directory does not exist: %s", dirname.c_str()))); str::trim(filename); diff --git a/externals/coda-oss/modules/c++/io/source/MMapInputStream.cpp b/externals/coda-oss/modules/c++/io/source/MMapInputStream.cpp index d942ac2231..e1391083a5 100644 --- a/externals/coda-oss/modules/c++/io/source/MMapInputStream.cpp +++ b/externals/coda-oss/modules/c++/io/source/MMapInputStream.cpp @@ -28,7 +28,7 @@ void io::MMapInputStream::open(const std::string& fname, char* flags) // std::cout << mLength << std::endl; mFile = fopen(fname.c_str(), "r"); if (!mFile) - throw sys::SystemException(FmtX("Failure while opening file: %s", fname.c_str())); + throw sys::SystemException(str::Format("Failure while opening file: %s", fname.c_str())); _map(); diff --git a/externals/coda-oss/modules/c++/io/source/StandardStreams.cpp b/externals/coda-oss/modules/c++/io/source/StandardStreams.cpp index 2323613990..3e374d09d5 100644 --- a/externals/coda-oss/modules/c++/io/source/StandardStreams.cpp +++ b/externals/coda-oss/modules/c++/io/source/StandardStreams.cpp @@ -33,7 +33,7 @@ void io::StandardOutStream::write(const void* buffer, sys::Size_T len) if (!std::cout.good()) throw except::IOException( Ctxt( - FmtX("std::cout stream is bad after requested write: (%d)", + str::Format("std::cout stream is bad after requested write: (%d)", len)) ); } @@ -53,7 +53,7 @@ void io::StandardErrStream::write(const void* buffer, sys::Size_T len) if (!std::cerr.good()) throw except::IOException( Ctxt( - FmtX("std::cerr stream is bad after requested write: (%d)", + str::Format("std::cerr stream is bad after requested write: (%d)", len) ) ); } diff --git a/externals/coda-oss/modules/c++/logging/include/logging/Enums.h b/externals/coda-oss/modules/c++/logging/include/logging/Enums.h index f7d30fb1ea..8569a8c49f 100644 --- a/externals/coda-oss/modules/c++/logging/include/logging/Enums.h +++ b/externals/coda-oss/modules/c++/logging/include/logging/Enums.h @@ -93,7 +93,7 @@ struct LogLevel final else if (s == "SEVERE") value = LOG_CRITICAL; else - throw except::InvalidFormatException(Ctxt(FmtX("Invalid enum value: %s", s.c_str()))); + throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %s", s.c_str()))); } //! int constructor @@ -120,7 +120,7 @@ struct LogLevel final value = LOG_CRITICAL; break; default: - throw except::InvalidFormatException(Ctxt(FmtX("Invalid enum value: %d", i))); + throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %d", i))); } } @@ -145,7 +145,7 @@ struct LogLevel final case 5: return std::string("CRITICAL"); default: - throw except::InvalidFormatException(Ctxt(FmtX("Invalid enum value: %d", value))); + throw except::InvalidFormatException(Ctxt(str::Format("Invalid enum value: %d", value))); } } diff --git a/externals/coda-oss/modules/c++/math.poly/include/math/poly/Fixed1D.h b/externals/coda-oss/modules/c++/math.poly/include/math/poly/Fixed1D.h index 5f14c6fcd4..03024de73f 100644 --- a/externals/coda-oss/modules/c++/math.poly/include/math/poly/Fixed1D.h +++ b/externals/coda-oss/modules/c++/math.poly/include/math/poly/Fixed1D.h @@ -203,14 +203,14 @@ template class Fixed1D _T& operator [] (size_t i) { if (i > _Order) - throw except::IndexOutOfRangeException(Ctxt(FmtX("index [%d] is not in range [0..%d]", i, _Order))); + throw except::IndexOutOfRangeException(Ctxt(str::Format("index [%d] is not in range [0..%d]", i, _Order))); return mCoef[i]; } _T operator [] (size_t i) const { if (i > _Order) - throw except::IndexOutOfRangeException(Ctxt(FmtX("index [%d] is not in range [0..%d]", i, _Order))); + throw except::IndexOutOfRangeException(Ctxt(str::Format("index [%d] is not in range [0..%d]", i, _Order))); return mCoef[i]; diff --git a/externals/coda-oss/modules/c++/net.ssl/source/SSLConnection.cpp b/externals/coda-oss/modules/c++/net.ssl/source/SSLConnection.cpp index 903fa077dc..433d737489 100644 --- a/externals/coda-oss/modules/c++/net.ssl/source/SSLConnection.cpp +++ b/externals/coda-oss/modules/c++/net.ssl/source/SSLConnection.cpp @@ -37,7 +37,7 @@ net::ssl::SSLConnection::SSLConnection(std::unique_ptr&& socket, mSSL = SSL_new(ctx); if (mSSL == nullptr) { - throw net::ssl::SSLException(Ctxt(FmtX("SSL_new failed"))); + throw net::ssl::SSLException(Ctxt(str::Format("SSL_new failed"))); } setupSocket(host); @@ -87,7 +87,7 @@ void net::ssl::SSLConnection::setupSocket(const std::string& hostName) #endif throw net::ssl::SSLException - (Ctxt(FmtX("SSL_connect failed: %d", SSL_get_error(mSSL, val)))); + (Ctxt(str::Format("SSL_connect failed: %d", SSL_get_error(mSSL, val)))); } if(mServerAuthentication) @@ -143,7 +143,7 @@ sys::SSize_T net::ssl::SSLConnection::read(sys::byte* b, sys::Size_T len) std::cout << "=============================================" << std::endl << std::endl; #endif - throw net::ssl::SSLException(Ctxt(FmtX("When receiving %d bytes", + throw net::ssl::SSLException(Ctxt(str::Format("When receiving %d bytes", len)) ); } else if (numBytes == 0) @@ -155,7 +155,7 @@ sys::SSize_T net::ssl::SSLConnection::read(sys::byte* b, sys::Size_T len) return -1; } #if defined(__DEBUG_SOCKET) - std::cout << FmtX("Read %d bytes from socket:", numBytes) << std::endl; + std::cout << str::Format("Read %d bytes from socket:", numBytes) << std::endl; std::cout << "---------------------------------------------" << std::endl; std::cout << std::string(b, numBytes) << std::endl; std::cout << "---------------------------------------------" << std::endl; @@ -172,7 +172,7 @@ void net::ssl::SSLConnection::write(const sys::byte* b, sys::Size_T len) const auto numBytes = SSL_write(mSSL, (const char*)b, len); if (static_cast(numBytes) != len) { - throw net::ssl::SSLException(Ctxt(FmtX("Tried sending %d bytes, %d sent", + throw net::ssl::SSLException(Ctxt(str::Format("Tried sending %d bytes, %d sent", len, numBytes)) ); } diff --git a/externals/coda-oss/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp b/externals/coda-oss/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp index 5a9d441480..63a721a818 100644 --- a/externals/coda-oss/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp +++ b/externals/coda-oss/modules/c++/net.ssl/source/SSLConnectionClientFactory.cpp @@ -60,12 +60,12 @@ void net::ssl::SSLConnectionClientFactory::initializeContext() if(method == nullptr) { - throw net::ssl::SSLException(Ctxt(FmtX("SSLv23_client_method failed"))); + throw net::ssl::SSLException(Ctxt(str::Format("SSLv23_client_method failed"))); } mCtx = SSL_CTX_new(method); if(mCtx == nullptr) { - throw net::ssl::SSLException(Ctxt(FmtX("SSL_CTX_new failed"))); + throw net::ssl::SSLException(Ctxt(str::Format("SSL_CTX_new failed"))); } if(mClientAuthentication) diff --git a/externals/coda-oss/modules/c++/net/source/DaemonUnix.cpp b/externals/coda-oss/modules/c++/net/source/DaemonUnix.cpp index 8683816f95..797f515788 100644 --- a/externals/coda-oss/modules/c++/net/source/DaemonUnix.cpp +++ b/externals/coda-oss/modules/c++/net/source/DaemonUnix.cpp @@ -258,12 +258,12 @@ void DaemonUnix::redirectStreamsTo(const std::string& filename) if (openFileFor(STDOUT_FILENO, filename, O_WRONLY|O_CREAT|O_TRUNC) < 0) { throw except::Exception( - Ctxt(FmtX("Failed to open file %s for STDOUT.", filename.c_str()))); + Ctxt(str::Format("Failed to open file %s for STDOUT.", filename.c_str()))); } if (openFileFor(STDERR_FILENO, filename, O_WRONLY|O_CREAT|O_TRUNC) < 0) { throw except::Exception( - Ctxt(FmtX("Failed to open file %s for STDERR.", filename.c_str()))); + Ctxt(str::Format("Failed to open file %s for STDERR.", filename.c_str()))); } } diff --git a/externals/coda-oss/modules/c++/net/source/Socket.cpp b/externals/coda-oss/modules/c++/net/source/Socket.cpp index 9c0c791b90..4fa436453c 100644 --- a/externals/coda-oss/modules/c++/net/source/Socket.cpp +++ b/externals/coda-oss/modules/c++/net/source/Socket.cpp @@ -115,7 +115,7 @@ size_t net::Socket::recv(void* b, size_t len, int flags) return static_cast(-1); } #if defined(__DEBUG_SOCKET) - std::cout << FmtX("Read %d bytes from socket:", numBytes) << std::endl; + std::cout << str::Format("Read %d bytes from socket:", numBytes) << std::endl; std::cout << "---------------------------------------------" << std::endl; std::cout << std::string(b, numBytes) << std::endl; std::cout << "---------------------------------------------" << std::endl; diff --git a/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h b/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h index c421beea9e..6e65ea9eb4 100644 --- a/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h +++ b/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h @@ -278,8 +278,8 @@ template class BasicPluginManager for (unsigned int i = 0; ops[i] != nullptr; i++) oss << ops[i] << ":"; - auto unsupported = FmtX("For plugin supporting ops %s version ", oss.str()); - unsupported += FmtX("[%d.%d] not supported (%d.%d)", majorVersion, minorVersion, mMajorVersion, mMinorVersion); + auto unsupported = str::Format("For plugin supporting ops %s version ", oss.str()); + unsupported += str::Format("[%d.%d] not supported (%d.%d)", majorVersion, minorVersion, mMajorVersion, mMinorVersion); eh->onPluginVersionUnsupported(unsupported); return; } @@ -290,7 +290,7 @@ template class BasicPluginManager if (! pluginHandler ) { eh->onPluginLoadFailed( - FmtX("Failed to spawn handler for op %s", ops[i])); + str::Format("Failed to spawn handler for op %s", ops[i])); // Keep going } mHandlers[ops[i]].first = pluginHandler; diff --git a/externals/coda-oss/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h b/externals/coda-oss/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h index 8d75266d52..72a895b00c 100644 --- a/externals/coda-oss/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h +++ b/externals/coda-oss/modules/c++/sio.lite/include/sio/lite/SioFileWriter.h @@ -173,7 +173,7 @@ template void writeSIO(const T* image, size_t rows, size_t cols, et = FileHeader::UNSIGNED; break; default: - throw except::Exception(Ctxt(FmtX("Unexpected es: %d", es))); + throw except::Exception(Ctxt(str::Format("Unexpected es: %d", es))); } } diff --git a/externals/coda-oss/modules/c++/str/include/str/Format.h b/externals/coda-oss/modules/c++/str/include/str/Format.h index 44808100f1..6261e204df 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Format.h +++ b/externals/coda-oss/modules/c++/str/include/str/Format.h @@ -65,152 +65,155 @@ inline auto Format(const char* format, const T1& t1, const T2& t2, const T3& t3, return Format_(format, t1, t2, t3, t4); } } -} + /*! * \param format The format * \param ... Any printf like thing */ -inline auto FmtX(const char* format) +inline auto Format(const char* format) { - return str::details::Format(format); + return details::Format(format); } -inline auto FmtX(const char* format, const char* pStr) +inline auto Format(const char* format, const char* pStr) { - return str::details::Format(format, pStr); + return details::Format(format, pStr); } -inline auto FmtX(const char* format, const std::string& s) +inline auto Format(const char* format, const std::string& s) { - return FmtX(format, s.c_str()); + return Format(format, s.c_str()); } -inline auto FmtX(const char* format, int i) +inline auto Format(const char* format, int i) { - return str::details::Format(format, i); + return details::Format(format, i); } -inline auto FmtX(const char* format, uint32_t i) +inline auto Format(const char* format, uint32_t i) { - return str::details::Format(format, i); + return details::Format(format, i); } -inline auto FmtX(const char* format, ptrdiff_t l) +inline auto Format(const char* format, ptrdiff_t l) { - return str::details::Format(format, l); + return details::Format(format, l); } -inline auto FmtX(const char* format, size_t ul) +inline auto Format(const char* format, size_t ul) { - return str::details::Format(format, ul); + return details::Format(format, ul); } -inline auto FmtX(const char* format, float f) +inline auto Format(const char* format, float f) { - return str::details::Format(format, f); + return details::Format(format, f); } -inline auto FmtX(const char* format, double d) +inline auto Format(const char* format, double d) { - return str::details::Format(format, d); + return details::Format(format, d); } -inline auto FmtX(const char* format, const void* p) +inline auto Format(const char* format, const void* p) { - return str::details::Format(format, p); + return details::Format(format, p); } -inline auto FmtX(const char* format, char ch, const char* pStr) +inline auto Format(const char* format, char ch, const char* pStr) { - return str::details::Format(format, ch, pStr); + return details::Format(format, ch, pStr); } -inline auto FmtX(const char* format, char ch, const std::string& s) +inline auto Format(const char* format, char ch, const std::string& s) { - return FmtX(format, ch, s.c_str()); + return Format(format, ch, s.c_str()); } -inline auto FmtX(const char* format, const std::string& s1, const std::string& s2) +inline auto Format(const char* format, const std::string& s1, const std::string& s2) { - return str::details::Format(format, s1.c_str(), s2.c_str()); + return details::Format(format, s1.c_str(), s2.c_str()); } -inline auto FmtX(const char* format, const std::string& s, size_t ul) +inline auto Format(const char* format, const std::string& s, size_t ul) { - return str::details::Format(format, s.c_str(), ul); + return details::Format(format, s.c_str(), ul); } -inline auto FmtX(const char* format, char ch1, char ch2) +inline auto Format(const char* format, char ch1, char ch2) { - return str::details::Format(format, ch1, ch2); + return details::Format(format, ch1, ch2); } -inline auto FmtX(const char* format, int i1, int i2) +inline auto Format(const char* format, int i1, int i2) { - return str::details::Format(format, i1, i2); + return details::Format(format, i1, i2); } -inline auto FmtX(const char* format, long l1, long l2) +inline auto Format(const char* format, long l1, long l2) { - return str::details::Format(format, l1, l2); + return details::Format(format, l1, l2); } -inline auto FmtX(const char* format, uint32_t ui1, uint32_t ui2) +inline auto Format(const char* format, uint32_t ui1, uint32_t ui2) { - return str::details::Format(format, ui1, ui2); + return details::Format(format, ui1, ui2); } -inline auto FmtX(const char* format, size_t ul1, size_t ul2) +inline auto Format(const char* format, size_t ul1, size_t ul2) { - return str::details::Format(format, ul1, ul2); + return details::Format(format, ul1, ul2); } -inline auto FmtX(const char* format, size_t ul1, int i2) +inline auto Format(const char* format, size_t ul1, int i2) { - return str::details::Format(format, ul1, i2); + return details::Format(format, ul1, i2); } -inline auto FmtX(const char* format, double d1, double d2) +inline auto Format(const char* format, double d1, double d2) { - return str::details::Format(format, d1, d2); + return details::Format(format, d1, d2); } -inline auto FmtX(const char* format, int i, const char* pStr) +inline auto Format(const char* format, int i, const char* pStr) { - return str::details::Format(format, i, pStr); + return details::Format(format, i, pStr); } -inline auto FmtX(const char* fmt, int i, const std::string& s) +inline auto Format(const char* fmt, int i, const std::string& s) { - return FmtX(fmt, i, s.c_str()); + return Format(fmt, i, s.c_str()); } -inline auto FmtX(const char* format, char ch1, char ch2, const std::string& s) +inline auto Format(const char* format, char ch1, char ch2, const std::string& s) { - return str::details::Format(format, ch1, ch2, s.c_str()); + return details::Format(format, ch1, ch2, s.c_str()); } -inline auto FmtX(const char* format, int i1, int i2, unsigned long ul) +inline auto Format(const char* format, int i1, int i2, unsigned long ul) { - return str::details::Format(format, i1, i2, ul); + return details::Format(format, i1, i2, ul); } -inline auto FmtX(const char* format, int i1, int i2, int i3) +inline auto Format(const char* format, int i1, int i2, int i3) { - return str::details::Format(format, i1, i2, i3); + return details::Format(format, i1, i2, i3); } -inline auto FmtX(const char* format, float f1, float f2, float f3) +inline auto Format(const char* format, float f1, float f2, float f3) { - return str::details::Format(format, f1, f2, f3); + return details::Format(format, f1, f2, f3); } -inline std::string FmtX(const char* format, const std::string& s1, int i2, int i3) +inline std::string Format(const char* format, const std::string& s1, int i2, int i3) { - return str::details::Format(format, s1.c_str(), i2, i3); + return details::Format(format, s1.c_str(), i2, i3); } -inline auto FmtX(const char* format, const std::string& s1, const std::string& s2, uint32_t ui) +inline auto Format(const char* format, const std::string& s1, const std::string& s2, uint32_t ui) { - return str::details::Format(format, s1.c_str(), s2.c_str(), ui); + return details::Format(format, s1.c_str(), s2.c_str(), ui); } -inline auto FmtX(const char* format, const std::string& s1, const std::string& s2, const std::string& s3) +inline auto Format(const char* format, const std::string& s1, const std::string& s2, const std::string& s3) { - return str::details::Format(format, s1.c_str(), s2.c_str(), s3.c_str()); + return details::Format(format, s1.c_str(), s2.c_str(), s3.c_str()); } -inline auto FmtX(const char* format, int i1, int i2, int i3, int i4) +inline auto Format(const char* format, int i1, int i2, int i3, int i4) { - return str::details::Format(format, i1, i2, i3, i4); + return details::Format(format, i1, i2, i3, i4); } -inline auto FmtX(const char* format, uint32_t ui1, uint32_t ui2, uint32_t ui3, uint32_t ui4) +inline auto Format(const char* format, uint32_t ui1, uint32_t ui2, uint32_t ui3, uint32_t ui4) { - return str::details::Format(format, ui1, ui2, ui3, ui4); + return details::Format(format, ui1, ui2, ui3, ui4); } -inline auto FmtX(const char* format, const char* pStr1, const std::string& s2, const char* pStr3, const std::string& s4) +inline auto Format(const char* format, const char* pStr1, const std::string& s2, const char* pStr3, const std::string& s4) { - return str::details::Format(format, pStr1, s2.c_str(), pStr3, s4.c_str()); + return details::Format(format, pStr1, s2.c_str(), pStr3, s4.c_str()); } -inline auto FmtX(const char* format, const std::string& s1, int i2, const std::string& s3, int i4) +inline auto Format(const char* format, const std::string& s1, int i2, const std::string& s3, int i4) { - return str::details::Format(format, s1.c_str(), i2, s3.c_str(), i4); + return details::Format(format, s1.c_str(), i2, s3.c_str(), i4); } +} + +#define FmtX(format, ...) str::Format(format, __VA_ARGS__) #endif // CODA_OSS_str_Format_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/sys/include/sys/ThreadInterface.h b/externals/coda-oss/modules/c++/sys/include/sys/ThreadInterface.h index e536fe48e7..cefbf8dcc4 100644 --- a/externals/coda-oss/modules/c++/sys/include/sys/ThreadInterface.h +++ b/externals/coda-oss/modules/c++/sys/include/sys/ThreadInterface.h @@ -132,7 +132,7 @@ struct CODA_OSS_API ThreadInterface : public Runnable // of nasty issues that could pop up (execution in freed memory, etc). if (isRunning()) { - std::cerr << Ctxt(FmtX("Thread object [%s] destructed before " \ + std::cerr << Ctxt(str::Format("Thread object [%s] destructed before " \ "thread terminated, aborting program.", getName().c_str())) << std::endl; abort(); diff --git a/externals/coda-oss/modules/c++/sys/source/DLLWin32.cpp b/externals/coda-oss/modules/c++/sys/source/DLLWin32.cpp index 466f7d2952..6fc96611fc 100644 --- a/externals/coda-oss/modules/c++/sys/source/DLLWin32.cpp +++ b/externals/coda-oss/modules/c++/sys/source/DLLWin32.cpp @@ -45,7 +45,7 @@ void sys::DLL::load(const std::string& libName) // Now we check the return value if (!mLib) - throw sys::DLLException(FmtX("Failed to load() DLL: %s", + throw sys::DLLException(str::Format("Failed to load() DLL: %s", mLibName.c_str() ) ); } @@ -75,7 +75,7 @@ retrieve(const std::string& functionName) // Now we check the ptr value if (ptr == nullptr) - throw sys::DLLException(FmtX("Failed to load function: %s", + throw sys::DLLException(str::Format("Failed to load function: %s", functionName.c_str())); return ptr; } diff --git a/externals/coda-oss/modules/c++/sys/source/FileUnix.cpp b/externals/coda-oss/modules/c++/sys/source/FileUnix.cpp index e603835a32..07d6c5ff94 100644 --- a/externals/coda-oss/modules/c++/sys/source/FileUnix.cpp +++ b/externals/coda-oss/modules/c++/sys/source/FileUnix.cpp @@ -43,7 +43,7 @@ void sys::File::create(const std::string& str, int accessFlags, if (mHandle < 0) { throw sys::SystemException(Ctxt( - FmtX("Error opening file [%d]: [%s]", mHandle, str.c_str()))); + str::Format("Error opening file [%d]: [%s]", mHandle, str.c_str()))); } } diff --git a/externals/coda-oss/modules/c++/sys/source/FileWin32.cpp b/externals/coda-oss/modules/c++/sys/source/FileWin32.cpp index 5e2f2b23d0..cf30c9f6cc 100644 --- a/externals/coda-oss/modules/c++/sys/source/FileWin32.cpp +++ b/externals/coda-oss/modules/c++/sys/source/FileWin32.cpp @@ -59,7 +59,7 @@ void sys::File::create(const std::string& str, if (mHandle == INVALID_HANDLE_VALUE) { throw sys::SystemException( - Ctxt(FmtX("Error opening file: [%s]", str.c_str()))); + Ctxt(str::Format("Error opening file: [%s]", str.c_str()))); } } @@ -169,7 +169,7 @@ sys::Off_T sys::File::lastModifiedTime() return (sys::Off_T)stInMillis; } throw sys::SystemException(Ctxt( - FmtX("Error getting last modified time for path %s", + str::Format("Error getting last modified time for path %s", mPath.c_str()))); } diff --git a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp index 5d5685ba92..d1806010d8 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp @@ -144,8 +144,8 @@ std::string sys::OSUnix::getPlatformName() const throw sys::SystemException("Uname failed"); std::string retval = name.sysname; - retval += FmtX(" (%s): %s", name.machine, name.release); - retval += FmtX(" [build: %s]", name.version); + retval += str::Format(" (%s): %s", name.machine, name.release); + retval += str::Format(" [build: %s]", name.version); return retval; } diff --git a/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp b/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp index 62ac0cda35..bde4cb5d28 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp @@ -59,7 +59,7 @@ std::string sys::OSWin32::getPlatformName() const platform = "Unknown Windows OS"; } auto retval = platform + ": "; - retval += FmtX("%d.%d [build: %d], ", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber); + retval += str::Format("%d.%d [build: %d], ", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber); retval += info.szCSDVersion; return retval; } diff --git a/externals/coda-oss/modules/c++/tiff/include/tiff/IFD.h b/externals/coda-oss/modules/c++/tiff/include/tiff/IFD.h index 706309e8f4..4975bdaaa8 100644 --- a/externals/coda-oss/modules/c++/tiff/include/tiff/IFD.h +++ b/externals/coda-oss/modules/c++/tiff/include/tiff/IFD.h @@ -155,7 +155,7 @@ class IFD : public io::Serializable const tiff::IFDEntry *mapEntry = tiff::KnownTagsRegistry::getInstance()[name]; //we can't add it if we don't know about it if (!mapEntry) - throw except::Exception(Ctxt(FmtX( + throw except::Exception(Ctxt(str::Format( "Unable to add IFD Entry: unknown tag [%s]", name.c_str()))); const auto id = mapEntry->getTagID(); diff --git a/externals/coda-oss/modules/c++/tiff/include/tiff/TiffFileWriter.h b/externals/coda-oss/modules/c++/tiff/include/tiff/TiffFileWriter.h index fb495a6766..f6474c6e2e 100644 --- a/externals/coda-oss/modules/c++/tiff/include/tiff/TiffFileWriter.h +++ b/externals/coda-oss/modules/c++/tiff/include/tiff/TiffFileWriter.h @@ -191,7 +191,7 @@ template void writeTIFF(const T* image, size_t rows, size_t cols, et = ::tiff::Const::SampleFormatType::UNSIGNED_INT; break; default: - throw except::Exception(Ctxt(FmtX("Unexpected es: %d", es))); + throw except::Exception(Ctxt(str::Format("Unexpected es: %d", es))); } } unsigned short alpha(0); diff --git a/externals/coda-oss/modules/c++/tiff/source/IFD.cpp b/externals/coda-oss/modules/c++/tiff/source/IFD.cpp index fb145461db..bb9d80e7dc 100644 --- a/externals/coda-oss/modules/c++/tiff/source/IFD.cpp +++ b/externals/coda-oss/modules/c++/tiff/source/IFD.cpp @@ -90,7 +90,7 @@ void tiff::IFD::addEntry(const std::string& name) tiff::IFDEntry *mapEntry = tiff::KnownTagsRegistry::getInstance()[name]; // we can't add it b/c we don't know about this tag if (!mapEntry) - throw except::Exception(Ctxt(FmtX( + throw except::Exception(Ctxt(str::Format( "Unable to add IFD Entry: unknown tag [%s]", name.c_str()))); unsigned short id = mapEntry->getTagID(); diff --git a/externals/coda-oss/modules/c++/tiff/source/ImageReader.cpp b/externals/coda-oss/modules/c++/tiff/source/ImageReader.cpp index 5fd42c6adc..9e5c1cbf7e 100644 --- a/externals/coda-oss/modules/c++/tiff/source/ImageReader.cpp +++ b/externals/coda-oss/modules/c++/tiff/source/ImageReader.cpp @@ -65,7 +65,7 @@ void tiff::ImageReader::getData(unsigned char *buffer, { unsigned short c = *(tiff::GenericType *)(*compression)[0]; if (c != tiff::Const::CompressionType::NO_COMPRESSION) - throw except::Exception(Ctxt(FmtX("Unsupported compression type: %d", c))); + throw except::Exception(Ctxt(str::Format("Unsupported compression type: %d", c))); } if (mIFD["StripOffsets"]) diff --git a/externals/coda-oss/modules/c++/tiff/source/TiffFileReader.cpp b/externals/coda-oss/modules/c++/tiff/source/TiffFileReader.cpp index e0d78f8417..812a1bb9ce 100644 --- a/externals/coda-oss/modules/c++/tiff/source/TiffFileReader.cpp +++ b/externals/coda-oss/modules/c++/tiff/source/TiffFileReader.cpp @@ -79,7 +79,7 @@ void tiff::FileReader::close() tiff::ImageReader *tiff::FileReader::operator[](const sys::Uint32_T index) const { if (index >= mImages.size()) - throw except::Exception(Ctxt(FmtX("Index out of range: %d", index))); + throw except::Exception(Ctxt(str::Format("Index out of range: %d", index))); return mImages[index]; } @@ -106,7 +106,7 @@ void tiff::FileReader::getData(unsigned char *buffer, const sys::Uint32_T numElementsToRead, const sys::Uint32_T imageIndex) { if (imageIndex >= mImages.size()) - throw except::Exception(Ctxt(FmtX("Index out of range", imageIndex))); + throw except::Exception(Ctxt(str::Format("Index out of range", imageIndex))); mImages[imageIndex]->getData(buffer, numElementsToRead); } diff --git a/externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp b/externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp index 2628ca7c84..4032f86fc0 100644 --- a/externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp +++ b/externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp @@ -81,7 +81,7 @@ std::string xml::lite::Attributes::getValue(int i) const } catch (const std::out_of_range& ex) { - throw except::NoSuchKeyException(Ctxt(FmtX("attributes[%d] not found, %s", i, ex.what()))); + throw except::NoSuchKeyException(Ctxt(str::Format("attributes[%d] not found, %s", i, ex.what()))); } } bool xml::lite::Attributes::getValue(int i, std::string& result) const @@ -125,7 +125,7 @@ std::string xml::lite::Attributes::getValue(const std::string& qname) const std::string retval; if (!getValue(qname, retval)) { - throw except::NoSuchKeyException(Ctxt(FmtX("QName '%s' could not be found", + throw except::NoSuchKeyException(Ctxt(str::Format("QName '%s' could not be found", qname.c_str()))); } @@ -152,7 +152,7 @@ std::string xml::lite::Attributes::getValue(const QName& qname) const { const auto uri = qname.getUri().value; const auto localName = qname.getName(); - throw except::NoSuchKeyException(Ctxt(FmtX("(uri: %s, localName: %s", uri, localName))); + throw except::NoSuchKeyException(Ctxt(str::Format("(uri: %s, localName: %s", uri, localName))); } return retval; } diff --git a/externals/coda-oss/modules/c++/zip/source/ZipEntry.cpp b/externals/coda-oss/modules/c++/zip/source/ZipEntry.cpp index 4c93526729..14bc85be17 100644 --- a/externals/coda-oss/modules/c++/zip/source/ZipEntry.cpp +++ b/externals/coda-oss/modules/c++/zip/source/ZipEntry.cpp @@ -50,7 +50,7 @@ void ZipEntry::inflate(sys::ubyte* out, sys::Size_T outLen, sys::ubyte* in, int zerr = inflateInit2(&zstream, -MAX_WBITS); if (zerr != Z_OK) { - throw except::IOException(Ctxt(FmtX("inflateInit2 failed [%d]", zerr))); + throw except::IOException(Ctxt(str::Format("inflateInit2 failed [%d]", zerr))); } // decompress @@ -58,7 +58,7 @@ void ZipEntry::inflate(sys::ubyte* out, sys::Size_T outLen, sys::ubyte* in, if (zerr != Z_STREAM_END) { - throw except::IOException(Ctxt(FmtX( + throw except::IOException(Ctxt(str::Format( "inflate failed [%d]: wanted: %d, got: %lu", zerr, Z_STREAM_END, zstream.total_out))); } diff --git a/externals/nitro/modules/c++/nitf/include/nitf/NITFException.hpp b/externals/nitro/modules/c++/nitf/include/nitf/NITFException.hpp index 46b9bac5bf..6c91837d71 100644 --- a/externals/nitro/modules/c++/nitf/include/nitf/NITFException.hpp +++ b/externals/nitro/modules/c++/nitf/include/nitf/NITFException.hpp @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef __NITF_EXCEPTION_HPP__ #define __NITF_EXCEPTION_HPP__ -#pragma once #include @@ -79,7 +79,11 @@ namespace nitf * \class NITFException * \brief The C++ wrapper for the nitf_Error */ -class NITFException /*final*/ : public except::Exception // no "final", SWIG doesn't like it +#ifndef SWIGPYTHON // no "final", SWIG doesn't like it +class NITFException final : public except::Exception +#else +class NITFException : public except::Exception +#endif { static except::Context make_Context_(const Error& error, const std::string& message) { diff --git a/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp b/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp index 035995bfc5..815943483e 100644 --- a/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp +++ b/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp @@ -151,7 +151,7 @@ class NITRO_NITFCPP_API Object */ std::string getObjectID() const { - return FmtX("%p", getNative()); + return str::Format("%p", getNative()); } bool isManaged() const noexcept { return isValid() && mHandle->isManaged(); } diff --git a/externals/nitro/modules/c++/nitf/source/FileHeader.cpp b/externals/nitro/modules/c++/nitf/source/FileHeader.cpp index d5facc2f87..73dc5d3572 100644 --- a/externals/nitro/modules/c++/nitf/source/FileHeader.cpp +++ b/externals/nitro/modules/c++/nitf/source/FileHeader.cpp @@ -200,7 +200,7 @@ nitf::ComponentInfo FileHeader::getImageInfo(int i) const { int num = getNumImages(); if (i < 0 || i >= num) - throw except::IndexOutOfRangeException(Ctxt(FmtX( + throw except::IndexOutOfRangeException(Ctxt(str::Format( "Index out of range: (%d <= %d <= %d)", 0, i, num))); return make_ComponentInfo(getNativeOrThrow()->imageInfo, i); } @@ -209,7 +209,7 @@ nitf::ComponentInfo FileHeader::getGraphicInfo(int i) const { int num = getNumGraphics(); if (i < 0 || i >= num) - throw except::IndexOutOfRangeException(Ctxt(FmtX( + throw except::IndexOutOfRangeException(Ctxt(str::Format( "Index out of range: (%d <= %d <= %d)", 0, i, num))); return make_ComponentInfo(getNativeOrThrow()->graphicInfo, i); } @@ -218,7 +218,7 @@ nitf::ComponentInfo FileHeader::getLabelInfo(int i) const { int num = getNumLabels(); if (i < 0 || i >= num) - throw except::IndexOutOfRangeException(Ctxt(FmtX( + throw except::IndexOutOfRangeException(Ctxt(str::Format( "Index out of range: (%d <= %d <= %d)", 0, i, num))); return make_ComponentInfo(getNativeOrThrow()->labelInfo, i); } @@ -227,7 +227,7 @@ nitf::ComponentInfo FileHeader::getTextInfo(int i) const { int num = getNumTexts(); if (i < 0 || i >= num) - throw except::IndexOutOfRangeException(Ctxt(FmtX( + throw except::IndexOutOfRangeException(Ctxt(str::Format( "Index out of range: (%d <= %d <= %d)", 0, i, num))); return make_ComponentInfo(getNativeOrThrow()->textInfo, i); } @@ -236,7 +236,7 @@ nitf::ComponentInfo FileHeader::getDataExtensionInfo(int i) const { int num = getNumDataExtensions(); if (i < 0 || i >= num) - throw except::IndexOutOfRangeException(Ctxt(FmtX( + throw except::IndexOutOfRangeException(Ctxt(str::Format( "Index out of range: (%d <= %d <= %d)", 0, i, num))); return make_ComponentInfo(getNativeOrThrow()->dataExtensionInfo, i); } @@ -245,7 +245,7 @@ nitf::ComponentInfo FileHeader::getReservedExtensionInfo(int i) const { int num = getNumReservedExtensions(); if (i < 0 || i >= num) - throw except::IndexOutOfRangeException(Ctxt(FmtX( + throw except::IndexOutOfRangeException(Ctxt(str::Format( "Index out of range: (%d <= %d <= %d)", 0, i, num))); return make_ComponentInfo(getNativeOrThrow()->reservedExtensionInfo, i); } diff --git a/externals/nitro/modules/c++/nitf/source/ImageSubheader.cpp b/externals/nitro/modules/c++/nitf/source/ImageSubheader.cpp index d45feee514..4e4f48f991 100644 --- a/externals/nitro/modules/c++/nitf/source/ImageSubheader.cpp +++ b/externals/nitro/modules/c++/nitf/source/ImageSubheader.cpp @@ -80,7 +80,7 @@ void ImageSubheader::setPixelInformation(std::string pvtype, if (!bandInfo) { - throw nitf::NITFException(Ctxt(FmtX("Out of Memory"))); + throw nitf::NITFException(Ctxt("Out of Memory")); } for (size_t i = 0; i < bandCount; i++) diff --git a/externals/nitro/modules/c++/nitf/source/TRE.cpp b/externals/nitro/modules/c++/nitf/source/TRE.cpp index 9b10e5f095..97f697bb96 100644 --- a/externals/nitro/modules/c++/nitf/source/TRE.cpp +++ b/externals/nitro/modules/c++/nitf/source/TRE.cpp @@ -96,7 +96,7 @@ nitf::Field TRE::getField(const std::string& key) const nitf_Field* field = ::nitf_TRE_getField(getNativeOrThrow(), key.c_str()); if (!field) throw except::NoSuchKeyException( - Ctxt(FmtX("Field does not exist in TRE: %s", key.c_str()))); + Ctxt(str::Format("Field does not exist in TRE: %s", key))); return nitf::Field(field); } diff --git a/externals/nitro/modules/c++/nitf/tests/test_create++.cpp b/externals/nitro/modules/c++/nitf/tests/test_create++.cpp index 64be835b37..a64f0868fb 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_create++.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_create++.cpp @@ -28,7 +28,7 @@ int main(int argc, char** argv) { if (argc != 2) { - throw nitf::NITFException(Ctxt(FmtX("Usage %s \n", + throw nitf::NITFException(Ctxt(str::Format("Usage %s \n", argv[0]))); } diff --git a/externals/nitro/modules/c++/nitf/tests/test_extract.cpp b/externals/nitro/modules/c++/nitf/tests/test_extract.cpp index ab72d78bdb..748e2981a0 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_extract.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_extract.cpp @@ -44,9 +44,9 @@ static std::vector extract_image(const nitf::ImageSubheader& subhe size_t band = 0; for (const auto& data : bandData) // for band, data in enumerate(bandData): { - auto outName = FmtX("%s_%d__", baseName, index); - outName += FmtX("%d_x_%d_", window.getNumRows(), window.getNumCols()); - outName += FmtX("%d_band_%d.out", static_cast(nbpp), static_cast(band)); + auto outName = str::Format("%s_%d__", baseName, index); + outName += str::Format("%d_x_%d_", window.getNumRows(), window.getNumCols()); + outName += str::Format("%d_band_%d.out", static_cast(nbpp), static_cast(band)); outName = sys::Path::joinPaths(outDir, outName); auto f = fopen(outName.c_str(), "wb"); // f = open(outName, "wb"); nitf::write(f, data); // fwrite(data.data(), sizeof(data[0]), data.size() / sizeof(data[0]), f); diff --git a/externals/nitro/modules/c++/nitf/tests/test_fhdr_clone++.cpp b/externals/nitro/modules/c++/nitf/tests/test_fhdr_clone++.cpp index 6149cc742c..3e0a3e8e38 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_fhdr_clone++.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_fhdr_clone++.cpp @@ -118,7 +118,7 @@ int main(int argc, char** argv) { if (argc != 2) { - throw nitf::NITFException(Ctxt(FmtX("Usage: %s \n", argv[0]))); + throw nitf::NITFException(Ctxt(str::Format("Usage: %s \n", argv[0]))); } nitf::Reader reader; diff --git a/externals/nitro/modules/c++/nitf/tests/test_functional.cpp b/externals/nitro/modules/c++/nitf/tests/test_functional.cpp index 6f9e9e8450..19413e5437 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_functional.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_functional.cpp @@ -34,7 +34,7 @@ int main(int argc, char **argv) { nitf::Reader reader; if ( argc != 2 ) - throw nitf::NITFException(Ctxt(FmtX("Usage: %s \n", argv[0]))); + throw nitf::NITFException(Ctxt(str::Format("Usage: %s \n", argv[0]))); nitf::IOHandle io(argv[1]); nitf::Record record = reader.read(io); diff --git a/externals/nitro/modules/c++/nitf/tests/test_j2k_nitf_read_region.cpp b/externals/nitro/modules/c++/nitf/tests/test_j2k_nitf_read_region.cpp index d1ab434621..e219c8293b 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_j2k_nitf_read_region.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_j2k_nitf_read_region.cpp @@ -47,8 +47,8 @@ void writeFile(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf, const std::string& prefix) { - auto filename = FmtX("%s-raw-", prefix); - filename += FmtX("%d_%d__%d_%d.out", x0, y0, x1, y1); + auto filename = str::Format("%s-raw-", prefix); + filename += str::Format("%d_%d__%d_%d.out", x0, y0, x1, y1); nitf::IOHandle outHandle(filename, NRT_ACCESS_WRITEONLY, NRT_CREATE); outHandle.write(buf.data(), buf.size()); printf("Wrote file: %s\n", filename.c_str()); @@ -58,8 +58,8 @@ void writeJ2K(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf, const j2k::Container& inContainer, const std::string& prefix) { - auto outName = FmtX("%s-raw-", prefix); - outName += FmtX("%d_%d__%d_%d.j2k", x0, y0, x1, y1); + auto outName = str::Format("%s-raw-", prefix); + outName += str::Format("%d_%d__%d_%d.j2k", x0, y0, x1, y1); const auto num_x_tiles = inContainer.getTilesX(); const auto num_y_tiles = inContainer.getTilesY(); @@ -217,7 +217,7 @@ int main(int argc, char **argv) const auto result_ = j2kReader.readRegion(0, 0, width, height, buf); const std::span result(result_.data(), result_.size()); - const auto namePrefix = FmtX("image-%d", (i + 1)); + const auto namePrefix = str::Format("image-%d", (i + 1)); // TODO: Update write to only output tiles in read region writeFile(0, 0, width, height, result, namePrefix); writeJ2K(0, 0, width, height, result, container, namePrefix); diff --git a/externals/nitro/modules/c++/nitf/tests/test_read_acftb.cpp b/externals/nitro/modules/c++/nitf/tests/test_read_acftb.cpp index a91ece7697..fcd4309712 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_read_acftb.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_read_acftb.cpp @@ -83,7 +83,7 @@ int main(int argc, char** argv) nitf::Reader reader; if (argc != 2) { - throw nitf::NITFException(Ctxt(FmtX("Usage: %s \n", + throw nitf::NITFException(Ctxt(str::Format("Usage: %s \n", argv[0]))); } nitf::IOHandle io(argv[1]); diff --git a/externals/nitro/modules/c++/nitf/unittests/test_j2k_loading++.cpp b/externals/nitro/modules/c++/nitf/unittests/test_j2k_loading++.cpp index fccc42361c..6e878d5184 100644 --- a/externals/nitro/modules/c++/nitf/unittests/test_j2k_loading++.cpp +++ b/externals/nitro/modules/c++/nitf/unittests/test_j2k_loading++.cpp @@ -168,8 +168,8 @@ TEST_CASE(test_j2k_nitf) void writeFile(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf, const std::string& prefix) { - auto filename = FmtX("%s-raw-", prefix); - filename += FmtX("%d_%d__%d_%d.out", x0, y0, x1, y1); + auto filename = str::Format("%s-raw-", prefix); + filename += str::Format("%d_%d__%d_%d.out", x0, y0, x1, y1); nitf::IOHandle outHandle(filename, NRT_ACCESS_WRITEONLY, NRT_CREATE); outHandle.write(buf.data(), buf.size()); //printf("Wrote file: %s\n", filename.c_str()); @@ -178,8 +178,8 @@ void writeJ2K(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf, const j2k::Container& inContainer, const std::string& prefix) { - auto outName = FmtX("%s-raw-", prefix); - outName += FmtX("%d_%d__%d_%d.j2k", x0, y0, x1, y1); + auto outName = str::Format("%s-raw-", prefix); + outName += str::Format("%d_%d__%d_%d.j2k", x0, y0, x1, y1); const auto num_x_tiles = inContainer.getTilesX(); const auto num_y_tiles = inContainer.getTilesY(); @@ -273,7 +273,7 @@ void test_j2k_nitf_read_region_(const std::string& testName, const auto result_ = j2kReader.readRegion(0, 0, width, height, buf); const auto result = sys::make_const_span(result_); - const auto namePrefix = FmtX("image-%d", (i + 1)); + const auto namePrefix = str::Format("image-%d", (i + 1)); // TODO: Update write to only output tiles in read region writeFile(0, 0, width, height, result, namePrefix); writeJ2K(0, 0, width, height, result, container, namePrefix);