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 =
25  pybind11::get_overload(static_cast<const std::exception*>(this), "what");
26  if (overload)
27  {
28  auto o = overload.operator()<pybind11::return_value_policy::reference>();
29  if (pybind11::detail::cast_is_temporary_value_reference<const char*>::value)
30  {
31 // pybind11 <=2.4: overload_caster_t, otherwise: override_caster_t
32 #if (PYBIND11_MAJOR_VERSION == 2 && PYBIND11_MINOR_VERSION <= 4)
33  static pybind11::detail::overload_caster_t<const char*> caster;
34 #else
35  static pybind11::detail::override_caster_t<const char*> caster;
36 #endif
37  return pybind11::detail::cast_ref<const char*>(std::move(o), caster);
38  }
39  else
40  return pybind11::detail::cast_safe<const char*>(std::move(o));
41  }
42  return exception::what();
43  }
44 };
45 
46 void bind_std_exception(std::function<pybind11::module&(std::string const& namespace_)>& M)
47 {
48  { // std::exception file:bits/exception.h line:61
49  pybind11::class_<std::exception, std::shared_ptr<std::exception>, PyCallBack_std_exception>
50  cl(M("std"), "exception", "");
51  cl.def(pybind11::init(
52  []() { return new std::exception(); },
53  []() { return new PyCallBack_std_exception(); }));
54  cl.def(pybind11::init([](PyCallBack_std_exception const& o)
55  { return new PyCallBack_std_exception(o); }));
56  cl.def(pybind11::init([](std::exception const& o) { return new std::exception(o); }));
57  cl.def(
58  "assign",
59  (class std::exception & (std::exception::*)(const class std::exception&)) &
60  std::exception::operator=,
61  "C++: std::exception::operator=(const class std::exception &) --> "
62  "class std::exception &",
63  pybind11::return_value_policy::automatic, pybind11::arg(""));
64  cl.def(
65  "what", (const char* (std::exception::*)() const) & std::exception::what,
66  "C++: std::exception::what() const --> const char *",
67  pybind11::return_value_policy::automatic);
68  }
69 }
PyCallBack_std_exception::what
const char * what() const override
Definition: exception.cpp:21
bind_std_exception
void bind_std_exception(std::function< pybind11::module &(std::string const &namespace_)> &M)
Definition: exception.cpp:46
PyCallBack_std_exception
Definition: exception.cpp:17


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:07