MyGUI  3.2.1
MyGUI_Diagnostic.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_DIAGNOSTIC_H__
00008 #define __MYGUI_DIAGNOSTIC_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 #include "MyGUI_Exception.h"
00012 #include "MyGUI_LogManager.h"
00013 #include <sstream>
00014 
00015 // for debugging
00016 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
00017 #   include <crtdbg.h>
00018 #endif
00019 
00020 #define MYGUI_LOG_SECTION "Core"
00021 #define MYGUI_LOG_FILENAME "MyGUI.log"
00022 #define MYGUI_LOG(level, text) MYGUI_LOGGING(MYGUI_LOG_SECTION, level, text)
00023 
00024 #define MYGUI_BASE_EXCEPT(desc, src)     throw MyGUI::Exception(desc, src, __FILE__, __LINE__);
00025 
00026 // MSVC specific: sets the breakpoint
00027 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
00028 #   define MYGUI_DBG_BREAK _CrtDbgBreak();
00029 #else
00030 #   define MYGUI_DBG_BREAK
00031 #endif
00032 
00033 #define MYGUI_EXCEPT(dest) \
00034 { \
00035     MYGUI_LOG(Critical, dest); \
00036     MYGUI_DBG_BREAK;\
00037     std::ostringstream stream; \
00038     stream << dest << "\n"; \
00039     MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
00040 }
00041 
00042 #define MYGUI_ASSERT(exp, dest) \
00043 { \
00044     if ( ! (exp) ) \
00045     { \
00046         MYGUI_LOG(Critical, dest); \
00047         MYGUI_DBG_BREAK;\
00048         std::ostringstream stream; \
00049         stream << dest << "\n"; \
00050         MYGUI_BASE_EXCEPT(stream.str().c_str(), "MyGUI"); \
00051     } \
00052 }
00053 
00054 #define MYGUI_ASSERT_RANGE(index, size, owner) MYGUI_ASSERT(index < size, owner << " : index number " << index << " out of range [" << size << "]");
00055 #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 << "]");
00056 #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");
00057 
00058 #if MYGUI_DEBUG_MODE == 1
00059 #   define MYGUI_REGISTER_VALUE(map, value) \
00060     { \
00061         MYGUI_LOG(Info, "Register value : '" << #value << "' = " << (int)value); \
00062         map[#value] = value; \
00063     }
00064 #   define MYGUI_DEBUG_ASSERT(exp, dest) MYGUI_ASSERT(exp, dest)
00065 #else
00066 #   define MYGUI_REGISTER_VALUE(map, value) map[#value] = value;
00067 #   define MYGUI_DEBUG_ASSERT(exp, dest) ((void)0)
00068 #endif
00069 
00070 
00071 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
00072 #   if MYGUI_COMP_VER < 1310 // VC++ 7.1
00073 #       define MYGUI_OBSOLETE_START(text)
00074 #       define MYGUI_OBSOLETE_END
00075 #   else
00076 #       define MYGUI_OBSOLETE_START(text) __declspec(deprecated(text))
00077 #       define MYGUI_OBSOLETE_END
00078 #   endif
00079 
00080 #elif MYGUI_COMPILER == MYGUI_COMPILER_GNUC
00081 #   if MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX && MYGUI_COMP_VER < 310 // gcc 3.1
00082 #       define MYGUI_OBSOLETE_START(text)
00083 #       define MYGUI_OBSOLETE_END
00084 #   else
00085 #       define MYGUI_OBSOLETE_START(text)
00086 #       define MYGUI_OBSOLETE_END __attribute__((deprecated))
00087 #   endif
00088 
00089 #else
00090 #   define MYGUI_OBSOLETE_START(text)
00091 #   define MYGUI_OBSOLETE_END
00092 
00093 #endif
00094 
00095 #define MYGUI_OBSOLETE(text)  MYGUI_OBSOLETE_START(text)MYGUI_OBSOLETE_END
00096 
00097 #endif // __MYGUI_DIAGNOSTIC_H__