return_arg.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright David Abrahams and Nikolay Mladenov 2003.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/python/module.hpp>
  6. #include <boost/python/class.hpp>
  7. #include <boost/python/def.hpp>
  8. #include <boost/python/return_arg.hpp>
  9. struct Widget
  10. {
  11. Widget()
  12. : sensitive_(true)
  13. {}
  14. bool get_sensitive() const
  15. {
  16. return sensitive_;
  17. }
  18. void set_sensitive(bool s)
  19. {
  20. this->sensitive_ = s;
  21. }
  22. private:
  23. bool sensitive_;
  24. };
  25. struct Label : Widget
  26. {
  27. Label() {}
  28. std::string get_label() const
  29. {
  30. return label_;
  31. }
  32. void set_label(const std::string &l)
  33. {
  34. label_ = l;
  35. }
  36. private:
  37. std::string label_;
  38. };
  39. void return_arg_f(boost::python::object) {}
  40. using namespace boost::python;
  41. BOOST_PYTHON_MODULE(return_arg_ext)
  42. {
  43. class_<Widget>("Widget")
  44. .def("sensitive", &Widget::get_sensitive)
  45. .def("sensitive", &Widget::set_sensitive, return_self<>())
  46. ;
  47. class_<Label, bases<Widget> >("Label")
  48. .def("label", &Label::get_label)//,return_arg<0>()) //error(s)
  49. .def("label", &Label::set_label, return_self<>())
  50. ;
  51. def("return_arg", return_arg_f, return_arg<1>());
  52. }
  53. #include "module_tail.cpp"