cppyabm
1.0.17
An agent-based library to integrate C++ and Python
examples
Cppy
build
_deps
pybind11-src
include
pybind11
detail
typeid.h
Go to the documentation of this file.
1
/*
2
pybind11/detail/typeid.h: Compiler-independent access to type identifiers
3
4
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
6
All rights reserved. Use of this source code is governed by a
7
BSD-style license that can be found in the LICENSE file.
8
*/
9
10
#pragma once
11
12
#include <cstdio>
13
#include <cstdlib>
14
15
#if defined(__GNUG__)
16
#include <cxxabi.h>
17
#endif
18
19
#include "
common.h
"
20
21
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
22
PYBIND11_NAMESPACE_BEGIN
(detail)
23
/// Erase all occurrences of a substring
24
inline
void
erase_all
(std::
string
&
string
, const std::
string
&search) {
25
for
(
size_t
pos = 0;;) {
26
pos =
string
.find(search, pos);
27
if
(pos == std::string::npos)
break
;
28
string
.erase(pos, search.length());
29
}
30
}
31
32
PYBIND11_NOINLINE
inline
void
clean_type_id
(std::string &
name
) {
33
#if defined(__GNUG__)
34
int
status = 0;
35
std::unique_ptr<char, void (*)(
void
*)> res {
36
abi::__cxa_demangle(
name
.c_str(),
nullptr
,
nullptr
, &status), std::free };
37
if
(status == 0)
38
name
= res.get();
39
#else
40
detail::erase_all
(
name
,
"class "
);
41
detail::erase_all
(
name
,
"struct "
);
42
detail::erase_all
(
name
,
"enum "
);
43
#endif
44
detail::erase_all
(
name
,
"pybind11::"
);
45
}
46
PYBIND11_NAMESPACE_END
(detail)
47
48
/// Return a string representation of a C++ type
49
template
<
typename
T>
static
std::string type_id() {
50
std::string
name
(
typeid
(T).
name
());
51
detail::clean_type_id
(
name
);
52
return
name
;
53
}
54
55
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
common.h
name
Annotation for function names.
Definition:
attr.h:36
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition:
common.h:16
erase_all
void erase_all(std::string &string, const std::string &search)
Erase all occurrences of a substring.
Definition:
typeid.h:24
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition:
common.h:17
PYBIND11_NAMESPACE
#define PYBIND11_NAMESPACE
Definition:
common.h:26
clean_type_id
PYBIND11_NOINLINE void clean_type_id(std::string &name)
Definition:
typeid.h:32
PYBIND11_NOINLINE
#define PYBIND11_NOINLINE
Definition:
common.h:88
Generated by
1.8.19