swig

Swig c++ w/ Java loses type on polymorphic callback functions [duplicate]

孤者浪人 提交于 2019-12-04 13:06:41
This question already has an answer here : Closed 7 years ago . Possible Duplicate: SWIG Java Retaining Class information of the objects bouncing from C++ Question : Why is my C++ swigged object losing its type when passed to a Java callback function? Setup : I've taken the Swig Java example for doing callbacks and added an object to be passed to the callback run(Parent p) . The callback works as expected but when I pass a Child object the Java seems to lose its type and think its of type Parent when it should be Child . This is based on the Swig java callback example . System Info : Ubuntu 8

Make C++ array of objects iterable in Python

会有一股神秘感。 提交于 2019-12-04 12:40:49
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, in __iter__ TypeError: 'SwigPyObject' object is not subscriptable >>> for i in test.lista: >>> print

Is there a way for CMake to utilize dependencies generated by `swig -MM`?

喜你入骨 提交于 2019-12-04 11:22:56
问题 SWIG generates wrapper code from your C/C++ in a desired target language (Python, Java, C#, etc) using an interface (.i) file that specifies the input code to be wrapped as described in the SWIG tutorial. CMake can be used to call swig in order to generate target code from the .i interface, as described in the SWIG documentation. However, using this method CMake only generates a dependency for the interface file itself, but not for the source files it includes. One can manually add

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

梦想的初衷 提交于 2019-12-04 09:58:24
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/foo.h" %} %include "../header/foo.h" Bar.i %module BarMod %import "Foo.i" %typemap("javapackage") Foo,

Fast conversion of C/C++ vector to Numpy array

旧城冷巷雨未停 提交于 2019-12-04 08:29:10
I'm using SWIG to glue together some C++ code to Python (2.6), and part of that glue includes a piece of code that converts large fields of data (millions of values) from the C++ side to a Numpy array. The best method I can come up with implements an iterator for the class and then provides a Python method: def __array__(self, dtype=float): return np.fromiter(self, dtype, self.size()) The problem is that each iterator next call is very costly, since it has to go through about three or four SWIG wrappers. It takes far too long. I can guarantee that the C++ data are stored contiguously (since

Return vector<pair<int,int>> & from c++ method to python list of tuples using swig typemap

…衆ロ難τιáo~ 提交于 2019-12-04 07:29:05
I'm having a lot of troubles trying to wrap a c++ method that returns a constant reference to a vector of pairs to a Python list of tuples using %typemap(out) . I currently have something like this: myclass.h: #inlcude <vector> using std::vector; class MyClass { private: const vector<pair<int,int>> & _myvector; public: MyClass(const vector<pair<int,int>> & myvector ); const vector<pair<int,int>> & GetMyVector() const; } myclass.cpp: #include "myclass.h" MyClass::MyClass(const vector<pair<int,int>> & myvector): _myvector(myvector){}; const vector<pair<int,int>> & MyClass::GetMyVector() const {

Passing Java Map<String, String> to C++ method using SWIG

◇◆丶佛笑我妖孽 提交于 2019-12-04 06:55:05
I have a method defined in C++: std::map<std::string, std::string> validate( std::map<std::string, std::string> key, std::map<std::string, std::string> value ); I want to consume this method in Java. So, I have to write a wrapper using Swig through which I will be able to pass Java Map as STL map to the c++ method. Please let me know how should I define the .i file for swig to make this work. Flexo In order to do this you'll need to tell SWIG to use java.util.Map for the input argument, using %typemap(jstype) . You'll also need to supply some code to convert from the Java map type to the C++

how to pass enum values from TCL script to C++ class using Swig

我的梦境 提交于 2019-12-04 05:36:26
问题 I am using following code 1) File : example.i %module example %{ /* Put header files here or function declarations like below */ #include "example.h" %} %include "example.h" 2) File example.h enum Type {one,two}; class myClass { public: myClass() {} static bool printVal(int val); static bool printEnum(Type val); }; 3) File example.cpp #include "example.h" #include <iostream> using namespace std; bool myClass::printVal(int val) { cout << " Int Val = " << val << endl; return 0; } bool myClass:

Swig typemap java object

岁酱吖の 提交于 2019-12-04 05:21:26
问题 I am trying to generate java bindings through swig for these two c++ functions C++ functions void SetUserData(void* data); void* GetUserData() const; On the java side I want it to look like this setUserData(Object object); getUserData() //return java.lang.Object I would like the void* pointer to point to any java object I pass to it. In my swig file I tried to add these lines //swig file %typemap(jstype) void* "java.lang.Object"; %apply Object {void*}; I get a compile error: b2Fixture.swig(22

How to handle exceptions from C++ via SWIG to Java

扶醉桌前 提交于 2019-12-04 04:48:19
We are implementing a wrapper on C++ code for exposure to Java clients. I have seen the SWIG documents about exception handling but what does this translate to in coding terms in the three layers (C++/SWIG/Java)? If anybody has working example(s) or advice, I would be grateful. Since I've wrestled with this (see my blog from my profile, it's on python, SWIG, exceptions and directors but should help) let me give you a few pieces of advice: Don't send C++ exceptions up to the Java stack. It'll crash your application. Make sure they're all wrapped in the correct manner. I know you're asking about