|
8 | 8 | namespacepy= pybind11; |
9 | 9 |
|
10 | 10 |
|
11 | | -voiddefine_parsedate(py::module_& m) |
| 11 | +// Funzione di esempio che accetta un array di stringhe in stile C |
| 12 | +externvoidset_dateformats(constchar **table); |
| 13 | + |
| 14 | +// Converte uno std::vector<char*> in un array di stringhe in stile C |
| 15 | +voidset_dateformats_wrapper(const std::vector<std::string>& formats) { |
| 16 | + std::vector<constchar*> c_formats; |
| 17 | +for (constauto& format : formats) { |
| 18 | + c_formats.push_back(format.c_str()); |
| 19 | + } |
| 20 | + c_formats.push_back(nullptr);// Aggiunge un terminatore nullo |
| 21 | + |
| 22 | +set_dateformats(c_formats.data()); |
| 23 | +} |
| 24 | + |
| 25 | +// Funzione di esempio che restituisce un array di stringhe in stile C |
| 26 | +externconstchar **get_dateformats(void); |
| 27 | + |
| 28 | +// Converte l'array di stringhe in stile C in uno std::vector<char*> |
| 29 | +std::vector<char*>get_dateformats_wrapper() { |
| 30 | +constchar **dateformats =get_dateformats(); |
| 31 | + std::vector<char*> result; |
| 32 | + |
| 33 | +// Assume che la fine dell'array sia segnata da un puntatore nullo |
| 34 | +for (size_t i =0; dateformats[i] !=nullptr; ++i) { |
| 35 | + result.push_back(const_cast<char*>(dateformats[i])); |
| 36 | + } |
| 37 | + |
| 38 | +return result; |
| 39 | +} |
| 40 | + |
| 41 | +PYBIND11_MODULE(parsedate, m) |
12 | 42 | { |
13 | 43 | m.def("parsedate", &parsedate,"",py::arg("dateString"),py::arg("now")); |
14 | 44 |
|
15 | 45 | m.def("parsedate_etc", &parsedate_etc,"",py::arg("dateString"),py::arg("now"),py::arg("_storedFlags")); |
16 | 46 |
|
17 | | -m.def("set_dateformats", &set_dateformats,"",py::arg("table")); |
| 47 | +m.def("set_dateformats", &set_dateformats_wrapper,"",py::arg("table")); |
18 | 48 |
|
19 | | -m.def("get_dateformats", &get_dateformats,"",py::arg("")); |
| 49 | +m.def("get_dateformats", &get_dateformats_wrapper,"", py::return_value_policy::take_ownership); |
20 | 50 |
|
21 | 51 | } |