boost-python

How to expose raw byte buffers with Boost::Python?

冷暖自知 提交于 2019-12-05 15:10:18
问题 I've got third party C++ library in which some class methods use raw byte buffers. I'm not quite sure how to deal in Boost::Python with it. C++ library header is something like: class CSomeClass { public: int load( unsigned char *& pInBufferData, int & iInBufferSize ); int save( unsigned char *& pOutBufferData, int & iOutBufferSize ); } In stuck with the Boost::Python code... class_<CSomeClass>("CSomeClass", init<>()) .def("load", &CSomeClass::load, (args(/* what do I put here??? */))) .def(

Boost Python and Cmake with Ubuntu and Python3.5

时间秒杀一切 提交于 2019-12-05 13:46:34
I'm having issues getting Boost Python to compile with Cmake. Everything works fine when compiled manually. Here is how I set everything up and ran it : Install python 3.5 : sudo apt-get install python3-dev Download the lastest version of Boost from http://www.boost.org/ Run bootstrap with correct flags : ./bootstrap.sh --with-python=python3.5 Compile Boost in directory : ./b2 Install Boost headers to /usr/local/include and Boost libs to /usr/lib/x86_64-linux-gnu sudo ./b2 install Compile example with proper flags : g++ greet_binding.cpp -I/usr/include/python3.5m -I/usr/local/include -lboost

Copying a boost.python object

我是研究僧i 提交于 2019-12-05 12:29:10
I have some boost python classes, which I instantiate in python. I want to copy them. So, if I have p = Bernoulli(0.5) I want to do q = Bernoulli(p) But what if I don't know p's type? I tried to do this: q = copy.deepcopy(p) but python said it couldn't pickle p. Is my only solution to add a clone() function to the interface of Bernoulli? Or can I have that method automatically generated somehow? Can copy.deepcopy be made to work with Boost.python objects? From http://mail.python.org/pipermail/cplusplus-sig/2009-May/014505.html #define PYTHON_ERROR(TYPE, REASON) \ { \ PyErr_SetString(TYPE,

How to get boost.python tutorial example to link with Python3?

一个人想着一个人 提交于 2019-12-05 12:13:16
I want to use boost.python with python 3.2+ (preferably 3.4) and Visual Studio 2010. When I try to make the libs\python\example\tutorial example against any Python3 (I have tested 3.0, 3.2 and 3.4) it doesn't link (see below). When I link it against 2.7 it works. The only change I make between attempts is updating user-config.jam in my home directory. So it works when user-config.jam is: # MSVC configuration using msvc : 10.0 ; # Python configuration: using python : 2.7 : C:\\Python27 : C:\\Python27\\include : C:\\Python27\\libs ; When I run bjam I get: C:\Boost\boost_1_55_0\libs\python

Setting metaclass of wrapped class with Boost.Python

霸气de小男生 提交于 2019-12-05 10:16:34
I have an Event class defined in C++ that I expose to Python using Boost. My scripts are expected to derive from this class, and I'd like to do some initialization whenever a new child class is defined. How can I set the metaclass of the exposed Event class such that whenever a Python script derives from this class, the metaclass could do the required initialization? I would like to avoid having to explicitly use a metaclass in the scripts... class KeyboardEvent(Event): # This is what I want pass class KeyboardEvent(Event, metaclass=EventMeta): # This is not a good solution pass Edit: Part of

Performance of Boost Python

风格不统一 提交于 2019-12-05 09:47:26
I working on a project where I'm experimenting with boost python. When looking into how to organize my python interface I ran into a comment that asserted there are performance concerns with boost python. Is there any actual concern with it's performance? In this case I'm working with a large project and we want to expose some of it to python. I'm finding that boost python makes it easy to expose the classes I already have. So I would prefer to stick with boost python's methods of exposing classes because it's so easy. Unless someone has an alternative that is just as easy to use and

boost.python: Argument types did not match C++ signature

主宰稳场 提交于 2019-12-05 09:43:27
I am having a strange problem when calling a C++ function in python. I exposed a class from which I want to call a function: class_<MyClass, std::shared_ptr<MyClass>>("MyClass", init<>()) // ... .def("someFunc", &MyClass::someFunc) ; I get a std::shared_ptr<MyClass> from a member variable from another class which is exposed via .def_readonly(...) When I try to call the function, I get the following error: File "pytest.py", line 27, in test_func cu.someFunc("string") Boost.Python.ArgumentError: Python argument types in MyClass.someFunc(MyClass, str) did not match C++ signature: result(MyClass

boost::python: expose a C++ class to a python script embedded in a C++ app

回眸只為那壹抹淺笑 提交于 2019-12-05 08:16:07
I am successfully able to load a python script file and call a function within using boost::python in a C++ app. In the boost python EmbeddingPython wiki there is a tip on how to load a python module . namespace bp = boost::python; bp::object import(const std::string& module, const std::string& path, bp::object& globals) { bp::dict locals; locals["module_name"] = module; locals["path"] = path; bp::exec("import imp\n" "new_module = imp.load_module(module_name, open(path), path, ('py', 'U', imp.PY_SOURCE))\n", globals, locals); return locals["new_module"]; } I can successfully use this to import

Pure virtual function call

巧了我就是萌 提交于 2019-12-05 07:54:04
I'm using boost.python to make python-modules written in c++. I have some base class with pure virtual functions which I have exported like this: class Base { virtual int getPosition() = 0; }; boost::python::class_<Base>("Base") .def("GetPosition", boost::python::pure_virtual(&Base::getPosition)); in Python I have code: class Test(Base): def GetPosition(self): return 404 Test obj obj.GetPosition() RuntimeError: Pure virtual function called What's wrong? This error happens when a constructor or a destructor directly or indirectly calls a pure virtual member. (Remember that during constructor

boost::python and set::erase -> weird behaviour

╄→尐↘猪︶ㄣ 提交于 2019-12-05 07:47:39
I'm trying to store objects in a std::set. Those objects are boost::shared_ptr<>, coming from the python environment. adding values to the set won't cause any troubles. But when I try to erase a value, even though I'm passing the very same reference, it won't work. Here is an example : #include <set> #include <iostream> #include <boost/shared_ptr.hpp> #include <boost/python.hpp> using namespace std; using namespace boost; using namespace boost::python; struct Bar { Bar() {} }; struct Foo { set< shared_ptr<Bar> > v_set; shared_ptr<Bar> v_ptr; Foo() {} void add( shared_ptr<Bar> v_param ) { cout