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 
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 TEUCHOS_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 TEUCHOS_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 TEUCHOS_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 TEUCHOS_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; // Just a guess!
00140   static int numPrimitiveObjs() { return 10; } // Just a guess!
00142   static void extractPrimitiveObjs(
00143     const mpf_class        &obj
00144     ,const int             numPrimitiveObjs
00145     ,primitiveType         primitiveObjs[]
00146     )
00147     {
00148 #ifdef TEUCHOS_DEBUG
00149       TEST_FOR_EXCEPTION( numPrimitiveObjs!=10 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00150 #endif
00151       TEST_FOR_EXCEPT(true); // ToDo: Implement
00152     }
00154   static void loadPrimitiveObjs(
00155     const int              numPrimitiveObjs
00156     ,const primitiveType   primitiveObjs[]
00157     ,mpf_class             *obj
00158     )
00159     {
00160 #ifdef TEUCHOS_DEBUG
00161       TEST_FOR_EXCEPTION( numPrimitiveObjs!=10 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00162 #endif
00163       TEST_FOR_EXCEPT(true); // ToDo: Implement
00164     }
00165 };
00166 
00167 #endif // HAVE_TEUCHOS_GNU_MP
00168 
00169 
00170 } // namespace Teuchos
00171 
00172 #endif // TEUCHOS_PRIMITIVE_TYPE_TRAITS_H

Generated on Tue Oct 20 12:45:26 2009 for Teuchos - Trilinos Tools Package by doxygen 1.4.7