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