PhoenixGenerator
2.8.0
Set of tools to generate code
Toggle main menu visibility
Loading...
Searching...
No Matches
NanobindTraitInclude.cpp
Go to the documentation of this file.
1
/***************************************
2
Auteur : Thibaut Oprinsen
3
Mail : thibaut.oprinsen@lapp.in2p3.fr
4
Licence : CeCILL-C
5
****************************************/
6
7
#include "
NanobindTraitInclude.h
"
8
10
NanobindTraitInclude::NanobindTraitInclude
()
11
:
PAbstractNanobindTraitBackend
()
12
{}
13
15
NanobindTraitInclude::~NanobindTraitInclude
(){}
16
17
18
// Get the header file to include for a given type
19
PString
get_nanobind_include
(
const
PString& type) {
20
static
const
std::map<PString, PString> type_to_header = {
21
{
"std::array"
,
"<nanobind/stl/array.h>"
},
22
{
"std::chrono"
,
"<nanobind/stl/chrono.h>"
},
23
{
"std::complex"
,
"<nanobind/stl/complex.h>"
},
24
{
"std::filesystem"
,
"<nanobind/stl/filesystem.h>"
},
25
{
"std::function"
,
"<nanobind/stl/function.h>"
},
26
{
"std::list"
,
"<nanobind/stl/list.h>"
},
27
{
"std::map"
,
"<nanobind/stl/map.h>"
},
28
{
"std::optional"
,
"<nanobind/stl/optional.h>"
},
29
{
"std::pair"
,
"<nanobind/stl/pair.h>"
},
30
{
"std::set"
,
"<nanobind/stl/set.h>"
},
31
{
"std::string"
,
"<nanobind/stl/string.h>"
},
32
{
"std::string_view"
,
"<nanobind/stl/string_view.h>"
},
33
{
"std::wstring"
,
"<nanobind/stl/wstring.h>"
},
34
{
"std::tuple"
,
"<nanobind/stl/tuple.h>"
},
35
{
"std::shared_ptr"
,
"<nanobind/stl/shared_ptr.h>"
},
36
{
"std::unique_ptr"
,
"<nanobind/stl/unique_ptr.h>"
},
37
{
"std::unordered_set"
,
"<nanobind/stl/unordered_set.h>"
},
38
{
"std::unordered_map"
,
"<nanobind/stl/unordered_map.h>"
},
39
{
"std::variant"
,
"<nanobind/stl/variant.h>"
},
40
{
"std::vector"
,
"<nanobind/stl/vector.h>"
},
41
{
"nb::ndarray"
,
"<nanobind/ndarray.h>"
},
42
{
"Eigen::Matrix"
,
"<nanobind/eigen/dense.h>"
},
43
{
"Eigen::Array"
,
"<nanobind/eigen/dense.h>"
},
44
{
"Eigen::Ref"
,
"<nanobind/eigen/dense.h>"
},
45
{
"Eigen::Map"
,
"<nanobind/eigen/dense.h>"
},
46
{
"Eigen::SparseMatrix"
,
"<nanobind/eigen/sparse.h>"
}
47
};
48
49
typedef
std::map<PString, PString>::const_iterator MapIt;
50
for
(MapIt it = type_to_header.begin(); it != type_to_header.end(); ++it) {
51
// Search if the type starts with the key + '<' (for templates)
52
PString key = it->first +
"<"
;
53
if
(type.substr(0, key.size()) == key) {
54
return
it->second;
55
}
56
// Or if the type is exactly the key (for non-templates)
57
if
(type == it->first) {
58
return
it->second;
59
}
60
}
61
62
return
""
;
63
}
64
66
70
void
NanobindTraitInclude::headerExtraInclude
(std::set<std::string> & setInclude,
const
PClassConfig
& classConfig,
const
GeneratorMode
& mode)
const
{
71
const
PVecClassAttribute
& listAttr(classConfig.
getListAttribute
());
72
for
(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
73
PString header =
get_nanobind_include
(it->getType());
74
if
(header !=
""
){
75
setInclude.insert(
"#include "
+ header);
76
}
77
}
78
}
79
get_nanobind_include
PString get_nanobind_include(const PString &type)
Definition
NanobindTraitInclude.cpp:19
NanobindTraitInclude.h
PVecClassAttribute
std::vector< PClassAttribute > PVecClassAttribute
Definition
PDataConfig.h:13
NanobindTraitInclude::headerExtraInclude
virtual void headerExtraInclude(std::set< std::string > &setInclude, const PClassConfig &classConfig, const GeneratorMode &mode) const
Add extra include in header.
Definition
NanobindTraitInclude.cpp:70
NanobindTraitInclude::~NanobindTraitInclude
virtual ~NanobindTraitInclude()
Destructor of NanobindTraitInclude.
Definition
NanobindTraitInclude.cpp:15
NanobindTraitInclude::NanobindTraitInclude
NanobindTraitInclude()
Constructor of NanobindTraitInclude.
Definition
NanobindTraitInclude.cpp:10
PAbstractNanobindTraitBackend::PAbstractNanobindTraitBackend
PAbstractNanobindTraitBackend()
Definition
PAbstractTraitBackend.h:67
PClassConfig
Class to describe a basic class.
Definition
PClassConfig.h:14
PClassConfig::getListAttribute
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
Definition
PClassConfig.cpp:167
GeneratorMode
All the genertor modes.
Definition
GeneratorMode.h:27
src
TraitBackEnd
Nanobind
NanobindTraitInclude
NanobindTraitInclude.cpp
Generated by
1.17.0