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 00040 namespace Teuchos { 00041 00042 00050 std::string demangleName( const std::string &mangledName ); 00051 00052 00057 template<typename T> 00058 std::string typeName( const T &t ) 00059 { 00060 return demangleName(typeid(t).name()); 00061 } 00062 00063 00068 template<typename T> 00069 class TypeNameTraits { 00070 public: 00072 static std::string name() 00073 { 00074 return demangleName(typeid(T).name()); 00075 } 00077 static std::string concreteName( T& t ) 00078 { 00079 return demangleName(typeid(t).name()); 00080 } 00081 }; 00082 00083 00084 #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \ 00085 template<> \ 00086 class TypeNameTraits<TYPE> { \ 00087 public: \ 00088 static std::string name() { return (#TYPE); } \ 00089 static std::string concreteName( const TYPE& t2 ) { (void)t2; return name(); } \ 00090 } \ 00091 00092 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(bool); 00093 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(char); 00094 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(int); 00095 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(short int); 00096 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(long int); 00097 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(float); 00098 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(double); 00099 00100 00101 template<typename T> 00102 class TypeNameTraits<T*> { 00103 public: 00104 typedef T* T_ptr; 00105 static std::string name() { return TypeNameTraits<T>::name() + "*"; } 00106 static std::string concreteName( T_ptr& /*t2*/ ) { return name(); } 00107 }; 00108 00109 00110 template<> 00111 class TypeNameTraits<std::string> { 00112 public: 00113 static std::string name() { return "string"; } 00114 static std::string concreteName( const std::string& /*t2*/ ) 00115 { return name(); } 00116 }; 00117 00118 00119 template<> 00120 class TypeNameTraits<void*> { 00121 public: 00122 static std::string name() { return "void*"; } 00123 static std::string concreteName( const std::string& t2 ) 00124 { (void)t2; return 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() 00135 { return "complex<"+TypeNameTraits<T>::name()+">"; } 00136 static std::string concreteName( const std::complex<T>& /*t2*/ ) 00137 { return name(); } 00138 }; 00139 00140 00141 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX) 00142 00143 00144 } // namespace Teuchos 00145 00146 00147 #endif // _TEUCHOS_TYPE_NAME_TRAITS_HPP_