19 #ifndef LUNCHBOX_DEBUG_H
20 #define LUNCHBOX_DEBUG_H
22 #include <lunchbox/defines.h>
36 LUNCHBOX_API
void abort();
42 LUNCHBOX_API
void checkHeap();
50 LUNCHBOX_API std::ostream&
sysError( std::ostream& os );
58 LUNCHBOX_API std::ostream&
backtrace( std::ostream& os );
60 LUNCHBOX_API std::string demangleTypeID(
const char* mangled );
63 # pragma warning( disable: 4100 ) // VS Bug
66 template<
class T >
inline std::string
className(
const T*
object )
67 {
return demangleTypeID(
typeid( *object ).name( )); }
70 template<
class T >
inline std::string
className(
const T&
object )
71 {
return demangleTypeID(
typeid(
object ).name( )); }
74 # pragma warning( default: 4100 )
78 # ifdef LB_RELEASE_ASSERT
79 # define LBASSERT(x) \
82 LBERROR << "##### Assert: " << #x << " #####" << std::endl \
83 << lunchbox::forceFlush; \
84 lunchbox::checkHeap(); \
86 # define LBASSERTINFO(x, info) \
89 LBERROR << "##### Assert: " << #x << " [" << info << "] #####" \
90 << std::endl << lunchbox::forceFlush; \
91 lunchbox::checkHeap(); \
93 # define LBCHECK(x) { const bool eqOk = x; LBASSERTINFO( eqOk, #x ) }
96 # define LBASSERTINFO(x, info)
97 # define LBCHECK(x) { x; }
100 # define LBUNIMPLEMENTED { LBERROR << "Unimplemented code" << std::endl \
101 << lunchbox::forceFlush; }
102 # define LBUNREACHABLE { LBERROR << "Unreachable code" << std::endl \
103 << lunchbox::forceFlush; }
104 # define LBDONTCALL \
105 { LBERROR << "Code is not supposed to be called in this context" \
106 << std::endl << lunchbox::forceFlush; }
107 # define LBABORT( info ) { \
108 LBERROR << "##### Abort: " << info << " #####" << std::endl \
109 << lunchbox::forceFlush; }
113 # define LBASSERT(x) \
117 LBERROR << "Assert: " << #x << " "; \
120 lunchbox::checkHeap(); \
122 # define LBASSERTINFO(x, info) \
126 LBERROR << "Assert: " << #x << " [" << info << "] "; \
129 lunchbox::checkHeap(); \
132 # define LBUNIMPLEMENTED \
133 { LBERROR << "Unimplemented code in " << lunchbox::className( this ) \
136 # define LBUNREACHABLE \
137 { LBERROR << "Unreachable code in " << lunchbox::className( this ) \
140 # define LBDONTCALL \
141 { LBERROR << "Code is not supposed to be called in this context, type " \
142 << lunchbox::className( this ) << " " ; \
145 # define LBCHECK(x) { const bool eqOk = x; LBASSERTINFO( eqOk, #x ) }
146 # define LBABORT( info ) { \
147 LBERROR << "Abort: " << info; \
151 #define LBSAFECAST( to, in ) static_cast< to >( in ); \
152 LBASSERT( in == 0 || dynamic_cast< to >( static_cast< to >( in )))
154 #endif //LUNCHBOX_DEBUG_H