Skip to content
Snippets Groups Projects
classname.hh 1.39 KiB
Newer Older
  • Learn to ignore specific revisions
  • // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
    // vi: set et ts=4 sw=2 sts=2:
    #ifndef DUNE_CLASSNAME_HH
    #define DUNE_CLASSNAME_HH
    
    /** \file
     * \brief A free function to provide the demangled class name
    
     *        of a given object or type as a string
    
    #include <string>
    #include <typeinfo>
    
    
    #endif // #if HAVE_CXA_DEMANGLE
    
      /** \brief Provide the demangled class name of a type T as a string */
    
        typedef typename std::remove_reference<T>::type TR;
        std::string className = typeid( TR ).name();
    
        char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status );
        if( demangled )
        {
          className = demangled;
          std::free( demangled );
        }
    
    #endif // #if HAVE_CXA_DEMANGLE
    
        if (std::is_const<TR>::value)
            className += " const";
        if (std::is_volatile<TR>::value)
            className += " volatile";
        if (std::is_lvalue_reference<T>::value)
            className += "&";
        else if (std::is_rvalue_reference<T>::value)
            className += "&&";
    
      /** \brief Provide the demangled class name of a given object as a string */
    
      std::string className ( T& )