From 0fa706b4eef533ead671310a9a7e063a910198cb Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 12 Feb 2010 02:22:24 +0100 Subject: added support for arrays in generated StructAccessors. Specifying JavaClass or JavaImplClass is no longer a requirement. It is now possible to generate StructAccessors from c headers without emitting any other binding code (force with EmitStruct ). --- .../runtime/StructAccessor.java.javame_cdc_fp | 39 +++++++++++++ .../sun/gluegen/runtime/StructAccessor.java.javase | 65 ++++++++++++++++++++++ 2 files changed, 104 insertions(+) (limited to 'src/java/com/sun/gluegen/runtime') diff --git a/src/java/com/sun/gluegen/runtime/StructAccessor.java.javame_cdc_fp b/src/java/com/sun/gluegen/runtime/StructAccessor.java.javame_cdc_fp index d670bcc..d97d2a0 100755 --- a/src/java/com/sun/gluegen/runtime/StructAccessor.java.javame_cdc_fp +++ b/src/java/com/sun/gluegen/runtime/StructAccessor.java.javame_cdc_fp @@ -98,6 +98,45 @@ public class StructAccessor { intBuffer().put(slot, v); } + public void setBytesAt(int slot, byte[] v) { + for (int i = 0; i < v.length; i++) { + bb.put(slot++, v[i]); + } + } + + public byte[] getBytesAt(int slot, byte[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = bb.get(slot++); + } + return v; + } + + public void setIntsAt(int slot, int[] v) { + for (int i = 0; i < v.length; i++) { + intBuffer().put(slot++, v[i]); + } + } + + public int[] getIntsAt(int slot, int[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = intBuffer().get(slot++); + } + return v; + } + + public void setFloatsAt(int slot, float[] v) { + for (int i = 0; i < v.length; i++) { + floatBuffer().put(slot++, v[i]); + } + } + + public float[] getFloatsAt(int slot, float[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = floatBuffer().get(slot++); + } + return v; + } + /** Retrieves the long at the specified slot (8-byte offset). */ public long getLongAt(int slot) { slot = slot << 1 ; // 8-byte to 4-byte offset diff --git a/src/java/com/sun/gluegen/runtime/StructAccessor.java.javase b/src/java/com/sun/gluegen/runtime/StructAccessor.java.javase index 5a0fa5d..9113859 100755 --- a/src/java/com/sun/gluegen/runtime/StructAccessor.java.javase +++ b/src/java/com/sun/gluegen/runtime/StructAccessor.java.javase @@ -143,6 +143,71 @@ public class StructAccessor { shortBuffer().put(slot, v); } + public void setBytesAt(int slot, byte[] v) { + for (int i = 0; i < v.length; i++) { + bb.put(slot++, v[i]); + } + } + + public byte[] getBytesAt(int slot, byte[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = bb.get(slot++); + } + return v; + } + + public void setCharsAt(int slot, char[] v) { + for (int i = 0; i < v.length; i++) { + charBuffer().put(slot++, v[i]); + } + } + + public char[] getCharsAt(int slot, char[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = charBuffer().get(slot++); + } + return v; + } + + public void setIntsAt(int slot, int[] v) { + for (int i = 0; i < v.length; i++) { + intBuffer().put(slot++, v[i]); + } + } + + public int[] getIntsAt(int slot, int[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = intBuffer().get(slot++); + } + return v; + } + + public void setFloatsAt(int slot, float[] v) { + for (int i = 0; i < v.length; i++) { + floatBuffer().put(slot++, v[i]); + } + } + + public float[] getFloatsAt(int slot, float[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = floatBuffer().get(slot++); + } + return v; + } + + public void setDoublesAt(int slot, double[] v) { + for (int i = 0; i < v.length; i++) { + doubleBuffer().put(slot++, v[i]); + } + } + + public double[] getDoublesAt(int slot, double[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = doubleBuffer().get(slot++); + } + return v; + } + //---------------------------------------------------------------------- // Internals only below this point // -- cgit v1.2.3