00001
00002
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 #ifndef TEUCHOS_PRIMITIVE_TYPE_TRAITS_H
00033 #define TEUCHOS_PRIMITIVE_TYPE_TRAITS_H
00034
00035 #include "Teuchos_TestForException.hpp"
00036 #ifdef HAVE_TEUCHOS_GNU_MP
00037 #include "gmp.h"
00038 #include "gmpxx.h"
00039 #endif
00040
00046 namespace Teuchos {
00047
00049
00059 template <class T> class PrimitiveTypeTraits {
00060 public:
00062 typedef T primitiveType;
00064 static int numPrimitiveObjs() { return 1; }
00066 static void extractPrimitiveObjs(
00067 const T &obj
00068 ,const int numPrimitiveObjs
00069 ,primitiveType primitiveObjs[]
00070 )
00071 {
00072 #ifdef _DEBUG
00073 TEST_FOR_EXCEPTION( numPrimitiveObjs!=1 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00074 #endif
00075 primitiveObjs[0] = obj;
00076 }
00078 static void loadPrimitiveObjs(
00079 const int numPrimitiveObjs
00080 ,const primitiveType primitiveObjs[]
00081 ,T *obj
00082 )
00083 {
00084 #ifdef _DEBUG
00085 TEST_FOR_EXCEPTION( numPrimitiveObjs!=1 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00086 #endif
00087 *obj = primitiveObjs[0];
00088 }
00089 };
00090
00091 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00092
00094
00096 template <class T> class PrimitiveTypeTraits< std::complex<T> > {
00097 public:
00099 typedef T primitiveType;
00101 static int numPrimitiveObjs() { return 2; }
00103 static void extractPrimitiveObjs(
00104 const std::complex<T> &obj
00105 ,const int numPrimitiveObjs
00106 ,primitiveType primitiveObjs[]
00107 )
00108 {
00109 #ifdef _DEBUG
00110 TEST_FOR_EXCEPTION( numPrimitiveObjs!=2 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00111 #endif
00112 primitiveObjs[0] = obj.real();
00113 primitiveObjs[1] = obj.imag();
00114 }
00116 static void loadPrimitiveObjs(
00117 const int numPrimitiveObjs
00118 ,const primitiveType primitiveObjs[]
00119 ,std::complex<T> *obj
00120 )
00121 {
00122 #ifdef _DEBUG
00123 TEST_FOR_EXCEPTION( numPrimitiveObjs!=2 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00124 #endif
00125 *obj = std::complex<T>( primitiveObjs[0], primitiveObjs[1] );
00126 }
00127 };
00128
00129 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00130
00131 #ifdef HAVE_TEUCHOS_GNU_MP
00132
00134
00138 template <> class PrimitiveTypeTraits<mpf_class> {
00139 public:
00141 typedef double primitiveType;
00143 static int numPrimitiveObjs() { return 10; }
00145 static void extractPrimitiveObjs(
00146 const mpf_class &obj
00147 ,const int numPrimitiveObjs
00148 ,primitiveType primitiveObjs[]
00149 )
00150 {
00151 #ifdef _DEBUG
00152 TEST_FOR_EXCEPTION( numPrimitiveObjs!=10 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00153 #endif
00154 TEST_FOR_EXCEPT(true);
00155 }
00157 static void loadPrimitiveObjs(
00158 const int numPrimitiveObjs
00159 ,const primitiveType primitiveObjs[]
00160 ,mpf_class *obj
00161 )
00162 {
00163 #ifdef _DEBUG
00164 TEST_FOR_EXCEPTION( numPrimitiveObjs!=10 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00165 #endif
00166 TEST_FOR_EXCEPT(true);
00167 }
00168 };
00169
00170 #endif // HAVE_TEUCHOS_GNU_MP
00171
00172
00173 }
00174
00175 #endif // TEUCHOS_PRIMITIVE_TYPE_TRAITS_H