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 738dabe94..c421beea9 100644 --- a/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h +++ b/externals/coda-oss/modules/c++/plugin/include/plugin/BasicPluginManager.h @@ -278,12 +278,9 @@ template class BasicPluginManager for (unsigned int i = 0; ops[i] != nullptr; i++) oss << ops[i] << ":"; - eh->onPluginVersionUnsupported( - str::Format("For plugin supporting ops %s version [%d.%d] not supported (%d.%d)", - oss.str().c_str(), majorVersion, minorVersion, - mMajorVersion, mMinorVersion - ) - ); + auto unsupported = FmtX("For plugin supporting ops %s version ", oss.str()); + unsupported += FmtX("[%d.%d] not supported (%d.%d)", majorVersion, minorVersion, mMajorVersion, mMinorVersion); + eh->onPluginVersionUnsupported(unsupported); return; } 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 3ecb9e81a..44808100f 100644 --- a/externals/coda-oss/modules/c++/str/include/str/Format.h +++ b/externals/coda-oss/modules/c++/str/include/str/Format.h @@ -26,8 +26,8 @@ #define CODA_OSS_str_Format_h_INCLUDED_ #include -#include -#include +#include +#include #include @@ -35,88 +35,132 @@ namespace str { - CODA_OSS_API std::string Format(const char* format, ...); +namespace details +{ +CODA_OSS_API std::string Format_(const char* format, ...); + +inline auto Format(const char* format) +{ + return Format_(format); +} + +template +inline auto Format(const char* format, const T1& t1) +{ + return Format_(format, t1); +} +template +inline auto Format(const char* format, const T1& t1, const T2& t2) +{ + return Format_(format, t1, t2); +} +template +inline auto Format(const char* format, const T1& t1, const T2& t2, const T3& t3) +{ + return Format_(format, t1, t2, t3); +} +template +inline auto Format(const char* format, const T1& t1, const T2& t2, const T3& t3, const T4& t4) +{ + return Format_(format, t1, t2, t3, t4); +} +} } /*! * \param format The format * \param ... Any printf like thing */ -//CODA_OSS_API std::string format(const char* format, ...); inline auto FmtX(const char* format) { - return str::Format(format); + return str::details::Format(format); } inline auto FmtX(const char* format, const char* pStr) { - return str::Format(format, pStr); + return str::details::Format(format, pStr); } inline auto FmtX(const char* format, const std::string& s) { - return str::Format(format, s.c_str()); + return FmtX(format, s.c_str()); } inline auto FmtX(const char* format, int i) { - return str::Format(format, i); + return str::details::Format(format, i); } inline auto FmtX(const char* format, uint32_t i) { - return str::Format(format, i); + return str::details::Format(format, i); } inline auto FmtX(const char* format, ptrdiff_t l) { - return str::Format(format, l); + return str::details::Format(format, l); } inline auto FmtX(const char* format, size_t ul) { - return str::Format(format, ul); + return str::details::Format(format, ul); } inline auto FmtX(const char* format, float f) { - return str::Format(format, f); + return str::details::Format(format, f); } inline auto FmtX(const char* format, double d) { - return str::Format(format, d); + return str::details::Format(format, d); +} +inline auto FmtX(const char* format, const void* p) +{ + return str::details::Format(format, p); } inline auto FmtX(const char* format, char ch, const char* pStr) { - return str::Format(format, ch, pStr); + return str::details::Format(format, ch, pStr); } inline auto FmtX(const char* format, char ch, const std::string& s) { - return str::Format(format, ch, s.c_str()); + return FmtX(format, ch, s.c_str()); } inline auto FmtX(const char* format, const std::string& s1, const std::string& s2) { - return str::Format(format, s1.c_str(), s2.c_str()); + return str::details::Format(format, s1.c_str(), s2.c_str()); } inline auto FmtX(const char* format, const std::string& s, size_t ul) { - return str::Format(format, s.c_str(), ul); + return str::details::Format(format, s.c_str(), ul); } inline auto FmtX(const char* format, char ch1, char ch2) { - return str::Format(format, ch1, ch2); + return str::details::Format(format, ch1, ch2); +} +inline auto FmtX(const char* format, int i1, int i2) +{ + return str::details::Format(format, i1, i2); } inline auto FmtX(const char* format, long l1, long l2) { - return str::Format(format, l1, l2); + return str::details::Format(format, l1, l2); +} +inline auto FmtX(const char* format, uint32_t ui1, uint32_t ui2) +{ + return str::details::Format(format, ui1, ui2); } inline auto FmtX(const char* format, size_t ul1, size_t ul2) { - return str::Format(format, ul1, ul2); + return str::details::Format(format, ul1, ul2); +} +inline auto FmtX(const char* format, size_t ul1, int i2) +{ + return str::details::Format(format, ul1, i2); } inline auto FmtX(const char* format, double d1, double d2) { - return str::Format(format, d1, d2); + return str::details::Format(format, d1, d2); } inline auto FmtX(const char* format, int i, const char* pStr) { - return str::Format(format, i, pStr); + return str::details::Format(format, i, pStr); } inline auto FmtX(const char* fmt, int i, const std::string& s) { @@ -125,44 +169,48 @@ inline auto FmtX(const char* fmt, int i, const std::string& s) inline auto FmtX(const char* format, char ch1, char ch2, const std::string& s) { - return str::Format(format, ch1, ch2, s.c_str()); + return str::details::Format(format, ch1, ch2, s.c_str()); } inline auto FmtX(const char* format, int i1, int i2, unsigned long ul) { - return str::Format(format, i1, i2, ul); + return str::details::Format(format, i1, i2, ul); } inline auto FmtX(const char* format, int i1, int i2, int i3) { - return str::Format(format, i1, i2, i3); + return str::details::Format(format, i1, i2, i3); } inline auto FmtX(const char* format, float f1, float f2, float f3) { - return str::Format(format, f1, f2, f3); + return str::details::Format(format, f1, f2, f3); } inline std::string FmtX(const char* format, const std::string& s1, int i2, int i3) { - return str::Format(format, s1.c_str(), i2, i3); + return str::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) { - return str::Format(format, s1.c_str(), s2.c_str(), ui); + return str::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) { - return str::Format(format, s1.c_str(), s2.c_str(), s3.c_str()); + return str::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) { - return str::Format(format, i1, i2, i3, i4); + return str::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) +{ + return str::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) { - return str::Format(format, pStr1, s2.c_str(), pStr3, s4.c_str()); + return str::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) { - return str::Format(format, s1.c_str(), i2, s3.c_str(), i4); + return str::details::Format(format, s1.c_str(), i2, s3.c_str(), i4); } #endif // CODA_OSS_str_Format_h_INCLUDED_ diff --git a/externals/coda-oss/modules/c++/str/source/Format.cpp b/externals/coda-oss/modules/c++/str/source/Format.cpp index 8fc1205c7..fdcfc8544 100644 --- a/externals/coda-oss/modules/c++/str/source/Format.cpp +++ b/externals/coda-oss/modules/c++/str/source/Format.cpp @@ -51,7 +51,7 @@ inline void va_end_(va_list& args) CODA_OSS_disable_warning_pop } -std::string str::Format(const char* format, ...) +std::string str::details::Format_(const char* format, ...) { va_list args; va_start(args, format); diff --git a/externals/coda-oss/modules/c++/str/tests/VersionTest.cpp b/externals/coda-oss/modules/c++/str/tests/VersionTest.cpp index 6b2c00b6d..aa1d9625d 100644 --- a/externals/coda-oss/modules/c++/str/tests/VersionTest.cpp +++ b/externals/coda-oss/modules/c++/str/tests/VersionTest.cpp @@ -23,17 +23,15 @@ #include #include -#define FORMAT_FUNC str::Format - int main() { - std::cout << FORMAT_FUNC("Your version of str is %d.%d.%d\n", + std::cout << FmtX("Your version of str is %d.%d.%d\n", STR_MAJOR_VERSION, STR_MINOR_VERSION, STR_MICRO_VERSION); - std::cout << "Specialization for string test..." << std::endl; + std::cout << "Specialization for string test...\n"; std::string ok("This test passes"); std::cout << str::toType(ok) << std::endl; - std::cout << "Testing the trim function..." << std::endl; + std::cout << "Testing the trim function...\n"; std::string s = " test "; std::cout << "'" << s << "', length: " << s.length() << std::endl; str::trim(s); diff --git a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp index e561186f5..5d5685ba9 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp @@ -143,8 +143,10 @@ std::string sys::OSUnix::getPlatformName() const if (uname(&name) == -1) throw sys::SystemException("Uname failed"); - return str::Format("%s (%s): %s [build: %s]", name.sysname, name.machine, - name.release, name.version); + std::string retval = name.sysname; + retval += FmtX(" (%s): %s", name.machine, name.release); + retval += FmtX(" [build: %s]", name.version); + return retval; } std::string sys::OSUnix::getNodeName() const diff --git a/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp b/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp index e50dee5ec..62ac0cda3 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSWin32.cpp @@ -58,9 +58,10 @@ std::string sys::OSWin32::getPlatformName() const { platform = "Unknown Windows OS"; } - return str::Format("%s: %d.%d [build: %d], %s", platform.c_str(), - info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber, - info.szCSDVersion); + auto retval = platform + ": "; + retval += FmtX("%d.%d [build: %d], ", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber); + retval += info.szCSDVersion; + return retval; } std::string sys::OSWin32::getNodeName() const diff --git a/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp b/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp index 9547c6b7d..035995bfc 100644 --- a/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp +++ b/externals/nitro/modules/c++/nitf/include/nitf/Object.hpp @@ -20,9 +20,9 @@ * */ +#pragma once #ifndef NITRO_nitf_Object_hpp_INCLUDED_ #define NITRO_nitf_Object_hpp_INCLUDED_ -#pragma once #include @@ -151,7 +151,7 @@ class NITRO_NITFCPP_API Object */ std::string getObjectID() const { - return str::Format("%p", getNative()); + return FmtX("%p", getNative()); } bool isManaged() const noexcept { return isValid() && mHandle->isManaged(); } diff --git a/externals/nitro/modules/c++/nitf/tests/test_extract.cpp b/externals/nitro/modules/c++/nitf/tests/test_extract.cpp index 86b3cd20c..ab72d78bd 100644 --- a/externals/nitro/modules/c++/nitf/tests/test_extract.cpp +++ b/externals/nitro/modules/c++/nitf/tests/test_extract.cpp @@ -44,8 +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): { - 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)); + 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)); 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_j2k_nitf_read_region.cpp b/externals/nitro/modules/c++/nitf/tests/test_j2k_nitf_read_region.cpp index d99d6b5c1..d1ab43462 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,8 @@ void writeFile(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, std::span buf, const std::string& prefix) { - const std::string filename = str::Format("%s-raw-%d_%d__%d_%d.out", prefix.c_str(), x0, y0, x1, y1); + auto filename = FmtX("%s-raw-", prefix); + filename += FmtX("%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()); @@ -57,7 +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) { - const std::string outName = str::Format("%s-raw-%d_%d__%d_%d.j2k", prefix.c_str(), x0, y0, x1, y1); + auto outName = FmtX("%s-raw-", prefix); + outName += FmtX("%d_%d__%d_%d.j2k", 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 ec6692e31..fccc42361 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,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) { - const std::string filename = str::Format("%s-raw-%d_%d__%d_%d.out", prefix.c_str(), x0, y0, x1, y1); + auto filename = FmtX("%s-raw-", prefix); + filename += FmtX("%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()); @@ -177,7 +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) { - const std::string outName = str::Format("%s-raw-%d_%d__%d_%d.j2k", prefix.c_str(), x0, y0, x1, y1); + auto outName = FmtX("%s-raw-", prefix); + outName += FmtX("%d_%d__%d_%d.j2k", x0, y0, x1, y1); const auto num_x_tiles = inContainer.getTilesX(); const auto num_y_tiles = inContainer.getTilesY();