exception.cpp
Go to the documentation of this file.
1 #include <pybind11/pybind11.h>
2 #include <pybind11/stl.h>
3 
4 #include <exception>
5 #include <functional>
6 #include <sstream> // __str__
7 #include <string>
8 
9 #ifndef BINDER_PYBIND11_TYPE_CASTER
10 #define BINDER_PYBIND11_TYPE_CASTER
11 PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
12 PYBIND11_DECLARE_HOLDER_TYPE(T, T*)
13 PYBIND11_MAKE_OPAQUE(std::shared_ptr<void>)
14 #endif
15 
16 // std::exception file:bits/exception.h line:61
17 struct PyCallBack_std_exception : public std::exception
18 {
19  using std::exception::exception;
20 
21  const char* what() const throw() override
22  {
23  pybind11::gil_scoped_acquire gil;
24  pybind11::function overload = pybind11::get_overload(
25  static_cast<const std::exception*>(this), "what");
26  if (overload)
27  {
28  auto o =
29  overload.operator()<pybind11::return_value_policy::reference>();
30  if (pybind11::detail::cast_is_temporary_value_reference<
31  const char*>::value)
32  {
33 // pybind11 <=2.4: overload_caster_t, otherwise: override_caster_t
34 #if (PYBIND11_MAJOR_VERSION == 2 && PYBIND11_MINOR_VERSION <= 4)
35  static pybind11::detail::overload_caster_t<const char*> caster;
36 #else
37  static pybind11::detail::override_caster_t<const char*> caster;
38 #endif
39  return pybind11::detail::cast_ref<const char*>(
40  std::move(o), caster);
41  }
42  else
43  return pybind11::detail::cast_safe<const char*>(std::move(o));
44  }
45  return exception::what();
46  }
47 };
48 
50  std::function<pybind11::module&(std::string const& namespace_)>& M)
51 {
52  { // std::exception file:bits/exception.h line:61
53  pybind11::class_<
54  std::exception, std::shared_ptr<std::exception>,
56  cl(M("std"), "exception", "");
57  cl.def(pybind11::init(
58  []() { return new std::exception(); },
59  []() { return new PyCallBack_std_exception(); }));
60  cl.def(pybind11::init([](PyCallBack_std_exception const& o) {
61  return new PyCallBack_std_exception(o);
62  }));
63  cl.def(pybind11::init(
64  [](std::exception const& o) { return new std::exception(o); }));
65  cl.def(
66  "assign",
67  (class std::exception &
68  (std::exception::*)(const class std::exception&)) &
69  std::exception::operator=,
70  "C++: std::exception::operator=(const class std::exception &) --> "
71  "class std::exception &",
72  pybind11::return_value_policy::automatic, pybind11::arg(""));
73  cl.def(
74  "what",
75  (const char* (std::exception::*)() const) & std::exception::what,
76  "C++: std::exception::what() const --> const char *",
77  pybind11::return_value_policy::automatic);
78  }
79 }
const char * what() const override
Definition: exception.cpp:21
void bind_std_exception(std::function< pybind11::module &(std::string const &namespace_)> &M)
Definition: exception.cpp:49


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:20