injected.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright David Abrahams 2003.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/python/module.hpp>
  6. #include <boost/python/class.hpp>
  7. #include "test_class.hpp"
  8. #include <memory>
  9. #include <boost/shared_ptr.hpp>
  10. #include <boost/python/make_constructor.hpp>
  11. #include <boost/python/args.hpp>
  12. using namespace boost::python;
  13. typedef test_class<> X;
  14. X* empty() { return new X(1000); }
  15. std::auto_ptr<X> sum(int a, int b) { return std::auto_ptr<X>(new X(a+b)); }
  16. boost::shared_ptr<X> product(int a, int b, int c)
  17. {
  18. return boost::shared_ptr<X>(new X(a*b*c));
  19. }
  20. BOOST_PYTHON_MODULE(injected_ext)
  21. {
  22. class_<X>("X", init<int>())
  23. .def("__init__", make_constructor(empty))
  24. .def("__init__", make_constructor(sum))
  25. .def("__init__", make_constructor(product
  26. , default_call_policies()
  27. , ( arg_("a"), arg_("b"), arg_("c"))
  28. ),
  29. "this is product's docstring")
  30. .def("value", &X::value)
  31. ;
  32. }