19 #ifndef LUNCHBOX_DEBUG_H 20 #define LUNCHBOX_DEBUG_H 36 LUNCHBOX_API
void abort(
bool dumpThreads =
false );
42 LUNCHBOX_API
void checkHeap();
50 LUNCHBOX_API std::ostream&
sysError( std::ostream& os );
63 LUNCHBOX_API std::string
backtrace(
const size_t skipFrames );
66 LUNCHBOX_API std::ostream&
backtrace( std::ostream& os );
68 LUNCHBOX_API std::string demangleTypeID(
const char* mangled );
71 # pragma warning( disable: 4100 ) // VS Bug 74 template<
class T >
inline std::string
className(
const T&
object )
75 {
return demangleTypeID(
typeid(
object ).name( )); }
78 template<
class T >
inline std::string
className(
const T*
object )
82 # pragma warning( default: 4100 ) 94 template<
class T >
inline std::string
format(
const T* data,
const size_t num )
96 std::ostringstream os;
97 os << num <<
" " <<
className( data ) <<
" @ " << std::hex
98 << (
const void*)data <<
": 0x";
99 for(
size_t i = 0; i < num; ++i )
102 os <<
" " << std::endl;
103 os <<
' ' << data[i];
108 template<>
inline std::string
format(
const uint8_t* data,
const size_t num )
110 std::ostringstream os;
111 os << num <<
" bytes @ " << std::hex << (
const void*)data <<
": 0x";
113 for(
size_t i = 0; i < num; ++i )
116 os <<
" " << std::endl;
117 else if( (i % 8) == 0 )
119 os <<
' ' << std::setw(2) << int( data[i] );
124 template<>
inline std::string
format(
const void* data,
const size_t num )
125 {
return format( reinterpret_cast< const uint8_t* >( data ), num ); }
127 template<
class T >
inline std::string
format(
const std::vector< T >& data )
128 {
return format< T >( &data[0], data.size( )); }
133 # ifdef LB_RELEASE_ASSERT 134 # define LBASSERT(x) \ 137 LBERROR << "##### Assert: " << #x << " #####" << std::endl \ 138 << lunchbox::forceFlush; \ 139 lunchbox::checkHeap(); \ 141 # define LBASSERTINFO(x, info) \ 144 LBERROR << "##### Assert: " << #x << " [" << info << "] #####" \ 145 << std::endl << lunchbox::forceFlush; \ 146 lunchbox::checkHeap(); \ 148 # define LBCHECK(x) { const bool eqOk = x; LBASSERTINFO( eqOk, #x ) } 151 # define LBASSERTINFO(x, info) 152 # define LBCHECK(x) { x; } 155 # define LBUNIMPLEMENTED { LBERROR << "Unimplemented code in " << __FILE__ \ 156 << ":" << __LINE__ << std::endl \ 157 << lunchbox::forceFlush; } 158 # define LBUNREACHABLE { LBERROR << "Unreachable code in " << __FILE__ \ 159 << ":" << __LINE__ << std::endl \ 160 << lunchbox::forceFlush; } 161 # define LBDONTCALL \ 162 { LBERROR << "Code is not supposed to be called in this context" \ 163 << std::endl << lunchbox::forceFlush; } 164 # define LBABORT( info ) { \ 165 LBERROR << "##### Abort: " << info << " #####" << std::endl \ 166 << lunchbox::forceFlush; } 170 # define LBASSERT(x) \ 174 LBERROR << "Assert: " << #x << " "; \ 177 lunchbox::checkHeap(); \ 179 # define LBASSERTINFO(x, info) \ 183 LBERROR << "Assert: " << #x << " [" << info << "] "; \ 186 lunchbox::checkHeap(); \ 189 # define LBUNIMPLEMENTED \ 190 { LBERROR << "Unimplemented code in " << __FILE__ << ":" << __LINE__ \ 191 << " " << lunchbox::className( *this ); \ 193 # define LBUNREACHABLE \ 194 { LBERROR << "Unreachable code in " << __FILE__ << ":" << __LINE__ \ 195 << " " << lunchbox::className( *this ); \ 197 # define LBDONTCALL \ 198 { LBERROR << "Code is not supposed to be called in this context, type " \ 199 << lunchbox::className( *this ); \ 202 # define LBCHECK(x) { const bool eqOk = x; LBASSERTINFO( eqOk, #x ) } 203 # define LBABORT( info ) { \ 204 LBERROR << "Abort: " << info; \ 208 #define LBSAFECAST( to, in ) static_cast< to >( in ); \ 209 LBASSERT( in == 0 || dynamic_cast< to >( static_cast< to >( in ))) 211 #endif //LUNCHBOX_DEBUG_H std::string className(const T &object)
Print the RTTI name of the given class.
std::ostream & sysError(std::ostream &os)
Print a textual description of the current system error.
std::string format(const T *data, const size_t num)
Format the given array in a human-readable form.
Includes compile-time defines of Lunchbox.
std::string backtrace(const size_t skipFrames)
Get the current call stack.
Abstraction layer and common utilities for multi-threaded programming.
This file contains logging classes.