summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/nio
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-21 11:06:52 +0200
committerSven Gothel <[email protected]>2011-07-21 11:06:52 +0200
commitdc4b259b6651bdc0cec0895bc74e26e504870c8e (patch)
treeafd356aa28e4091ce12c8c6bc5e3a6b9edf48a58 /src/java/com/jogamp/common/nio
parent8e0d7f00c69d79bcdac4be508e5b5999b423e904 (diff)
GlueGen proper size / alignment of primitive and compound types usage [2/2] - Fin
MachineDesction == MD MD.StaticConfig: - enum for all supported static configs (ID -> MD) - verified at runtime: test runtime queried-MD versus static-MD, hard fail if not compatible (size/alignment) SizeThunk primitive sizes: - Add notion of fixed native size (eg. int64_t) and otherwise (eg. long) java struct 'wrappers' code generation: - single class using size/offset arrays of all MachineDescription configurations - at runtime the array idx is queried in static block - type aligment for not fixed-native-size types (SizeThunk, undef long/int) via StructAccessor junit test: - add float test - fix native code - add java (create, write) -> native (verify) test works (tested) on: linux 32/64 and windows 32/64
Diffstat (limited to 'src/java/com/jogamp/common/nio')
-rw-r--r--src/java/com/jogamp/common/nio/StructAccessor.java65
1 files changed, 59 insertions, 6 deletions
diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java
index 5c0e70a..41da290 100644
--- a/src/java/com/jogamp/common/nio/StructAccessor.java
+++ b/src/java/com/jogamp/common/nio/StructAccessor.java
@@ -113,6 +113,37 @@ public class StructAccessor {
bb.putInt(byteOffset, v);
}
+ /** Retrieves the int at the specified byteOffset. */
+ public final int getIntAt(int byteOffset, int nativeSizeInBytes) {
+ switch(nativeSizeInBytes) {
+ case 2:
+ return (int) bb.getShort(byteOffset) & 0x0000FFFF ;
+ case 4:
+ return bb.getInt(byteOffset);
+ case 8:
+ return (int) ( bb.getLong(byteOffset) & 0x00000000FFFFFFFFL ) ;
+ default:
+ throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes);
+ }
+ }
+
+ /** Puts a int at the specified byteOffset. */
+ public final void setIntAt(int byteOffset, int v, int nativeSizeInBytes) {
+ switch(nativeSizeInBytes) {
+ case 2:
+ bb.putShort(byteOffset, (short) ( v & 0x0000FFFF ) );
+ break;
+ case 4:
+ bb.putInt(byteOffset, v);
+ break;
+ case 8:
+ bb.putLong(byteOffset, (long)v & 0x00000000FFFFFFFFL );
+ break;
+ default:
+ throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes);
+ }
+ }
+
/** Retrieves the float at the specified byteOffset. */
public final float getFloatAt(int byteOffset) {
return bb.getFloat(byteOffset);
@@ -133,20 +164,42 @@ public class StructAccessor {
bb.putDouble(byteOffset, v);
}
- /**
- * Retrieves the long at the specified byteOffset.
- */
+ /** Retrieves the long at the specified byteOffset. */
public final long getLongAt(int byteOffset) {
return bb.getLong(byteOffset);
}
- /**
- * Puts a long at the specified byteOffset.
- */
+ /** Puts a long at the specified byteOffset. */
public final void setLongAt(int byteOffset, long v) {
bb.putLong(byteOffset, v);
}
+ /** Retrieves the long at the specified byteOffset. */
+ public final long getLongAt(int byteOffset, int nativeSizeInBytes) {
+ switch(nativeSizeInBytes) {
+ case 4:
+ return (long) bb.getInt(byteOffset) & 0x00000000FFFFFFFFL;
+ case 8:
+ return bb.getLong(byteOffset);
+ default:
+ throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes);
+ }
+ }
+
+ /** Puts a long at the specified byteOffset. */
+ public final void setLongAt(int byteOffset, long v, int nativeSizeInBytes) {
+ switch(nativeSizeInBytes) {
+ case 4:
+ bb.putInt(byteOffset, (int) ( v & 0x00000000FFFFFFFFL ) );
+ break;
+ case 8:
+ bb.putLong(byteOffset, v);
+ break;
+ default:
+ throw new InternalError("invalid nativeSizeInBytes "+nativeSizeInBytes);
+ }
+ }
+
public final void setBytesAt(int byteOffset, byte[] v) {
for (int i = 0; i < v.length; i++) {
bb.put(byteOffset++, v[i]);