00001 #pragma ident "$Id: DebugUtils.hpp 2938 2011-10-23 19:39:11Z yanweignss $"
00002
00008 #ifndef GPSTK_DEBUGUTILS_HPP
00009 #define GPSTK_DEBUGUTILS_HPP
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <string>
00034 #include "Exception.hpp"
00035
00036 namespace gpstk
00037 {
00040 NEW_EXCEPTION_CLASS(AssertFailedException, Exception);
00041
00045 class DebugUtils
00046 {
00047 public:
00048 static void assertion(const char* cond, const char* file, int line);
00049
00050 static void nullPointer(const char* ptr, const char* file, int line);
00051
00052 protected:
00053 static std::string what(const char* msg, const char* file, int line);
00054
00055 private:
00056 DebugUtils(){}
00057
00058 };
00059
00060
00061
00062
00063
00064 #if defined(_DEBUG)
00065 #define GPSTK_ASSERT_DBG(cond) \
00066 if (!(cond)) DebugUtils::assertion(#cond, __FILE__, __LINE__); else (void) 0
00067 #else
00068 #define GPSTK_ASSERT_DBG(cond)
00069 #endif
00070
00071
00072 #define GPSTK_ASSERT(cond) \
00073 if (!(cond)) DebugUtils::assertion(#cond, __FILE__, __LINE__); else (void) 0
00074
00075
00076 #define GPSTK_CHECK_PTR(ptr) \
00077 if (!(ptr)) DebugUtils::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0
00078
00079
00080 #if defined(_DEBUG)
00081 # define GPSTK_STDOUT_DBG(outstr) \
00082 std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
00083 #else
00084 # define GPSTK_STDOUT_DBG(outstr)
00085 #endif
00086
00087
00088 #if defined(_DEBUG)
00089 # define GPSTK_STDERR_DBG(outstr) \
00090 std::cerr << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
00091 #else
00092 # define GPSTK_STDERR_DBG(outstr)
00093 #endif
00094
00095
00096 }
00097
00098
00099 #endif //GPSTK_DEBUGUTILS_HPP
00100