Sacado_Traits.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_Traits.hpp,v 1.7 2008/06/16 17:06:35 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/Sacado_Traits.hpp,v $ 
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 namespace Sacado {
00055 
00057 
00061   template <typename A, typename B> struct Promote {};
00062 
00064   template <typename A> struct Promote<A,A> {
00065     typedef A type;
00066   };
00067 
00069 #define SACADO_PROMOTE_SPECIALIZATION(type1,type2,type3) \
00070   template <> struct Promote< type1, type2 > {       \
00071     typedef type3 type;                        \
00072   };                 \
00073   template <> struct Promote< type2, type1 > {       \
00074     typedef type3 type;                  \
00075   };
00076 
00077   SACADO_PROMOTE_SPECIALIZATION(double,float,double)
00078   SACADO_PROMOTE_SPECIALIZATION(double,long,double)
00079   SACADO_PROMOTE_SPECIALIZATION(double,int,double)
00080   SACADO_PROMOTE_SPECIALIZATION(float,long,float)
00081   SACADO_PROMOTE_SPECIALIZATION(float,int,float)
00082 
00083 #undef SACADO_PROMOTE_SPECIALIZATION
00084 
00086 
00090   template <typename T> struct ScalarType {};
00091 
00093 
00097   template <typename T> struct ValueType {};
00098 
00100 
00104   template <typename T> struct ScalarValueType {};
00105 
00107 
00111   template <typename T> struct IsADType {};
00112 
00114 
00118   template <typename T> struct IsScalarType {};
00119 
00121 
00124   template <typename T> struct Value {};
00125 
00127   template <typename T> struct MarkConstant {
00128     static void eval(T& x) {}
00129   };
00130 
00132 #define SACADO_BUILTIN_SPECIALIZATION(t)                  \
00133   template <> struct ScalarType< t > {              \
00134     typedef t type;                 \
00135   };                                                      \
00136   template <> struct ValueType< t > {             \
00137     typedef t type;                 \
00138   };                                                      \
00139   template <> struct ScalarValueType< t > {     \
00140     typedef t type;                 \
00141   };                                                      \
00142   template <> struct IsADType< t > {              \
00143     static const bool value = false;              \
00144   };                                                      \
00145   template <> struct IsScalarType< t > {            \
00146     static const bool value = true;             \
00147   };                                                      \
00148   template <> struct Value< t > {             \
00149     static const t& eval(const t& x) { return x; }        \
00150   };
00151 
00152   SACADO_BUILTIN_SPECIALIZATION(char)
00153   SACADO_BUILTIN_SPECIALIZATION(float)
00154   SACADO_BUILTIN_SPECIALIZATION(double)
00155   SACADO_BUILTIN_SPECIALIZATION(int)
00156   SACADO_BUILTIN_SPECIALIZATION(unsigned int)
00157   SACADO_BUILTIN_SPECIALIZATION(long)
00158   SACADO_BUILTIN_SPECIALIZATION(unsigned long)
00159   SACADO_BUILTIN_SPECIALIZATION(bool)
00160 
00161 #undef SACADO_BUILTIN_SPECIALIZATION
00162 
00163 } // namespace Sacado
00164 
00165 #endif // SACADO_TRAITS_HPP

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