Skip to content

Commit

Permalink
latest from CODA-OSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Sep 12, 2023
1 parent 7a363b4 commit a681ebd
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 43 deletions.
112 changes: 80 additions & 32 deletions externals/coda-oss/modules/c++/str/include/str/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,97 +26,141 @@
#define CODA_OSS_str_Format_h_INCLUDED_

#include <stdarg.h>
#include<stdint.h>
#include<stddef.h>
#include <stdint.h>
#include <stddef.h>

#include <string>

#include "config/Exports.h"

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<typename T1>
inline auto Format(const char* format, const T1& t1)
{
return Format_(format, t1);
}
template <typename T1, typename T2>
inline auto Format(const char* format, const T1& t1, const T2& t2)
{
return Format_(format, t1, t2);
}
template <typename T1, typename T2, typename T3>
inline auto Format(const char* format, const T1& t1, const T2& t2, const T3& t3)
{
return Format_(format, t1, t2, t3);
}
template <typename T1, typename T2, typename T3, typename T4>
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)
{
Expand All @@ -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_
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/str/source/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions externals/coda-oss/modules/c++/str/tests/VersionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
#include <iostream>
#include <import/str.h>

#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<std::string>(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);
Expand Down
6 changes: 4 additions & 2 deletions externals/coda-oss/modules/c++/sys/source/OSUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions externals/coda-oss/modules/c++/sys/source/OSWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a681ebd

Please sign in to comment.