popassert.h

Go to the documentation of this file.
00001 
00006 #ifndef POPASSERT_H
00007 #define POPASSERT_H
00008 
00009 
00010   #ifdef NDEBUG // ASSERTIONS DISABLED
00011 
00012     #define POP_ASSERT(test, cause)
00013     #define POP_ILLEGAL(cause)
00014 
00015   #else         // ASSERTIONS ENABLED
00016 
00017     #ifdef WIN32         // Under Windows
00018 
00019       #define POP_ASSERT(test, cause)
00020       #define POP_ILLEGAL(cause)
00021 
00022     #elif defined(LINUX) // Under Linux
00023 
00024       #include <sstream>
00025       #include <execinfo.h>
00026 
00027       #define GET_BACKTRACE(stream)                                                 \
00028       {                                                                             \
00029         const int max_stack_size = 1024;                                            \
00030         void *buffer[max_stack_size];                                               \
00031         char **symbols;                                                             \
00032                                                                                     \
00033         int nb_symbols = backtrace(buffer, max_stack_size);                         \
00034         stream << "STACK TRACE (" << nb_symbols - 1 << " frames)" << std::endl;     \
00035                                                                                     \
00036         symbols = backtrace_symbols(buffer, nb_symbols);                            \
00037                                                                                     \
00038         for (int i = 1; i < nb_symbols; ++i)                                        \
00039           stream << symbols[i] << std::endl;                                        \
00040                                                                                     \
00041         free(symbols);                                                              \
00042       }
00043 
00044       #define POP_ASSERT(test, cause)                                               \
00045       {                                                                             \
00046         if (!(test))                                                                \
00047         {                                                                           \
00048           std::ostringstream o;                                                     \
00049                                                                                     \
00050           o << "Xdialog --cr-wrap --wrap --left --default-no --title "              \
00051             << "\"ASSERTION FAILED\" --yesno "                                      \
00052             << "\"FAILED TEST: "  << #test                << std::endl              \
00053             << "FILE NAME: "      << __FILE__             << std::endl              \
00054             << "LINE NUMBER: "    << __LINE__             << std::endl              \
00055             << "FUNCTION: "       << __PRETTY_FUNCTION__  << std::endl              \
00056             << "REASON: "         << cause                << std::endl;             \
00057           GET_BACKTRACE(o);                                                         \
00058           o << "Do you want to cancel the current execution?\""                     \
00059             << " 0 0" << std::endl;                                                 \
00060                                                                                     \
00061           if (!system(o.str().c_str()))                                             \
00062             abort();                                                                \
00063         }                                                                           \
00064       }
00065 
00066       #define POP_ILLEGAL(cause)                                                    \
00067       {                                                                             \
00068         std::ostringstream o;                                                       \
00069                                                                                     \
00070         o << "Xdialog --cr-wrap --wrap --left --default-no --title "                \
00071           << "\"ILLEGAL called\" --yesno "                                          \
00072           << "\"FILE NAME: "    << __FILE__             << std::endl                \
00073           << "LINE NUMBER: "    << __LINE__             << std::endl                \
00074           << "FUNCTION: "       << __PRETTY_FUNCTION__  << std::endl                \
00075           << "REASON: "         << cause                << std::endl;               \
00076         GET_BACKTRACE(o);                                                           \
00077         o << "Do you want to cancel the current execution?\""                       \
00078           << " 0 0" << std::endl;                                                   \
00079                                                                                     \
00080         if (!system(o.str().c_str()))                                               \
00081           abort();                                                                  \
00082       }
00083 
00084 
00085 
00086     #else // Not Windows or Linux
00087 
00088       #error "OS not supported"
00089 
00090     #endif
00091 
00092   #endif  // DEBUG
00093 
00094 #endif  // POPASSERT_H
00095 
00096 // Other macros to define: WARNING, INFO, DBGOP, PRECONDITION, POSTCONDITION

Generated on Fri Dec 5 03:20:33 2008 for Mathematical Ray-tracer by  doxygen 1.5.4