ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
demangle.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2
3#ifndef TTG_DEMANGLE_H_INCLUDED
4#define TTG_DEMANGLE_H_INCLUDED
5
6#include <cxxabi.h>
7#include <string>
8#include <typeinfo>
9#include <memory>
10#define HAVE_CXA_DEMANGLE
11#ifdef HAVE_CXA_DEMANGLE
12
13namespace ttg {
14 namespace detail {
15 template <typename T>
16 static std::string demangled_type_name(T *x = nullptr) {
17 const char *name = nullptr;
18 if constexpr (std::is_void_v<T>)
19 name = "void";
20 else
21 name = (x != nullptr) ? typeid(*x).name() : // this works for polymorphic types
22 typeid(T).name();
23 static size_t buf_size = 1024;
24 static std::unique_ptr<char, decltype(std::free) *> buf{reinterpret_cast<char *>(malloc(sizeof(char) * buf_size)),
25 std::free};
26 int status;
27 char *res = abi::__cxa_demangle(name, buf.get(), &buf_size, &status);
28 if (status != 0 || res == nullptr) {
29 return name;
30 } else {
31 if (res != buf.get()) {
32 buf.release();
33 buf = std::unique_ptr<char, decltype(std::free) *>{res, std::free};
34 }
35 return res;
36 }
37 }
38#else
39template <typename T>
40std::string demangled_type_name(T* x = nullptr) {
41 const char* name = (x != nullptr) ? typeid(*x).name() : // this works for polymorphic types
42 typeid(T).name();
43 return std::string(name);
44}
45#endif
46 } // namespace detail
47} // namespace ttg
48
49#endif // TTG_DEMANGLE_H_INCLUDED
top-level TTG namespace contains runtime-neutral functionality
Definition keymap.h:9