refactor: convert lt_assert from macro to variadic template function
This commit is contained in:
parent
ae336e3bba
commit
e1fdeb2692
3 changed files with 27 additions and 9 deletions
|
@ -12,13 +12,25 @@ struct FailedAssertion: std::exception
|
|||
}
|
||||
};
|
||||
|
||||
#define lt_assert(x, ...) \
|
||||
{ \
|
||||
if (!(x)) \
|
||||
{ \
|
||||
log_crt(__VA_ARGS__); \
|
||||
throw ::lt::FailedAssertion(__FILE__, __LINE__); \
|
||||
} \
|
||||
|
||||
template<typename Expression_T, typename... Args>
|
||||
constexpr void lt_assert(Expression_T &&expression, std::format_string<Args...> fmt, Args &&...args)
|
||||
{
|
||||
if (!static_cast<bool>(expression))
|
||||
{
|
||||
Logger::log(LogLvl::critical, fmt, std::forward<Args>(args)...);
|
||||
throw ::lt::FailedAssertion(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Expression_T>
|
||||
constexpr void lt_assert(Expression_T &&expression, const char *message)
|
||||
{
|
||||
if (!static_cast<bool>(expression))
|
||||
{
|
||||
Logger::log(LogLvl::critical, message);
|
||||
throw ::lt::FailedAssertion(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lt
|
||||
|
|
|
@ -12,8 +12,8 @@ try
|
|||
|
||||
application = lt::create_application();
|
||||
|
||||
lt_assert(application, "Failed to create application");
|
||||
lt_assert(application->sanity_check(), "Failed to verify the sanity of the application");
|
||||
lt::lt_assert(application, "Failed to create application");
|
||||
lt::lt_assert(application->sanity_check(), "Failed to verify the sanity of the application");
|
||||
|
||||
application->game_loop();
|
||||
|
||||
|
|
|
@ -53,6 +53,12 @@ public:
|
|||
);
|
||||
}
|
||||
|
||||
void static log(LogLvl lvl, const char *message)
|
||||
{
|
||||
instance().spd_logger->log((spdlog::level::level_enum)lvl, message);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Logger();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue