From 870b814f5e5a2801d845b6cf3056b72ba7c6fe13 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 14 Mar 2016 20:46:56 +0000 Subject: [PATCH] Add C++11 std::array container support for Java --- CHANGES.current | 3 + Examples/test-suite/cpp11_li_std_array.i | 2 +- .../java/cpp11_li_std_array_runme.java | 82 +++++++++++++++++++ Lib/java/std_array.i | 42 ++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/java/cpp11_li_std_array_runme.java create mode 100644 Lib/java/std_array.i diff --git a/CHANGES.current b/CHANGES.current index 50a7c8dac..815e4b181 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.9 (in progress) =========================== +2016-03-14: wsfulton + [Java] Add std_array.i for C++11 std::array support. + 2016-03-12: wsfulton [Java, C#, D] Fix static const char member variables wrappers with %javaconst(1) %csconst(1) or %dmanifestconst. diff --git a/Examples/test-suite/cpp11_li_std_array.i b/Examples/test-suite/cpp11_li_std_array.i index 74e34370c..19304d9e6 100644 --- a/Examples/test-suite/cpp11_li_std_array.i +++ b/Examples/test-suite/cpp11_li_std_array.i @@ -1,6 +1,6 @@ %module cpp11_li_std_array -#if defined(SWIGPYTHON) || defined(SWIGRUBY) +#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) %{ #include diff --git a/Examples/test-suite/java/cpp11_li_std_array_runme.java b/Examples/test-suite/java/cpp11_li_std_array_runme.java new file mode 100644 index 000000000..dcd14b367 --- /dev/null +++ b/Examples/test-suite/java/cpp11_li_std_array_runme.java @@ -0,0 +1,82 @@ +import cpp11_li_std_array.*; + +public class cpp11_li_std_array_runme { + + static { + try { + System.loadLibrary("cpp11_li_std_array"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + private static ArrayInt6 ToArray6(int [] a) { + ArrayInt6 ai = new ArrayInt6(); + if (a.length != 6) + throw new RuntimeException("a is incorrect size"); + for (int i=0; i<6; ++i) + ai.set(i, a[i]); + return ai; + } + + private static void compareContainers(ArrayInt6 actual, int[] expected) { + if (actual.size() != expected.length) + throw new RuntimeException("Sizes are different: " + actual.size() + " " + expected.length); + for (int i=0; i + +namespace std { + + template class array { + public: + typedef T& reference; + typedef const T& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + array(); + array(const array& other); + size_type size() const; + %rename(isEmpty) empty; + bool empty() const; + void fill(const T& u); + %extend { + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && isize()); + if (i>=0 && i