swig

How to SWIG std::string& to C# ref string

那年仲夏 提交于 2019-12-08 15:48:30
问题 I'm trying to convert a C++ function with std::string reference to C#. My API looks like this: void GetStringDemo(std::string& str); Ideally I would like to see something like this from C# void GetStringDemoWrap(ref string); I understand I need to create a typemap for this, and I tried a few things by playing around with the std_string.i file, but I don't think I'm getting anywhere. Does anyone has any example. I'm new to both Swig and C# so I'm not able to come up with any genuine ideas. 回答1

SWIG C++ to Python: Warning(362): operator= ignored

大憨熊 提交于 2019-12-08 15:44:05
问题 I am exporting a C++ class to Python and I noticed that during compilation, SWIG issued the following warning: Warning(362): operator= ignored I am not sure why the operator is being overloaded, because it says in the SWIG documentation, that SWIG is capable of handling operators such as the assignment operator There is nothing special about my class, it is declared like this: class Foo { public: Foo(); Foo& operator= (const Foo&); // etc .. }; Why is SWIG failing to generate wrapper code for

How to wrap callbacks in Java with SWIG

血红的双手。 提交于 2019-12-08 13:27:21
问题 Following up from this thread: How should I write the .i file to wrap callbacks in Java or C# I realize that my question is similar but the answer to that question was tailored specific to void* user data argument, while my callback takes an enum and a char* . This is how my callback is defined and used in my header file typedef void (*Callback_t)(const Log SomeLog, const char *Text); virtual void SetCallback(const Callback_t SomeCallback, const Log SomeLog) = 0; where Log is an enum. I'm

Does a function type “extern __declspec(dllimport) INT __cdecl” makes sense in C/C++ or SWIG?

眉间皱痕 提交于 2019-12-08 10:43:25
问题 I am trying to wrap a DLL, using its header file, through SWIG. I got a syntax error while processing my interface .i file using SWIG. After tracking down what was the offending line (line number of the printed by SWIG error message did not match the true offending line), I found that the minimum non-processable SWIG interface file is: /* example.i */ %module example %{ extern __declspec(dllimport) INT __cdecl function(int argument); %} extern __declspec(dllimport) INT __cdecl function(int

Binding with SWIG - typedef'ed types bound incorrectly

我只是一个虾纸丫 提交于 2019-12-08 08:57:32
问题 I have swig.i file like that: %module ogr_api %{ #include "ogr_api.h" %} %inline %{ typedef void *OGRSFDriverH; %} /* OGRSFDriverRegistrar */ OGRDataSourceH OGROpen( const char *, int, OGRSFDriverH * )` and I get the following .c wrapper: ... SWIGEXPORT void * D_OGROpen(char * jarg1, int jarg2, void * jarg3) { ... That is SWIG translates OGRSFDriverH to just void*. I need to save the type name. How could I do it? Also I loss const in the first argument, but this is the next question. 回答1:

Implement support for std::vector without std_vector.i

别等时光非礼了梦想. 提交于 2019-12-08 08:23:44
Okay, I've already asked 2 questions about my problem and despite the fact that the replies were really helpful, I am not able to find an optimal solution for my problem. Let me explain my main objective/problem now. Due to some constraints I can't use std_vector.i in my swig interface, but I need to use a C++ object of (vector of vectors of string) vector<vector<string>> in Python. I implemented a solution where I am converting whole vector<vector<string> > to Python "List of Lists" wherein I am doing the following conversions: each C++ string to Python String using PyString_FromString() each

%typemap and %exception for error codes from C functions for SWIG, Python

我怕爱的太早我们不能终老 提交于 2019-12-08 07:44:53
问题 I've got some C code that I want to expose to Python. It has a calling convention like this: int add(int a, int b, int *err) where the return value would be (a+b) or whatever, but if something went wrong, then I would get an error code in *err. I want to wrap this function so that it behaves like this, from the Python perspective: def add(a,b): if something_bad: raise RuntimeError("something bad") return a+b This should be easy, right? But I'm not finding it so. Here is something that I have

Error: “warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro redefinition”

橙三吉。 提交于 2019-12-08 07:16:25
问题 I'm trying to compile a SWIG project, and it keeps on giving errors like this: swig_wrap.cpp(55): warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro redefinition And errors like this: fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? Compiler Visual Studio 2015+Update 3. SWIG v3.0.12 回答1: Add the following to your .i file: %begin %{ #include "stdafx.h" %} This section injects code into the generated

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

走远了吗. 提交于 2019-12-08 06:30:23
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 , then returns a tuple of result1 and result2 . ResultType is a container type that is used widely

Implement support for std::vector without std_vector.i

ぐ巨炮叔叔 提交于 2019-12-08 06:09:40
问题 Okay, I've already asked 2 questions about my problem and despite the fact that the replies were really helpful, I am not able to find an optimal solution for my problem. Let me explain my main objective/problem now. Due to some constraints I can't use std_vector.i in my swig interface, but I need to use a C++ object of (vector of vectors of string) vector<vector<string>> in Python. I implemented a solution where I am converting whole vector<vector<string> > to Python "List of Lists" wherein