debug.h

00001 
00002 /* Copyright (c) 2007-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQBASE_DEBUG_H
00019 #define EQBASE_DEBUG_H
00020 
00021 #include <eq/base/defines.h>
00022 #include <eq/base/log.h>
00023 
00024 // assertions
00025 // #define EQ_RELEASE_ASSERT
00026 
00027 namespace eq
00028 {
00029 namespace base
00030 {
00032 EQ_EXPORT void abort();
00033 
00035 EQ_EXPORT void checkHeap();
00036 }
00037 }
00038 
00039 #ifdef NDEBUG
00040 
00041 #  ifdef EQ_RELEASE_ASSERT
00042 #    define EQASSERT(x)                                                 \
00043     {                                                                   \
00044         if( !(x) )                                                      \
00045             EQERROR << "##### Assert: " << #x << " #####" << std::endl  \
00046                     << eq::base::forceFlush;                            \
00047         eq::base::checkHeap();                                          \
00048     }
00049 #    define EQASSERTINFO(x, info)                                       \
00050     {                                                                   \
00051         if( !(x) )                                                      \
00052             EQERROR << "##### Assert: " << #x << " [" << info << "] #####" \
00053                     << std::endl << eq::base::forceFlush;               \
00054         eq::base::checkHeap();                                          \
00055     }
00056 #    define EQCHECK(x) { const bool eqResult = x; EQASSERTINFO( eqResult, #x ) }
00057 #  else
00058 #    define EQASSERT(x)
00059 #    define EQASSERTINFO(x, info)
00060 #    define EQCHECK(x) { x; }
00061 #  endif
00062 
00063 #  define EQUNIMPLEMENTED { EQERROR << "Unimplemented code" << std::endl \
00064                                     << eq::base::forceFlush; }
00065 #  define EQUNREACHABLE   { EQERROR << "Unreachable code" << std::endl  \
00066                                     << eq::base::forceFlush; }
00067 #  define EQDONTCALL                                                    \
00068     { EQERROR << "Code is not supposed to be called in this context"    \
00069               << std::endl << eq::base::forceFlush; }
00070 #  define EQABORT( info ) {                                         \
00071         EQERROR << "##### Abort: " << info << " #####" << std::endl \
00072                 << eq::base::forceFlush; }
00073 
00074 #else // NDEBUG
00075 
00076 #  define EQASSERT(x)                                                   \
00077     {                                                                   \
00078         if( !(x) )                                                      \
00079         {                                                               \
00080             EQERROR << "Assert: " << #x << std::endl << eq::base::forceFlush; \
00081             eq::base::abort();                                     \
00082         }                                                               \
00083         eq::base::checkHeap();                                          \
00084     } 
00085 #  define EQASSERTINFO(x, info)                                         \
00086     {                                                                   \
00087         if( !(x) )                                                      \
00088         {                                                               \
00089             EQERROR << "Assert: " << #x << " [" << info << "]" << std::endl \
00090                     << eq::base::forceFlush;                            \
00091             eq::base::abort();                                          \
00092         }                                                               \
00093         eq::base::checkHeap();                                          \
00094     }
00095 
00096 #  define EQUNIMPLEMENTED                                               \
00097     { EQERROR << "Unimplemented code in " << typeid(*this).name()       \
00098               << std::endl << eq::base::forceFlush;                     \
00099         eq::base::abort(); }
00100 #  define EQUNREACHABLE                                          \
00101     { EQERROR << "Unreachable code in " << typeid(*this).name()  \
00102               << std::endl << eq::base::forceFlush;              \
00103         eq::base::abort(); }
00104 #  define EQDONTCALL                                                    \
00105     { EQERROR << "Code is not supposed to be called in this context, type " \
00106               << typeid(*this).name() << std::endl << eq::base::forceFlush; \
00107         eq::base::abort(); }
00108 
00109 #  define EQCHECK(x) { const bool eqResult = x; EQASSERTINFO( eqResult, #x ) }
00110 #  define EQABORT( info ) {                                             \
00111         EQERROR << "Abort: " << info << std::endl << eq::base::forceFlush; \
00112         eq::base::abort(); }
00113 
00114 #endif // NDEBUG
00115 
00116 #define EQSAFECAST( to, in ) static_cast< to >( in );   \
00117     EQASSERT( in == 0 || dynamic_cast< to >( static_cast< to >( in )))
00118 
00119 
00120 #endif //EQBASE_DEBUG_H
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8