Teuchos_TypeNameTraits.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 #ifndef _TEUCHOS_TYPE_NAME_TRAITS_HPP_
00030 #define _TEUCHOS_TYPE_NAME_TRAITS_HPP_
00031 
00037 #include "Teuchos_ConstTypeTraits.hpp"
00038 
00039 #if defined(__IBMCPP__) && __IBMCPP__ < 900
00040 # define TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
00041 #endif
00042 
00043 namespace  Teuchos {
00044 
00045 
00053 TEUCHOS_LIB_DLL_EXPORT std::string demangleName( const std::string &mangledName );
00054 
00055 
00060 template<typename T>
00061 class TypeNameTraits {
00062 public:
00064   static std::string name()
00065     {
00066       return demangleName(typeid(T).name());
00067     }
00069 #ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
00070   static std::string concreteName( const T& t )
00071 #else
00072   // the IBM compilers on AIX have a problem with const
00073   static std::string concreteName( T t )
00074 #endif
00075     {
00076       return demangleName(typeid(t).name());
00077     }
00078 };
00079 
00080 
00090 template<typename T>
00091 std::string typeName( const T &t )
00092 {
00093   typedef typename ConstTypeTraits<T>::NonConstType ncT;
00094 #ifndef TEUCHOS_TYPE_NAME_TRAITS_OLD_IBM
00095   return TypeNameTraits<ncT>::concreteName(t);
00096 #else
00097   // You can't pass general objects to AIX by value as above.  This means that
00098   // you will not get the concrete name printed on AIX but that is life on
00099   // such compilers.
00100   return TypeNameTraits<ncT>::name();
00101 #endif
00102 }
00103 
00104 
00113 template<typename T>
00114 std::string concreteTypeName( const T &t )
00115 {
00116   typedef typename ConstTypeTraits<T>::NonConstType ncT;
00117   return TypeNameTraits<ncT>::concreteName(t);
00118 }
00119 
00120 
00121 #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \
00122 template<> \
00123 class TEUCHOS_LIB_DLL_EXPORT TypeNameTraits<TYPE> { \
00124 public: \
00125   static std::string name() { return (#TYPE); } \
00126   static std::string concreteName(const TYPE&) { return name(); } \
00127 } \
00128 
00129 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(bool);
00130 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(char);
00131 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(int);
00132 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(short int);
00133 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(long int);
00134 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(float);
00135 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(double);
00136 
00137 
00138 template<typename T>
00139 class TEUCHOS_LIB_DLL_EXPORT TypeNameTraits<T*> {
00140 public:
00141   typedef T* T_ptr;
00142   static std::string name() { return TypeNameTraits<T>::name() + "*"; }
00143   static std::string concreteName(T_ptr) { return name(); }
00144 };
00145 
00146 
00147 template<>
00148 class TEUCHOS_LIB_DLL_EXPORT TypeNameTraits<std::string> {
00149 public:
00150   static std::string name() { return "string"; }
00151   static std::string concreteName(const std::string&)
00152     { return name(); }
00153 };
00154 
00155 
00156 template<>
00157 class TEUCHOS_LIB_DLL_EXPORT TypeNameTraits<void*> {
00158 public:
00159   static std::string name() { return "void*"; }
00160   static std::string concreteName(const std::string&) { return name(); }
00161 };
00162 
00163 
00164 #ifdef HAVE_TEUCHOS_COMPLEX
00165 
00166 
00167 template<typename T>
00168 class TEUCHOS_LIB_DLL_EXPORT TypeNameTraits<std::complex<T> > {
00169 public:
00170   static std::string name()
00171     { return "complex<"+TypeNameTraits<T>::name()+">"; }
00172   static std::string concreteName(const std::complex<T>&)
00173     { return name(); }
00174 };
00175 
00176 
00177 #endif // HAVE_TEUCHOS_COMPLEX
00178  
00179 
00180 } // namespace Teuchos
00181 
00182 
00183 #endif // _TEUCHOS_TYPE_NAME_TRAITS_HPP_

Generated on Tue Jul 13 09:23:00 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7