MyGUI 3.4.2
MyGUI_Diagnostic.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_DIAGNOSTIC_H_
8#define MYGUI_DIAGNOSTIC_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Exception.h"
12#include "MyGUI_LogManager.h"
13#include <sstream>
14
15#define MYGUI_LOG_SECTION "Core"
16#define MYGUI_LOG_FILENAME "MyGUI.log"
17#define MYGUI_LOG(level, text) MYGUI_LOGGING(MYGUI_LOG_SECTION, level, text)
18
19#define MYGUI_BASE_EXCEPT(desc, src) throw MyGUI::Exception(desc, src, __FILE__, __LINE__)
20
21#define MYGUI_EXCEPT(dest) \
22do { \
23 MYGUI_LOG(Critical, dest); \
24 std::ostringstream stream; \
25 stream << dest << "\n"; \
26 MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
27} while (false)
28
29#define MYGUI_ASSERT(exp, dest) \
30do { \
31 if ( ! (exp) ) \
32 { \
33 MYGUI_LOG(Critical, dest); \
34 std::ostringstream stream; \
35 stream << dest << "\n"; \
36 MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
37 } \
38} while (false)
39
40#define MYGUI_ASSERT_RANGE(index, size, owner) MYGUI_ASSERT(index < size, owner << " : index number " << index << " out of range [" << size << "]")
41#define MYGUI_ASSERT_RANGE_AND_NONE(index, size, owner) MYGUI_ASSERT(index < size || index == MyGUI::ITEM_NONE, owner << " : index number " << index << " out of range [" << size << "]")
42#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner) MYGUI_ASSERT((index <= size) || (index == MyGUI::ITEM_NONE), owner << " : insert index number " << index << " out of range [" << size << "] or not ITEM_NONE")
43
44#if MYGUI_DEBUG_MODE == 1
45# define MYGUI_REGISTER_VALUE(map, value) \
46 do { \
47 MYGUI_LOG(Info, "Register value : '" << #value << "' = " << (int)value); \
48 map[#value] = value; \
49 } while (false)
50# define MYGUI_DEBUG_ASSERT(exp, dest) MYGUI_ASSERT(exp, dest)
51#else
52# define MYGUI_REGISTER_VALUE(map, value) map[#value] = value
53# define MYGUI_DEBUG_ASSERT(exp, dest) ((void)0)
54#endif
55
56#if __cplusplus >= 201402L
57# define MYGUI_OBSOLETE(text) [[deprecated(text)]]
58#else
59# if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
60# define MYGUI_OBSOLETE_START(text) __declspec(deprecated(text))
61# define MYGUI_OBSOLETE_END
62# elif MYGUI_COMPILER == MYGUI_COMPILER_GNUC
63# define MYGUI_OBSOLETE_START(text)
64# define MYGUI_OBSOLETE_END __attribute__((deprecated))
65# else
66# define MYGUI_OBSOLETE_START(text)
67# define MYGUI_OBSOLETE_END
68# endif
69#
70
71# define MYGUI_OBSOLETE(text) MYGUI_OBSOLETE_START(text)MYGUI_OBSOLETE_END
72#endif
73
74#endif // MYGUI_DIAGNOSTIC_H_