Skip to content

Commit 08d7b56

Browse files
committed
util: switch LogPrint and error to variadic templates
1 parent 9eaa0af commit 08d7b56

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/util.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,40 +76,33 @@ int LogPrintStr(const std::string &str);
7676

7777
#define LogPrintf(...) LogPrint(NULL, __VA_ARGS__)
7878

79-
/**
80-
* When we switch to C++11, this can be switched to variadic templates instead
81-
* of this macro-based construction (see tinyformat.h).
82-
*/
83-
#define MAKE_ERROR_AND_LOG_FUNC(n) \
84-
/** Print to debug.log if -debug=category switch is given OR category is NULL. */ \
85-
template<TINYFORMAT_ARGTYPES(n)> \
86-
static inline int LogPrint(const char* category, const char* format, TINYFORMAT_VARARGS(n)) \
87-
{ \
88-
if(!LogAcceptCategory(category)) return 0; \
89-
return LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
90-
} \
91-
/** Log error and return false */ \
92-
template<TINYFORMAT_ARGTYPES(n)> \
93-
static inline bool error(const char* format, TINYFORMAT_VARARGS(n)) \
94-
{ \
95-
LogPrintStr("ERROR: " + tfm::format(format, TINYFORMAT_PASSARGS(n)) + "\n"); \
96-
return false; \
97-
}
79+
template<typename T1, typename... Args>
80+
static inline int LogPrint(const char* category, const char* fmt, const T1& v1, const Args&... args)
81+
{
82+
if(!LogAcceptCategory(category)) return 0; \
83+
return LogPrintStr(tfm::format(fmt, v1, args...));
84+
}
9885

99-
TINYFORMAT_FOREACH_ARGNUM(MAKE_ERROR_AND_LOG_FUNC)
86+
template<typename T1, typename... Args>
87+
bool error(const char* fmt, const T1& v1, const Args&... args)
88+
{
89+
LogPrintStr("ERROR: " + tfm::format(fmt, v1, args...) + "\n");
90+
return false;
91+
}
10092

10193
/**
10294
* Zero-arg versions of logging and error, these are not covered by
103-
* TINYFORMAT_FOREACH_ARGNUM
95+
* the variadic templates above (and don't take format arguments but
96+
* bare strings).
10497
*/
105-
static inline int LogPrint(const char* category, const char* format)
98+
static inline int LogPrint(const char* category, const char* s)
10699
{
107100
if(!LogAcceptCategory(category)) return 0;
108-
return LogPrintStr(format);
101+
return LogPrintStr(s);
109102
}
110-
static inline bool error(const char* format)
103+
static inline bool error(const char* s)
111104
{
112-
LogPrintStr(std::string("ERROR: ") + format + "\n");
105+
LogPrintStr(std::string("ERROR: ") + s + "\n");
113106
return false;
114107
}
115108

0 commit comments

Comments
 (0)