TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Errors.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITYCORE_ERRORS_H
20 #define TRINITYCORE_ERRORS_H
21 
22 #include "Define.h"
23 
24 namespace Trinity
25 {
26  DECLSPEC_NORETURN TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
27  DECLSPEC_NORETURN TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...) ATTR_NORETURN ATTR_PRINTF(5, 6);
28 
29  DECLSPEC_NORETURN TC_COMMON_API void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_NORETURN ATTR_PRINTF(4, 5);
30 
31  DECLSPEC_NORETURN TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
32 
33  DECLSPEC_NORETURN TC_COMMON_API void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
34 
35  TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message);
36 
37  DECLSPEC_NORETURN TC_COMMON_API void AbortHandler(int sigval) ATTR_NORETURN;
38 
39 } // namespace Trinity
40 
41 #if COMPILER == COMPILER_MICROSOFT
42 #define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127))
43 #define ASSERT_END __pragma(warning(pop))
44 #else
45 #define ASSERT_BEGIN
46 #define ASSERT_END
47 #endif
48 
49 #define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, ##__VA_ARGS__); } while(0) ASSERT_END
50 #define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END
51 #define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
52 #define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
53 #define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
54 
55 #define ASSERT WPAssert
56 #define ABORT WPAbort
57 
58 template <typename T> inline T* ASSERT_NOTNULL(T* pointer)
59 {
60  ASSERT(pointer);
61  return pointer;
62 }
63 
64 #endif
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963
T * ASSERT_NOTNULL(T *pointer)
Definition: Errors.h:58
void Assert(char const *file, int line, char const *function, char const *message)
Definition: Errors.cpp:39
void Abort(char const *file, int line, char const *function)
Definition: Errors.cpp:91
#define ATTR_NORETURN
COREDEBUG.
Definition: Define.h:88
#define ATTR_PRINTF(F, V)
Definition: Define.h:89
void Fatal(char const *file, int line, char const *function, char const *message,...)
Definition: Errors.cpp:62
void AbortHandler(int)
Definition: Errors.cpp:99
#define TC_COMMON_API
Definition: Define.h:116
#define DECLSPEC_NORETURN
Definition: Define.h:69
#define ASSERT
Definition: Errors.h:55
Definition: Common.h:172
#define const
Definition: zconf.h:217
void Warning(char const *file, int line, char const *function, char const *message)
Definition: Errors.cpp:85
void Error(char const *file, int line, char const *function, char const *message)
Definition: Errors.cpp:77