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
00058 template <class T> class PrimitiveTypeTraits {
00059 public:
00061 typedef T primitiveType;
00063 static int numPrimitiveObjs() { return 1; }
00065 static void extractPrimitiveObjs(
00066 const T &obj
00067 ,const int numPrimitiveObjs
00068 ,primitiveType primitiveObjs[]
00069 )
00070 {
00071 #ifdef _DEBUG
00072 TEST_FOR_EXCEPTION( numPrimitiveObjs!=1 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00073 #endif
00074 primitiveObjs[0] = obj;
00075 }
00077 static void loadPrimitiveObjs(
00078 const int numPrimitiveObjs
00079 ,const primitiveType primitiveObjs[]
00080 ,T *obj
00081 )
00082 {
00083 #ifdef _DEBUG
00084 TEST_FOR_EXCEPTION( numPrimitiveObjs!=1 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00085 #endif
00086 *obj = primitiveObjs[0];
00087 }
00088 };
00089
00090 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00091
00094 template <class T> class PrimitiveTypeTraits< std::complex<T> > {
00095 public:
00097 typedef T primitiveType;
00099 static int numPrimitiveObjs() { return 2; }
00101 static void extractPrimitiveObjs(
00102 const std::complex<T> &obj
00103 ,const int numPrimitiveObjs
00104 ,primitiveType primitiveObjs[]
00105 )
00106 {
00107 #ifdef _DEBUG
00108 TEST_FOR_EXCEPTION( numPrimitiveObjs!=2 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00109 #endif
00110 primitiveObjs[0] = obj.real();
00111 primitiveObjs[1] = obj.imag();
00112 }
00114 static void loadPrimitiveObjs(
00115 const int numPrimitiveObjs
00116 ,const primitiveType primitiveObjs[]
00117 ,std::complex<T> *obj
00118 )
00119 {
00120 #ifdef _DEBUG
00121 TEST_FOR_EXCEPTION( numPrimitiveObjs!=2 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00122 #endif
00123 *obj = std::complex<T>( primitiveObjs[0], primitiveObjs[1] );
00124 }
00125 };
00126
00127 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00128
00129 #ifdef HAVE_TEUCHOS_GNU_MP
00130
00135 template <> class PrimitiveTypeTraits<mpf_class> {
00136 public:
00138 typedef double primitiveType;
00140 static int numPrimitiveObjs() { return 10; }
00142 static void extractPrimitiveObjs(
00143 const mpf_class &obj
00144 ,const int numPrimitiveObjs
00145 ,primitiveType primitiveObjs[]
00146 )
00147 {
00148 #ifdef _DEBUG
00149 TEST_FOR_EXCEPTION( numPrimitiveObjs!=10 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00150 #endif
00151 TEST_FOR_EXCEPT(true);
00152 }
00154 static void loadPrimitiveObjs(
00155 const int numPrimitiveObjs
00156 ,const primitiveType primitiveObjs[]
00157 ,mpf_class *obj
00158 )
00159 {
00160 #ifdef _DEBUG
00161 TEST_FOR_EXCEPTION( numPrimitiveObjs!=10 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00162 #endif
00163 TEST_FOR_EXCEPT(true);
00164 }
00165 };
00166
00167 #endif // HAVE_TEUCHOS_GNU_MP
00168
00169
00170 }
00171
00172 #endif // TEUCHOS_PRIMITIVE_TYPE_TRAITS_H