Line | |
---|
1 | #include <boost/python.hpp> |
---|
2 | #include <boost/python/suite/indexing/vector_indexing_suite.hpp> |
---|
3 | #include <vector> |
---|
4 | |
---|
5 | using namespace boost::python; |
---|
6 | |
---|
7 | class Abstract |
---|
8 | { |
---|
9 | public: |
---|
10 | virtual std::string f() =0; |
---|
11 | }; |
---|
12 | |
---|
13 | class Concrete1 : public Abstract |
---|
14 | { |
---|
15 | public: |
---|
16 | virtual std::string f() { return "harru"; } |
---|
17 | }; |
---|
18 | |
---|
19 | typedef std::vector<Abstract*> ListOfObjects; |
---|
20 | |
---|
21 | class DoesSomething |
---|
22 | { |
---|
23 | public: |
---|
24 | DoesSomething() {} |
---|
25 | |
---|
26 | ListOfObjects returnList() |
---|
27 | { |
---|
28 | ListOfObjects lst; |
---|
29 | lst.push_back(new Concrete1()); return lst; |
---|
30 | } |
---|
31 | }; |
---|
32 | |
---|
33 | BOOST_PYTHON_MODULE(pointer_vector_ext) |
---|
34 | { |
---|
35 | class_<Abstract, boost::noncopyable>("Abstract", no_init) |
---|
36 | .def("f", &Abstract::f) |
---|
37 | ; |
---|
38 | |
---|
39 | class_<ListOfObjects>("ListOfObjects") |
---|
40 | .def( vector_indexing_suite<ListOfObjects>() ) |
---|
41 | ; |
---|
42 | |
---|
43 | class_<DoesSomething>("DoesSomething") |
---|
44 | .def("returnList", &DoesSomething::returnList) |
---|
45 | ; |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
Note: See
TracBrowser
for help on using the repository browser.