/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/check_numeric_type.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_CHECK_NUMERIC_TYPE_INCLUDED
00002 # define CPPAD_CHECK_NUMERIC_TYPE_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 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 $begin CheckNumericType$$
00016 $spell
00017         cppad.hpp
00018         CppAD
00019 $$
00020 
00021 $section Check NumericType Class Concept$$
00022 
00023 $index numeric, check$$
00024 $index check, numeric$$
00025 $index concept, check numeric$$
00026 
00027 $head Syntax$$
00028 $code # include <cppad/check_numeric_type.hpp>$$
00029 $pre
00030 $$
00031 $syntax%CheckNumericType<%NumericType%>()%$$
00032 
00033 
00034 $head Purpose$$
00035 The syntax 
00036 $syntax%
00037         CheckNumericType<%NumericType%>()
00038 %$$
00039 preforms compile and run time checks that the type specified
00040 by $italic NumericType$$ satisfies all the requirements for 
00041 a $xref/NumericType/$$ class. 
00042 If a requirement is not satisfied,
00043 a an error message makes it clear what condition is not satisfied.
00044 
00045 $head Include$$
00046 The file $code cppad/check_numeric_type.hpp$$ is included by $code cppad/cppad.hpp$$
00047 but it can also be included separately with out the rest
00048 if the CppAD include files.
00049 
00050 $head Example$$
00051 $children%
00052         example/check_numeric_type.cpp
00053 %$$
00054 The file $xref/CheckNumericType.cpp/$$
00055 contains an example and test of this function. 
00056 It returns true, if it succeeds an false otherwise.
00057 The comments in this example suggest a way to change the example
00058 so an error message occurs.
00059 
00060 $end
00061 ---------------------------------------------------------------------------
00062 */
00063 
00064 
00065 
00066 namespace CppAD {
00067 
00068 # ifdef NDEBUG
00069         template <class NumericType>
00070         inline void CheckNumericType(void)
00071         { }
00072 # else
00073         template <class NumericType>
00074         NumericType CheckNumericType(void)
00075         {       // only need execute once per value NumericType type
00076                 static bool runOnce = false;
00077                 if( runOnce )
00078                         return NumericType(0);
00079                 runOnce = true;
00080 
00081                 /*
00082                 contructors
00083                 */
00084                 NumericType check_NumericType_default_constructor;
00085                 NumericType check_NumericType_constructor_from_int(1);
00086 
00087                 const NumericType x(1);
00088 
00089                 NumericType check_NumericType_copy_constructor(x);
00090 
00091                 // assignment
00092                 NumericType check_NumericType_assignment;
00093                 check_NumericType_assignment = x;
00094 
00095                 /*
00096                 unary operators
00097                 */
00098                 const NumericType check_NumericType_unary_plus(1);
00099                 NumericType check_NumericType_unary_plus_result = 
00100                         + check_NumericType_unary_plus;
00101 
00102                 const NumericType check_NumericType_unary_minus(1);
00103                 NumericType check_NumericType_unary_minus_result = 
00104                         - check_NumericType_unary_minus;
00105 
00106                 /*
00107                 binary operators
00108                 */
00109                 const NumericType check_NumericType_binary_addition(1);
00110                 NumericType check_NumericType_binary_addition_result = 
00111                         check_NumericType_binary_addition + x;
00112 
00113                 const NumericType check_NumericType_binary_subtraction(1);
00114                 NumericType check_NumericType_binary_subtraction_result =
00115                         check_NumericType_binary_subtraction - x;
00116 
00117                 const NumericType check_NumericType_binary_multiplication(1);
00118                 NumericType check_NumericType_binary_multiplication_result =
00119                         check_NumericType_binary_multiplication * x;
00120 
00121                 const NumericType check_NumericType_binary_division(1);
00122                 NumericType check_NumericType_binary_division_result =
00123                         check_NumericType_binary_division / x;
00124 
00125                 /*
00126                 computed assignment operators
00127                 */
00128                 NumericType 
00129                 check_NumericType_computed_assignment_addition(1);
00130                 check_NumericType_computed_assignment_addition += x;
00131 
00132                 NumericType 
00133                 check_NumericType_computed_assignment_subtraction(1);
00134                 check_NumericType_computed_assignment_subtraction -= x;
00135 
00136                 NumericType 
00137                 check_NumericType_computed_assignment_multiplication(1);
00138                 check_NumericType_computed_assignment_multiplication *= x;
00139 
00140                 NumericType 
00141                 check_NumericType_computed_assignment_division(1);
00142                 check_NumericType_computed_assignment_division /= x;
00143 
00144                 /* 
00145                 use all values so as to avoid warnings
00146                 */
00147                 check_NumericType_default_constructor = x;
00148                 return
00149                         + check_NumericType_default_constructor
00150                         + check_NumericType_constructor_from_int
00151                         + check_NumericType_copy_constructor
00152                         + check_NumericType_assignment
00153                         + check_NumericType_unary_plus_result
00154                         + check_NumericType_unary_minus_result
00155                         + check_NumericType_binary_addition_result
00156                         + check_NumericType_binary_subtraction_result
00157                         + check_NumericType_binary_multiplication_result
00158                         + check_NumericType_binary_division_result
00159                         + check_NumericType_computed_assignment_addition
00160                         + check_NumericType_computed_assignment_subtraction
00161                         + check_NumericType_computed_assignment_multiplication
00162                         + check_NumericType_computed_assignment_division
00163                 ;
00164         }
00165 # endif
00166 
00167 } // end namespace CppAD
00168 
00169 # endif

Generated on Sun Nov 14 14:06:32 2010 for Coin-All by  doxygen 1.4.7