From 3f6d7351816b0e089495b2f15dc1c956f3151f5a Mon Sep 17 00:00:00 2001 From: hop311 Date: Sun, 4 Feb 2024 14:08:32 +0000 Subject: Reworked ReturnByValue, warn_or_error, expect_date_[identifier_or_]string --- src/openvic-simulation/utility/Logger.hpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/openvic-simulation/utility/Logger.hpp') diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp index 53decb3..7a2c3d0 100644 --- a/src/openvic-simulation/utility/Logger.hpp +++ b/src/openvic-simulation/utility/Logger.hpp @@ -75,16 +75,16 @@ namespace OpenVic { size_t message_count; }; - template + template struct log { - log(log_channel_t& log_channel, Ts&&... ts, source_location const& location) { + log(log_channel_t& log_channel, Args&&... args, source_location const& location) { std::stringstream stream; stream << StringUtils::get_filename(location.file_name()) << "(" /* Function name removed to reduce clutter. It is already included * in Godot's print functions, so this was repeating it. */ //<< location.line() << ") `" << location.function_name() << "`: "; << location.line() << "): "; - ((stream << std::forward(ts)), ...); + ((stream << std::forward(args)), ...); stream << std::endl; log_channel.queue.push(stream.str()); if (log_channel.func) { @@ -109,19 +109,28 @@ public: \ static inline size_t get_##name##_count() { \ return name##_channel.message_count; \ } \ - template \ + template \ struct name { \ - name(Ts&&... ts, source_location const& location = source_location::current()) { \ - log { name##_channel, std::forward(ts)..., location }; \ + name(Args&&... args, source_location const& location = source_location::current()) { \ + log { name##_channel, std::forward(args)..., location }; \ } \ }; \ - template \ - name(Ts&&...) -> name; + template \ + name(Args&&...) -> name; LOG_FUNC(info) LOG_FUNC(warning) LOG_FUNC(error) #undef LOG_FUNC + + template + static inline constexpr void warn_or_error(bool warn, Args&&... args) { + if (warn) { + warning(std::forward(args)...); + } else { + error(std::forward(args)...); + } + } }; } -- cgit v1.2.3-56-ga3b1