MyGUI  3.2.0
MyGUI_Diagnostic.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_DIAGNOSTIC_H__
24 #define __MYGUI_DIAGNOSTIC_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Exception.h"
28 #include "MyGUI_LogManager.h"
29 #include <sstream>
30 
31 // for debugging
32 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
33  #include <crtdbg.h>
34 #endif
35 
36 #define MYGUI_LOG_SECTION "Core"
37 #define MYGUI_LOG_FILENAME "MyGUI.log"
38 #define MYGUI_LOG(level, text) MYGUI_LOGGING(MYGUI_LOG_SECTION, level, text)
39 
40 #define MYGUI_BASE_EXCEPT(desc, src) throw MyGUI::Exception(desc, src, __FILE__, __LINE__);
41 
42 // MSVC specific: sets the breakpoint
43 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
44  #define MYGUI_DBG_BREAK _CrtDbgBreak();
45 #else
46  #define MYGUI_DBG_BREAK
47 #endif
48 
49 #define MYGUI_EXCEPT(dest) \
50 { \
51  MYGUI_LOG(Critical, dest); \
52  MYGUI_DBG_BREAK;\
53  std::ostringstream stream; \
54  stream << dest << "\n"; \
55  MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
56 }
57 
58 #define MYGUI_ASSERT(exp, dest) \
59 { \
60  if ( ! (exp) ) \
61  { \
62  MYGUI_LOG(Critical, dest); \
63  MYGUI_DBG_BREAK;\
64  std::ostringstream stream; \
65  stream << dest << "\n"; \
66  MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
67  } \
68 }
69 
70 #define MYGUI_ASSERT_RANGE(index, size, owner) MYGUI_ASSERT(index < size, owner << " : index number " << index << " out of range [" << size << "]");
71 #define MYGUI_ASSERT_RANGE_AND_NONE(index, size, owner) MYGUI_ASSERT(index < size || index == ITEM_NONE, owner << " : index number " << index << " out of range [" << size << "]");
72 #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");
73 
74 #if MYGUI_DEBUG_MODE == 1
75  #define MYGUI_REGISTER_VALUE(map, value) \
76  { \
77  MYGUI_LOG(Info, "Register value : '" << #value << "' = " << (int)value); \
78  map[#value] = value; \
79  }
80  #define MYGUI_DEBUG_ASSERT(exp, dest) MYGUI_ASSERT(exp, dest)
81 #else
82  #define MYGUI_REGISTER_VALUE(map, value) map[#value] = value;
83  #define MYGUI_DEBUG_ASSERT(exp, dest) ((void)0)
84 #endif
85 
86 
87 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
88  #if MYGUI_COMP_VER < 1310 // VC++ 7.1
89  #define MYGUI_OBSOLETE_START(text)
90  #define MYGUI_OBSOLETE_END
91  #else
92  #define MYGUI_OBSOLETE_START(text) __declspec(deprecated(text))
93  #define MYGUI_OBSOLETE_END
94  #endif
95 
96 #elif MYGUI_COMPILER == MYGUI_COMPILER_GNUC
97  #if MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX && MYGUI_COMP_VER < 310 // gcc 3.1
98  #define MYGUI_OBSOLETE_START(text)
99  #define MYGUI_OBSOLETE_END
100  #else
101  #define MYGUI_OBSOLETE_START(text)
102  #define MYGUI_OBSOLETE_END __attribute__((deprecated))
103  #endif
104 
105 #else
106  #define MYGUI_OBSOLETE_START(text)
107  #define MYGUI_OBSOLETE_END
108 
109 #endif
110 
111 #define MYGUI_OBSOLETE(text) MYGUI_OBSOLETE_START(text)MYGUI_OBSOLETE_END
112 
113 #endif // __MYGUI_DIAGNOSTIC_H__