ReportHandler.hpp

00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #ifndef STK_UTIL_ENVIRONMENT_REPORTHANDLER_HPP
00010 #define STK_UTIL_ENVIRONMENT_REPORTHANDLER_HPP
00011 
00012 #include <iosfwd>
00013 #include <string>
00014 
00015 namespace stk {
00016 
00021 
00027 typedef void (*REH)(const char *message, int type);
00028 
00041 void default_report_handler(const char *message, int type);
00042 
00051 REH set_report_handler(REH reh);
00052 
00062 void report(const char *message, int type);
00063 
00072 std::string source_relative_path(const std::string &path);
00073 
00077 
00078 } // namespace stk
00079 
00084 
00092 #define XSTR_TRACE_LINE(s) STR_TRACE_LINE(s)
00093 #define STR_TRACE_LINE(s) #s
00094 
00095 #ifdef __PRETTY_FUNCTION__
00096 
00097 #define COUT_TRACE  " Function::Line="<<__PRETTY_FUNCTION__<<":"<<__LINE__
00098 #define STR_TRACE   (std::string(__FILE__) +  ":" + XSTR_TRACE_LINE(__LINE__) + " in " + std::string(__PRETTY_FUNCTION__))
00099 
00100 #else
00101 
00102 #define COUT_TRACE  " File::Line="<<__FILE__<<":"<<__LINE__
00103 #define STR_TRACE   (std::string(__FILE__) +  ":" + XSTR_TRACE_LINE(__LINE__))
00104 
00105 #endif
00106 
00107 #define StackTrace std::string(std::string("  exception thrown from ") + stk::source_relative_path(STR_TRACE))
00108 
00109 #ifdef NDEBUG
00110 #  define ThrowAssert(expr)   ((void) (0))
00111 #  define ThrowAssertMsg(expr,message)  ((void) (0))
00112 #else
00113 #  define ThrowAssert(expr)   ((expr) ? (void) 0 : throw std::runtime_error(std::string("Assertion ") + #expr + " failed\n" + StackTrace))
00114 #  define ThrowAssertMsg(expr,message)  ((expr) ? (void) 0 : throw std::runtime_error(std::string(message) + ", assertion " + #expr + " failed\n" + StackTrace))
00115 #endif
00116 
00117 #define ThrowRequire(expr)    ((expr) ? (void) 0 : throw std::runtime_error(std::string("Requirement ") + #expr + " failed\n" + StackTrace))
00118 #define ThrowRequireMsg(expr,message) ((expr) ? (void) 0 : throw std::runtime_error(std::string(message) + ", requirement " + #expr + " failed\n" + StackTrace))
00119 
00123 
00124 #endif // STK_UTIL_ENVIRONMENT_REPORTHANDLER_HPP
Generated on Wed Apr 13 10:05:49 2011 for Sierra Toolkit by  doxygen 1.6.3