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