swig

SWIG- Convert C++ enum to Python enum

感情迁移 提交于 2019-12-10 16:02:01
问题 I am working to get C++ class enum to python enum using swig. I have the following implementation in example.h file. namespace colors{ enum class Color{ RED = 0, BLUE = 1, GREEN = 2 }; } My Swig interface file is %module api %{ #include "example.h" %} %include "example.h" But after using swig tool the interface provides the following usage import pywarp_example as impl impl.RED The question arise here is that is it possible to access enum like below thats the way we use in python? impl.Color

Cross compiling Gnu Radio for Openwrt

别等时光非礼了梦想. 提交于 2019-12-10 15:54:50
问题 I'm attempting to install Gnu Radio on OpenWRT "Attittude Adjustment" (latest trunk sources). I've cross compiled GR and everything seems to have compiled and linked just fine. However, importing the module in Python results in the following: root@OpenWrt:/usr/lib/python2.7/dist-packages/gnuradio/gr# python Python 2.7.3 (default, Jul 21 2012, 17:36:54) [GCC 4.6.3 20120201 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gnuradio import gr

SWIG C function pointer and JAVA

久未见 提交于 2019-12-10 14:40:05
问题 I have some code in C and one of the method has a function pointer as argument. I'm trying to use the C code in my Android app. I decided to use SWIG to do all the work in generating the java files I need. Everything works well with regular function (the one that doesn't have a function pointer as argument). But I'm not sure how I can pass my JAVA method as a callback to the C function. Here is an example : here is my multiply.h file typedef int (*callback_t) (int a, int b, int c); int foo

Add new method to a Python Swig Template class

佐手、 提交于 2019-12-10 14:25:58
问题 I need to add a new method to my swig template class, for example: I am declaring a template class in myswig.i as follows: %template(DoubleVector) vector<double>; this will generate a class named "DoubleVector" in the generated .py file with some generated methods. lets suppose they are func1(), func2() and func3(). These are generated functions and i have no control over them. Now, if I want to add a new method called "func4()" to this class(DoubleVector), how may I do it? Is it possible? I

How to get SWIG to apply templates when wrapping a template class containing vectors?

假如想象 提交于 2019-12-10 12:40:55
问题 I am trying to use SWIG to wrap (in C#) some c++ code that contains a template class that itself wraps a std::vector<T> . I have seen various references on the internet on how to declare the templates for the vector types, but can't get this to work with the extra layer of abstraction. This is what I am doing in the interface.i file for example: // interface.i file %module myNamespaceWrapper %{ #include "myVector.h" %} %include "myVector.h" %include "std_string.i" %include "std_vector.i"

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

时光怂恿深爱的人放手 提交于 2019-12-10 10:29:04
问题 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. 回答1: The Shiboken bindings tool used to generate the PySide bindings for Qt turns out to be the right tool

How to convert numpy ndarray to C float *[]

浪尽此生 提交于 2019-12-10 10:16:40
问题 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

Bug writing audio using custom video writer library

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 04:35:45
问题 I'm trying to wrap a little handy piece of C++ code that is intended to generate video+audio on windows using VFW, the C++ library lives here and the descriptions says: Uses Video for Windows (so it's not portable). Handy if you want to quickly record a video somewhere and don't feel like wading through the VfW docs yourself. I'd like to use that C++ library on Python so I've decided to wrap it up using swig. Thing is, I'm having some problems when it comes to encode the audio, for some

SWIG Python Structure Array

ε祈祈猫儿з 提交于 2019-12-10 03:50:56
问题 I've been searching for a few days trying to figure out how to turn an array of structures into a Python list. I have a function that returns a pointer to the beginning of the array. struct foo { int member; }; struct foo *bar() { struct foo *t = malloc(sizeof(struct foo) * 4); ... do stuff with the structs ... return t; } After calling the function from Python I get a single structure but trying to access the other elements of the array causes an error: foo = bar() print foo[1].member

Extracting SWIG wrapped C++ instance/pointer for use in Cython

折月煮酒 提交于 2019-12-09 22:05:41
问题 I have an instance of a class from SWIG-wrapped C++ library from which I would like to extract its reference, in order to be able to use it inside a Cython file, in which I am directly linking to the same C++ library by using a more lightweight self-made Cython wrapper of the same class. I know it would not be as easy as accessing some hidden attribute, but I imagine there might be some function within SWIG or CPython that could potentially do that if linked to from within Cython (some