Ginkgo  Generated from pipelines/1589998975 branch based on develop. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
name_demangling.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_BASE_NAME_DEMANGLING_HPP_
6 #define GKO_PUBLIC_CORE_BASE_NAME_DEMANGLING_HPP_
7 
8 
9 #include <ginkgo/config.hpp>
10 
11 
12 #ifdef GKO_HAVE_CXXABI_H
13 #include <cxxabi.h>
14 #endif // GKO_HAVE_CXXABI_H
15 
16 
17 #include <memory>
18 #include <string>
19 
20 
21 namespace gko {
22 
28 namespace name_demangling {
29 
30 
31 inline std::string get_type_name(const std::type_info& tinfo)
32 {
33 #ifdef GKO_HAVE_CXXABI_H
34  int status{};
35  const std::string name(
36  std::unique_ptr<char[], void (*)(void*)>(
37  abi::__cxa_demangle(tinfo.name(), nullptr, nullptr, &status),
38  std::free)
39  .get());
40  if (!status)
41  return name;
42  else
43 #endif // GKO_HAVE_CXXABI_H
44  return std::string(tinfo.name());
45 }
46 
47 
56 template <typename T>
57 std::string get_static_type(const T&)
58 {
59  return get_type_name(typeid(T));
60 }
61 
62 
71 template <typename T>
72 std::string get_dynamic_type(const T& t)
73 {
74  return get_type_name(typeid(t));
75 }
76 
77 
78 namespace detail {
79 
80 
81 template <typename T>
82 std::string get_enclosing_scope(const T&)
83 {
84  auto name = get_type_name(typeid(T));
85  auto found = name.rfind(':');
86  if (found == std::string::npos) {
87  return name;
88  }
89  return name.substr(0, found - 1);
90 }
91 
92 
93 } // namespace detail
94 
95 
109 #define GKO_FUNCTION_NAME gko::name_demangling::get_enclosing_scope([] {})
110 
111 
112 } // namespace name_demangling
113 } // namespace gko
114 
115 
116 #endif // GKO_PUBLIC_CORE_BASE_NAME_DEMANGLING_HPP_
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::name_demangling::get_static_type
std::string get_static_type(const T &)
This function uses name demangling facilities to get the name of the static type (T) of the object pa...
Definition: name_demangling.hpp:57
gko::name_demangling::get_dynamic_type
std::string get_dynamic_type(const T &t)
This function uses name demangling facilities to get the name of the dynamic type of the object passe...
Definition: name_demangling.hpp:72