TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
typeid_name.cpp
1// Copyright (c) 2013-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2013-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Olivier Parcollet, Nils Wentzell
19
20#include "./first_include.hpp"
21#include "./typeid_name.hpp"
22
23#include <boost/algorithm/string/erase.hpp>
24
25#include <sstream>
26#include <string>
27#include <typeinfo>
28
29#ifdef __GNUC__
30#include <cxxabi.h>
31#endif
32
33namespace triqs::utility {
34
35 std::string demangle(const char *name) {
36 std::stringstream fs;
37#ifdef __GNUC__
38 int status{};
39 char *demangled = abi::__cxa_demangle(name, nullptr, nullptr, &status);
40 if (!status) {
41 std::string res(demangled);
42 boost::erase_all(res, ", boost::tuples::null_type");
43 boost::erase_all(res, ", -1");
44 boost::erase_all(res, ", void");
45 fs << res;
46 free(demangled); // NOLINT
47 } else
48 fs << name;
49#else
50 fs << name;
51#endif
52 return fs.str();
53 }
54
55 std::string demangle(std::string const &name) { return demangle(name.c_str()); }
56
57 std::string get_name(std::type_info const &info) { return demangle(info.name()); }
58
59} // namespace triqs::utility
Compiler / platform glue and the dcomplex alias (must be included before any Boost header).
std::string demangle(const char *name)
Demangle a mangled C++ symbol name to a human-readable string.
std::string get_name(std::type_info const &info)
Demangle the name corresponding to an std::type_info.
Helper functions built around std::type_info.