summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Bindings/LuaState.cpp2
-rw-r--r--src/Bindings/LuaState.h2
-rw-r--r--src/Bindings/ManualBindings.cpp4
-rw-r--r--src/Bindings/ManualBindings.h8
-rw-r--r--src/CommandOutput.cpp4
-rw-r--r--src/CommandOutput.h9
-rw-r--r--src/Globals.h2
-rw-r--r--src/Logger.cpp44
-rw-r--r--src/Logger.h16
-rw-r--r--src/LoggerSimple.h76
-rw-r--r--src/OSSupport/File.cpp7
-rw-r--r--src/OSSupport/File.h8
-rw-r--r--src/StringUtils.cpp43
-rw-r--r--src/StringUtils.h22
-rw-r--r--src/Vector3.h61
-rw-r--r--src/fmt.h18
-rw-r--r--src/main.cpp2
17 files changed, 230 insertions, 98 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index b7f5f17e0..c1612e6a1 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -2107,7 +2107,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth)
-int cLuaState::ApiParamError(fmt::StringRef a_Msg)
+int cLuaState::ApiParamError(fmt::string_view a_Msg)
{
// Retrieve current function name
lua_Debug entry;
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index bd75d8635..94b4ec16d 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -838,7 +838,7 @@ public:
/** Prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error.
To be used for bindings when they detect bad parameters.
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
- int ApiParamError(fmt::StringRef a_Msg);
+ int ApiParamError(fmt::string_view a_Msg);
/** Formats and prints the message using printf-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error.
To be used for bindings when they detect bad parameters.
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 5bf5062c9..9909b233a 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -116,7 +116,7 @@ int cManualBindings::tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Er
-int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, fmt::ArgList a_ArgList)
+int cManualBindings::vlua_do_error(lua_State * L, const char * a_pFormat, fmt::printf_args a_ArgList)
{
// Retrieve current function name
lua_Debug entry;
@@ -129,7 +129,7 @@ int cManualBindings::lua_do_error(lua_State * L, const char * a_pFormat, fmt::Ar
// Copied from luaL_error and modified
luaL_where(L, 1);
- AString FmtMsg = Printf(msg.c_str(), a_ArgList);
+ AString FmtMsg = vPrintf(msg.c_str(), a_ArgList);
lua_pushlstring(L, FmtMsg.data(), FmtMsg.size());
lua_concat(L, 2);
return lua_error(L);
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index 173f62649..137956046 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -51,8 +51,12 @@ public:
// Helper functions:
static cPluginLua * GetLuaPlugin(lua_State * L);
static int tolua_do_error(lua_State * L, const char * a_pMsg, tolua_Error * a_pToLuaError);
- static int lua_do_error(lua_State * L, const char * a_pFormat, fmt::ArgList a_ArgList);
- FMT_VARIADIC(static int, lua_do_error, lua_State *, const char *)
+ static int vlua_do_error(lua_State * L, const char * a_pFormat, fmt::printf_args a_ArgList);
+ template <typename... Args>
+ static int lua_do_error(lua_State * L, const char * a_Format, const Args & ... args)
+ {
+ return vlua_do_error(L, a_Format, fmt::make_printf_args(args...));
+ }
/** Binds the DoWith(ItemName) functions of regular classes. */
diff --git a/src/CommandOutput.cpp b/src/CommandOutput.cpp
index a558facdb..2d363da06 100644
--- a/src/CommandOutput.cpp
+++ b/src/CommandOutput.cpp
@@ -13,9 +13,9 @@
////////////////////////////////////////////////////////////////////////////////
// cCommandOutputCallback:
-void cCommandOutputCallback::Out(const char * a_Fmt, fmt::ArgList args)
+void cCommandOutputCallback::vOut(const char * a_Fmt, fmt::printf_args args)
{
- AString Output = Printf(a_Fmt, args);
+ AString Output = ::vPrintf(a_Fmt, args);
Output.append("\n");
Out(Output);
}
diff --git a/src/CommandOutput.h b/src/CommandOutput.h
index 6cba4de7f..cb40b05a6 100644
--- a/src/CommandOutput.h
+++ b/src/CommandOutput.h
@@ -17,9 +17,14 @@ class cCommandOutputCallback
public:
virtual ~cCommandOutputCallback() {} // Force a virtual destructor in subclasses
+ void vOut(const char * a_Fmt, fmt::printf_args);
+
/** Syntax sugar function, calls Out() with Printf()-ed parameters; appends a newline" */
- void Out(const char * a_Fmt, fmt::ArgList);
- FMT_VARIADIC(void, Out, const char *)
+ template <typename... Args>
+ void Out(const char * a_Fmt, const Args & ... a_Args)
+ {
+ vOut(a_Fmt, fmt::make_printf_args(a_Args...));
+ }
/** Called when the command wants to output anything; may be called multiple times */
virtual void Out(const AString & a_Text) = 0;
diff --git a/src/Globals.h b/src/Globals.h
index 94fc7ce27..387dffc81 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -235,7 +235,7 @@ template class SizeChecker<UInt8, 1>;
// Common headers (part 1, without macros):
-#include "fmt/format.h"
+#include "fmt.h"
#include "StringUtils.h"
#include "OSSupport/CriticalSection.h"
#include "OSSupport/Event.h"
diff --git a/src/Logger.cpp b/src/Logger.cpp
index f0080e73c..819cd09e7 100644
--- a/src/Logger.cpp
+++ b/src/Logger.cpp
@@ -46,9 +46,9 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
AString Line;
#ifdef _DEBUG
- Printf(Line, "[%04llx|%02d:%02d:%02d] %s\n", static_cast<UInt64>(std::hash<std::thread::id>()(std::this_thread::get_id())), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ Printf(Line, "[%04llx|%02d:%02d:%02d] %s\n", static_cast<UInt64>(std::hash<std::thread::id>()(std::this_thread::get_id())), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message);
#else
- Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message.c_str());
+ Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, a_Message);
#endif
@@ -63,18 +63,18 @@ void cLogger::LogSimple(AString a_Message, eLogLevel a_LogLevel)
-void cLogger::LogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList)
+void cLogger::vLogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList)
{
- LogSimple(Printf(a_Format, a_ArgList), a_LogLevel);
+ LogSimple(vPrintf(a_Format, a_ArgList), a_LogLevel);
}
-void cLogger::LogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList)
+void cLogger::vLogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList)
{
- LogSimple(fmt::format(a_Format, a_ArgList), a_LogLevel);
+ LogSimple(fmt::vformat(a_Format, a_ArgList), a_LogLevel);
}
@@ -117,72 +117,72 @@ void cLogger::DetachListener(cListener * a_Listener)
////////////////////////////////////////////////////////////////////////////////
// Global functions
-void FLOG(const char * a_Format, fmt::ArgList a_ArgList)
+void vFLOG(const char * a_Format, fmt::format_args a_ArgList)
{
- cLogger::GetInstance().LogFormat(a_Format, cLogger::llRegular, a_ArgList);
+ cLogger::GetInstance().vLogFormat(a_Format, cLogger::llRegular, a_ArgList);
}
-void FLOGINFO(const char * a_Format, fmt::ArgList a_ArgList)
+void vFLOGINFO(const char * a_Format, fmt::format_args a_ArgList)
{
- cLogger::GetInstance().LogFormat( a_Format, cLogger::llInfo, a_ArgList);
+ cLogger::GetInstance().vLogFormat( a_Format, cLogger::llInfo, a_ArgList);
}
-void FLOGWARNING(const char * a_Format, fmt::ArgList a_ArgList)
+void vFLOGWARNING(const char * a_Format, fmt::format_args a_ArgList)
{
- cLogger::GetInstance().LogFormat( a_Format, cLogger::llWarning, a_ArgList);
+ cLogger::GetInstance().vLogFormat( a_Format, cLogger::llWarning, a_ArgList);
}
-void FLOGERROR(const char * a_Format, fmt::ArgList a_ArgList)
+void vFLOGERROR(const char * a_Format, fmt::format_args a_ArgList)
{
- cLogger::GetInstance().LogFormat( a_Format, cLogger::llError, a_ArgList);
+ cLogger::GetInstance().vLogFormat(a_Format, cLogger::llError, a_ArgList);
}
-void LOG(const char * a_Format, fmt::ArgList a_ArgList)
+void vLOG(const char * a_Format, fmt::printf_args a_ArgList)
{
- cLogger::GetInstance().LogPrintf(a_Format, cLogger::llRegular, a_ArgList);
+ cLogger::GetInstance().vLogPrintf(a_Format, cLogger::llRegular, a_ArgList);
}
-void LOGINFO(const char * a_Format, fmt::ArgList a_ArgList)
+void vLOGINFO(const char * a_Format, fmt::printf_args a_ArgList)
{
- cLogger::GetInstance().LogPrintf( a_Format, cLogger::llInfo, a_ArgList);
+ cLogger::GetInstance().vLogPrintf(a_Format, cLogger::llInfo, a_ArgList);
}
-void LOGWARNING(const char * a_Format, fmt::ArgList a_ArgList)
+void vLOGWARNING(const char * a_Format, fmt::printf_args a_ArgList)
{
- cLogger::GetInstance().LogPrintf( a_Format, cLogger::llWarning, a_ArgList);
+ cLogger::GetInstance().vLogPrintf(a_Format, cLogger::llWarning, a_ArgList);
}
-void LOGERROR(const char * a_Format, fmt::ArgList a_ArgList)
+void vLOGERROR(const char * a_Format, fmt::printf_args a_ArgList)
{
- cLogger::GetInstance().LogPrintf( a_Format, cLogger::llError, a_ArgList);
+ cLogger::GetInstance().vLogPrintf( a_Format, cLogger::llError, a_ArgList);
}
diff --git a/src/Logger.h b/src/Logger.h
index 14c02d825..e6c4460fa 100644
--- a/src/Logger.h
+++ b/src/Logger.h
@@ -59,12 +59,20 @@ public:
};
/** Log a message formatted with a printf style formatting string. */
- void LogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList);
- FMT_VARIADIC(void, LogPrintf, const char *, eLogLevel)
+ void vLogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList);
+ template <typename... Args>
+ void LogPrintf(const char * a_Format, eLogLevel a_LogLevel, const Args & ... args)
+ {
+ vLogPrintf(a_Format, a_LogLevel, fmt::make_printf_args(args...));
+ }
/** Log a message formatted with a python style formatting string. */
- void LogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::ArgList a_ArgList);
- FMT_VARIADIC(void, LogFormat, const char *, eLogLevel)
+ void vLogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList);
+ template <typename... Args>
+ void LogFormat(const char * a_Format, eLogLevel a_LogLevel, const Args & ... args)
+ {
+ vLogFormat(a_Format, a_LogLevel, fmt::make_format_args(args...));
+ }
/** Logs the simple text message at the specified log level. */
void LogSimple(AString a_Message, eLogLevel a_LogLevel = llRegular);
diff --git a/src/LoggerSimple.h b/src/LoggerSimple.h
index 5c0487607..83d1c4e86 100644
--- a/src/LoggerSimple.h
+++ b/src/LoggerSimple.h
@@ -4,31 +4,63 @@
// python style format specified logging
-extern void FLOG(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, FLOG, const char *)
-
-extern void FLOGINFO(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, FLOGINFO, const char *)
-
-extern void FLOGWARNING(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, FLOGWARNING, const char *)
-
-extern void FLOGERROR(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, FLOGERROR, const char *)
+extern void vFLOG(const char * a_Format, fmt::format_args a_ArgList);
+template <typename... Args>
+void FLOG(const char * a_Format, const Args & ... args)
+{
+ vFLOG(a_Format, fmt::make_format_args(args...));
+}
+
+extern void vFLOGINFO(const char * a_Format, fmt::format_args a_ArgList);
+template <typename... Args>
+void FLOGINFO(const char * a_Format, const Args & ... args)
+{
+ vFLOGINFO(a_Format, fmt::make_format_args(args...));
+}
+
+extern void vFLOGWARNING(const char * a_Format, fmt::format_args a_ArgList);
+template <typename... Args>
+void FLOGWARNING(const char * a_Format, const Args & ... args)
+{
+ vFLOGWARNING(a_Format, fmt::make_format_args(args...));
+}
+
+extern void vFLOGERROR(const char * a_Format, fmt::format_args a_ArgList);
+template <typename... Args>
+void FLOGERROR(const char * a_Format, const Args & ... args)
+{
+ vFLOGERROR(a_Format, fmt::make_format_args(args...));
+}
// printf style format specified logging (DEPRECATED)
-extern void LOG(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, LOG, const char *)
-
-extern void LOGINFO(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, LOGINFO, const char *)
-
-extern void LOGWARNING(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, LOGWARNING, const char *)
-
-extern void LOGERROR(const char * a_Format, fmt::ArgList a_ArgList);
-FMT_VARIADIC(void, LOGERROR, const char *)
+extern void vLOG(const char * a_Format, fmt::printf_args a_ArgList);
+template <typename... Args>
+void LOG(const char * a_Format, const Args & ... args)
+{
+ vLOG(a_Format, fmt::make_printf_args(args...));
+}
+
+extern void vLOGINFO(const char * a_Format, fmt::printf_args a_ArgList);
+template <typename... Args>
+void LOGINFO(const char * a_Format, const Args & ... args)
+{
+ vLOGINFO(a_Format, fmt::make_printf_args(args...));
+}
+
+extern void vLOGWARNING(const char * a_Format, fmt::printf_args a_ArgList);
+template <typename... Args>
+void LOGWARNING(const char * a_Format, const Args & ... args)
+{
+ vLOGWARNING(a_Format, fmt::make_printf_args(args...));
+}
+
+extern void vLOGERROR(const char * a_Format, fmt::printf_args a_ArgList);
+template <typename... Args>
+void LOGERROR(const char * a_Format, const Args & ... args)
+{
+ vLOGERROR(a_Format, fmt::make_printf_args(args...));
+}
// Macro variants
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index 3dd97f36c..e882daae7 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -692,10 +692,11 @@ AString cFile::GetExecutableExt(void)
-int cFile::Printf(const char * a_Fmt, fmt::ArgList a_ArgList)
+int cFile::vPrintf(const char * a_Fmt, fmt::printf_args a_ArgList)
{
- AString buf = ::Printf(a_Fmt, a_ArgList);
- return Write(buf.c_str(), buf.length());
+ fmt::memory_buffer Buffer;
+ fmt::printf(Buffer, fmt::to_string_view(a_Fmt), a_ArgList);
+ return Write(Buffer.data(), Buffer.size());
}
diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h
index 59bb61974..0bb877186 100644
--- a/src/OSSupport/File.h
+++ b/src/OSSupport/File.h
@@ -163,8 +163,12 @@ public:
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */
static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp
- int Printf(const char * a_Fmt, fmt::ArgList);
- FMT_VARIADIC(int, Printf, const char *)
+ int vPrintf(const char * a_Fmt, fmt::printf_args);
+ template <typename... Args>
+ int Printf(const char * a_Fmt, const Args & ... a_Args)
+ {
+ return vPrintf(a_Fmt, fmt::make_printf_args(a_Args...));
+ }
/** Flushes all the bufferef output into the file (only when writing) */
void Flush(void);
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 438f1864e..43bf8750b 100644
--- a/src/StringUtils.cpp
+++ b/src/StringUtils.cpp
@@ -52,10 +52,12 @@ static unsigned char HexToDec(char a_HexChar)
-AString & Printf(AString & str, const char * format, fmt::ArgList args)
+AString & vPrintf(AString & str, const char * format, fmt::printf_args args)
{
ASSERT(format != nullptr);
- str = fmt::sprintf(format, args);
+ fmt::memory_buffer Buffer;
+ fmt::printf(Buffer, fmt::to_string_view(format), args);
+ str.assign(Buffer.data(), Buffer.size());
return str;
}
@@ -63,10 +65,23 @@ AString & Printf(AString & str, const char * format, fmt::ArgList args)
-AString Printf(const char * format, fmt::ArgList args)
+AString vPrintf(const char * format, fmt::printf_args args)
{
ASSERT(format != nullptr);
- return fmt::sprintf(format, args);
+ return fmt::vsprintf(format, args);
+}
+
+
+
+
+
+AString & vAppendPrintf(AString & a_String, const char * format, fmt::printf_args args)
+{
+ ASSERT(format != nullptr);
+ fmt::memory_buffer Buffer;
+ fmt::printf(Buffer, fmt::to_string_view(format), args);
+ a_String.append(Buffer.data(), Buffer.size());
+ return a_String;
}
@@ -630,18 +645,18 @@ format binary data this way:
*/
AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine)
{
- fmt::MemoryWriter Output;
+ fmt::memory_buffer Output;
/* If formatting the data from the comment above:
Hex holds: "31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 "
Chars holds: "1234567890abcdef" */
- fmt::MemoryWriter Hex, Chars;
+ fmt::memory_buffer Hex, Chars;
if (a_Size > 0)
{
// Same as std::ceil(static_cast<float>(a_Size) / a_BytesPerLine);
const size_t NumLines = a_Size / a_BytesPerLine + (a_Size % a_BytesPerLine != 0);
const size_t CharsPerLine = 14 + 4 * a_BytesPerLine;
- Output.buffer().reserve(NumLines * CharsPerLine);
+ Output.reserve(NumLines * CharsPerLine);
}
for (size_t i = 0; i < a_Size; i += a_BytesPerLine)
@@ -650,12 +665,20 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, siz
for (size_t j = 0; j < k; j++)
{
Byte c = (static_cast<const Byte *>(a_Data))[i + j];
- Hex << HEX(c >> 4) << HEX(c & 0xf) << ' ';
- Chars << ((c >= ' ') ? static_cast<char>(c) : '.');
+ Hex.push_back(HEX(c >> 4));
+ Hex.push_back(HEX(c & 0xf));
+ Hex.push_back(' ');
+ Chars.push_back((c >= ' ') ? static_cast<char>(c) : '.');
} // for j
// Write Hex with a dynamic fixed width
- Output.write("{0:08x}: {1:{2}} {3}\n", i, Hex.c_str(), a_BytesPerLine * 3, Chars.c_str());
+ auto HexStr = fmt::string_view(Hex.data(), Hex.size());
+ auto CharsStr = fmt::string_view(Chars.data(), Chars.size());
+ fmt::format_to(
+ Output, "{0:08x}: {1:{2}} {3}\n",
+ i, HexStr, a_BytesPerLine * 3, CharsStr
+ );
+
Hex.clear();
Chars.clear();
} // for i
diff --git a/src/StringUtils.h b/src/StringUtils.h
index 428578c03..0013762a2 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -23,21 +23,29 @@ typedef std::map<AString, AString> AStringMap;
/** Output the formatted text into the string.
Returns a_Dst. */
-extern AString & Printf(AString & a_Dst, const char * format, fmt::ArgList args);
-FMT_VARIADIC(AString &, Printf, AString &, const char *)
+extern AString & vPrintf(AString & a_Dst, const char * format, fmt::printf_args args);
+template <typename... Args>
+AString & Printf(AString & a_Dst, const char * a_Format, const Args & ... args)
+{
+ return vPrintf(a_Dst, a_Format, fmt::make_printf_args(args...));
+}
/** Output the formatted text into string
Returns the formatted string by value. */
-extern AString Printf(const char * format, fmt::ArgList args);
-FMT_VARIADIC(AString, Printf, const char *)
+extern AString vPrintf(const char * format, fmt::printf_args args);
+template <typename... Args>
+AString Printf(const char * a_Format, const Args & ... args)
+{
+ return vPrintf(a_Format, fmt::make_printf_args(args...));
+}
/** Add the formated string to the existing data in the string.
Returns a_Dst. */
+extern AString & vAppendPrintf(AString & a_Dst, const char * a_Format, fmt::printf_args args);
template <typename... Args>
-extern AString & AppendPrintf(AString & a_Dst, const char * format, const Args & ... args)
+extern AString & AppendPrintf(AString & a_Dst, const char * a_Format, const Args & ... a_Args)
{
- a_Dst += Printf(format, args...);
- return a_Dst;
+ return vAppendPrintf(a_Dst, a_Format, fmt::make_printf_args(a_Args...));
}
/** Split the string at any of the listed delimiters.
diff --git a/src/Vector3.h b/src/Vector3.h
index b3d54514b..4445c6336 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -384,22 +384,6 @@ public:
z = -z;
}
- // tolua_end
-
- /** Allows formatting a Vector<T> using the same format specifiers as for T
- e.g. `fmt::format("{0:0.2f}", Vector3f{0.0231f, 1.2146f, 1.0f}) == "{0.02, 1.21, 1.00}"` */
- template <typename ArgFormatter>
- friend void format_arg(fmt::BasicFormatter<char, ArgFormatter> & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec)
- {
- std::array<T, 3> Data{{a_Vec.x, a_Vec.y, a_Vec.z}};
-
- a_Formatter.writer() << '{';
- fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(), ", "));
- a_Formatter.writer() << '}';
- }
-
- // tolua_begin
-
/** The max difference between two coords for which the coords are assumed equal. */
static const double EPS;
@@ -411,6 +395,51 @@ public:
+namespace fmt
+{
+
+template <typename What>
+class formatter<Vector3<What>>:
+ public fmt::formatter<What>
+{
+ using Super = fmt::formatter<What>;
+
+ template <typename FormatContext, size_t Len>
+ void Write(FormatContext & a_Ctx, const char (& a_Str)[Len])
+ {
+ auto Itr = std::copy_n(&a_Str[0], Len - 1, a_Ctx.out());
+ a_Ctx.advance_to(Itr);
+ }
+
+ template <typename FormatContext>
+ void Write(FormatContext & a_Ctx, const What & a_Arg)
+ {
+ auto Itr = Super::format(a_Arg, a_Ctx);
+ a_Ctx.advance_to(Itr);
+ }
+
+public:
+
+ template <typename FormatContext>
+ auto format(const Vector3<What> & a_Vec, FormatContext & a_Ctx)
+ -> typename FormatContext::iterator
+ {
+ Write(a_Ctx, "{");
+ Write(a_Ctx, a_Vec.x);
+ Write(a_Ctx, ", ");
+ Write(a_Ctx, a_Vec.y);
+ Write(a_Ctx, ", ");
+ Write(a_Ctx, a_Vec.z);
+ Write(a_Ctx, "}");
+ return a_Ctx.out();
+ }
+};
+
+}
+
+
+
+
template <> inline Vector3<int> Vector3<int>::Floor(void) const
{
diff --git a/src/fmt.h b/src/fmt.h
new file mode 100644
index 000000000..0fe69845a
--- /dev/null
+++ b/src/fmt.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#ifdef __clang__
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wunknown-pragmas"
+ #pragma clang diagnostic ignored "-Wunknown-warning-option"
+ #pragma clang diagnostic ignored "-Wsigned-enum-bitfield"
+ #pragma clang diagnostic ignored "-Wundefined-func-template"
+ #pragma clang diagnostic ignored "-Wc++2a-compat"
+#endif
+
+#include <fmt/format.h>
+#include <fmt/printf.h>
+
+#ifdef __clang__
+ #pragma clang diagnostic pop
+#endif
+
diff --git a/src/main.cpp b/src/main.cpp
index 4ff13c157..1df96663a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -235,7 +235,7 @@ static void UniversalMain(std::unique_ptr<cSettingsRepositoryInterface> a_Overri
cRoot Root;
Root.Start(std::move(a_OverridesRepo));
}
- catch (const fmt::FormatError & exc)
+ catch (const fmt::format_error & exc)
{
cRoot::m_TerminateEventRaised = true;
FLOGERROR("Formatting exception: {0}", exc.what());