Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.55 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Boost.python overloaded constructor for numpy array and python list
  2. using boost;
  3. using boost::python;
  4.  
  5. shared_ptr<MyClass> CreateWithList(list lst)
  6. {
  7.     // construct with a list here
  8. }
  9.  
  10. shared_ptr<MyClass> CreateWithPyArrayObject(PyArrayObject* obj)
  11. {
  12.     // construct with numpy array here
  13. }
  14.  
  15.  
  16. BOOST_PYTHON_MODULE(mymodule)
  17. {
  18.     class_<MyClass, boost::noncopyable, boost::shared_ptr<MyClass> >
  19.         ("MyClass", no_init)
  20.         .def("__init__", make_constructor(&CreateWithList))
  21.         .def("__init__", make_constructor(&CreateWithPyArrayObject))
  22. }