From 72b42ef62ed45ce5ab1248dfdb4f1267bd28d579 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Tue, 24 Mar 2020 19:26:40 +0100 Subject: [PATCH] [BL] Replace OGS_FATAL macro with spdlog version. --- BaseLib/Error.h | 60 +++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/BaseLib/Error.h b/BaseLib/Error.h index c03c5b35ea6..e4fce46b575 100644 --- a/BaseLib/Error.h +++ b/BaseLib/Error.h @@ -10,57 +10,23 @@ #pragma once -#ifdef OGS_FATAL_ABORT - #include <cstdlib> #include "Logging.h" -namespace BaseLib -{ -namespace detail -{ -template <typename Msg> -[[noreturn]] - bool error_impl(Msg&& msg) -{ - ERR("{:s}", msg.data()); - std::abort(); -} - -} // namespace detail - -} // namespace BaseLib - +#ifdef OGS_FATAL_ABORT +#define OGS_FATAL(...) \ + { \ + BaseLib::console->critical("{}:{} {}() ", __FILE__, __LINE__, \ + __FUNCTION__, fmt::format(__VA_ARGS__)); \ + std::abort(); \ + } #else // OGS_FATAL_ABORT - #include <stdexcept> - -namespace BaseLib -{ -namespace detail -{ -template <typename Msg> -[[noreturn]] - bool error_impl(Msg&& msg) -{ - throw std::runtime_error(std::forward<Msg>(msg)); -} - -} // namespace detail - -} // namespace BaseLib - +#define OGS_FATAL(...) \ + { \ + BaseLib::console->critical("{}:{} {}() ", __FILE__, __LINE__, \ + __FUNCTION__, fmt::format(__VA_ARGS__)); \ + throw std::runtime_error(fmt::format(__VA_ARGS__)); \ + } #endif // OGS_FATAL_ABORT -#include "FileTools.h" -#include "StringTools.h" - -#define OGS_STR(x) #x -#define OGS_STRINGIFY(x) OGS_STR(x) -#define OGS_LOCATION \ - (" at " + BaseLib::extractBaseName(__FILE__) + \ - ", line " OGS_STRINGIFY(__LINE__)) - -#define OGS_FATAL(fmt, ...) \ - BaseLib::detail::error_impl(BaseLib::format(fmt, ##__VA_ARGS__) + \ - OGS_LOCATION) -- GitLab