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 6c72fa108..571565cab 100644 --- a/externals/coda-oss/modules/c++/cli/include/cli/Value.h +++ b/externals/coda-oss/modules/c++/cli/include/cli/Value.h @@ -106,10 +106,7 @@ class CODA_OSS_API Value { if (index >= mValues.size()) throw except::IndexOutOfRangeException( - Ctxt( - FmtX( - "Invalid index: %d", - index))); + Ctxt(FmtX("Invalid index: %d", index))); return str::toType(mValues[index]); } diff --git a/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp b/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp index be702484e..3694e7ed3 100644 --- a/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp +++ b/externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp @@ -317,8 +317,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.c_str())); + parseError(FmtX("Conflicting option: %c%s", mPrefixChar, op)); flagMap[op] = arg; } for (std::vector::const_iterator it = @@ -328,8 +327,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.c_str())); + parseError(FmtX("Conflicting option: %c%c%s", mPrefixChar, mPrefixChar, op)); flagMap[op] = arg; } } @@ -458,8 +456,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } else { - throw except::Exception(Ctxt( - FmtX("Invalid option: [%s]", argStr.c_str()))); + throw except::Exception(Ctxt(FmtX("Invalid option: [%s]", argStr))); } } } @@ -500,8 +497,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } else { - throw except::Exception(Ctxt( - FmtX("Invalid option: [%s]", argStr.c_str()))); + throw except::Exception(Ctxt(FmtX("Invalid option: [%s]", argStr))); } } @@ -549,10 +545,7 @@ std::unique_ptr cli::ArgumentParser::parse(const std::string& prog } if (!added) - parseError( - FmtX( - "option requires value or has exceeded its max: [%s]", - argVar.c_str())); + parseError(FmtX("option requires value or has exceeded its max: [%s]", argVar)); currentResults->put(argVar, v); break; @@ -677,11 +670,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.c_str())); + parseError(FmtX("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.c_str())); + parseError(FmtX("too many arguments, %d supported: [%s]", maxArgs, argId)); } diff --git a/externals/coda-oss/modules/c++/pch.h b/externals/coda-oss/modules/c++/pch.h index 236c1100a..7952e6efa 100644 --- a/externals/coda-oss/modules/c++/pch.h +++ b/externals/coda-oss/modules/c++/pch.h @@ -103,10 +103,10 @@ CODA_OSS_disable_warning_pop // change we want to rebuild everything anyway. #include "gsl/gsl.h" #include "config/Exports.h" +#include "mem/SharedPtr.h" +#include "sys/filesystem.h" #include "except/Throwable.h" #include "sys/Conf.h" -#include "sys/filesystem.h" -#include "mem/SharedPtr.h" #include "xml/lite/xerces_.h" #pragma comment(lib, "xerces-c") 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 c82944681..738dabe94 100644 --- a/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h +++ b/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h @@ -279,7 +279,7 @@ template class BasicPluginManager for (unsigned int i = 0; ops[i] != nullptr; i++) oss << ops[i] << ":"; eh->onPluginVersionUnsupported( - FmtX("For plugin supporting ops %s version [%d.%d] not supported (%d.%d)", + str::Format("For plugin supporting ops %s version [%d.%d] not supported (%d.%d)", oss.str().c_str(), majorVersion, minorVersion, mMajorVersion, mMinorVersion ) 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 240943807..20df7a024 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Format.h +++ b/externals/coda-oss/modules/c++/str/include/str/Format.h @@ -21,23 +21,20 @@ */ -#ifndef __STR_FORMAT_H__ -#define __STR_FORMAT_H__ +#pragma once +#ifndef CODA_OSS_str_Format_h_INCLUDED_ +#define CODA_OSS_str_Format_h_INCLUDED_ #include +#include +#include + #include #include "config/Exports.h" namespace str { - -/*! - * \param format The format - * \param ... Any printf like thing - */ -CODA_OSS_API std::string format(const char* format, ...); - struct CODA_OSS_API Format final { Format(const char* format, ...); @@ -47,14 +44,99 @@ struct CODA_OSS_API Format final return mString; } - operator std::string& () noexcept - { - return mString; - } - -protected: +private: std::string mString; }; +/*! + * \param format The format + * \param ... Any printf like thing + */ +//CODA_OSS_API std::string format(const char* format, ...); + +inline std::string format(const char* format) +{ + return Format(format); +} + +inline std::string format(const char* format, const char* pStr) +{ + return Format(format, pStr); +} +inline std::string format(const char* format, const std::string& s) +{ + return Format(format, s.c_str()); +} +inline std::string format(const char* format, int i) +{ + return Format(format, i); +} +inline std::string format(const char* format, uint32_t i) +{ + return Format(format, i); +} +inline std::string format(const char* format, ptrdiff_t l) +{ + return Format(format, l); +} +inline std::string format(const char* format, size_t ul) +{ + return Format(format, ul); +} +inline std::string format(const char* format, float f) +{ + return Format(format, f); +} + +inline std::string format(const char* format, char ch, const char* pStr) +{ + return Format(format, ch, pStr); +} +inline std::string format(const char* format, char ch, const std::string& s) +{ + return Format(format, ch, s.c_str()); +} +inline std::string format(const char* format, const std::string& s1, const std::string& s2) +{ + return Format(format, s1.c_str(), s2.c_str()); +} +inline std::string format(const char* format, const std::string& s, size_t ul) +{ + return Format(format, s.c_str(), ul); +} +inline std::string format(const char* format, char ch1, char ch2) +{ + return Format(format, ch1, ch2); +} +inline std::string format(const char* format, size_t ul1, size_t ul2) +{ + return Format(format, ul1, ul2); +} +inline std::string format(const char* format, int i, const std::string& s) +{ + return Format(format, i, s.c_str()); +} +inline std::string format(const char* format, int i, const char* pStr) +{ + return Format(format, i, pStr); +} + +inline std::string format(const char* format, char ch1, char ch2, const std::string& s) +{ + return Format(format, ch1, ch2, s.c_str()); +} +inline std::string format(const char* format, int i1, int i2, unsigned long ul) +{ + return Format(format, i1, i2, ul); +} +inline std::string format(const char* format, int i1, int i2, int i3) +{ + return Format(format, i1, i2, i3); +} +inline std::string format(const char* format, const std::string& s1, const std::string& s2, uint32_t ui) +{ + return Format(format, s1.c_str(), s2.c_str(), ui); +} + } -#endif +#endif // CODA_OSS_str_Format_h_INCLUDED_ \ No newline at end of file diff --git a/externals/coda-oss/modules/c++/str/source/Format.cpp b/externals/coda-oss/modules/c++/str/source/Format.cpp index b89c974e8..1117ced91 100644 --- a/externals/coda-oss/modules/c++/str/source/Format.cpp +++ b/externals/coda-oss/modules/c++/str/source/Format.cpp @@ -51,14 +51,14 @@ inline void va_end_(va_list& args) CODA_OSS_disable_warning_pop } -std::string str::format(const char *format, ...) -{ - va_list args; - va_start(args, format); - auto retval = vformat(format, args); - va_end_(args); - return retval; -} +//std::string str::format(const char *format, ...) +//{ +// va_list args; +// va_start(args, format); +// auto retval = vformat(format, args); +// va_end_(args); +// return retval; +//} str::Format::Format(const char* format, ...) { diff --git a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp index c9241b639..e561186f5 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp @@ -143,7 +143,7 @@ std::string sys::OSUnix::getPlatformName() const if (uname(&name) == -1) throw sys::SystemException("Uname failed"); - return FmtX("%s (%s): %s [build: %s]", name.sysname, name.machine, + return str::Format("%s (%s): %s [build: %s]", name.sysname, name.machine, name.release, name.version); } diff --git a/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp b/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp index e381f2f91..e50dee5ec 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp @@ -58,7 +58,7 @@ std::string sys::OSWin32::getPlatformName() const { platform = "Unknown Windows OS"; } - return FmtX("%s: %d.%d [build: %d], %s", platform.c_str(), + return str::Format("%s: %d.%d [build: %d], %s", platform.c_str(), info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber, info.szCSDVersion); } 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 a70077ad1..2628ca7c8 100644 --- a/externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp +++ b/externals/coda-oss/modules/c++/xml.lite/source/Attributes.cpp @@ -152,8 +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.c_str(), localName.c_str()))); + throw except::NoSuchKeyException(Ctxt(FmtX("(uri: %s, localName: %s", uri, localName))); } return retval; } diff --git a/externals/nitro/modules/c++/nitf/include/nitf/Enum.hpp b/externals/nitro/modules/c++/nitf/include/nitf/Enum.hpp index 564b1b525..4c657eb01 100644 --- a/externals/nitro/modules/c++/nitf/include/nitf/Enum.hpp +++ b/externals/nitro/modules/c++/nitf/include/nitf/Enum.hpp @@ -32,6 +32,7 @@ #include // std::nothrow #include "str/Manip.h" +#include "str/Encoding.h" namespace nitf { diff --git a/externals/nitro/modules/c++/nitf/tests/test_extract.cpp b/externals/nitro/modules/c++/nitf/tests/test_extract.cpp index e8c7ac725..86b3cd20c 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_extract.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_extract.cpp @@ -44,7 +44,7 @@ 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 = str::format("%s_%d__%d_x_%d_%d_band_%d.out", + std::string outName = str::Format("%s_%d__%d_x_%d_%d_band_%d.out", baseName.c_str(), index, window.getNumRows(), window.getNumCols(), static_cast(nbpp), static_cast(band)); outName = sys::Path::joinPaths(outDir, outName); auto f = fopen(outName.c_str(), "wb"); // f = open(outName, "wb"); 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 1f0d4cf04..37f247fc0 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,7 +47,7 @@ void writeFile(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf, const std::string& prefix) { - const auto filename = str::format("%s-raw-%d_%d__%d_%d.out", prefix.c_str(), x0, y0, x1, y1); + const std::string filename = str::Format("%s-raw-%d_%d__%d_%d.out", prefix.c_str(), 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()); @@ -57,7 +57,7 @@ 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) { - const auto outName = str::format("%s-raw-%d_%d__%d_%d.j2k", prefix.c_str(), x0, y0, x1, y1); + const std::string outName = str::Format("%s-raw-%d_%d__%d_%d.j2k", prefix.c_str(), x0, y0, x1, y1); const auto num_x_tiles = inContainer.getTilesX(); const auto num_y_tiles = inContainer.getTilesY(); 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 22de200df..d0ffa5243 100644 --- a/externals/nitro/modules/c++/nitf/unittests/test_j2k_loading++.cpp +++ b/externals/nitro/modules/c++/nitf/unittests/test_j2k_loading++.cpp @@ -168,7 +168,7 @@ 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) { - const auto filename = str::format("%s-raw-%d_%d__%d_%d.out", prefix.c_str(), x0, y0, x1, y1); + const std::string filename = str::Format("%s-raw-%d_%d__%d_%d.out", prefix.c_str(), 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()); @@ -177,7 +177,7 @@ 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) { - const auto outName = str::format("%s-raw-%d_%d__%d_%d.j2k", prefix.c_str(), x0, y0, x1, y1); + const std::string outName = str::Format("%s-raw-%d_%d__%d_%d.j2k", prefix.c_str(), x0, y0, x1, y1); const auto num_x_tiles = inContainer.getTilesX(); const auto num_y_tiles = inContainer.getTilesY(); diff --git a/six/modules/c++/samples/test_dump_images.cpp b/six/modules/c++/samples/test_dump_images.cpp index 6da9cf50b..4d7b3ca0d 100644 --- a/six/modules/c++/samples/test_dump_images.cpp +++ b/six/modules/c++/samples/test_dump_images.cpp @@ -161,7 +161,7 @@ int main(int argc, char** argv) for (size_t i = 0, total = container->size(); i < total; ++i) { const six::Data* data = container->getData(i); - std::string filename = FmtX("%s_DES_%d.xml", base.c_str(), i); + std::string filename = FmtX("%s_DES_%d.xml", base.string(), i); const auto xmlFile = fs::path(outputDir) / filename; io::FileOutputStream xmlStream(xmlFile.string()); diff --git a/six/modules/c++/samples/test_parse_xml.cpp b/six/modules/c++/samples/test_parse_xml.cpp index bea972ac5..7e4d0c2a0 100644 --- a/six/modules/c++/samples/test_parse_xml.cpp +++ b/six/modules/c++/samples/test_parse_xml.cpp @@ -95,7 +95,7 @@ std::vector extractXML(std::string inputFile, nitf::Off size = deReader.getSize(); const auto typeID = subheader.typeID(); - const std::string outputFile = FmtX("%s-%s%d.xml", prefix.c_str(), typeID.c_str(), i); + const std::string outputFile = FmtX("%s-%s%d.xml", prefix, typeID, i); const auto fileName = outputDir / outputFile; { std::vector xml(size);