swig

SWIG c++ to python : vector problems

回眸只為那壹抹淺笑 提交于 2021-02-08 01:49:13
问题 I am following the documentation here: http://www.swig.org/Doc3.0/Library.html#Library_stl_cpp_library to write a wrapper to a simple example code involving vectors. Here is the header file: ### word.h ### #include<string> #include<vector> class Word{ public: Word(std::string word, int numWords, std::vector<double> &values); ~Word(); void updateWord(std::string newWord); std::string getWord(); void processValues(); private: std::string theWord; int totalWords; std::vector<double> values; };

SWIG c++ to python : vector problems

跟風遠走 提交于 2021-02-08 01:49:10
问题 I am following the documentation here: http://www.swig.org/Doc3.0/Library.html#Library_stl_cpp_library to write a wrapper to a simple example code involving vectors. Here is the header file: ### word.h ### #include<string> #include<vector> class Word{ public: Word(std::string word, int numWords, std::vector<double> &values); ~Word(); void updateWord(std::string newWord); std::string getWord(); void processValues(); private: std::string theWord; int totalWords; std::vector<double> values; };

mix VTK and SWIG Python

混江龙づ霸主 提交于 2021-02-07 09:33:47
问题 Here is my class: #include <vtkPolyData> class VTKUtilities Mesh3D MeshfromVTKPolyData(vtkPolyData* pdmesh) { Mesh3D mesh; //... //my conversion code to do the actual conversion //... return mesh; } I tried wrapping this to python by SWIG but I try to call my function in python like this: import VTKUtilities import vtk pd = vtk.vtkPolyData() VTKUtilities.MeshfromVTKPolyData(pd) I get errors like : NotImplementedError: Wrong number of arguments... for VTKUtilities_MeshfromVTKPolyData ...

Looking for a convenient way to call Java from C++

自闭症网瘾萝莉.ら 提交于 2021-02-05 12:55:49
问题 It seems most documentation or helper libraries relating to JNI (Java Native Interface) are concerned with calling native code from Java. This seems to be the main use of it, even though it is capable of more. I want to mostly work in the opposite direction: modify an existing (fairly large) portable C++ program by adding some Java libraries to it. For example, I want to make it call databases via JDBC, or message queue systems via JMS, or send emails, or call my own Java classes, etc. But

Python C wrapper for reading variable argument lengths

和自甴很熟 提交于 2021-02-04 08:33:19
问题 I am trying to replace MATLAB/MEX and switch to Python. I came across SWIG, ctypes & Cython as possible solutions and started trying out SWIG (which seems very simple). My C functions have variable argument lengths of the form main(int argc, char *argv[]) . I found solutions online, but getting this working with SWIG lead to a lot of issues. Are the other methods (ctypes / Cython) any simpler? Any example to do this task with SWIG will be helpful. 回答1: There's actually an example in the SWIG

How to to pass a C# delegate (callback) with a ref struct parameter to C++ using SWIG

烂漫一生 提交于 2021-01-29 05:15:21
问题 I am attempting to build C++ wrappers (using SWIG) for System.Text.Json.Utf8JsonWriter and System.Text.Json.Utf8JsonReader that allow C++ code to read and write JSON to the same reader/writer as client C# code. To do this I'm creating abstract classes in the C++ that match the interface of the Utf8JsonWriter and Utf8JsonReader class and then using SWIG director feature to enable me to create a derived class in C# that implements this interface and acts as a proxy calling the corresponding

Add hand-wrapped method to Swig output

喜夏-厌秋 提交于 2021-01-27 23:22:53
问题 I have a SWIG module where I want to add a hand-rolled method. %module frob %inline %{ int Foo(int x, int y) { return x+y; } PyObject* Bar(PyObject* self, PyObject* args) { return PyString_FromString("Hello from Bar"); } %} However, when I ran swig over it swig -python frob.i , I saw that SWIG actually wrapped both Foo and Bar as _wrap_Foo, _wrap_Bar. SWIGINTERN PyObject *_wrap_Foo(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { // ... result = (int)Foo(arg1,arg2); // ... } SWIGINTERN

Importing a .pyd (created with SWIG) in Python 2.7.3 on Mac

ⅰ亾dé卋堺 提交于 2021-01-27 13:41:48
问题 I have created a .pyd file with SWIG under Windows named (_example.pyd). I am able to send the file to my email and import it with another Windows machine using the same version of Python (Python 2.7.3) with this simple command: .>>> import _example .>>> But when I send it to my email and tried to import the file with a Mac, I get: "No module named _example" Any ideas? In both cases, I saved the file into the Python path. 回答1: This is because Python extensions (.pyd files) are essentially

What is the correct way to import a python module wrapped with swig in c++

我怕爱的太早我们不能终老 提交于 2021-01-07 03:28:48
问题 Creating a python module with swig is the easy part. But what if this module has to interact with my C++ application that imports it from its embedded python instance? For example @Flexo has made a pretty good example on how to expose the python module to the application here: How can I implement a C++ class in Python, to be called by C++? All I want is that the application and the module are able to interact with each other like sharing variables and calling callbacks and so on so I found

SWIG struct pointer as output parameter

自作多情 提交于 2021-01-05 09:48:46
问题 I have a struct: struct some_struct_s { int arg1; int arg2; }; I have a C function: int func(some_struct_s *output); Both are %included into my SWIG file. I want some_struct_s *output to be treated like an output parameter. Python example: int_val, some_struct_output = func() "Output parameters" is covered in the manual for POD-types (sec 10.1.3), but not for non-POD types. How do I tell SWIG I want some_struct_s *output to be an output parameter? 回答1: From the documentation: 11.5.7 "argout"