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 #ifndef _TEUCHOS_TYPE_NAME_TRAITS_HPP_ 00030 #define _TEUCHOS_TYPE_NAME_TRAITS_HPP_ 00031 00037 #include "Teuchos_ConfigDefs.hpp" 00038 00039 #if defined(HAVE_GCC_ABI_DEMANGLE) && defined(HAVE_TEUCHOS_DEMANGLE) 00040 # include <cxxabi.h> 00041 #endif 00042 00043 #ifdef HAVE_TEUCHOS_ARPREC 00044 #include "mp/mpreal.h" 00045 #endif 00046 00047 #ifdef HAVE_TEUCHOS_GNU_MP 00048 #include "gmp.h" 00049 #include "gmpxx.h" 00050 #endif 00051 00052 00053 namespace Teuchos { 00054 00055 00063 std::string demangleName( const std::string &mangledName ); 00064 00065 00070 template<typename T> 00071 std::string typeName( const T &t ) 00072 { 00073 return demangleName(typeid(t).name()); 00074 } 00075 00081 template<typename T> 00082 class TypeNameTraits { 00083 public: 00084 static std::string name() 00085 { 00086 return demangleName(typeid(T).name()); 00087 } 00088 }; 00089 00090 00091 #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \ 00092 template<> \ 00093 class TypeNameTraits<TYPE> { \ 00094 public: \ 00095 static std::string name() { return (#TYPE); } \ 00096 } \ 00097 00098 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(bool); 00099 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(char); 00100 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(int); 00101 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(short int); 00102 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(long int); 00103 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(float); 00104 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(double); 00105 00106 00107 template<typename T> 00108 class TypeNameTraits<T*> { 00109 public: 00110 static std::string name() { return TypeNameTraits<T>::name() + "*"; } 00111 }; 00112 00113 00114 template<> 00115 class TypeNameTraits<std::string> { 00116 public: 00117 static std::string name() { return "string"; } 00118 }; 00119 00120 00121 template<typename T> 00122 class TypeNameTraits<std::vector<T> > { 00123 public: 00124 static std::string name() { return "vector<"+TypeNameTraits<T>::name()+">"; } 00125 }; 00126 00127 00128 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX) 00129 00130 00131 template<typename T> 00132 class TypeNameTraits<std::complex<T> > { 00133 public: 00134 static std::string name() { return "complex<"+TypeNameTraits<T>::name()+">"; } 00135 }; 00136 00137 00138 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX) 00139 00140 00141 } // namespace Teuchos 00142 00143 00144 #endif // _TEUCHOS_TYPE_NAME_TRAITS_HPP_
1.4.7