swig

SWIG : Unable to access constructor with double pointer

旧时模样 提交于 2019-12-08 05:21:29
I am new to SWIG. I have created a python module to use c++ classes. My cpp header code is GradedComplex.h : class GradedComplex { public: typedef std::complex<double> dcomplex; typedef Item<dcomplex> item_type; typedef ItemComparator<dcomplex> comparator; typedef std::set<item_type, comparator> grade_type; private: int n_; std::vector<grade_type *> grade_; std::vector<double> thre_; public: GradedComplex(int n, double *thre); ~GradedComplex(); void push(item_type item); void avg(double *buf); }; And CPP code is #include <iostream> #include "GradedComplex.h" using namespace std; GradedComplex:

Passing reference from Python to c++ function wrapped with swig for return value

蓝咒 提交于 2019-12-08 04:32:08
问题 Disclaimer, I am a swig and python noob I have my own c++ library and I am wrapping it to use in python with swig. My c++ class is like this: public MyCppClass() { public: void MyFunction(char* outCharPtr, string& outStr, int& outInt, long& outLong) { outCharPtr = new char[2]; outCharPtr[0] = "o"; outCharPtr[1] = "k"; outStr = "This is a result"; outInt = 1; outLong = (long)12345; } } Now I wrap this class using swig and say the module is called MyClass. What I want to achieve in python is

Python SWIG: convert C++ return parameter to return value, and convert raw C++ type to Python type

好久不见. 提交于 2019-12-08 03:38:06
问题 I'm trying to modify an existing SWIG Python interface for a C++ library, to add Python wrappers for more functions, and I would greatly appreciate some help from someone experienced with SWIG. Specifically I'm working on a function with a signature like this: void execute(int x, double y, ResultType& result1, ResultType& result2); This function accepts two empty ResultType objects and fills them in as a output parameters. In Python, this has to translate to a function that takes only x and y

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

空扰寡人 提交于 2019-12-08 00:50:14
问题 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

Unmanaged C# calls to a static library

狂风中的少年 提交于 2019-12-08 00:25:57
问题 I'm using swig to generate C# wrappers for some C code base to be used from C#. When I run swig, it generates a wrapper c file that exposes all the functionality to the generated PInvoke C# file... For example: // This is in KodLogic_wrap.c SWIGEXPORT void SWIGSTDCALL CSharp_DMGameMode_timeLimit_set(void * jarg1, unsigned short jarg2) { ... } // This is in KodLogicPInvoke.cs [global::System.Runtime.InteropServices.DllImport("KodLogic", EntryPoint="CSharp_DMGameMode_timeLimit_set")] This works

How to create SWIG interface file?

馋奶兔 提交于 2019-12-07 22:58:14
问题 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

How to apply a SWIG typemap for a double pointer struct argument

空扰寡人 提交于 2019-12-07 22:41:26
问题 I have an API that I am trying to wrap using SWIG such that I can call the underlying C library from python. I have got stuck with a particular API fn: int update_tracks(track_t **phash_tracks, const pdws_t *pdw_frame, const rdws_t *rdw_frame, lib_t *lib, lib_meta_t *lib_meta, const cfg_t *cfg); Its the double pointer to track_t data structure that I can't handle. All the single pointers work fine. This is the only API fn that has a double pointer to track_t All the others only have a single

Using SWIG with a build system [closed]

江枫思渺然 提交于 2019-12-07 20:42:59
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Anyone have experience with using SWIG (the interface generator)? I have a C project which I would like to expose to a bunch of other languages/frameworks, like Python, Java, .NET, Perl, PHP, Ruby. I would like

Delete an object and all references to it in Python?

你说的曾经没有我的故事 提交于 2019-12-07 19:41:36
问题 Is there a way to remove all references to an object at once? I know that's unpythonic, so I'll explain what I'm trying to do and maybe someone knows a better way. I'm writing an object-oriented wrapper around a SWIG wrapper for a C library. When a proxy for one of the C objects is deleted, it also deletes child objects (directly in C). I'd like that to also trigger deletion of their proxy objects in Python. Otherwise I run into a situation where there are Python objects carrying around

Swig and multidimensional arrays

我们两清 提交于 2019-12-07 16:48:53
问题 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 =