java: converted wrappers for std::vector to inherit from AbstractList<>
ADD
src/autobox.i
+// Java typemaps for autoboxing in return types of generics
+%define AUTOBOX(CTYPE, JTYPE)
+%typemap(autobox) CTYPE, const CTYPE&, CTYPE& "JTYPE"
+%enddef
+AUTOBOX(double, Double)
+AUTOBOX(float, Float)
+AUTOBOX(boolean, Boolean)
+AUTOBOX(signed char, Byte)
+AUTOBOX(short, Short)
+AUTOBOX(int, Integer)
+AUTOBOX(long, Long)
+AUTOBOX(SWIGTYPE, $typemap(jstype,$1_basetype))
\ No newline at end of file

MODIFY
src/bma250e/javaupm_bma250e.i
src/bma250e/javaupm_bma250e.i
%module javaupm_bma250e
%include "../upm.i"
%include "typemaps.i"
-%include "std_vector.i"
+%include "../upm_stdvector.i"
%ignore getAccelerometer(float *, float *, float *);
+%typemap(javaimports) SWIGTYPE %{
+import java.util.AbstractList;
+import java.lang.Float;
+%}
+
+%typemap(javaout) upm::BMA250E {
+ return new $&javaclassname($jnicall, true);
+}
+%typemap(javaout) std::vector<float> {
+ return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
+}
+%typemap(jstype) std::vector<float> "AbstractList<Float>"
+
%template(floatVector) std::vector<float>;
%include "bma250e_defs.h"

MODIFY
src/bmg160/javaupm_bmg160.i
src/bmg160/javaupm_bmg160.i
%module javaupm_bmg160
%include "../upm.i"
%include "typemaps.i"
-%include "std_vector.i"
+%include "../upm_stdvector.i"
%ignore getGyroscope(float *, float *, float *);
+%typemap(javaimports) SWIGTYPE %{
+import java.util.AbstractList;
+import java.lang.Float;
+%}
+
+%typemap(javaout) SWIGTYPE {
+ return new $&javaclassname($jnicall, true);
+}
+%typemap(javaout) std::vector<float> {
+ return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
+}
+%typemap(jstype) std::vector<float> "AbstractList<Float>"
+
%template(floatVector) std::vector<float>;
%include "bmg160_defs.h"

MODIFY
src/bmm150/javaupm_bmm150.i
src/bmm150/javaupm_bmm150.i
%module javaupm_bmm150
%include "../upm.i"
%include "typemaps.i"
-%include "std_vector.i"
+%include "../upm_stdvector.i"
%ignore getMagnetometer(float *, float *, float *);
+%typemap(javaimports) SWIGTYPE %{
+import java.util.AbstractList;
+import java.lang.Float;
+%}
+
+%typemap(javaout) SWIGTYPE {
+ return new $&javaclassname($jnicall, true);
+}
+%typemap(javaout) std::vector<float> {
+ return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
+}
+%typemap(jstype) std::vector<float> "AbstractList<Float>"
+
%template(floatVector) std::vector<float>;
%include "bmm150_defs.h"

MODIFY
src/bmx055/javaupm_bmx055.i
src/bmx055/javaupm_bmx055.i
%include "../upm.i"
%include "cpointer.i"
%include "typemaps.i"
-%include "std_vector.i"
+%include "../upm_stdvector.i"
%apply int {mraa::Edge};
%ignore getMagnetometer(float *, float *, float *);
%ignore getGyroscope(float *, float *, float *);
+%typemap(javaimports) SWIGTYPE %{
+import java.util.AbstractList;
+import java.lang.Float;
+%}
+
+%typemap(javaout) SWIGTYPE {
+ return new $&javaclassname($jnicall, true);
+}
+%typemap(javaout) std::vector<float> {
+ return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
+}
+%typemap(jstype) std::vector<float> "AbstractList<Float>"
+
%template(floatVector) std::vector<float>;
%include "bmg160_defs.h"

