boost-python

c++ pointers to overloaded functions

耗尽温柔 提交于 2019-12-10 20:32:10
问题 I'm trying to expose a overloaded function using boost::python. the function prototypes are: #define FMS_lvl2_DLL_API __declspec(dllexport) void FMS_lvl2_DLL_API write(const char *key, const char* data); void FMS_lvl2_DLL_API write(string& key, const char* data); void FMS_lvl2_DLL_API write(int key, const char *data); I'v seen this answer: How do I specify a pointer to an overloaded function? doing this: BOOST_PYTHON_MODULE(python_bridge) { class_<FMS_logic::logical_file, boost::noncopyable>(

Pass by reference in Boost::Python

五迷三道 提交于 2019-12-10 19:36:55
问题 Consider something like: struct Parameter { int a; Parameter(){a = 0;} void setA(int newA){a = newA;} }; struct MyClass { void changeParameter(Parameter &p){ p.setA(-1);} }; Well, let's fast forward, and imagine I already wrapped those classes, exposing everything to python, and imagine also I instantiate an object of Parameter in the C++ code, which I pass to the python script, and that python script uses a MyClass object to modify the instance of Parameter I created at the beginning in the

Adding python script to c++ project

我的未来我决定 提交于 2019-12-10 19:35:56
问题 How would I go about adding a script written in python to a c++ project? Thanks Edit: Basically all the script does is email some data. I would like to pass the data and maybe the email address to a function written in python. Hope that clears things up.. 回答1: You could look at Boost.Python which is a "a C++ library which enables seamless interoperability between C++ and the Python programming language." You have to be more specific, though. 回答2: You may be interested in Boost.Python:

hello world python extension in c++ using boost?

社会主义新天地 提交于 2019-12-10 13:25:56
问题 Here's my simple first attempt at a python extension using boost. Can someone help me to understand what's causing the compilation error? #include <iostream> using namespace std; void say_hello(const char* name) { cout << "Hello " << name << "!\n"; } #include <boost/python/module.hpp> #include <boost/python/def.hpp> using namespace boost::python; BOOST_PYTHON_MODULE(hello) { def("say_hello", say_hello); } user@host:~$ g++ main.cpp -o test.so In file included from /usr/include/boost/python

How do I import modules in boost::python embedded python code?

一曲冷凌霜 提交于 2019-12-10 12:36:08
问题 I'm using boost::python to embed some python code into an app. I was able to get print statements or other expressions to be evaluated properly, but when I try to import modules, it is not importing and application is exiting. Further the globals() function call in the embedded code gives a runtime error too. #include <boost/python.hpp> using namespace boost; using namespace boost::python; using namespace boost::python::api; int main(void) { Py_Initialize(); object main_module = import("_

How to avoid redundancy between c++ and boost::python docs?

扶醉桌前 提交于 2019-12-10 09:33:13
问题 I'm adding a python module in a c++ code, using boost::python. The c++ project is documented with doxygen. I want to create a documentation for the python module but I don't know how not to be redundant like this : #include <boost/python.hpp> using namespace boost::python; /** @brief Sum two integers * @param a an integer * @param b another integer * @return sum of integers */ int sum(int a, int b) { return a+b; } BOOST_PYTHON_MODULE(pymodule) { def("sum",&sum,args("a","b"), "Sum two integers

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

这一生的挚爱 提交于 2019-12-10 09:28:34
问题 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:\

Return a structure to Python from C++ using BOOST.python

情到浓时终转凉″ 提交于 2019-12-10 09:24:37
问题 I have written a C++ method from which I need to return a structure to Python. I'm already able to send an OpenCV mat from Python to C++ using BOOST following the method described in this link. Now I need to go the other way; return from C++ to Python, and then access that structure in Python. Can it be done? Any samples or reference links would be good. I have tried googling before posting this question and I couldn't get any samples or explanation links. 回答1: You can use another function

Copying a boost.python object

北城以北 提交于 2019-12-10 07:37:05
问题 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? 回答1: From http://mail.python.org

How do I pass a pre-populated “unsigned char*” buffer to a C++ method using boost.python?

不羁的心 提交于 2019-12-09 18:36:13
问题 I have a C++ class with a member function that takes an unsigned char* buffer and an unsigned int length as arguments and operates on them. I've wrapped this class with Boost::Python and would like to pass a pre-populated buffer to the class from a Python script. The Python-side buffer is created with struct.pack. I can't figure out how to make the argument type match and keep getting Boost.Python.ArgumentError. include/Example.h #ifndef EXAMPLECLASS_H_ #define EXAMPLECLASS_H_ #include