summaryrefslogtreecommitdiff
path: root/src/common/Debugging/Errors.h
diff options
context:
space:
mode:
authorKargatum <dowlandtop@yandex.com>2022-01-26 05:15:51 +0700
committerGitHub <noreply@github.com>2022-01-25 23:15:51 +0100
commite8f34b23096dd9d487edff6b08639a81e7336813 (patch)
tree431c9d858a53ffe610582ed8f3962886c51642c2 /src/common/Debugging/Errors.h
parent2fec54c4429a03b406b30bbce29c5b376ad04e31 (diff)
feat(Core/Common): add support fmt style for ASSERT and ABORT (#10355)
* feat(Core/Common): add support fmt style for ASSERT and ABORT * correct CheckCompactArrayMaskOverflow * 1 * Update src/server/game/Spells/Spell.cpp
Diffstat (limited to 'src/common/Debugging/Errors.h')
-rw-r--r--src/common/Debugging/Errors.h97
1 files changed, 55 insertions, 42 deletions
diff --git a/src/common/Debugging/Errors.h b/src/common/Debugging/Errors.h
index 0a109ca225..fec93713d2 100644
--- a/src/common/Debugging/Errors.h
+++ b/src/common/Debugging/Errors.h
@@ -1,55 +1,65 @@
/*
- * Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
- * Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation; either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ACORE_ERRORS_H_
#define _ACORE_ERRORS_H_
-#include "Define.h"
-#include <string>
+#include "StringFormat.h"
namespace Acore
{
- [[noreturn]] void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message);
- [[noreturn]] void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message, char const* format, ...) ATTR_PRINTF(6, 7);
-
- [[noreturn]] void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_PRINTF(4, 5);
-
- [[noreturn]] void Error(char const* file, int line, char const* function, char const* message);
-
- [[noreturn]] void Abort(char const* file, int line, char const* function);
-
- [[noreturn]] void Abort(char const* file, int line, char const* function, char const* message, ...);
-
- void Warning(char const* file, int line, char const* function, char const* message);
-
- [[noreturn]] void AbortHandler(int sigval);
+ // Default function
+ [[noreturn]] AC_COMMON_API void Assert(std::string_view file, uint32 line, std::string_view function, std::string_view debugInfo, std::string_view message, std::string_view fmtMessage = {});
+ [[noreturn]] AC_COMMON_API void Fatal(std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmtMessage = {});
+ [[noreturn]] AC_COMMON_API void Error(std::string_view file, uint32 line, std::string_view function, std::string_view message);
+ [[noreturn]] AC_COMMON_API void Abort(std::string_view file, uint32 line, std::string_view function, std::string_view fmtMessage = {});
+
+ template<typename... Args>
+ AC_COMMON_API inline void Assert(std::string_view file, uint32 line, std::string_view function, std::string_view debugInfo, std::string_view message, std::string_view fmt, Args&&... args)
+ {
+ Assert(file, line, function, debugInfo, message, StringFormatFmt(fmt, std::forward<Args>(args)...));
+ }
+
+ template<typename... Args>
+ AC_COMMON_API inline void Fatal(std::string_view file, uint32 line, std::string_view function, std::string_view message, std::string_view fmt, Args&&... args)
+ {
+ Fatal(file, line, function, message, StringFormatFmt(fmt, std::forward<Args>(args)...));
+ }
+
+ template<typename... Args>
+ AC_COMMON_API inline void Abort(std::string_view file, uint32 line, std::string_view function, std::string_view fmt, Args&&... args)
+ {
+ Abort(file, line, function, StringFormatFmt(fmt, std::forward<Args>(args)...));
+ }
+
+ AC_COMMON_API void Warning(std::string_view file, uint32 line, std::string_view function, std::string_view message);
+
+ [[noreturn]] AC_COMMON_API void AbortHandler(int sigval);
} // namespace Acore
-std::string GetDebugInfo();
+AC_COMMON_API std::string GetDebugInfo();
-#if AC_COMPILER == AC_COMPILER_MICROSOFT
-#define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127))
-#define ASSERT_END __pragma(warning(pop))
-#else
-#define ASSERT_BEGIN
-#define ASSERT_END
-#endif
-
-#if AC_PLATFORM == AC_PLATFORM_WINDOWS
-#define EXCEPTION_ASSERTION_FAILURE 0xC0000420L
-#endif
-
-#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, GetDebugInfo(), #cond, ##__VA_ARGS__); } while(0) ASSERT_END
-#define WPAssert_NODEBUGINFO(cond, ...) ASSERT_BEGIN do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, "", #cond, ##__VA_ARGS__); } while(0) ASSERT_END
-#define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) Acore::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END
-#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Acore::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
-#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Acore::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
-#define WPAbort() ASSERT_BEGIN do { Acore::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
-#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { Acore::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END
+#define WPAssert(cond, ...) do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, GetDebugInfo(), #cond, ##__VA_ARGS__); } while(0)
+#define WPAssert_NODEBUGINFO(cond) do { if (!(cond)) Acore::Assert(__FILE__, __LINE__, __FUNCTION__, "", #cond); } while(0)
+#define WPFatal(cond, ...) do { if (!(cond)) Acore::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0)
+#define WPError(cond, msg) do { if (!(cond)) Acore::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0)
+#define WPWarning(cond, msg) do { if (!(cond)) Acore::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0)
+#define WPAbort(...) do { Acore::Abort(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0)
#ifdef PERFORMANCE_PROFILING
#define ASSERT(cond, ...) ((void)0)
@@ -59,13 +69,16 @@ std::string GetDebugInfo();
#define ASSERT_NODEBUGINFO WPAssert_NODEBUGINFO
#endif
+#if AC_PLATFORM == AC_PLATFORM_WINDOWS
+#define EXCEPTION_ASSERTION_FAILURE 0xC0000420L
+#endif
+
#define ABORT WPAbort
-#define ABORT_MSG WPAbort_MSG
template <typename T>
-inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr)
+inline T* ASSERT_NOTNULL_IMPL(T* pointer, std::string_view expr)
{
- ASSERT(pointer, "%s", expr);
+ ASSERT(pointer, "{}", expr);
return pointer;
}