00001 # ifndef CPPAD_CPPAD_ASSERT_INCLUDED 00002 # define CPPAD_CPPAD_ASSERT_INCLUDED 00003 00004 /* -------------------------------------------------------------------------- 00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell 00006 00007 CppAD is distributed under multiple licenses. This distribution is under 00008 the terms of the 00009 Common Public License Version 1.0. 00010 00011 A copy of this license is included in the COPYING file of this distribution. 00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00013 -------------------------------------------------------------------------- */ 00014 00015 /* 00016 ------------------------------------------------------------------------------- 00017 $begin cppad_assert$$ 00018 $spell 00019 CppAD 00020 exp 00021 const 00022 bool 00023 $$ 00024 00025 $index assert, error macro $$ 00026 $index error, assert macro$$ 00027 $index macro, error assert$$ 00028 00029 $section CppAD Assertions During Execution$$ 00030 00031 $head Syntax$$ 00032 $syntax%CPPAD_ASSERT_KNOWN(%exp%, %msg%) 00033 %$$ 00034 $syntax%CPPAD_ASSERT_UNKNOWN(%exp%)%$$ 00035 00036 00037 $head Purpose$$ 00038 If the preprocessor symbol $code NDEBUG/$$ is not defined, 00039 these CppAD macros are used to detect and report errors. 00040 They are documented here because they correspond to the C++ 00041 source code that the error is reported at. 00042 00043 $head Restriction$$ 00044 The CppAD user should not uses these macros. 00045 You can however write your own macros that do not begin with $code CPPAD$$ 00046 and that call the $cref/CppAD error handler/ErrorHandler/$$. 00047 00048 $subhead Known$$ 00049 $index CPPAD_ASSERT_KNOWN$$ 00050 The $code CPPAD_ASSERT_KNOWN$$ macro is used to check for an error 00051 with a known cause. 00052 For example, many CppAD routines uses these macros 00053 to make sure their arguments conform to their specifications. 00054 00055 $subhead Unknown$$ 00056 $index CPPAD_ASSERT_UNKNOWN$$ 00057 The $code CPPAD_ASSERT_UNKNOWN$$ macro is used to check that the 00058 CppAD internal data structures conform as expected. 00059 If this is not the case, CppAD does not know why the error has 00060 occurred; for example, the user may have written past the end 00061 of an allocated array. 00062 00063 $head Exp$$ 00064 The argument $italic exp$$ is a C++ source code expression 00065 that results in a $code bool$$ value that should be true. 00066 If it is false, an error has occurred. 00067 This expression may be execute any number of times 00068 (including zero times) so it must have not side effects. 00069 00070 $head Msg$$ 00071 The argument $italic msg$$ has prototype 00072 $syntax% 00073 const char *%msg% 00074 %$$ 00075 and contains a $code '\0'$$ terminated character string. 00076 This string is a description of the error 00077 corresponding to $italic exp$$ being false. 00078 00079 $head Error Handler$$ 00080 These macros use the 00081 $cref/CppAD error handler/ErrorHandler/$$ to report errors. 00082 This error handler can be replaced by the user. 00083 00084 $end 00085 ------------------------------------------------------------------------------ 00086 */ 00087 00088 # include <cassert> 00089 # include <iostream> 00090 # include <cppad/config.h> 00091 # include <cppad/error_handler.hpp> 00092 00093 # ifdef NDEBUG 00094 # define CPPAD_ASSERT_KNOWN(exp, msg) // do nothing 00095 # else 00096 # define CPPAD_ASSERT_KNOWN(exp, msg) \ 00097 { if( ! ( exp ) ) \ 00098 ErrorHandler::Call( \ 00099 true , \ 00100 __LINE__ , \ 00101 __FILE__ , \ 00102 #exp , \ 00103 msg ); \ 00104 } 00105 # endif 00106 00107 # ifdef NDEBUG 00108 # define CPPAD_ASSERT_UNKNOWN(exp) // do nothing 00109 # else 00110 # define CPPAD_ASSERT_UNKNOWN(exp) \ 00111 { if( ! ( exp ) ) \ 00112 ErrorHandler::Call( \ 00113 false , \ 00114 __LINE__ , \ 00115 __FILE__ , \ 00116 #exp , \ 00117 "" ); \ 00118 } 00119 # endif 00120 00121 # endif