Teuchos_PrimitiveTypeTraits.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 // ////////////////////////////////////////////////////////////////////////
00030 // Teuchos_PrimitiveTypeTraits.hpp
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; // Just a guess!
00143   static int numPrimitiveObjs() { return 10; } // Just a guess!
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); // ToDo: Implement
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); // ToDo: Implement
00167     }
00168 };
00169 
00170 #endif // HAVE_TEUCHOS_GNU_MP
00171 
00172 
00173 } // namespace Teuchos
00174 
00175 #endif // TEUCHOS_PRIMITIVE_TYPE_TRAITS_H

Generated on Thu Sep 18 12:41:17 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1