MODIFY
src/lsm303agr/javaupm_lsm303agr.i
src/lsm303agr/javaupm_lsm303agr.i
%module javaupm_lsm303agr
%include "../upm.i"
%include "typemaps.i"
-%include "std_vector.i"
+%include "../upm_stdvector.i"
%ignore getMagnetometer(float *, float *, float *);
%ignore getAccelerometer(float *, float *, float *);
+%typemap(javaimports) SWIGTYPE %{
+import java.util.AbstractList;
+import java.lang.Float;
+%}
+
+%typemap(javaout) SWIGTYPE {
+ return new $&javaclassname($jnicall, true);
+}
+%typemap(javaout) std::vector<float> {
+ return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
+}
+%typemap(jstype) std::vector<float> "AbstractList<Float>"
+
%template(floatVector) std::vector<float>;
%include "lsm303agr_defs.h"

MODIFY
src/lsm303d/javaupm_lsm303d.i
src/lsm303d/javaupm_lsm303d.i
%module javaupm_lsm303d
%include "../upm.i"
%include "typemaps.i"
-%include "std_vector.i"
+%include "../upm_stdvector.i"
%ignore getMagnetometer(float *, float *, float *);
%ignore getAccelerometer(float *, float *, float *);
+%typemap(javaimports) SWIGTYPE %{
+import java.util.AbstractList;
+import java.lang.Float;
+%}
+
+%typemap(javaout) SWIGTYPE {
+ return new $&javaclassname($jnicall, true);
+}
+%typemap(javaout) std::vector<float> {
+ return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
+}
+%typemap(jstype) std::vector<float> "AbstractList<Float>"
+
%template(floatVector) std::vector<float>;
%include "lsm303d_defs.h"

ADD
src/upm_stdvector.i
+%include "autobox.i"
+
+%{
+#include <vector>
+#include <stdexcept>
+%}
+
+%include <stdint.i>
+%include <std_except.i>
+
+namespace std {
+
+ template<class T> class vector {
+ public:
+ typedef size_t size_type;
+ typedef T value_type;
+ typedef const value_type& const_reference;
+ vector();
+ vector(size_type n);
+ vector(const vector& o);
+ size_type capacity() const;
+ void reserve(size_type n);
+ %rename(isEmpty) empty;
+ bool empty() const;
+ void clear();
+ void push_back(const value_type& x);
+ %extend {
+ const_reference get_impl(int i) throw (std::out_of_range) {
+ // at will throw if needed, swig will handle
+ return self->at(i);
+ }
+ value_type set(int i, const value_type& VECTOR_VALUE_IN) throw (std::out_of_range) {
+ const T old = $self->at(i);
+ $self->at(i) = VECTOR_VALUE_IN;
+ return old;
+ }
+ int32_t size() const {
+ return $self->size();
+ }
+ void removeRange(int32_t from, int32_t to) {
+ $self->erase($self->begin()+from, $self->begin()+to);
+ }
+ }
+ };
+}
+
+%typemap(javabase) std::vector "java.util.AbstractList<$typemap(autobox,$1_basetype::value_type)>"
+%typemap(javainterface) std::vector "java.util.RandomAccess"
+%typemap(jstype) std::vector set "$typemap(autobox,$1_basetype)"
+%typemap(jstype) std::vector &VECTOR_VALUE_IN "$typemap(autobox,$1_basetype)"
+%typemap(javacode) std::vector %{
+ $javaclassname(java.util.Collection<$typemap(autobox,$1_basetype::value_type)> e) {
+ this.reserve(e.size());
+ for($typemap(autobox,$1_basetype::value_type) value : e) {
+ this.push_back(value);
+ }
+ }
+ public $typemap(autobox,$1_basetype::value_type) get(int idx) {
+ return get_impl(idx);
+ }
+%}
\ No newline at end of file

java: converted wrappers for std::vector to inherit from AbstractList<>

Signed-off-by: Bogdan Ichim <bogdan.ichim@rinftech.com>
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>