swig

nested structure array access in python using SWIG

限于喜欢 提交于 2019-12-06 07:53:50
I haven't been able to figure out how to access the array elements SubStatus in the following nested structure. I do seem to be able to see the first element, but don't understand how to force indexing, e.g., as a list. Any help is much appreciated. status.h: // Data Types typedef char CHAR; // 8 bits signed typedef short SHORT; // 16 bits signed typedef long LONG; // 32 bits signed typedef unsigned char UCHAR; // 8 bits unsigned typedef unsigned short USHORT; // 16 bits usigned #define FUNC_TYPE // built in C, leave reference as C #define DLL_API extern FUNC_TYPE __declspec(dllimport) // Sub

How to create SWIG interface file?

自闭症网瘾萝莉.ら 提交于 2019-12-06 07:17:19
I am new to SWIG And less time to do things. I am trying to bind c++ classes to python. I have set up SWIG in windows and tried running it. It was successful My example.i file is like /* File: example.i */ %module example %{ #define SWIG_FILE_WITH_INIT #include "Item.h" }% #include "Item.h" But it seems it has to include or declare the header files class, constructor, templates etc... Can anyone suggest how to create a SWIG interface file. Follwing are the header file (Item.h) that i need to create interface file. #ifndef __ITEM_H__ #define __ITEM_H__ #include <complex> #include <functional>

Catching a Python exception in C++

让人想犯罪 __ 提交于 2019-12-06 06:11:23
问题 I am developing a server-client application in which the client calls a server's API which gives a Python interface for user input. It means the client interface and server interface is written in Python whereas the socket code is in C++. On the server side:- I have a class, Test , in C++ and this class is inherited in Python named TestPython using director feature of SWIG. Also I have an exception class MyException in C++. Now a function of TestPython class throws MyException() from Python

Wrapping C++ Qt widget for using in Python with PySide

对着背影说爱祢 提交于 2019-12-06 05:57:31
What is the best approach for wrapping a custom C++ library with custom Qt display widgets in Python for using in a PySide based QApplication? Does the C++ library need special treatment for wrapping with SWIG? Will wrapped Qt widgets integrate properly with PySide? I would appreciate any comments on the appropriate nomenclature needed to refine my unsuccessful searches on this subject. The Shiboken bindings tool used to generate the PySide bindings for Qt turns out to be the right tool for the job. The basic procedure for generating the bindings for a custom C++ library is outlined here: http

Wrapping c++ functions in python with ctypes on windows : function not found

怎甘沉沦 提交于 2019-12-06 05:54:41
I need to run a series of python scripts calculating various scripts, that are working fine, but one of them runs very slowly and has to be done in C++. The C++ code is ready, but I need to find a way to call the C++ function from the python and get the return value. I found information about SWIG, but didn't get it to work on Windows with Visual Studio (I have to do it in VS on Windows, because of other constraints). I found ctypes much easier for my very simple function with standart input and output values. So I did many tests with ctypes, tried all the examples I could find online, and

Make C++ array of objects iterable in Python

笑着哭i 提交于 2019-12-06 05:37:23
问题 I have searched on the web and didn't get success. I'm wrapping the sample code below to Python (using SWIG): class atomo { public: int i; atomo(int a) { i = a; }; }; class funa { public: atomo *lista[3]; funa() { lista[0] = new atomo(1); lista[1] = new atomo(2); lista[2] = new atomo(3); }; }; But Python can't iterate over or access lista using the comands >>> test = myModule.funa() >>> test.lista[0] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 6

SWIG Importing generated class from a different module and package into the current class

懵懂的女人 提交于 2019-12-06 05:35:04
问题 I'm having difficulty getting the SWIG typemap(javapackage) to work properly. I tried making a simple version of the problem, and even that seems to fail. foo.h: #ifndef FOO_H #define FOO_H class Foo { public: Foo() {}; int doSomething() { return 1 }; }; #endif bar.h: #ifndef BAR_H #define BAR_H #include "foo.h" class Bar { public: Bar() {}; int doSomething(Foo foo) { return foo.doSomething(); }; }; #endif Foo.i %module FooMod %include "typemaps.i" %include "stdint.i" %{ #include "../header

String parameters

僤鯓⒐⒋嵵緔 提交于 2019-12-06 05:13:54
问题 I'm trying to use swig to interface with c++, and I'm having problems using a std::string& parameter. This is on Fedora 19 with golang 1.1-2, swig 2.0.10-1, and gcc 4.8.1-1. I don't know C++. I do know C, and had hoped to wing it. At any rate, _swig_wrap_pinput ends up with a null pointer. What am I overlooking? Here's my test case: st.i %module st %{ #include <string> extern void pinput(std::string& pstring); %} %include <std_string.i> #include <string> void pinput(std::string& pstring); st

Swig and multidimensional arrays

你。 提交于 2019-12-06 01:17:37
I am using Swig to interface python with C code. I want to call a C function that takes for argument a struct containing an int** var: typedef struct { (...) int** my2Darray; } myStruct; void myCFunction( myStruct struct ); I am struggling with multi dimensional arrays. My code looks like this: In the interface file, I am using carray like this: %include carrays.i %array_class( int, intArray ); %array_class( intArray, intArrayArray ); In python, I have: myStruct = myModule.myStruct() var = myModule.intArrayArray(28) for j in range(28): var1 = myModule.intArray(28) for i in range(28): var1[i] =

How to convert numpy ndarray to C float *[]

Deadly 提交于 2019-12-05 21:48:24
I have code in C , which I would like to use in python , I used SWIG to wrap the C-code, and got successfully a python module imported in my python code. Now I have the following code: import flame import numpy as np data = np.random.rand(3,2).astype(np.float32, copy=False) N = 3 M = 2 print data flameobject = flame.Flame_New() flame.Flame_SetDataMatrix( flameobject, data, N, M, 0 ) and this gives error: TypeError: in method 'Flame_SetDataMatrix', argument 2 of type 'float *[]' I understand that I should pass a float array pointer to the method, but how can I convert my Numpy multi-dimensional