2024-08-11 16:19:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <pybind11/pybind11.h>
|
|
|
|
|
|
|
|
#include "test_cpp_transporter_traveler_type.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace pybind11_tests {
|
|
|
|
namespace test_cpp_transporter {
|
|
|
|
|
|
|
|
namespace py = pybind11;
|
|
|
|
|
|
|
|
inline void wrap_traveler(py::module_ m) {
|
|
|
|
py::class_<Traveler>(m, "Traveler")
|
|
|
|
.def(py::init<std::string>())
|
|
|
|
.def("__cpp_transporter__",
|
|
|
|
[](py::handle self,
|
2024-08-11 20:30:08 +00:00
|
|
|
const py::str & /*cpp_abi_code*/,
|
|
|
|
const py::str & /*cpp_typeid_name*/,
|
|
|
|
const py::str &pointer_kind) {
|
2024-08-11 16:19:51 +00:00
|
|
|
auto pointer_kind_cpp = pointer_kind.cast<std::string>();
|
|
|
|
if (pointer_kind_cpp != "raw_pointer_ephemeral") {
|
|
|
|
throw std::runtime_error("Unknown pointer_kind: \"" + pointer_kind_cpp
|
|
|
|
+ "\"");
|
|
|
|
}
|
|
|
|
auto *self_cpp_ptr = py::cast<Traveler *>(self);
|
|
|
|
return py::capsule(static_cast<void *>(self_cpp_ptr), typeid(Traveler).name());
|
|
|
|
})
|
|
|
|
.def_readwrite("luggage", &Traveler::luggage);
|
|
|
|
|
|
|
|
m.def("get_luggage", [](const Traveler &person) { return person.luggage; });
|
2024-08-25 21:28:34 +00:00
|
|
|
}
|
2024-08-11 16:19:51 +00:00
|
|
|
|
|
|
|
} // namespace test_cpp_transporter
|
|
|
|
} // namespace pybind11_tests
|