00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef XAPIAN_INCLUDED_OMASSERT_H
00027 #define XAPIAN_INCLUDED_OMASSERT_H
00028
00040 #define CompileTimeAssert(COND)\
00041 do {\
00042 typedef int xapian_compile_time_check_[(COND) ? 1 : -1];\
00043 } while (0)
00044
00045 #ifndef XAPIAN_DEBUG
00046
00047
00048 # ifdef XAPIAN_DEBUG_PARANOID
00049 # error XAPIAN_DEBUG_PARANOID defined without XAPIAN_DEBUG
00050 # endif
00051 #else
00052
00053 #include <xapian/error.h>
00054
00055 #include "utils.h"
00056
00057 #define XAPIAN_ASSERT_LOCATION__(LINE,MSG) __FILE__":"#LINE": "#MSG
00058 #define XAPIAN_ASSERT_LOCATION_(LINE,MSG) XAPIAN_ASSERT_LOCATION__(LINE,MSG)
00059 #define XAPIAN_ASSERT_LOCATION(MSG) XAPIAN_ASSERT_LOCATION_(__LINE__,MSG)
00060
00061
00062
00063
00064 #ifdef XAPIAN_DEBUG_PARANOID
00065 # define AssertParanoid(COND) Assert(COND)
00066 # define AssertRelParanoid(A,REL,B) AssertRel(A,REL,B)
00067 # define AssertEqParanoid(A,B) AssertEq(A,B)
00068 # define AssertEqDoubleParanoid(A,B) AssertEqDouble(A,B)
00069 #endif
00070
00075 #define Assert(COND) \
00076 do {\
00077 if (rare(!(COND)))\
00078 throw Xapian::AssertionError(XAPIAN_ASSERT_LOCATION(COND));\
00079 } while (0)
00080
00088 #define AssertRel(A,REL,B) \
00089 do {\
00090 if (rare(!((A) REL (B)))) {\
00091 std::string xapian_assertion_msg(XAPIAN_ASSERT_LOCATION(A REL B));\
00092 xapian_assertion_msg += " : values were ";\
00093 xapian_assertion_msg += om_tostring(A);\
00094 xapian_assertion_msg += " and ";\
00095 xapian_assertion_msg += om_tostring(B);\
00096 throw Xapian::AssertionError(xapian_assertion_msg);\
00097 }\
00098 } while (0)
00099
00107 #define AssertEq(A,B) AssertRel(A,==,B)
00108
00110 #define AssertEqDouble(A,B) \
00111 do {\
00112 using Xapian::Internal::within_DBL_EPSILON;\
00113 if (rare(within_DBL_EPSILON(A,B))) {\
00114 std::string xapian_assertion_msg(XAPIAN_ASSERT_LOCATION(within_DBL_EPSILON(A,B)));\
00115 xapian_assertion_msg += " : values were ";\
00116 xapian_assertion_msg += om_tostring(A);\
00117 xapian_assertion_msg += " and ";\
00118 xapian_assertion_msg += om_tostring(B);\
00119 throw Xapian::AssertionError(xapian_assertion_msg);\
00120 }\
00121 } while (0)
00122
00123 #endif
00124
00125
00126
00127
00128
00129
00130 #ifndef Assert
00131 # define Assert(COND) (void)0
00132 # define AssertRel(A,REL,B) (void)0
00133 # define AssertEq(A,B) (void)0
00134 # define AssertEqDouble(A,B) (void)0
00135 #endif
00136
00137 #ifndef AssertParanoid
00138 # define AssertParanoid(COND) (void)0
00139 # define AssertRelParanoid(A,REL,B) (void)0
00140 # define AssertEqParanoid(A,B) (void)0
00141 # define AssertEqDoubleParanoid(A,B) (void)0
00142 #endif
00143
00144 #endif // XAPIAN_INCLUDED_OMASSERT_H