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 
00042 namespace Teuchos {
00043 
00045 
00055 template <class T> class PrimitiveTypeTraits {
00056 public:
00058   typedef T  primitiveType;
00060   static int numPrimitiveObjs() { return 1; }
00062   static void extractPrimitiveObjs(
00063     const T                &obj
00064     ,const int             numPrimitiveObjs
00065     ,primitiveType         primitiveObjs[]
00066     )
00067     {
00068 #ifdef _DEBUG
00069       TEST_FOR_EXCEPTION( numPrimitiveObjs!=1 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00070 #endif
00071       primitiveObjs[0] = obj;
00072     }
00074   static void loadPrimitiveObjs(
00075     const int              numPrimitiveObjs
00076     ,const primitiveType   primitiveObjs[]
00077     ,T                     *obj
00078     )
00079     {
00080 #ifdef _DEBUG
00081       TEST_FOR_EXCEPTION( numPrimitiveObjs!=1 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00082 #endif
00083       *obj = primitiveObjs[0];
00084     }
00085 };
00086 
00087 #ifdef HAVE_COMPLEX
00088 
00090 
00092 template <class T> class PrimitiveTypeTraits< std::complex<T> > {
00093 public:
00095   typedef T  primitiveType;
00097   static int numPrimitiveObjs() { return 2; }
00099   static void extractPrimitiveObjs(
00100     const std::complex<T>  &obj
00101     ,const int             numPrimitiveObjs
00102     ,primitiveType         primitiveObjs[]
00103     )
00104     {
00105 #ifdef _DEBUG
00106       TEST_FOR_EXCEPTION( numPrimitiveObjs!=2 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00107 #endif
00108       primitiveObjs[0] = obj.real();
00109       primitiveObjs[1] = obj.imag();
00110     }
00112   static void loadPrimitiveObjs(
00113     const int              numPrimitiveObjs
00114     ,const primitiveType   primitiveObjs[]
00115     ,std::complex<T>       *obj
00116     )
00117     {
00118 #ifdef _DEBUG
00119       TEST_FOR_EXCEPTION( numPrimitiveObjs!=2 || primitiveObjs==NULL, std::invalid_argument, "Error!" );
00120 #endif
00121       *obj = std::complex<T>( primitiveObjs[0], primitiveObjs[1] );
00122     }
00123 };
00124 
00125 #endif // HAVE_COMPLEX
00126 
00127 } // namespace Teuchos
00128 
00129 #endif // TEUCHOS_PRIMITIVE_TYPE_TRAITS_H

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