Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
name_demangling.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_BASE_NAME_DEMANGLING_HPP_
34#define GKO_PUBLIC_CORE_BASE_NAME_DEMANGLING_HPP_
35
36
37#include <ginkgo/config.hpp>
38
39
40#ifdef GKO_HAVE_CXXABI_H
41#include <cxxabi.h>
42#endif // GKO_HAVE_CXXABI_H
43
44
45#include <memory>
46#include <string>
47
48
49namespace gko {
50
56namespace name_demangling {
57
58
59inline std::string get_type_name(const std::type_info& tinfo)
60{
61#ifdef GKO_HAVE_CXXABI_H
62 int status{};
63 const std::string name(
64 std::unique_ptr<char[], void (*)(void*)>(
65 abi::__cxa_demangle(tinfo.name(), nullptr, nullptr, &status),
66 std::free)
67 .get());
68 if (!status)
69 return name;
70 else
71#endif // GKO_HAVE_CXXABI_H
72 return std::string(tinfo.name());
73}
74
75
84template <typename T>
85std::string get_static_type(const T&)
86{
87 return get_type_name(typeid(T));
88}
89
90
99template <typename T>
100std::string get_dynamic_type(const T& t)
101{
102 return get_type_name(typeid(t));
103}
104
105
106namespace detail {
107
108
109template <typename T>
110std::string get_enclosing_scope(const T&)
111{
112 auto name = get_type_name(typeid(T));
113 auto found = name.rfind(':');
114 if (found == std::string::npos) {
115 return name;
116 }
117 return name.substr(0, found - 1);
118}
119
120
121} // namespace detail
122
123
137#define GKO_FUNCTION_NAME gko::name_demangling::get_enclosing_scope([] {})
138
139
140} // namespace name_demangling
141} // namespace gko
142
143
144#endif // GKO_PUBLIC_CORE_BASE_NAME_DEMANGLING_HPP_
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:85
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:100
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803