| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Thibaut Oprinsen | ||
| 3 | Mail : thibaut.oprinsen@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "NanobindTraitInclude.h" | ||
| 8 | |||
| 9 | ///Constructor of NanobindTraitInclude | ||
| 10 | 1 | NanobindTraitInclude::NanobindTraitInclude() | |
| 11 | 1 | : PAbstractNanobindTraitBackend() | |
| 12 | 1 | {} | |
| 13 | |||
| 14 | ///Destructor of NanobindTraitInclude | ||
| 15 | 2 | NanobindTraitInclude::~NanobindTraitInclude(){} | |
| 16 | |||
| 17 | |||
| 18 | // Get the header file to include for a given type | ||
| 19 | 5 | 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 |
6/11✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→41) taken 4 times.
✓ Branch 2 (4→5) taken 1 times.
✗ Branch 3 (4→41) not taken.
✓ Branch 4 (33→34) taken 1 times.
✓ Branch 6 (38→39) taken 26 times.
✓ Branch 7 (38→40) taken 1 times.
✗ Branch 8 (76→77) not taken.
✗ Branch 9 (76→78) not taken.
✗ Branch 10 (85→86) not taken.
✗ Branch 11 (85→87) not taken.
|
33 | }; |
| 48 | |||
| 49 | typedef std::map<PString, PString>::const_iterator MapIt; | ||
| 50 |
2/2✓ Branch 0 (68→42) taken 113 times.
✓ Branch 1 (68→69) taken 2 times.
|
115 | 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 |
2/2✓ Branch 0 (43→44) taken 113 times.
✓ Branch 2 (44→45) taken 113 times.
|
113 | PString key = it->first + "<"; |
| 53 |
3/3✓ Branch 0 (47→48) taken 113 times.
✓ Branch 2 (50→51) taken 1 times.
✓ Branch 3 (50→54) taken 112 times.
|
113 | if(type.substr(0, key.size()) == key) { |
| 54 |
1/1✓ Branch 0 (52→53) taken 1 times.
|
1 | return it->second; |
| 55 | } | ||
| 56 | // Or if the type is exactly the key (for non-templates) | ||
| 57 |
2/2✓ Branch 0 (56→57) taken 2 times.
✓ Branch 1 (56→60) taken 110 times.
|
112 | if(type == it->first) { |
| 58 |
1/1✓ Branch 0 (58→59) taken 2 times.
|
2 | return it->second; |
| 59 | } | ||
| 60 | 113 | } | |
| 61 | |||
| 62 | 2 | return ""; | |
| 63 | 1 | } | |
| 64 | |||
| 65 | ///Add extra include in header | ||
| 66 | /** @param[out] setInclude : set of includes to be used in the generated code | ||
| 67 | * @param fs : stream to write to | ||
| 68 | * @param mode : generator mode | ||
| 69 | */ | ||
| 70 | 2 | void NanobindTraitInclude::headerExtraInclude(std::set<std::string> & setInclude, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 71 | 2 | const PVecClassAttribute & listAttr(classConfig.getListAttribute()); | |
| 72 |
2/2✓ Branch 0 (25→4) taken 5 times.
✓ Branch 1 (25→26) taken 2 times.
|
14 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 73 |
2/2✓ Branch 0 (6→7) taken 5 times.
✓ Branch 2 (7→8) taken 5 times.
|
5 | PString header = get_nanobind_include(it->getType()); |
| 74 |
3/3✓ Branch 0 (8→9) taken 5 times.
✓ Branch 2 (9→10) taken 3 times.
✓ Branch 3 (9→14) taken 2 times.
|
5 | if(header != ""){ |
| 75 |
2/2✓ Branch 0 (10→11) taken 3 times.
✓ Branch 2 (11→12) taken 3 times.
|
3 | setInclude.insert("#include " + header); |
| 76 | } | ||
| 77 | 5 | } | |
| 78 | 2 | } | |
| 79 | |||
| 80 |