CppUnit project page CppUnit home page

typename.h

Go to the documentation of this file.
00001 #ifndef CPPTL_TYPENAME_H_INCLUDED
00002 # define CPPTL_TYPENAME_H_INCLUDED
00003 
00004 # include <cpptl/forwards.h>
00005 # include <cpptl/conststring.h>
00006 # ifndef CPPTL_NO_RTTI
00007 #  include <cpptl/stringtools.h>
00008 #  include <typeinfo>
00009 # endif
00010 
00011 // AIX: demangle library
00012 // http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.vacpp7a.doc/proguide/ref/demangle.htm
00013 
00014 namespace CppTL {
00015 
00016 # ifndef CPPTL_NO_RTTI
00017    inline std::string CPPUT_API 
00018    demangleTypeInfoName( const std::type_info &type )
00019    {
00020       CppTL::ConstString typeName( type.name() );
00021       const int classKeywordLength = 6;
00022       size_type startIndex = 0;
00023       if ( typeName.substr( 0, classKeywordLength ) == "class " )
00024          startIndex = classKeywordLength;
00025       while ( startIndex < typeName.length()  &&  isDigit( typeName[startIndex] ) )
00026          ++startIndex;
00027       return typeName.substr(startIndex).str();
00028    }
00029 #endif
00030 
00031    template<class AType>
00032    std::string getTypeName( CppTL::Type<AType>, 
00033                             const char *hint )
00034    {
00035 # ifndef CPPTL_NO_RTTI
00036       return demangleTypeInfoName( typeid( AType ) );
00037 # else
00038       return hint;
00039 # endif
00040    }
00041 
00042 
00043    template<typename Object>
00044    std::string getObjectTypeName( const Object &object,
00045                                   const char *hint )
00046    {
00047 # ifndef CPPTL_NO_RTTI
00048       return demangleTypeInfoName( typeid(object) );
00049 # else
00050       return hint;
00051 # endif
00052    }
00053 
00054 } // namespace CppUT
00055 
00056 
00057 #endif // CPPTL_TYPENAME_H_INCLUDED

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers