From 1738dd9f63fa10cdb51f547eaf09a9870c20b174 Mon Sep 17 00:00:00 2001 From: Myles Busig Date: Wed, 19 Jun 2024 19:29:45 -0600 Subject: [PATCH] Change log level to use an enum instead of uint --- include/mtl/log.hpp | 11 +++++++++-- src/gba/log.cpp | 12 ++++++------ src/log.cpp | 11 +++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/mtl/log.hpp b/include/mtl/log.hpp index cffa01f..97c1fc3 100644 --- a/include/mtl/log.hpp +++ b/include/mtl/log.hpp @@ -8,6 +8,13 @@ namespace mtl { namespace log { +enum class level : uint32_t { + error = 1, + warn = 2, + info = 3, + debug = 4, +}; + #ifdef __GBA__ constexpr char endl_char = 0; #else @@ -32,10 +39,10 @@ constexpr char endl_char = '\n'; */ class stream : public basic_string_stream { private: - uint32_t m_log_level; + level m_log_level; public: - stream(istring& str, uint32_t log_level); + stream(istring& str, level log_level); ~stream(); using basic_string_stream::operator=; diff --git a/src/gba/log.cpp b/src/gba/log.cpp index 5e3678c..ecd487d 100644 --- a/src/gba/log.cpp +++ b/src/gba/log.cpp @@ -39,7 +39,7 @@ static volatile uint16_t& flags = *reinterpret_cast(0x4FFF700); static string_ext string(reinterpret_cast(0x4FFF600), 256); }; // namespace reg -stream::stream(istring& buf, uint32_t log_level) +stream::stream(istring& buf, level log_level) : basic_string_stream(buf), m_log_level(log_level) { reg::enable = 0xC0DE; } @@ -48,14 +48,14 @@ stream::~stream() { } void stream::flush() { - reg::flags = 0x100 | m_log_level; + reg::flags = 0x100 | static_cast(m_log_level); clear(); } -stream debug(reg::string, 4); -stream info(reg::string, 3); -stream warn(reg::string, 2); -stream error(reg::string, 1); +stream debug(reg::string, level::debug); +stream info(reg::string, level::info); +stream warn(reg::string, level::warn); +stream error(reg::string, level::error); } // namespace log diff --git a/src/log.cpp b/src/log.cpp index 05b01eb..8fbb91d 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,6 +1,5 @@ #include "mtl/log.hpp" -#include #include namespace mtl { @@ -9,7 +8,7 @@ namespace log { static string<512> buffer; -stream::stream(istring& buf, uint32_t log_level) +stream::stream(istring& buf, level log_level) : basic_string_stream(buf), m_log_level(log_level) { } stream::~stream() { } @@ -18,10 +17,10 @@ void stream::flush() { clear(); } -stream debug(buffer, 4); -stream info(buffer, 3); -stream warn(buffer, 2); -stream error(buffer, 1); +stream debug(buffer, level::debug); +stream info(buffer, level::info); +stream warn(buffer, level::warn); +stream error(buffer, level::error); } // namespace log