aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/Logger.hpp
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-05-02 11:25:32 +0200
committer GitHub <noreply@github.com>2023-05-02 11:25:32 +0200
commit9f772a314dc130df95fe5e3b018a9ba60e5be5b1 (patch)
treeab138ae3c615adeb51972b4bfff992dea86cd69c /extension/src/openvic2/Logger.hpp
parentbe43b260128664756054a289cf9d22319def1f8a (diff)
parent112de0ac9c7ce26bd75d06e4cd3bc91adee716e3 (diff)
Merge pull request #97 from Spartan322/update/clang-format
Diffstat (limited to 'extension/src/openvic2/Logger.hpp')
-rw-r--r--extension/src/openvic2/Logger.hpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/extension/src/openvic2/Logger.hpp b/extension/src/openvic2/Logger.hpp
index 624df29..d097cc6 100644
--- a/extension/src/openvic2/Logger.hpp
+++ b/extension/src/openvic2/Logger.hpp
@@ -8,76 +8,80 @@
namespace OpenVic2 {
- #ifndef __cpp_lib_source_location
- #include <string>
- //Implementation of std::source_location for compilers that do not support it
- //Note: uses non-standard extensions that are supported by Clang, GCC, and MSVC
- //https://clang.llvm.org/docs/LanguageExtensions.html#source-location-builtins
- //https://stackoverflow.com/a/67970107
+#ifndef __cpp_lib_source_location
+#include <string>
+ // Implementation of std::source_location for compilers that do not support it
+ // Note: uses non-standard extensions that are supported by Clang, GCC, and MSVC
+ // https://clang.llvm.org/docs/LanguageExtensions.html#source-location-builtins
+ // https://stackoverflow.com/a/67970107
class source_location {
std::string _file;
int _line;
std::string _function;
- public:
- source_location(std::string f, int l, std::string n) : _file(f), _line(l), _function(n) {}
+ public:
+ source_location(std::string f, int l, std::string n) : _file(f),
+ _line(l),
+ _function(n) {}
static source_location current(std::string f = __builtin_FILE(), int l = __builtin_LINE(), std::string n = __builtin_FUNCTION()) {
return source_location(f, l, n);
}
inline char const* file_name() const { return _file.c_str(); }
- inline int line() const {return _line; }
+ inline int line() const { return _line; }
inline char const* function_name() const { return _function.c_str(); }
};
- #endif
+#endif
class Logger {
using log_func_t = std::function<void(std::string&&)>;
- #ifdef __cpp_lib_source_location
+#ifdef __cpp_lib_source_location
using source_location = std::source_location;
- #else
+#else
using source_location = OpenVic2::source_location;
- #endif
+#endif
static log_func_t info_func, error_func;
static char const* get_filename(char const* filepath);
- template <typename... Ts>
+ template<typename... Ts>
struct log {
log(log_func_t log_func, Ts&&... ts, const source_location& location) {
if (log_func) {
std::stringstream stream;
- stream << std::endl << get_filename(location.file_name()) << "(" << location.line() << ") `" << location.function_name() << "`: ";
+ stream << std::endl
+ << get_filename(location.file_name()) << "(" << location.line() << ") `" << location.function_name() << "`: ";
((stream << std::forward<Ts>(ts)), ...);
stream << std::endl;
log_func(stream.str());
}
}
};
+
public:
static void set_info_func(log_func_t log_func);
static void set_error_func(log_func_t log_func);
- template <typename... Ts>
+ template<typename... Ts>
struct info {
info(Ts&&... ts, const source_location& location = source_location::current()) {
- log<Ts...>{ info_func, std::forward<Ts>(ts)..., location };
+ log<Ts...> { info_func, std::forward<Ts>(ts)..., location };
}
};
- template <typename... Ts>
+ template<typename... Ts>
info(Ts&&...) -> info<Ts...>;
- template <typename... Ts>
+ template<typename... Ts>
struct error {
error(Ts&&... ts, const source_location& location = source_location::current()) {
- log<Ts...>{ error_func, std::forward<Ts>(ts)..., location };
+ log<Ts...> { error_func, std::forward<Ts>(ts)..., location };
}
};
- template <typename... Ts>
+ template<typename... Ts>
error(Ts&&...) -> error<Ts...>;
};
}