PhoenixGenerator  2.2.0
Set of tools to generate code
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
8
13
16
17
18// Get the header file to include for a given type
19PString 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
70void 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
PString get_nanobind_include(const PString &type)
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
virtual void headerExtraInclude(std::set< std::string > &setInclude, const PClassConfig &classConfig, const GeneratorMode &mode) const
Add extra include in header.
virtual ~NanobindTraitInclude()
Destructor of NanobindTraitInclude.
NanobindTraitInclude()
Constructor of NanobindTraitInclude.
Class to describe a basic class.
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
All the genertor modes.