00001 #ifndef SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_
00002 #define SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #include "SimTKcommon/internal/common.h"
00085 #include "SimTKcommon/internal/Exception.h"
00086
00087 #include <string>
00088 #include <iostream>
00089 #include <exception>
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 #define SimTK_INDEXCHECK_ALWAYS(lb,ix,ub,where) \
00103 do{if(!((lb)<=(ix)&&(ix)<(ub)))SimTK_THROW5(SimTK::Exception::IndexOutOfRange, \
00104 #ix,(lb),(ix),(ub),(where));}while(false)
00105
00106
00107 #define SimTK_SIZECHECK_ALWAYS(sz,maxsz,where) \
00108 do{if(!(0<=(sz)&&(sz)<=(maxsz)))SimTK_THROW4(SimTK::Exception::SizeOutOfRange, \
00109 #sz,(sz),(maxsz),(where));}while(false)
00110
00111
00112 #define SimTK_SIZECHECK_NONNEG_ALWAYS(sz,where) \
00113 do{if((sz)<0)SimTK_THROW3(SimTK::Exception::SizeWasNegative, \
00114 #sz,(sz),(where));}while(false)
00115
00116
00117
00118 #define SimTK_VALUECHECK_ALWAYS(lb,val,ub,valName,where) \
00119 do{if(!(lb)<=(val)&&(val)<=(ub)))SimTK_THROW5(SimTK::Exception::ValueOutOfRange, \
00120 (valName),(lb),(val),(ub),(where));}while(false)
00121
00122
00123 #define SimTK_VALUECHECK_NONNEG_ALWAYS(val,valName,where) \
00124 do{if((val)<0)SimTK_THROW3(SimTK::Exception::ValueWasNegative, \
00125 (valName),(val),(where));}while(false)
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 #define SimTK_APIARGCHECK_ALWAYS(cond,className,methodName,msg) \
00136 do{if(!(cond))SimTK_THROW3(SimTK::Exception::APIArgcheckFailed, \
00137 (className),(methodName),(msg)); \
00138 }while(false)
00139 #define SimTK_APIARGCHECK1_ALWAYS(cond,className,methodName,fmt,a1) \
00140 do{if(!(cond))SimTK_THROW4(SimTK::Exception::APIArgcheckFailed, \
00141 (className),(methodName),(fmt),(a1)); \
00142 }while(false)
00143 #define SimTK_APIARGCHECK2_ALWAYS(cond,className,methodName,fmt,a1,a2) \
00144 do{if(!(cond))SimTK_THROW5(SimTK::Exception::APIArgcheckFailed, \
00145 (className),(methodName),(fmt),(a1),(a2)); \
00146 }while(false)
00147 #define SimTK_APIARGCHECK3_ALWAYS(cond,className,methodName,fmt,a1,a2,a3) \
00148 do{if(!(cond))SimTK_THROW6(SimTK::Exception::APIArgcheckFailed, \
00149 (className),(methodName),(fmt),(a1),(a2),(a3)); \
00150 }while(false)
00151 #define SimTK_APIARGCHECK4_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4) \
00152 do{if(!(cond))SimTK_THROW7(SimTK::Exception::APIArgcheckFailed, \
00153 (className),(methodName),(fmt),(a1),(a2),(a3),(a4)); \
00154 }while(false)
00155 #define SimTK_APIARGCHECK5_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4,a5) \
00156 do{if(!(cond))SimTK_THROW8(SimTK::Exception::APIArgcheckFailed, \
00157 (className),(methodName),(fmt),(a1),(a2),(a3),(a4),(a5)); \
00158 }while(false)
00159
00160
00161 #if defined(NDEBUG) && !defined(SimTK_KEEP_RANGECHECK)
00162 #define SimTK_INDEXCHECK(lb,ix,ub,where)
00163 #define SimTK_SIZECHECK(sz,maxsz,where)
00164 #define SimTK_SIZECHECK_NONNEG(sz,where)
00165 #define SimTK_VALUECHECK(lb,val,ub,valName,where)
00166 #define SimTK_VALUECHECK_NONNEG(val,valName,where)
00167 #else
00168 #define SimTK_INDEXCHECK(lb,ix,ub,where) SimTK_INDEXCHECK_ALWAYS(lb,ix,ub,where)
00169 #define SimTK_SIZECHECK(sz,maxsz,where) SimTK_SIZECHECK_ALWAYS(sz,maxsz,where)
00170 #define SimTK_SIZECHECK_NONNEG(sz,where) SimTK_SIZECHECK_NONNEG_ALWAYS(sz,where)
00171 #define SimTK_VALUECHECK(lb,val,ub,valName,where) SimTK_VALUECHECK_ALWAYS(lb,val,ub,valName,where)
00172 #define SimTK_VALUECHECK_NONNEG(val,valName,where) SimTK_VALUECHECK_NONNEG_ALWAYS(val,valName,where)
00173 #endif
00174
00175 #if defined(NDEBUG) && !defined(SimTK_KEEP_APIARGCHECK)
00176 #define SimTK_APIARGCHECK(cond,className,methodName,msg)
00177 #define SimTK_APIARGCHECK1(cond,className,methodName,fmt,a1)
00178 #define SimTK_APIARGCHECK2(cond,className,methodName,fmt,a1,a2)
00179 #define SimTK_APIARGCHECK3(cond,className,methodName,fmt,a1,a2,a3)
00180 #define SimTK_APIARGCHECK4(cond,className,methodName,fmt,a1,a2,a3,a4)
00181 #define SimTK_APIARGCHECK5(cond,className,methodName,fmt,a1,a2,a3,a4,a5)
00182 #else
00183 #define SimTK_APIARGCHECK(cond,className,methodName,msg) \
00184 SimTK_APIARGCHECK_ALWAYS(cond,className,methodName,msg)
00185 #define SimTK_APIARGCHECK1(cond,className,methodName,fmt,a1) \
00186 SimTK_APIARGCHECK1_ALWAYS(cond,className,methodName,fmt,a1)
00187 #define SimTK_APIARGCHECK2(cond,className,methodName,fmt,a1,a2) \
00188 SimTK_APIARGCHECK2_ALWAYS(cond,className,methodName,fmt,a1,a2)
00189 #define SimTK_APIARGCHECK3(cond,className,methodName,fmt,a1,a2,a3) \
00190 SimTK_APIARGCHECK3_ALWAYS(cond,className,methodName,fmt,a1,a2,a3)
00191 #define SimTK_APIARGCHECK4(cond,className,methodName,fmt,a1,a2,a3,a4) \
00192 SimTK_APIARGCHECK4_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4)
00193 #define SimTK_APIARGCHECK5(cond,className,methodName,fmt,a1,a2,a3,a4,a5) \
00194 SimTK_APIARGCHECK5_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4,a5)
00195 #endif
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED_ALWAYS(cond,objType,objName,methodNm) \
00208 do{if(!(cond)) SimTK_THROW3(SimTK::Exception::RealizeTopologyMustBeCalledFirst, \
00209 (objType),(objName),(methodNm));}while(false)
00210 #define SimTK_STAGECHECK_EQ_ALWAYS(currentStage,targetStage,methodNm) \
00211 do{if((currentStage)!=(targetStage)) SimTK_THROW3(SimTK::Exception::StageIsWrong, \
00212 (currentStage),(targetStage),(methodNm));}while(false)
00213 #define SimTK_STAGECHECK_GE_ALWAYS(currentStage,targetStage,methodNm) \
00214 do{if(!((currentStage)>=(targetStage))) SimTK_THROW3(SimTK::Exception::StageTooLow, \
00215 (currentStage),(targetStage),(methodNm));}while(false)
00216 #define SimTK_STAGECHECK_LT_ALWAYS(currentStage,targetStage,methodNm) \
00217 do{if((currentStage)>=(targetStage)) SimTK_THROW3(SimTK::Exception::StageTooHigh, \
00218 (currentStage),(targetStage),(methodNm));}while(false)
00219 #define SimTK_STAGECHECK_RANGE_ALWAYS(lower,current,upper,methodNm) \
00220 do{if(!((lower)<=(current)&&(current)<=(upper))) SimTK_THROW4(SimTK::Exception::StageOutOfRange, \
00221 (lower),(current),(upper),(methodNm));}while(false)
00222
00223
00224 #if defined(NDEBUG) && !defined(SimTK_KEEP_STAGECHECK)
00225 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED(cond,objType,objName,methodName)
00226 #define SimTK_STAGECHECK_EQ(currentStage,targetStage,methodNm)
00227 #define SimTK_STAGECHECK_GE(currentStage,targetStage,methodNm)
00228 #define SimTK_STAGECHECK_LE(currentStage,targetStage,methodNm)
00229 #define SimTK_STAGECHECK_RANGE(lower,current,upper,methodNm)
00230 #else
00231 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED(cond,objType,objName,methodName) \
00232 SimTK_STAGECHECK_TOPOLOGY_REALIZED_ALWAYS(cond,objType,objName,methodName)
00233 #define SimTK_STAGECHECK_EQ(currentStage,targetStage,methodNm) \
00234 SimTK_STAGECHECK_EQ_ALWAYS(currentStage,targetStage,methodNm)
00235 #define SimTK_STAGECHECK_GE(currentStage,targetStage,methodNm) \
00236 SimTK_STAGECHECK_GE_ALWAYS(currentStage,targetStage,methodNm)
00237 #define SimTK_STAGECHECK_LE(currentStage,targetStage,methodNm) \
00238 SimTK_STAGECHECK_LE_ALWAYS(currentStage,targetStage,methodNm)
00239 #define SimTK_STAGECHECK_RANGE(lower,current,upper,methodNm) \
00240 SimTK_STAGECHECK_RANGE_ALWAYS(lower,current,upper,methodNm)
00241 #endif
00242
00243
00244
00245
00246
00247
00248
00249
00250 #define SimTK_ASSERT_ALWAYS(cond,msg) \
00251 do{if(!(cond))SimTK_THROW2(SimTK::Exception::Assert,#cond,(msg));}while(false)
00252 #define SimTK_ASSERT1_ALWAYS(cond,msg,a1) \
00253 do{if(!(cond))SimTK_THROW3(SimTK::Exception::Assert,#cond,(msg),(a1));}while(false)
00254 #define SimTK_ASSERT2_ALWAYS(cond,msg,a1,a2) \
00255 do{if(!(cond))SimTK_THROW4(SimTK::Exception::Assert,#cond,(msg),(a1),(a2));}while(false)
00256 #define SimTK_ASSERT3_ALWAYS(cond,msg,a1,a2,a3) \
00257 do{if(!(cond))SimTK_THROW5(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3));}while(false)
00258 #define SimTK_ASSERT4_ALWAYS(cond,msg,a1,a2,a3,a4) \
00259 do{if(!(cond))SimTK_THROW6(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3),(a4));}while(false)
00260
00261
00262
00263
00264 #if defined(NDEBUG) && !defined(SimTK_KEEP_ASSERT)
00265 #define SimTK_ASSERT(cond,msg)
00266 #define SimTK_ASSERT(cond,msg)
00267 #define SimTK_ASSERT1(cond,msg,a1)
00268 #define SimTK_ASSERT2(cond,msg,a1,a2)
00269 #define SimTK_ASSERT3(cond,msg,a1,a2,a3)
00270 #define SimTK_ASSERT4(cond,msg,a1,a2,a3,a4)
00271 #else
00272 #define SimTK_ASSERT(cond,msg) SimTK_ASSERT_ALWAYS(cond,msg)
00273 #define SimTK_ASSERT1(cond,msg,a1) SimTK_ASSERT1_ALWAYS(cond,msg,a1)
00274 #define SimTK_ASSERT2(cond,msg,a1,a2) SimTK_ASSERT2_ALWAYS(cond,msg,a1,a2)
00275 #define SimTK_ASSERT3(cond,msg,a1,a2,a3) SimTK_ASSERT3_ALWAYS(cond,msg,a1,a2,a3)
00276 #define SimTK_ASSERT4(cond,msg,a1,a2,a3,a4) SimTK_ASSERT4_ALWAYS(cond,msg,a1,a2,a3,a4)
00277 #endif
00278
00279
00280 #endif // SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_
00281
00282
00283