pointer_vector.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. using namespace boost::python;
  8. class Abstract
  9. {
  10. public:
  11. virtual ~Abstract() {}; // silence compiler warningsa
  12. virtual std::string f() =0;
  13. };
  14. class Concrete1 : public Abstract
  15. {
  16. public:
  17. virtual std::string f() { return "harru"; }
  18. };
  19. typedef std::vector<Abstract*> ListOfObjects;
  20. class DoesSomething
  21. {
  22. public:
  23. DoesSomething() {}
  24. ListOfObjects returnList()
  25. {
  26. ListOfObjects lst;
  27. lst.push_back(new Concrete1()); return lst;
  28. }
  29. };
  30. BOOST_PYTHON_MODULE(pointer_vector_ext)
  31. {
  32. class_<Abstract, boost::noncopyable>("Abstract", no_init)
  33. .def("f", &Abstract::f)
  34. ;
  35. class_<ListOfObjects>("ListOfObjects")
  36. .def( vector_indexing_suite<ListOfObjects>() )
  37. ;
  38. class_<DoesSomething>("DoesSomething")
  39. .def("returnList", &DoesSomething::returnList)
  40. ;
  41. }