1 // Copyright Joel de Guzman 2005-2006. 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.hpp> 5 #include <boost/python/suite/indexing/vector_indexing_suite.hpp> 6 #include <vector> 7 8 using namespace boost::python; 9 10 class Abstract 11 { 12 public: ~Abstract()13 virtual ~Abstract() {}; // silence compiler warningsa 14 virtual std::string f() =0; 15 }; 16 17 class Concrete1 : public Abstract 18 { 19 public: f()20 virtual std::string f() { return "harru"; } 21 }; 22 23 typedef std::vector<Abstract*> ListOfObjects; 24 25 class DoesSomething 26 { 27 public: DoesSomething()28 DoesSomething() {} 29 returnList()30 ListOfObjects returnList() 31 { 32 ListOfObjects lst; 33 lst.push_back(new Concrete1()); return lst; 34 } 35 }; 36 BOOST_PYTHON_MODULE(pointer_vector_ext)37BOOST_PYTHON_MODULE(pointer_vector_ext) 38 { 39 class_<Abstract, boost::noncopyable>("Abstract", no_init) 40 .def("f", &Abstract::f) 41 ; 42 43 class_<ListOfObjects>("ListOfObjects") 44 .def( vector_indexing_suite<ListOfObjects>() ) 45 ; 46 47 class_<DoesSomething>("DoesSomething") 48 .def("returnList", &DoesSomething::returnList) 49 ; 50 } 51 52 53