summaryrefslogtreecommitdiff
path: root/Doc/Manual/Java.html
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2011-01-14 19:06:43 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2011-01-14 19:06:43 +0000
commitef865e06d5e8c8f9498068d5ca9ce2a4338e9eaa (patch)
tree7dd3bab217354255a3735b10c8a2ae5df18af255 /Doc/Manual/Java.html
parent9adb49455808c4f4a7f2d82c6becfd61c8544ad2 (diff)
downloadswig-ef865e06d5e8c8f9498068d5ca9ce2a4338e9eaa.tar.gz
Added some missing multi-argument typemaps: (char *STRING, size_t LENGTH) and (char *STRING, int LENGTH) - Java patch is from Volker Grabsch. Elements of the primitive_types.i testcase for this moved into char_binary.i. Documentation for this enhanced.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12393 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Doc/Manual/Java.html')
-rw-r--r--Doc/Manual/Java.html43
1 files changed, 43 insertions, 0 deletions
diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html
index ef5604a05..c6ef2b425 100644
--- a/Doc/Manual/Java.html
+++ b/Doc/Manual/Java.html
@@ -4401,6 +4401,49 @@ well suited for applications in which you need to create buffers,
package binary data, etc.
</p>
+<H3><a name="Java_binary_char"></a>Binary data vs Strings</H3>
+
+<p>
+By default SWIG handles <tt>char *</tt> as a string but there is a handy multi-argument typemap available as mentioned in <a href="Library.html#Library_nn10">Passing binary data</a>.
+The following simple example demonstrates using a byte array instead of passing the default string type and length to the wrapped function.
+</p>
+
+
+<div class="code">
+<pre>
+%apply (char *STRING, size_t LENGTH) { (const char data[], size_t len) }
+%inline %{
+void binaryChar1(const char data[], size_t len) {
+ printf("len: %d data: ", len);
+ for (size_t i=0; i&lt;len; ++i)
+ printf("%x ", data[i]);
+ printf("\n");
+}
+%}
+</pre>
+</div>
+
+<p>
+Calling from Java requires just the byte array to be passed in as the multi-argument typemap being applied reduces the number of arguments in the target language to one, from the original two:
+</p>
+
+<div class="code">
+<pre>
+byte[] data = "hi\0jk".getBytes();
+example.binaryChar1(data);
+</pre>
+</div>
+
+<p>
+resulting in the output
+</p>
+
+<div class="code"><pre>
+$ java runme
+len: 5 data: 68 69 0 6a 6b
+</pre></div>
+
+
<H3><a name="Java_heap_allocations"></a>23.8.5 Overriding new and delete to allocate from Java heap</H3>