Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>%module Rec %include "various.i" %apply char **STRING_ARRAY { char **db } %include "sab1.hpp" </code></pre> <p>The file <code>various.i</code> which you linked to should work this way, just put it somewhere where SWIG can find it, in your project include directory or SWIG include path.</p> <p>Using <code>%include</code> instead of <code>#include "sab1.hpp"</code> means we shouldn't have to copy the definition of classes we want to wrap. The <code>%apply</code> directive applies the typemap from <code>various.i</code> to all arguments of <code>char**</code> type with the name <code>db</code>. If there are other argument names you want to wrap, add them like this:</p> <pre><code>%apply char **STRING_ARRAY { char **db, char **foo, char **bar } </code></pre> <p>If you just want to wrap <em>all</em> argument of type <code>char**</code> (unsafe!), simply omit the name:</p> <pre><code>%apply char **STRING_ARRAY { char ** } </code></pre> <p>As your C++ code expects the array to contain 2 strings, then as long as you pass an array of 2 or more <code>String</code>s from Java, it should be fine. The typemap will add a third null pointer to the array, but your C++ code won't notice. If you pass an array with fewer than 2 <code>String</code>s, you will likely crash your C++ code.</p> <p>If any of the C++ functions you are wrapping also <em>returns</em> an array of strings, then you are in trouble. SWIG will attempt to convert those back into Java arrays, but may crash when it looks for a third element in the array (it will keep looking for elements until it finds a null pointer). If you don't mind discarding the return value, you can do this:</p> <pre><code>%module Rec %include "various.i" %typemap(jni) char **db = char **STRING_ARRAY; %typemap(jtype) char **db = char **STRING_ARRAY; %typemap(jstype) char **db = char **STRING_ARRAY; %typemap(in) char **db = char **STRING_ARRAY; %typemap(freearg) char **db = char **STRING_ARRAY; %typemap(javain) char **db = char **STRING_ARRAY; %include "sab1.hpp" </code></pre> <p>This will only apply the parts of the typemap that deal with input arguments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload