Skip to content

Commit 1f519da

Browse files
committed
refactor: replace ODR_CHECK macros and usages with templated functions supporting printf-style messages
1 parent d1ef1e7 commit 1f519da

3 files changed

Lines changed: 186 additions & 70 deletions

File tree

include/Utils.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "Log.hpp"
23
#include "Math.hpp"
34

45
#include <algorithm>
@@ -13,23 +14,26 @@
1314
#include <type_traits>
1415
#include <vector>
1516

16-
#define ODR_CHECK(expr, msg) \
17-
{ \
18-
if (!(expr)) \
19-
logf(LogLevel::Warn, "[%s] check failed: %s", __FUNCTION__, msg); \
20-
}
17+
namespace odr
18+
{
2119

22-
#define ODR_CHECK_AND_REPAIR(check_expr, msg, repair_expr) \
23-
{ \
24-
if (!(check_expr)) \
25-
{ \
26-
logf(LogLevel::Warn, "[%s] check failed: %s", __FUNCTION__, msg); \
27-
repair_expr; \
28-
} \
29-
}
20+
template<class... Args>
21+
inline void check(const bool ok, const char* fmt, Args&&... args)
22+
{
23+
if (!ok)
24+
logf(LogLevel::Warn, fmt, std::forward<Args>(args)...);
25+
}
3026

31-
namespace odr
27+
template<class Repair, class... Args>
28+
inline void check_and_repair(const bool ok, Repair&& repair, const char* fmt, Args&&... args)
3229
{
30+
if (!ok)
31+
{
32+
logf(LogLevel::Warn, fmt, std::forward<Args>(args)...);
33+
std::forward<Repair>(repair)();
34+
}
35+
}
36+
3337
template<class C, class T, T C::*member>
3438
struct PtrCmp
3539
{

0 commit comments

Comments
 (0)