#pragma once #include #include "Types.h" #include "Array.h" #include "UTF.h" #include "Str.h" namespace lwe { /// A helper class for holding error information and handling them. /// @tparam T The character data type to use. /// @tparam N The number data type to use. class Log { private: static void (*logCb)(const Log&); static Log lastLog; Array tags; UInt_64 code; Str_8 msg; public: static void SetCallback(void (*newLogCb)(const Log&)); static void Raise(const Log& log); /// Retrieves the last log raised. static Log GetLastLog(); /// Default members initialization. Log(); /// Initializes members with the given information. /// @param [in] tags The tags to associate this log with. /// @param [in] code The unique code to use. /// @param [in] msg Detailed information about what happened. Log(std::initializer_list tags, const UInt_64 code, const Str_8& msg); /// Initializes members with the given information. /// @param [in] tags The tags to associate this log with. /// @param [in] code The unique code to use. /// @param [in] msg Detailed information about what happened. Log(Array& tags, const UInt_64 code, const Str_8& msg); /// Copies all members from the given log. /// @param [in] log The log to copy from. Log(const Log& log); /// Copies all members from the given log. /// @param [in] log The log to copy from. /// @returns The log that has been assigned to. Log& operator=(const Log& log); /* /// Compares with another given log. /// @param [in] log The log to compare with. /// @returns Whether or not they are equal. bool operator==(const Log log); /// Compares with another given log. /// @param [in] log The log to compare with. /// @returns Whether or not they are equal. bool operator!=(const Log log); */ /// Checks whether or not this log has the given tags. /// @param [in] tags The tags to look for. /// @returns True if all tags were found, otherwise false. bool HasTags(const std::initializer_list tags) const; /// Checks whether or not this log has the given tags. /// @param [in] tags The tags to look for. /// @returns True if all tags were found, otherwise false. bool HasTags(const Array& tags) const; /// Checks whether or not this log has the given tag. /// @param [in] tag The tag to look for. /// @returns True if tag was found, otherwise false. bool HasTag(const Str_8& tag) const; /// Retrieves all the tags. /// @returns The result. Array GetTags() const; UInt_64 GetCode() const; /// Retrieves the detailed error message string. /// @returns The error message. Str_8 GetMsg() const; Str_8 ToStr() const; /// Retrieves whether or not this is a valid object. /// @returns The result. /// @note To be a valid object it must have one or more tags and a message size greater than zero. bool IsValid() const; }; } #ifndef LWE_LOG_INT #ifdef LWE_DEBUG #define LWE_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), LWE_FILE, LWE_FUNC, Str_8::FromNum((UInt_32)LWE_LINE)}, code, msg}) #else #define LWE_LOG_INT(type, code, msg) Log::Raise({{type, GetAcronym_8(), LWE_FUNC}, code, msg}) #endif #endif #ifndef LWE_LOG #ifdef LWE_DEBUG #define LWE_LOG(type, code, msg) lwe::Log::Raise({{type, lwe::GetAppName_8(), LWE_FILE, LWE_FUNC, lwe::Str_8::FromNum((lwe::UInt_32)LWE_LINE)}, code, msg}) #else #define LWE_LOG(type, code, msg) lwe::Log::Raise({{type, lwe::GetAppName_8(), LWE_FUNC}, code, msg}) #endif #endif