// Copyright David Abrahams 2003. Permission to copy, use, // modify, sell and distribute this software is granted provided this // copyright notice appears in all copies. This software is provided // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. #include #include using namespace boost::python; //using boost::python::to_python_converter; class A{ public: A() {}; virtual void print() = 0; virtual ~A() {}; }; class a: public A { public: a(int n):i(n) {}; int i; virtual void print() {std::cout << i ;}; virtual ~a() {}; }; class tst { public: A *f1; A *f2; tst & set_f1(A & ff) {f1 = &ff; return *this;}; tst & set_f2(A & ff) {f2 = &ff; return *this;}; void print_f1() {std::cout<< "f1: "; f1->print(); std::cout << std::endl;} ; void print_f2() {std::cout<< "f2: "; f2->print(); std::cout << std::endl;} ; }; object set_f1(back_reference self, A & ff) { self.get().set_f1(ff); return self.source(); }; object set_f2(back_reference self, A & ff) { self.get().set_f2(ff); return self.source(); }; BOOST_PYTHON_MODULE(test_ext) { class_ ("A",no_init ) .def("print", &A::print); class_ > ("a", init()) .def_readonly("i", &a::i); class_("tst", init<>()) .def("set_f1", set_f1, with_custodian_and_ward<1,2>() ) .def("set_f2", set_f2, with_custodian_and_ward<1,2>() ) .def("print_f1", &tst::print_f1) .def("print_f2", &tst::print_f2); }