1 // Copyright David Abrahams 2004. Distributed under the Boost 2 // Software License, Version 1.0. (See accompanying 3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 #include <boost/python/module.hpp> 5 #include <boost/python/def.hpp> 6 #include <boost/python/class.hpp> 7 #include <boost/python/reference_existing_object.hpp> 8 #include <boost/python/return_value_policy.hpp> 9 10 struct A {}; 11 12 struct V 13 { ~VV14 virtual ~V() {}; // silence compiler warningsa 15 virtual void f() = 0; 16 insideV17 const A* inside() {return &a;} 18 19 A a; 20 }; 21 outside(const V & v)22const A* outside(const V& v) {return &v.a;} 23 BOOST_PYTHON_MODULE(bienstman1_ext)24BOOST_PYTHON_MODULE(bienstman1_ext) 25 { 26 using namespace boost::python; 27 using boost::shared_ptr; 28 using boost::python::return_value_policy; 29 using boost::python::reference_existing_object; 30 31 class_<A>("A"); 32 33 class_<V, boost::noncopyable>("V", no_init) 34 .def("inside", &V::inside, 35 return_value_policy<reference_existing_object>()) 36 .def("outside", outside, 37 return_value_policy<reference_existing_object>()) 38 ; 39 } 40 41