enable_shared_from_this.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright David Abrahams 2002.
  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/call_method.hpp>
  8. #include <boost/python/extract.hpp>
  9. #include <boost/python/def.hpp>
  10. #include <boost/enable_shared_from_this.hpp>
  11. #include <boost/shared_ptr.hpp>
  12. #include "test_class.hpp"
  13. #include <memory>
  14. using namespace boost::python;
  15. using boost::shared_ptr;
  16. class Test;
  17. typedef shared_ptr<Test> TestPtr;
  18. class Test : public boost::enable_shared_from_this<Test> {
  19. public:
  20. static TestPtr construct() {
  21. return TestPtr(new Test);
  22. }
  23. void act() {
  24. TestPtr kungFuDeathGrip(shared_from_this());
  25. }
  26. void take(TestPtr t) {
  27. }
  28. };
  29. BOOST_PYTHON_MODULE(enable_shared_from_this_ext)
  30. {
  31. class_<Test, TestPtr, boost::noncopyable>("Test")
  32. .def("construct", &Test::construct).staticmethod("construct")
  33. .def("act", &Test::act)
  34. .def("take", &Test::take)
  35. ;
  36. }
  37. #include "module_tail.cpp"