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
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
00103
00104
00105
00106
00107
00108
00109
00110
00111 #define SimTK_INDEXCHECK_ALWAYS(lb,ix,ub,where) \
00112 do{if(!((lb)<=(ix)&&(ix)<(ub)))SimTK_THROW5(SimTK::Exception::IndexOutOfRange, \
00113 #ix,(lb),(ix),(ub),(where));}while(false)
00114
00115
00116 #define SimTK_SIZECHECK_ALWAYS(sz,maxsz,where) \
00117 do{if(!(0<=(sz)&&(sz)<=(maxsz)))SimTK_THROW4(SimTK::Exception::SizeOutOfRange, \
00118 #sz,(sz),(maxsz),(where));}while(false)
00119
00120
00121 #define SimTK_SIZECHECK_NONNEG_ALWAYS(sz,where) \
00122 do{if((sz)<0)SimTK_THROW3(SimTK::Exception::SizeWasNegative, \
00123 #sz,(sz),(where));}while(false)
00124
00125
00126
00127 #define SimTK_VALUECHECK_ALWAYS(lb,val,ub,valName,where) \
00128 do{if(!(lb)<=(val)&&(val)<=(ub)))SimTK_THROW5(SimTK::Exception::ValueOutOfRange, \
00129 (valName),(lb),(val),(ub),(where));}while(false)
00130
00131
00132 #define SimTK_VALUECHECK_NONNEG_ALWAYS(val,valName,where) \
00133 do{if((val)<0)SimTK_THROW3(SimTK::Exception::ValueWasNegative, \
00134 (valName),(val),(where));}while(false)
00135
00136
00137
00138 #if defined(NDEBUG) && !defined(SimTK_KEEP_RANGECHECK)
00139 #define SimTK_INDEXCHECK(lb,ix,ub,where)
00140 #define SimTK_SIZECHECK(sz,maxsz,where)
00141 #define SimTK_SIZECHECK_NONNEG(sz,where)
00142 #define SimTK_VALUECHECK(lb,val,ub,valName,where)
00143 #define SimTK_VALUECHECK_NONNEG(val,valName,where)
00144 #else
00145 #define SimTK_INDEXCHECK(lb,ix,ub,where) SimTK_INDEXCHECK_ALWAYS(lb,ix,ub,where)
00146 #define SimTK_SIZECHECK(sz,maxsz,where) SimTK_SIZECHECK_ALWAYS(sz,maxsz,where)
00147 #define SimTK_SIZECHECK_NONNEG(sz,where) SimTK_SIZECHECK_NONNEG_ALWAYS(sz,where)
00148 #define SimTK_VALUECHECK(lb,val,ub,valName,where) SimTK_VALUECHECK_ALWAYS(lb,val,ub,valName,where)
00149 #define SimTK_VALUECHECK_NONNEG(val,valName,where) SimTK_VALUECHECK_NONNEG_ALWAYS(val,valName,where)
00150 #endif
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED_ALWAYS(cond,objType,objName,methodNm) \
00168 do{if(!(cond)) SimTK_THROW3(SimTK::Exception::RealizeTopologyMustBeCalledFirst, \
00169 (objType),(objName),(methodNm));}while(false)
00170 #define SimTK_STAGECHECK_EQ_ALWAYS(currentStage,targetStage,methodNm) \
00171 do{if((currentStage)!=(targetStage)) SimTK_THROW3(SimTK::Exception::StageIsWrong, \
00172 (currentStage),(targetStage),(methodNm));}while(false)
00173 #define SimTK_STAGECHECK_GE_ALWAYS(currentStage,targetStage,methodNm) \
00174 do{if(!((currentStage)>=(targetStage))) SimTK_THROW3(SimTK::Exception::StageTooLow, \
00175 (currentStage),(targetStage),(methodNm));}while(false)
00176 #define SimTK_STAGECHECK_LT_ALWAYS(currentStage,targetStage,methodNm) \
00177 do{if((currentStage)>=(targetStage)) SimTK_THROW3(SimTK::Exception::StageTooHigh, \
00178 (currentStage),(targetStage),(methodNm));}while(false)
00179 #define SimTK_STAGECHECK_RANGE_ALWAYS(lower,current,upper,methodNm) \
00180 do{if(!((lower)<=(current)&&(current)<=(upper))) SimTK_THROW4(SimTK::Exception::StageOutOfRange, \
00181 (lower),(current),(upper),(methodNm));}while(false)
00182
00183
00184 #if defined(NDEBUG) && !defined(SimTK_KEEP_STAGECHECK)
00185 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED(cond,objType,objName,methodName)
00186 #define SimTK_STAGECHECK_EQ(currentStage,targetStage,methodNm)
00187 #define SimTK_STAGECHECK_GE(currentStage,targetStage,methodNm)
00188 #define SimTK_STAGECHECK_LT(currentStage,targetStage,methodNm)
00189 #define SimTK_STAGECHECK_RANGE(lower,current,upper,methodNm)
00190 #else
00191 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED(cond,objType,objName,methodName) \
00192 SimTK_STAGECHECK_TOPOLOGY_REALIZED_ALWAYS(cond,objType,objName,methodName)
00193 #define SimTK_STAGECHECK_EQ(currentStage,targetStage,methodNm) \
00194 SimTK_STAGECHECK_EQ_ALWAYS(currentStage,targetStage,methodNm)
00195 #define SimTK_STAGECHECK_GE(currentStage,targetStage,methodNm) \
00196 SimTK_STAGECHECK_GE_ALWAYS(currentStage,targetStage,methodNm)
00197 #define SimTK_STAGECHECK_LT(currentStage,targetStage,methodNm) \
00198 SimTK_STAGECHECK_LE_ALWAYS(currentStage,targetStage,methodNm)
00199 #define SimTK_STAGECHECK_RANGE(lower,current,upper,methodNm) \
00200 SimTK_STAGECHECK_RANGE_ALWAYS(lower,current,upper,methodNm)
00201 #endif
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #define SimTK_APIARGCHECK_ALWAYS(cond,className,methodName,msg) \
00212 do{if(!(cond))SimTK_THROW4(SimTK::Exception::APIArgcheckFailed, \
00213 #cond,(className),(methodName),(msg)); \
00214 }while(false)
00215 #define SimTK_APIARGCHECK1_ALWAYS(cond,className,methodName,fmt,a1) \
00216 do{if(!(cond))SimTK_THROW5(SimTK::Exception::APIArgcheckFailed, \
00217 #cond,(className),(methodName),(fmt),(a1)); \
00218 }while(false)
00219 #define SimTK_APIARGCHECK2_ALWAYS(cond,className,methodName,fmt,a1,a2) \
00220 do{if(!(cond))SimTK_THROW6(SimTK::Exception::APIArgcheckFailed, \
00221 #cond,(className),(methodName),(fmt),(a1),(a2)); \
00222 }while(false)
00223 #define SimTK_APIARGCHECK3_ALWAYS(cond,className,methodName,fmt,a1,a2,a3) \
00224 do{if(!(cond))SimTK_THROW7(SimTK::Exception::APIArgcheckFailed, \
00225 #cond,(className),(methodName),(fmt),(a1),(a2),(a3)); \
00226 }while(false)
00227 #define SimTK_APIARGCHECK4_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4) \
00228 do{if(!(cond))SimTK_THROW8(SimTK::Exception::APIArgcheckFailed, \
00229 #cond,(className),(methodName),(fmt),(a1),(a2),(a3),(a4)); \
00230 }while(false)
00231 #define SimTK_APIARGCHECK5_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4,a5) \
00232 do{if(!(cond))SimTK_THROW9(SimTK::Exception::APIArgcheckFailed, \
00233 #cond,(className),(methodName),(fmt),(a1),(a2),(a3),(a4),(a5)); \
00234 }while(false)
00235
00236 #if defined(NDEBUG) && !defined(SimTK_KEEP_APIARGCHECK)
00237 #define SimTK_APIARGCHECK(cond,className,methodName,msg)
00238 #define SimTK_APIARGCHECK1(cond,className,methodName,fmt,a1)
00239 #define SimTK_APIARGCHECK2(cond,className,methodName,fmt,a1,a2)
00240 #define SimTK_APIARGCHECK3(cond,className,methodName,fmt,a1,a2,a3)
00241 #define SimTK_APIARGCHECK4(cond,className,methodName,fmt,a1,a2,a3,a4)
00242 #define SimTK_APIARGCHECK5(cond,className,methodName,fmt,a1,a2,a3,a4,a5)
00243 #else
00244 #define SimTK_APIARGCHECK(cond,className,methodName,msg) \
00245 SimTK_APIARGCHECK_ALWAYS(cond,className,methodName,msg)
00246 #define SimTK_APIARGCHECK1(cond,className,methodName,fmt,a1) \
00247 SimTK_APIARGCHECK1_ALWAYS(cond,className,methodName,fmt,a1)
00248 #define SimTK_APIARGCHECK2(cond,className,methodName,fmt,a1,a2) \
00249 SimTK_APIARGCHECK2_ALWAYS(cond,className,methodName,fmt,a1,a2)
00250 #define SimTK_APIARGCHECK3(cond,className,methodName,fmt,a1,a2,a3) \
00251 SimTK_APIARGCHECK3_ALWAYS(cond,className,methodName,fmt,a1,a2,a3)
00252 #define SimTK_APIARGCHECK4(cond,className,methodName,fmt,a1,a2,a3,a4) \
00253 SimTK_APIARGCHECK4_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4)
00254 #define SimTK_APIARGCHECK5(cond,className,methodName,fmt,a1,a2,a3,a4,a5) \
00255 SimTK_APIARGCHECK5_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4,a5)
00256 #endif
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 #define SimTK_ERRCHK_ALWAYS(cond,whereChecked,msg) \
00269 do{if(!(cond))SimTK_THROW3(SimTK::Exception::ErrorCheck, \
00270 #cond,(whereChecked),(msg)); \
00271 }while(false)
00272 #define SimTK_ERRCHK1_ALWAYS(cond,whereChecked,fmt,a1) \
00273 do{if(!(cond))SimTK_THROW4(SimTK::Exception::ErrorCheck, \
00274 #cond,(whereChecked),(fmt),(a1)); \
00275 }while(false)
00276 #define SimTK_ERRCHK2_ALWAYS(cond,whereChecked,fmt,a1,a2) \
00277 do{if(!(cond))SimTK_THROW5(SimTK::Exception::ErrorCheck, \
00278 #cond,(whereChecked),(fmt),(a1),(a2)); \
00279 }while(false)
00280 #define SimTK_ERRCHK3_ALWAYS(cond,whereChecked,fmt,a1,a2,a3) \
00281 do{if(!(cond))SimTK_THROW6(SimTK::Exception::ErrorCheck, \
00282 #cond,(whereChecked),(fmt),(a1),(a2),(a3)); \
00283 }while(false)
00284 #define SimTK_ERRCHK4_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4) \
00285 do{if(!(cond))SimTK_THROW7(SimTK::Exception::ErrorCheck, \
00286 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4)); \
00287 }while(false)
00288 #define SimTK_ERRCHK5_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5) \
00289 do{if(!(cond))SimTK_THROW8(SimTK::Exception::ErrorCheck, \
00290 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4),(a5)); \
00291 }while(false)
00292 #define SimTK_ERRCHK6_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6) \
00293 do{if(!(cond))SimTK_THROW9(SimTK::Exception::ErrorCheck, \
00294 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4),(a5),(a6)); \
00295 }while(false)
00296 #define SimTK_ERRCHK7_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6,a7) \
00297 do{if(!(cond))SimTK_THROW10(SimTK::Exception::ErrorCheck, \
00298 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4),(a5),(a6),(a7)); \
00299 }while(false)
00300
00301 #if defined(NDEBUG) && !defined(SimTK_KEEP_ERRCHK)
00302 #define SimTK_ERRCHK(cond,whereChecked,msg)
00303 #define SimTK_ERRCHK1(cond,whereChecked,fmt,a1)
00304 #define SimTK_ERRCHK2(cond,whereChecked,fmt,a1,a2)
00305 #define SimTK_ERRCHK3(cond,whereChecked,fmt,a1,a2,a3)
00306 #define SimTK_ERRCHK4(cond,whereChecked,fmt,a1,a2,a3,a4)
00307 #define SimTK_ERRCHK5(cond,whereChecked,fmt,a1,a2,a3,a4,a5)
00308 #define SimTK_ERRCHK6(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6)
00309 #define SimTK_ERRCHK7(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6)
00310 #else
00311 #define SimTK_ERRCHK(cond,whereChecked,msg) \
00312 SimTK_ERRCHK_ALWAYS(cond,whereChecked,msg)
00313 #define SimTK_ERRCHK1(cond,whereChecked,fmt,a1) \
00314 SimTK_ERRCHK1_ALWAYS(cond,whereChecked,fmt,a1)
00315 #define SimTK_ERRCHK2(cond,whereChecked,fmt,a1,a2) \
00316 SimTK_ERRCHK2_ALWAYS(cond,whereChecked,fmt,a1,a2)
00317 #define SimTK_ERRCHK3(cond,whereChecked,fmt,a1,a2,a3) \
00318 SimTK_ERRCHK3_ALWAYS(cond,whereChecked,fmt,a1,a2,a3)
00319 #define SimTK_ERRCHK4(cond,whereChecked,fmt,a1,a2,a3,a4) \
00320 SimTK_ERRCHK4_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4)
00321 #define SimTK_ERRCHK5(cond,whereChecked,fmt,a1,a2,a3,a4,a5) \
00322 SimTK_ERRCHK5_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5)
00323 #define SimTK_ERRCHK6(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6) \
00324 SimTK_ERRCHK6_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6)
00325 #define SimTK_ERRCHK7(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6,a7) \
00326 SimTK_ERRCHK7_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6,a7)
00327 #endif
00328
00329
00330
00331
00332
00333
00334
00335
00336 #define SimTK_ASSERT_ALWAYS(cond,msg) \
00337 do{if(!(cond))SimTK_THROW2(SimTK::Exception::Assert,#cond,(msg));}while(false)
00338 #define SimTK_ASSERT1_ALWAYS(cond,msg,a1) \
00339 do{if(!(cond))SimTK_THROW3(SimTK::Exception::Assert,#cond,(msg),(a1));}while(false)
00340 #define SimTK_ASSERT2_ALWAYS(cond,msg,a1,a2) \
00341 do{if(!(cond))SimTK_THROW4(SimTK::Exception::Assert,#cond,(msg),(a1),(a2));}while(false)
00342 #define SimTK_ASSERT3_ALWAYS(cond,msg,a1,a2,a3) \
00343 do{if(!(cond))SimTK_THROW5(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3));}while(false)
00344 #define SimTK_ASSERT4_ALWAYS(cond,msg,a1,a2,a3,a4) \
00345 do{if(!(cond))SimTK_THROW6(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3),(a4));}while(false)
00346 #define SimTK_ASSERT5_ALWAYS(cond,msg,a1,a2,a3,a4,a5) \
00347 do{if(!(cond))SimTK_THROW7(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3),(a4),(a5));}while(false)
00348
00349
00350
00351
00352 #if defined(NDEBUG) && !defined(SimTK_KEEP_ASSERT)
00353 #define SimTK_ASSERT(cond,msg)
00354 #define SimTK_ASSERT(cond,msg)
00355 #define SimTK_ASSERT1(cond,msg,a1)
00356 #define SimTK_ASSERT2(cond,msg,a1,a2)
00357 #define SimTK_ASSERT3(cond,msg,a1,a2,a3)
00358 #define SimTK_ASSERT4(cond,msg,a1,a2,a3,a4)
00359 #define SimTK_ASSERT5(cond,msg,a1,a2,a3,a4,a5)
00360 #else
00361 #define SimTK_ASSERT(cond,msg) SimTK_ASSERT_ALWAYS(cond,msg)
00362 #define SimTK_ASSERT1(cond,msg,a1) SimTK_ASSERT1_ALWAYS(cond,msg,a1)
00363 #define SimTK_ASSERT2(cond,msg,a1,a2) SimTK_ASSERT2_ALWAYS(cond,msg,a1,a2)
00364 #define SimTK_ASSERT3(cond,msg,a1,a2,a3) SimTK_ASSERT3_ALWAYS(cond,msg,a1,a2,a3)
00365 #define SimTK_ASSERT4(cond,msg,a1,a2,a3,a4) SimTK_ASSERT4_ALWAYS(cond,msg,a1,a2,a3,a4)
00366 #define SimTK_ASSERT5(cond,msg,a1,a2,a3,a4,a5) SimTK_ASSERT5_ALWAYS(cond,msg,a1,a2,a3,a4,a5)
00367 #endif
00368
00369
00370 #endif // SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_
00371
00372
00373