From d4ecf95ca538be6397ded2e9639a0ce16bd62a95 Mon Sep 17 00:00:00 2001 From: bofdahof <172177156+bofdahof@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:20:24 +1000 Subject: [PATCH] Console: misc refactors - use C++20 contains where appropriate - add nolint redundant qualifier - remove old todo - remove redundant enum name - add const - remove redundant classname - remove redundant inline - remove redundant namespace --- src/Base/Console.cpp | 193 +++++++++++++++--------------- src/Base/Console.h | 272 +++++++++++++++++++++---------------------- 2 files changed, 232 insertions(+), 233 deletions(-) diff --git a/src/Base/Console.cpp b/src/Base/Console.cpp index 2ae3f1deb5..2bfe93b442 100644 --- a/src/Base/Console.cpp +++ b/src/Base/Console.cpp @@ -55,12 +55,12 @@ public: std::string notifier; std::string msg; - ConsoleEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, - IntendedRecipient recipient, - ContentType content, + ConsoleEvent(const ConsoleSingleton::FreeCAD_ConsoleMsgType type, + const IntendedRecipient recipient, + const ContentType content, const std::string& notifier, const std::string& msg) - : QEvent(QEvent::User) + : QEvent(QEvent::User) // NOLINT , msgtype(type) , recipient(recipient) , content(content) @@ -88,8 +88,7 @@ public: void customEvent(QEvent* ev) override { if (ev->type() == QEvent::User) { - ConsoleEvent* ce = static_cast(ev); - switch (ce->msgtype) { + switch (const auto ce = static_cast(ev); ce->msgtype) { case ConsoleSingleton::MsgType_Txt: Console().notifyPrivate(LogStyle::Message, ce->recipient, @@ -159,7 +158,7 @@ ConsoleSingleton::ConsoleSingleton() ConsoleSingleton::~ConsoleSingleton() { ConsoleOutput::destruct(); - for (ILogger* Iter : _aclObservers) { + for (ILogger* Iter : _aclObservers) { // NOLINT delete Iter; } } @@ -186,10 +185,11 @@ ConsoleSingleton::~ConsoleSingleton() * switches off warnings and error messages and restore the state before the modification. * If the observer \a sObs doesn't exist then nothing happens. */ -ConsoleMsgFlags ConsoleSingleton::SetEnabledMsgType(const char* sObs, ConsoleMsgFlags type, bool on) +ConsoleMsgFlags ConsoleSingleton::SetEnabledMsgType(const char* sObs, + const ConsoleMsgFlags type, + const bool on) const { - ILogger* pObs = Get(sObs); - if (pObs) { + if (ILogger* pObs = Get(sObs)) { ConsoleMsgFlags flags = 0; if (type & MsgType_Err) { @@ -235,10 +235,9 @@ ConsoleMsgFlags ConsoleSingleton::SetEnabledMsgType(const char* sObs, ConsoleMsg return 0; } -bool ConsoleSingleton::IsMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType type) const +bool ConsoleSingleton::IsMsgTypeEnabled(const char* sObs, const FreeCAD_ConsoleMsgType type) const { - ILogger* pObs = Get(sObs); - if (pObs) { + if (const ILogger* pObs = Get(sObs)) { switch (type) { case MsgType_Txt: return pObs->bMsg; @@ -260,7 +259,7 @@ bool ConsoleSingleton::IsMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType return false; } -void ConsoleSingleton::SetConnectionMode(ConnectionMode mode) +void ConsoleSingleton::SetConnectionMode(const ConnectionMode mode) { connectionMode = mode; @@ -282,7 +281,7 @@ void ConsoleSingleton::SetConnectionMode(ConnectionMode mode) void ConsoleSingleton::AttachObserver(ILogger* pcObserver) { // double insert !! - assert(_aclObservers.find(pcObserver) == _aclObservers.end()); + assert(!_aclObservers.contains(pcObserver)); _aclObservers.insert(pcObserver); } @@ -297,11 +296,11 @@ void ConsoleSingleton::DetachObserver(ILogger* pcObserver) _aclObservers.erase(pcObserver); } -void Base::ConsoleSingleton::notifyPrivate(LogStyle category, - IntendedRecipient recipient, - ContentType content, - const std::string& notifiername, - const std::string& msg) +void ConsoleSingleton::notifyPrivate(const LogStyle category, + const IntendedRecipient recipient, + const ContentType content, + const std::string& notifiername, + const std::string& msg) const { for (ILogger* Iter : _aclObservers) { if (Iter->isActive(category)) { @@ -314,9 +313,9 @@ void Base::ConsoleSingleton::notifyPrivate(LogStyle category, } } -void ConsoleSingleton::postEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, - IntendedRecipient recipient, - ContentType content, +void ConsoleSingleton::postEvent(const FreeCAD_ConsoleMsgType type, + const IntendedRecipient recipient, + const ContentType content, const std::string& notifiername, const std::string& msg) { @@ -336,12 +335,12 @@ ILogger* ConsoleSingleton::Get(const char* Name) const return nullptr; } -int* ConsoleSingleton::GetLogLevel(const char* tag, bool create) +int* ConsoleSingleton::GetLogLevel(const char* tag, const bool create) { if (!tag) { tag = ""; } - if (_logLevels.find(tag) != _logLevels.end()) { + if (_logLevels.contains(tag)) { return &_logLevels[tag]; } if (!create) { @@ -352,14 +351,14 @@ int* ConsoleSingleton::GetLogLevel(const char* tag, bool create) return &ret; } -void ConsoleSingleton::Refresh() +void ConsoleSingleton::Refresh() const { if (_bCanRefresh) { qApp->processEvents(QEventLoop::ExcludeUserInputEvents); } } -void ConsoleSingleton::EnableRefresh(bool enable) +void ConsoleSingleton::EnableRefresh(const bool enable) { _bCanRefresh = enable; } @@ -392,85 +391,85 @@ ConsoleSingleton& ConsoleSingleton::Instance() // ConsoleSingleton Methods structure PyMethodDef ConsoleSingleton::Methods[] = { {"PrintMessage", - ConsoleSingleton::sPyMessage, + sPyMessage, METH_VARARGS, "PrintMessage(obj) -> None\n\n" "Print a message to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintLog", - ConsoleSingleton::sPyLog, + sPyLog, METH_VARARGS, "PrintLog(obj) -> None\n\n" "Print a log message to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintError", - ConsoleSingleton::sPyError, + sPyError, METH_VARARGS, "PrintError(obj) -> None\n\n" "Print an error message to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintDeveloperError", - ConsoleSingleton::sPyDeveloperError, + sPyDeveloperError, METH_VARARGS, "PrintDeveloperError(obj) -> None\n\n" "Print an error message intended only for Developers to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintUserError", - ConsoleSingleton::sPyUserError, + sPyUserError, METH_VARARGS, "PrintUserError(obj) -> None\n\n" "Print an error message intended only for the User to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintTranslatedUserError", - ConsoleSingleton::sPyTranslatedUserError, + sPyTranslatedUserError, METH_VARARGS, "PrintTranslatedUserError(obj) -> None\n\n" "Print an already translated error message intended only for the User to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintWarning", - ConsoleSingleton::sPyWarning, + sPyWarning, METH_VARARGS, "PrintWarning(obj) -> None\n\n" "Print a warning message to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintDeveloperWarning", - ConsoleSingleton::sPyDeveloperWarning, + sPyDeveloperWarning, METH_VARARGS, "PrintDeveloperWarning(obj) -> None\n\n" "Print an warning message intended only for Developers to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintUserWarning", - ConsoleSingleton::sPyUserWarning, + sPyUserWarning, METH_VARARGS, "PrintUserWarning(obj) -> None\n\n" "Print a warning message intended only for the User to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintTranslatedUserWarning", - ConsoleSingleton::sPyTranslatedUserWarning, + sPyTranslatedUserWarning, METH_VARARGS, "PrintTranslatedUserWarning(obj) -> None\n\n" "Print an already translated warning message intended only for the User to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintCritical", - ConsoleSingleton::sPyCritical, + sPyCritical, METH_VARARGS, "PrintCritical(obj) -> None\n\n" "Print a critical message to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintNotification", - ConsoleSingleton::sPyNotification, + sPyNotification, METH_VARARGS, "PrintNotification(obj) -> None\n\n" "Print a user notification to the output.\n\n" "obj : object\n The string representation is printed."}, {"PrintTranslatedNotification", - ConsoleSingleton::sPyTranslatedNotification, + sPyTranslatedNotification, METH_VARARGS, "PrintTranslatedNotification(obj) -> None\n\n" "Print an already translated notification to the output.\n\n" "obj : object\n The string representation is printed."}, {"SetStatus", - ConsoleSingleton::sPySetStatus, + sPySetStatus, METH_VARARGS, "SetStatus(observer, type, status) -> None\n\n" "Set the status for either 'Log', 'Msg', 'Wrn' or 'Error' for an observer.\n\n" @@ -478,7 +477,7 @@ PyMethodDef ConsoleSingleton::Methods[] = { "type : str\n Message type.\n" "status : bool"}, {"GetStatus", - ConsoleSingleton::sPyGetStatus, + sPyGetStatus, METH_VARARGS, "GetStatus(observer, type) -> bool or None\n\n" "Get the status for either 'Log', 'Msg', 'Wrn' or 'Error' for an observer.\n" @@ -486,7 +485,7 @@ PyMethodDef ConsoleSingleton::Methods[] = { "observer : str\n Logging interface name.\n" "type : str\n Message type."}, {"GetObservers", - ConsoleSingleton::sPyGetObservers, + sPyGetObservers, METH_VARARGS, "GetObservers() -> list of str\n\n" "Get the names of the current logging interfaces."}, @@ -500,7 +499,7 @@ PyObject* FC_PYCONSOLE_MSG(std::function func, P PyObject* output {}; PyObject* notifier {}; - const char* notifierStr = ""; + auto notifierStr = ""; auto retrieveString = [](PyObject* pystr) { PyObject* unicode = nullptr; @@ -539,9 +538,8 @@ PyObject* FC_PYCONSOLE_MSG(std::function func, P PY_TRY { - const char* string = retrieveString(output); - if (string) { + if (const char* string = retrieveString(output)) { func(notifierStr, string); /*process message*/ } } @@ -555,9 +553,10 @@ PyObject* ConsoleSingleton::sPyMessage(PyObject* /*self*/, PyObject* args) return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { Instance() - .Send(notifier, "%s", msg); + .Send( + notifier, + "%s", + msg); }, args); } @@ -576,9 +575,10 @@ PyObject* ConsoleSingleton::sPyDeveloperWarning(PyObject* /*self*/, PyObject* ar return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { Instance() - .Send(notifier, "%s", msg); + .Send( + notifier, + "%s", + msg); }, args); } @@ -587,10 +587,10 @@ PyObject* ConsoleSingleton::sPyUserWarning(PyObject* /*self*/, PyObject* args) { return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { - Instance() - .Send(notifier, "%s", msg); + Instance().Send( + notifier, + "%s", + msg); }, args); } @@ -599,10 +599,10 @@ PyObject* ConsoleSingleton::sPyTranslatedUserWarning(PyObject* /*self*/, PyObjec { return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { - Instance() - .Send(notifier, "%s", msg); + Instance().Send( + notifier, + "%s", + msg); }, args); } @@ -611,10 +611,10 @@ PyObject* ConsoleSingleton::sPyError(PyObject* /*self*/, PyObject* args) { return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { - Instance() - .Send(notifier, "%s", msg); + Instance().Send( + notifier, + "%s", + msg); }, args); } @@ -624,9 +624,10 @@ PyObject* ConsoleSingleton::sPyDeveloperError(PyObject* /*self*/, PyObject* args return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { Instance() - .Send(notifier, "%s", msg); + .Send( + notifier, + "%s", + msg); }, args); } @@ -635,10 +636,10 @@ PyObject* ConsoleSingleton::sPyUserError(PyObject* /*self*/, PyObject* args) { return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { - Instance() - .Send(notifier, "%s", msg); + Instance().Send( + notifier, + "%s", + msg); }, args); } @@ -647,10 +648,10 @@ PyObject* ConsoleSingleton::sPyTranslatedUserError(PyObject* /*self*/, PyObject* { return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { - Instance() - .Send(notifier, "%s", msg); + Instance().Send( + notifier, + "%s", + msg); }, args); } @@ -660,9 +661,10 @@ PyObject* ConsoleSingleton::sPyLog(PyObject* /*self*/, PyObject* args) return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { Instance() - .Send(notifier, "%s", msg); + .Send( + notifier, + "%s", + msg); }, args); } @@ -671,10 +673,10 @@ PyObject* ConsoleSingleton::sPyCritical(PyObject* /*self*/, PyObject* args) { return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { - Instance() - .Send(notifier, "%s", msg); + Instance().Send( + notifier, + "%s", + msg); }, args); } @@ -684,9 +686,10 @@ PyObject* ConsoleSingleton::sPyNotification(PyObject* /*self*/, PyObject* args) return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { Instance() - .Send(notifier, "%s", msg); + .Send( + notifier, + "%s", + msg); }, args); } @@ -696,9 +699,10 @@ PyObject* ConsoleSingleton::sPyTranslatedNotification(PyObject* /*self*/, PyObje return FC_PYCONSOLE_MSG( [](const std::string& notifier, const char* msg) { Instance() - .Send(notifier, "%s", msg); + .Send( + notifier, + "%s", + msg); }, args); } @@ -714,7 +718,7 @@ PyObject* ConsoleSingleton::sPyGetStatus(PyObject* /*self*/, PyObject* args) PY_TRY { bool b = false; - ILogger* pObs = Instance().Get(pstr1); + const ILogger* pObs = Instance().Get(pstr1); if (!pObs) { Py_Return; } @@ -759,9 +763,8 @@ PyObject* ConsoleSingleton::sPySetStatus(PyObject* /*self*/, PyObject* args) PY_TRY { - bool status = asBoolean(pyStatus); - ILogger* pObs = Instance().Get(pstr1); - if (pObs) { + const bool status = asBoolean(pyStatus); + if (ILogger* pObs = Instance().get(pstr1)) { if (strcmp(pstr2, "Log") == 0) { pObs->bLog = status; } @@ -803,13 +806,13 @@ PyObject* ConsoleSingleton::sPyGetObservers(PyObject* /*self*/, PyObject* args) PY_TRY { Py::List list; - for (auto i : Instance()._aclObservers) { + for (const auto i : Instance()._aclObservers) { list.append(Py::String(i->Name() ? i->Name() : "")); } - return Py::new_reference_to(list); + return new_reference_to(list); } PY_CATCH } -Base::ILogger::~ILogger() = default; +ILogger::~ILogger() = default; diff --git a/src/Base/Console.h b/src/Base/Console.h index 09352cf1b8..3e3540a4dc 100644 --- a/src/Base/Console.h +++ b/src/Base/Console.h @@ -485,7 +485,6 @@ using PyMethodDef = struct PyMethodDef; // clang-format on // NOLINTEND(bugprone-reserved-identifier,bugprone-macro-parentheses,cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while) -// TODO: Get rid of this typedef using ConsoleMsgFlags = unsigned int; namespace Base @@ -494,8 +493,8 @@ namespace Base #ifndef FC_LOG_NO_TIMING inline FC_DURATION GetDuration(FC_TIME_POINT& tp) { - auto tnow = std::chrono::FC_TIME_CLOCK::now(); - auto dc = std::chrono::duration_cast(tnow - tp); + const auto tnow = std::chrono::FC_TIME_CLOCK::now(); + const auto dc = std::chrono::duration_cast(tnow - tp); tp = tnow; return dc; } @@ -580,20 +579,20 @@ public: /** * Returns whether a LogStyle category is active or not */ - bool isActive(Base::LogStyle category) const + bool isActive(const LogStyle category) const { switch (category) { - case Base::LogStyle::Log: + case LogStyle::Log: return bLog; - case Base::LogStyle::Warning: + case LogStyle::Warning: return bWrn; - case Base::LogStyle::Error: + case LogStyle::Error: return bErr; - case Base::LogStyle::Message: + case LogStyle::Message: return bMsg; - case Base::LogStyle::Critical: + case LogStyle::Critical: return bCritical; - case Base::LogStyle::Notification: + case LogStyle::Notification: return bNotification; } @@ -712,81 +711,78 @@ public: Notification can be direct or via queue. */ - template - inline void Send(const std::string& notifiername, const char* pMsg, Args&&... args); + void Send(const std::string& notifiername, const char* pMsg, Args&&... args); /// Prints a Message template - inline void Message(const char* pMsg, Args&&... args); + void Message(const char* pMsg, Args&&... args); /// Prints a warning Message template - inline void Warning(const char* pMsg, Args&&... args); + void Warning(const char* pMsg, Args&&... args); /// Prints a error Message template - inline void Error(const char* pMsg, Args&&... args); + void Error(const char* pMsg, Args&&... args); /// Prints a log Message template - inline void Log(const char* pMsg, Args&&... args); + void Log(const char* pMsg, Args&&... args); /// Prints a Critical Message template - inline void Critical(const char* pMsg, Args&&... args); + void Critical(const char* pMsg, Args&&... args); /// Sends a User Notification template - inline void UserNotification(const char* pMsg, Args&&... args); + void UserNotification(const char* pMsg, Args&&... args); /// Sends an already translated User Notification template - inline void UserTranslatedNotification(const char* pMsg, Args&&... args); + void UserTranslatedNotification(const char* pMsg, Args&&... args); /// Prints a Message with source indication template - inline void Message(const std::string& notifier, const char* pMsg, Args&&... args); + void Message(const std::string& notifier, const char* pMsg, Args&&... args); /// Prints a warning Message with source indication template - inline void Warning(const std::string& notifier, const char* pMsg, Args&&... args); + void Warning(const std::string& notifier, const char* pMsg, Args&&... args); template - inline void DeveloperWarning(const std::string& notifier, const char* pMsg, Args&&... args); + void DeveloperWarning(const std::string& notifier, const char* pMsg, Args&&... args); template - inline void UserWarning(const std::string& notifier, const char* pMsg, Args&&... args); + void UserWarning(const std::string& notifier, const char* pMsg, Args&&... args); template - inline void - TranslatedUserWarning(const std::string& notifier, const char* pMsg, Args&&... args); + void TranslatedUserWarning(const std::string& notifier, const char* pMsg, Args&&... args); /// Prints a error Message with source indication template - inline void Error(const std::string& notifier, const char* pMsg, Args&&... args); + void Error(const std::string& notifier, const char* pMsg, Args&&... args); template - inline void DeveloperError(const std::string& notifier, const char* pMsg, Args&&... args); + void DeveloperError(const std::string& notifier, const char* pMsg, Args&&... args); template /// A noexcept DeveloperError for use in destructors. When compiled in debug, terminates via an /// assert. In release, the exception is silently caught and dropped. - inline void - DestructorError(const std::string& notifier, const char* pMsg, Args&&... args) noexcept; + void DestructorError(const std::string& notifier, const char* pMsg, Args&&... args) noexcept; template - inline void UserError(const std::string& notifier, const char* pMsg, Args&&... args); + void UserError(const std::string& notifier, const char* pMsg, Args&&... args); template - inline void TranslatedUserError(const std::string& notifier, const char* pMsg, Args&&... args); + void TranslatedUserError(const std::string& notifier, const char* pMsg, Args&&... args); /// Prints a log Message with source indication template - inline void Log(const std::string& notifier, const char* pMsg, Args&&... args); + void Log(const std::string& notifier, const char* pMsg, Args&&... args); /// Prints a Critical Message with source indication template - inline void Critical(const std::string& notifier, const char* pMsg, Args&&... args); + void Critical(const std::string& notifier, const char* pMsg, Args&&... args); /// Sends a User Notification with source indication template - inline void UserNotification(const std::string& notifier, const char* pMsg, Args&&... args); + void UserNotification(const std::string& notifier, const char* pMsg, Args&&... args); /// Sends an already translated User Notification with source indication template - inline void - UserTranslatedNotification(const std::string& notifier, const char* pMsg, Args&&... args); + void UserTranslatedNotification(const std::string& notifier, const char* pMsg, Args&&... args); // Notify a message directly to observers - template - inline void Notify(const std::string& notifiername, const std::string& msg); + template + void Notify(const std::string& notifiername, const std::string& msg); /// Attaches an Observer to FCConsole void AttachObserver(ILogger* pcObserver); @@ -815,19 +811,19 @@ public: }; /// Enables or disables message types of a certain console observer - ConsoleMsgFlags SetEnabledMsgType(const char* sObs, ConsoleMsgFlags type, bool on); + ConsoleMsgFlags SetEnabledMsgType(const char* sObs, ConsoleMsgFlags type, bool on) const; /// Checks if message types of a certain console observer are enabled bool IsMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType type) const; void SetConnectionMode(ConnectionMode mode); int* GetLogLevel(const char* tag, bool create = true); - void SetDefaultLogLevel(int level) + void SetDefaultLogLevel(const int level) { _defaultLogLevel = level; } - inline int LogLevel(int level) const + int LogLevel(const int level) const { return level < 0 ? _defaultLogLevel : level; } @@ -840,10 +836,10 @@ public: static PyMethodDef Methods[]; - void Refresh(); + void Refresh() const; void EnableRefresh(bool enable); - inline constexpr FreeCAD_ConsoleMsgType getConsoleMsg(Base::LogStyle style); + constexpr FreeCAD_ConsoleMsgType getConsoleMsg(LogStyle style); private: // python exports goes here +++++++++++++++++++++++++++++++++++++++++++ @@ -879,7 +875,7 @@ public: ConsoleSingleton& operator=(ConsoleSingleton&&) = delete; private: - void postEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, + void postEvent(FreeCAD_ConsoleMsgType type, IntendedRecipient recipient, ContentType content, const std::string& notifiername, @@ -888,7 +884,7 @@ private: IntendedRecipient recipient, ContentType content, const std::string& notifiername, - const std::string& msg); + const std::string& msg) const; // singleton static void Destruct(); @@ -912,16 +908,15 @@ inline ConsoleSingleton& Console() return ConsoleSingleton::Instance(); } -inline constexpr ConsoleSingleton::FreeCAD_ConsoleMsgType -ConsoleSingleton::getConsoleMsg(Base::LogStyle style) +constexpr ConsoleSingleton::FreeCAD_ConsoleMsgType ConsoleSingleton::getConsoleMsg(LogStyle style) { - constexpr std::array msgTypes {// In order of Base::LogStyle - FreeCAD_ConsoleMsgType::MsgType_Wrn, - FreeCAD_ConsoleMsgType::MsgType_Txt, - FreeCAD_ConsoleMsgType::MsgType_Err, - FreeCAD_ConsoleMsgType::MsgType_Log, - FreeCAD_ConsoleMsgType::MsgType_Critical, - FreeCAD_ConsoleMsgType::MsgType_Notification}; + constexpr std::array msgTypes {// In order of LogStyle + MsgType_Wrn, + MsgType_Txt, + MsgType_Err, + MsgType_Log, + MsgType_Critical, + MsgType_Notification}; return msgTypes.at(static_cast(style)); } @@ -959,11 +954,11 @@ public: bool refresh; LogLevel(const char* tag, - bool print_tag = true, - int print_src = 0, - bool print_time = false, - bool add_eol = true, - bool refresh = false) + const bool print_tag = true, + const int print_src = 0, + const bool print_time = false, + const bool add_eol = true, + const bool refresh = false) : tag(tag) , lvl(*Console().GetLogLevel(tag)) , print_tag(print_tag) @@ -973,7 +968,7 @@ public: , refresh(refresh) {} - bool isEnabled(int lev) const + bool isEnabled(const int lev) const { return lev <= level(); } @@ -1005,94 +1000,95 @@ public: * @see UserTranslatedNotification */ template -inline void Base::ConsoleSingleton::Message(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Message(const char* pMsg, Args&&... args) { Message(std::string(""), pMsg, std::forward(args)...); } template -inline void -Base::ConsoleSingleton::Message(const std::string& notifier, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Message(const std::string& notifier, const char* pMsg, Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send(notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::Warning(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Warning(const char* pMsg, Args&&... args) { Warning(std::string(""), pMsg, std::forward(args)...); } template -inline void -Base::ConsoleSingleton::Warning(const std::string& notifier, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Warning(const std::string& notifier, const char* pMsg, Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send(notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::DeveloperWarning(const std::string& notifier, - const char* pMsg, - Args&&... args) +void Base::ConsoleSingleton::DeveloperWarning(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); -} - -template -inline void -Base::ConsoleSingleton::UserWarning(const std::string& notifier, const char* pMsg, Args&&... args) -{ - Send( + Send( notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::TranslatedUserWarning(const std::string& notifier, - const char* pMsg, - Args&&... args) +void Base::ConsoleSingleton::UserWarning(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send( + Send( notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::Error(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::TranslatedUserWarning(const std::string& notifier, + const char* pMsg, + Args&&... args) +{ + Send( + notifier, + pMsg, + std::forward(args)...); +} + +template +void Base::ConsoleSingleton::Error(const char* pMsg, Args&&... args) { Error(std::string(""), pMsg, std::forward(args)...); } template -inline void -Base::ConsoleSingleton::Error(const std::string& notifier, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Error(const std::string& notifier, const char* pMsg, Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send(notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::DeveloperError(const std::string& notifier, - const char* pMsg, - Args&&... args) +void Base::ConsoleSingleton::DeveloperError(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send( + notifier, + pMsg, + std::forward(args)...); } template -inline void Base::ConsoleSingleton::DestructorError(const std::string& notifier, - const char* pMsg, - Args&&... args) noexcept +void Base::ConsoleSingleton::DestructorError(const std::string& notifier, + const char* pMsg, + Args&&... args) noexcept { try { - Send(notifier, pMsg, std::forward(args)...); + Send( + notifier, + pMsg, + std::forward(args)...); } catch (...) { assert("An exception was thrown while attempting console output in a destructor" && false); @@ -1100,90 +1096,90 @@ inline void Base::ConsoleSingleton::DestructorError(const std::string& notifier, } template -inline void -Base::ConsoleSingleton::UserError(const std::string& notifier, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::UserError(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send( + Send( notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::TranslatedUserError(const std::string& notifier, - const char* pMsg, - Args&&... args) +void Base::ConsoleSingleton::TranslatedUserError(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send( + Send( notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::Critical(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Critical(const char* pMsg, Args&&... args) { Critical(std::string(""), pMsg, std::forward(args)...); } template -inline void -Base::ConsoleSingleton::Critical(const std::string& notifier, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Critical(const std::string& notifier, const char* pMsg, Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send(notifier, pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::UserNotification(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::UserNotification(const char* pMsg, Args&&... args) { UserNotification(std::string(""), pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::UserNotification(const std::string& notifier, - const char* pMsg, - Args&&... args) +void Base::ConsoleSingleton::UserNotification(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send( + notifier, + pMsg, + std::forward(args)...); } template -inline void Base::ConsoleSingleton::UserTranslatedNotification(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::UserTranslatedNotification(const char* pMsg, Args&&... args) { UserTranslatedNotification(std::string(""), pMsg, std::forward(args)...); } template -inline void Base::ConsoleSingleton::UserTranslatedNotification(const std::string& notifier, - const char* pMsg, - Args&&... args) +void Base::ConsoleSingleton::UserTranslatedNotification(const std::string& notifier, + const char* pMsg, + Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send( + notifier, + pMsg, + std::forward(args)...); } template -inline void Base::ConsoleSingleton::Log(const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Log(const char* pMsg, Args&&... args) { Log(std::string(""), pMsg, std::forward(args)...); } template -inline void -Base::ConsoleSingleton::Log(const std::string& notifier, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Log(const std::string& notifier, const char* pMsg, Args&&... args) { - Send(notifier, pMsg, std::forward(args)...); + Send(notifier, pMsg, std::forward(args)...); } template -inline void -Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, Args&&... args) +void Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, Args&&... args) { std::string format; try { @@ -1202,7 +1198,7 @@ Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, } else { - auto type = getConsoleMsg(category); + const auto type = getConsoleMsg(category); postEvent(type, recipient, contenttype, notifiername, format); } @@ -1211,7 +1207,7 @@ Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, template -inline void Base::ConsoleSingleton::Notify(const std::string& notifiername, const std::string& msg) +void Base::ConsoleSingleton::Notify(const std::string& notifiername, const std::string& msg) { notifyPrivate(category, recipient, contenttype, notifiername, msg); }