Sacado_Traits.hpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 //
00031 // The forward-mode AD classes in Sacado are a derivative work of the
00032 // expression template classes in the Fad package by Nicolas Di Cesare.  
00033 // The following banner is included in the original Fad source code:
00034 //
00035 // ************ DO NOT REMOVE THIS BANNER ****************
00036 //
00037 //  Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
00038 //  http://www.ann.jussieu.fr/~dicesare
00039 //
00040 //            CEMRACS 98 : C++ courses, 
00041 //         templates : new C++ techniques 
00042 //            for scientific computing 
00043 // 
00044 //********************************************************
00045 //
00046 //  NumericalTraits class to illustrate TRAITS
00047 //
00048 //********************************************************
00049 // @HEADER
00050 
00051 #ifndef SACADO_TRAITS_HPP
00052 #define SACADO_TRAITS_HPP
00053 
00054 #include "Sacado_ConfigDefs.h"
00055 #include <string>
00056 
00057 #ifdef HAVE_SACADO_COMPLEX
00058 #include <complex>
00059 #endif
00060 
00061 namespace Sacado {
00062 
00064 
00068   template <typename A, typename B> struct Promote {};
00069 
00071   template <typename A> struct Promote<A,A> {
00072     typedef A type;
00073   };
00074 
00076 #define SACADO_PROMOTE_SPECIALIZATION(type1,type2,type3) \
00077   template <> struct Promote< type1, type2 > {       \
00078     typedef type3 type;                        \
00079   };                 \
00080   template <> struct Promote< type2, type1 > {       \
00081     typedef type3 type;                  \
00082   };
00083 
00084   SACADO_PROMOTE_SPECIALIZATION(double,float,double)
00085   SACADO_PROMOTE_SPECIALIZATION(double,long,double)
00086   SACADO_PROMOTE_SPECIALIZATION(double,int,double)
00087   SACADO_PROMOTE_SPECIALIZATION(float,long,float)
00088   SACADO_PROMOTE_SPECIALIZATION(float,int,float)
00089 #ifdef HAVE_SACADO_COMPLEX
00090   SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,std::complex<float>,std::complex<double>)
00091   SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,double,std::complex<double>)
00092   SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,float,std::complex<double>)
00093   SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,long,std::complex<double>)
00094   SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,int,std::complex<double>)
00095   SACADO_PROMOTE_SPECIALIZATION(std::complex<float>,float,std::complex<float>)
00096   SACADO_PROMOTE_SPECIALIZATION(std::complex<float>,long,std::complex<float>)
00097   SACADO_PROMOTE_SPECIALIZATION(std::complex<float>,int,std::complex<float>)
00098 #endif // HAVE_SACADO_COMPLEX
00099 
00100 #undef SACADO_PROMOTE_SPECIALIZATION
00101 
00103 
00107   template <typename T> struct ScalarType {};
00108 
00110 
00114   template <typename T> struct ValueType {};
00115 
00117 
00121   template <typename T> struct IsADType {};
00122 
00124 
00128   template <typename T> struct IsScalarType {};
00129 
00131 
00134   template <typename T> struct Value {};
00135 
00137 
00141   template <typename T> struct ScalarValue {};
00142 
00144   template <typename T> struct MarkConstant {
00145     static void eval(T& x) {}
00146   };
00147 
00149   template <typename T> struct StringName {};
00150 
00152 #define SACADO_BUILTIN_SPECIALIZATION(t,NAME)     \
00153   template <> struct ScalarType< t > {              \
00154     typedef t type;                 \
00155   };                                                      \
00156   template <> struct ValueType< t > {             \
00157     typedef t type;                 \
00158   };                                                      \
00159   template <> struct IsADType< t > {              \
00160     static const bool value = false;              \
00161   };                                                      \
00162   template <> struct IsScalarType< t > {            \
00163     static const bool value = true;             \
00164   };                                                      \
00165   template <> struct Value< t > {             \
00166     static const t& eval(const t& x) { return x; }        \
00167   };                \
00168   template <> struct ScalarValue< t > {             \
00169     static const t& eval(const t& x) { return x; }        \
00170   };                \
00171   template <> struct StringName< t > {        \
00172     static std::string eval() { return NAME; }      \
00173   };
00174 
00175   SACADO_BUILTIN_SPECIALIZATION(char,"char")
00176   SACADO_BUILTIN_SPECIALIZATION(float,"float")
00177   SACADO_BUILTIN_SPECIALIZATION(double,"double")
00178   SACADO_BUILTIN_SPECIALIZATION(int,"int")
00179   SACADO_BUILTIN_SPECIALIZATION(unsigned int,"unsigned int")
00180   SACADO_BUILTIN_SPECIALIZATION(long,"long")
00181   SACADO_BUILTIN_SPECIALIZATION(unsigned long,"unsigned long")
00182   SACADO_BUILTIN_SPECIALIZATION(bool,"bool")
00183 #ifdef HAVE_SACADO_COMPLEX
00184   SACADO_BUILTIN_SPECIALIZATION(std::complex<double>,"std::complex<double>")
00185   SACADO_BUILTIN_SPECIALIZATION(std::complex<float>,"std::complex<float>")
00186 #endif
00187 
00188 #undef SACADO_BUILTIN_SPECIALIZATION
00189 
00190 } // namespace Sacado
00191 
00192 #endif // SACADO_TRAITS_HPP

Generated on Wed May 12 21:39:39 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7