test_cpp_conduit_traveler_bindings.h
Go to the documentation of this file.
1 // Copyright (c) 2024 The pybind Community.
2 
3 #pragma once
4 
5 #include <pybind11/pybind11.h>
6 
8 
9 #include <string>
10 
11 namespace pybind11_tests {
12 namespace test_cpp_conduit {
13 
14 namespace py = pybind11;
15 
16 inline void wrap_traveler(py::module_ m) {
17  py::class_<Traveler>(m, "Traveler")
18  .def(py::init<std::string>())
19  .def_readwrite("luggage", &Traveler::luggage)
20  // See issue #3788:
21  .def("__getattr__", [](const Traveler &self, const std::string &key) {
22  return "Traveler GetAttr: " + key + " luggage: " + self.luggage;
23  });
24 
25  m.def("get_luggage", [](const Traveler &person) { return person.luggage; });
26 
27  py::class_<PremiumTraveler, Traveler>(m, "PremiumTraveler")
28  .def(py::init<std::string, int>())
29  .def_readwrite("points", &PremiumTraveler::points)
30  // See issue #3788:
31  .def("__getattr__", [](const PremiumTraveler &self, const std::string &key) {
32  return "PremiumTraveler GetAttr: " + key + " points: " + std::to_string(self.points);
33  });
34 
35  m.def("get_points", [](const PremiumTraveler &person) { return person.points; });
36 }
37 
38 inline void wrap_lonely_traveler(py::module_ m) {
39  py::class_<LonelyTraveler>(std::move(m), "LonelyTraveler");
40 }
41 
42 inline void wrap_very_lonely_traveler(py::module_ m) {
43  py::class_<VeryLonelyTraveler, LonelyTraveler>(std::move(m), "VeryLonelyTraveler");
44 }
45 
46 } // namespace test_cpp_conduit
47 } // namespace pybind11_tests
pybind11_tests::test_cpp_conduit::Traveler::luggage
std::string luggage
Definition: test_cpp_conduit_traveler_types.h:12
pybind11_tests::test_cpp_conduit::PremiumTraveler::points
int points
Definition: test_cpp_conduit_traveler_types.h:18
pybind11_tests::test_cpp_conduit::Traveler
Definition: test_cpp_conduit_traveler_types.h:10
pybind11_tests::test_cpp_conduit::wrap_traveler
void wrap_traveler(py::module_ m)
Definition: test_cpp_conduit_traveler_bindings.h:16
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
test_cpp_conduit_traveler_types.h
pybind11_tests
Definition: exo_planet_pybind11.cpp:10
pybind11_tests::test_cpp_conduit::PremiumTraveler
Definition: test_cpp_conduit_traveler_types.h:15
key
const gtsam::Symbol key('X', 0)
pybind11.h
pybind11_tests::test_cpp_conduit::wrap_lonely_traveler
void wrap_lonely_traveler(py::module_ m)
Definition: test_cpp_conduit_traveler_bindings.h:38
pybind11_tests::test_cpp_conduit::wrap_very_lonely_traveler
void wrap_very_lonely_traveler(py::module_ m)
Definition: test_cpp_conduit_traveler_bindings.h:42
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
test_cpp_conduit
Definition: test_cpp_conduit.py:1


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:06:17