MyGUI 3.4.1
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// for debugging
16#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
17# include <crtdbg.h>
18#endif
19
20#define MYGUI_LOG_SECTION "Core"
21#define MYGUI_LOG_FILENAME "MyGUI.log"
22#define MYGUI_LOG(level, text) MYGUI_LOGGING(MYGUI_LOG_SECTION, level, text)
23
24#define MYGUI_BASE_EXCEPT(desc, src) throw MyGUI::Exception(desc, src, __FILE__, __LINE__)
25
26#define MYGUI_EXCEPT(dest) \
27do { \
28 MYGUI_LOG(Critical, dest); \
29 std::ostringstream stream; \
30 stream << dest << "\n"; \
31 MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
32} while (false)
33
34#define MYGUI_ASSERT(exp, dest) \
35do { \
36 if ( ! (exp) ) \
37 { \
38 MYGUI_LOG(Critical, dest); \
39 std::ostringstream stream; \
40 stream << dest << "\n"; \
41 MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
42 } \
43} while (false)
44
45#define MYGUI_ASSERT_RANGE(index, size, owner) MYGUI_ASSERT(index < size, owner << " : index number " << index << " out of range [" << size << "]")
46#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 << "]")
47#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")
48
49#if MYGUI_DEBUG_MODE == 1
50# define MYGUI_REGISTER_VALUE(map, value) \
51 do { \
52 MYGUI_LOG(Info, "Register value : '" << #value << "' = " << (int)value); \
53 map[#value] = value; \
54 } while (false)
55# define MYGUI_DEBUG_ASSERT(exp, dest) MYGUI_ASSERT(exp, dest)
56#else
57# define MYGUI_REGISTER_VALUE(map, value) map[#value] = value
58# define MYGUI_DEBUG_ASSERT(exp, dest) ((void)0)
59#endif
60
61
62#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
63# if MYGUI_COMP_VER < 1310 // VC++ 7.1
64# define MYGUI_OBSOLETE_START(text)
65# define MYGUI_OBSOLETE_END
66# else
67# define MYGUI_OBSOLETE_START(text) __declspec(deprecated(text))
68# define MYGUI_OBSOLETE_END
69# endif
70
71#elif MYGUI_COMPILER == MYGUI_COMPILER_GNUC
72# if MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX && MYGUI_COMP_VER < 310 // gcc 3.1
73# define MYGUI_OBSOLETE_START(text)
74# define MYGUI_OBSOLETE_END
75# else
76# define MYGUI_OBSOLETE_START(text)
77# define MYGUI_OBSOLETE_END __attribute__((deprecated))
78# endif
79
80#else
81# define MYGUI_OBSOLETE_START(text)
82# define MYGUI_OBSOLETE_END
83
84#endif
85
86#define MYGUI_OBSOLETE(text) MYGUI_OBSOLETE_START(text)MYGUI_OBSOLETE_END
87
88#endif // MYGUI_DIAGNOSTIC_H_