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