diff options
author | Michael Bien <[email protected]> | 2011-02-09 22:19:22 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-02-09 22:19:22 +0100 |
commit | e581ea0e1f65101a7d4baf99d18fa43e1aa20b01 (patch) | |
tree | d41b99d3ea1dd68e7054e63778aee5208980409d | |
parent | e20879b9f124ecca8bc7467013e118d1b7f5782b (diff) |
- removed CDC impl for com.jogamp.common.nio
- generified class hierarchy (casts no longer needed in client code)
- @Override where needed and other minor changes
-rw-r--r-- | src/java/com/jogamp/common/nio/AbstractBuffer.java | 13 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/AbstractLongBuffer.java | 17 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/nio/Buffers.java | 123 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/Int64Buffer.java | 23 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java | 89 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/nio/Int64BufferSE.java | 2 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/NativeBuffer.java | 8 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/PointerBuffer.java | 27 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java | 92 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/nio/PointerBufferSE.java | 2 | ||||
-rw-r--r-- | src/java/com/jogamp/common/nio/StructAccessor.java | 59 |
11 files changed, 83 insertions, 372 deletions
diff --git a/src/java/com/jogamp/common/nio/AbstractBuffer.java b/src/java/com/jogamp/common/nio/AbstractBuffer.java index f3ad9eb..870f3c0 100644 --- a/src/java/com/jogamp/common/nio/AbstractBuffer.java +++ b/src/java/com/jogamp/common/nio/AbstractBuffer.java @@ -34,14 +34,12 @@ package com.jogamp.common.nio; import com.jogamp.common.os.*; import java.nio.ByteBuffer; -import java.nio.Buffer; -import java.util.HashMap; /** * @author Michael Bien * @author Sven Gothel */ -public abstract class AbstractBuffer implements NativeBuffer { +public abstract class AbstractBuffer<B extends AbstractBuffer> implements NativeBuffer<B> { protected final ByteBuffer bb; protected int capacity; @@ -70,13 +68,13 @@ public abstract class AbstractBuffer implements NativeBuffer { return position; } - public final NativeBuffer position(int newPos) { + public final B position(int newPos) { if (0 > newPos || newPos >= capacity) { throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + "My capacity is "+capacity()+"."); } position = newPos; - return this; + return (B)this; } public final int remaining() { @@ -87,9 +85,9 @@ public abstract class AbstractBuffer implements NativeBuffer { return position < capacity; } - public final NativeBuffer rewind() { + public final B rewind() { position = 0; - return this; + return (B) this; } public boolean hasArray() { @@ -108,6 +106,7 @@ public abstract class AbstractBuffer implements NativeBuffer { return bb.isDirect(); } + @Override public String toString() { return "AbstractBuffer[capacity "+capacity+", position "+position+", elementSize "+(bb.capacity()/capacity)+", ByteBuffer.capacity "+bb.capacity()+"]"; } diff --git a/src/java/com/jogamp/common/nio/AbstractLongBuffer.java b/src/java/com/jogamp/common/nio/AbstractLongBuffer.java index c1ff409..c097e2e 100644 --- a/src/java/com/jogamp/common/nio/AbstractLongBuffer.java +++ b/src/java/com/jogamp/common/nio/AbstractLongBuffer.java @@ -33,8 +33,6 @@ package com.jogamp.common.nio; import com.jogamp.common.os.*; import java.nio.ByteBuffer; -import java.nio.Buffer; -import java.util.HashMap; /** * Hardware independent container for native pointer arrays. @@ -45,12 +43,10 @@ import java.util.HashMap; * @author Michael Bien * @author Sven Gothel */ -public abstract class AbstractLongBuffer extends AbstractBuffer { +public abstract class AbstractLongBuffer<B extends AbstractLongBuffer> extends AbstractBuffer<B> { protected long[] backup; - protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap(); - static { NativeLibrary.ensureNativeLibLoaded(); } @@ -67,6 +63,7 @@ public abstract class AbstractLongBuffer extends AbstractBuffer { } } + @Override public final boolean hasArray() { return true; } @@ -104,13 +101,13 @@ public abstract class AbstractLongBuffer extends AbstractBuffer { } /** Absolute put method. Put the pointer value at the given index */ - public abstract AbstractLongBuffer put(int index, long value); + public abstract B put(int index, long value); /** Relative put method. Put the pointer value at the current position and increment the position by one. */ - public final AbstractLongBuffer put(long value) { + public final B put(long value) { put(position, value); position++; - return this; + return (B) this; } /** @@ -133,13 +130,13 @@ public abstract class AbstractLongBuffer extends AbstractBuffer { /** * Relative bulk get method. Copy the source values <code> src[position .. capacity] [</code> * to this buffer and increment the position by <code>capacity-position</code>. */ - public AbstractLongBuffer put(AbstractLongBuffer src) { + public B put(B src) { if (remaining() < src.remaining()) { throw new IndexOutOfBoundsException(); } while (src.hasRemaining()) { put(src.get()); } - return this; + return (B) this; } } diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java index a1ea320..9b7db23 100755 --- a/src/java/com/jogamp/common/nio/Buffers.java +++ b/src/java/com/jogamp/common/nio/Buffers.java @@ -38,7 +38,6 @@ */ package com.jogamp.common.nio; -import com.jogamp.common.os.Platform; import java.nio.*; /** @@ -217,14 +216,12 @@ public class Buffers { return ((ShortBuffer) buffer).slice(); } else if (buffer instanceof FloatBuffer) { return ((FloatBuffer) buffer).slice(); - } else if (Platform.isJavaSE()) { - if (buffer instanceof DoubleBuffer) { - return ((DoubleBuffer) buffer).slice(); - } else if (buffer instanceof LongBuffer) { - return ((LongBuffer) buffer).slice(); - } else if (buffer instanceof CharBuffer) { - return ((CharBuffer) buffer).slice(); - } + } else if (buffer instanceof DoubleBuffer) { + return ((DoubleBuffer) buffer).slice(); + } else if (buffer instanceof LongBuffer) { + return ((LongBuffer) buffer).slice(); + } else if (buffer instanceof CharBuffer) { + return ((CharBuffer) buffer).slice(); } throw new IllegalArgumentException("unexpected buffer type: " + buffer.getClass()); } @@ -249,19 +246,13 @@ public class Buffers { * implementation. */ public static ByteBuffer nativeOrder(ByteBuffer buf) { - if (Platform.isJavaSE()) { - return buf.order(ByteOrder.nativeOrder()); - } else { - // JSR 239 does not support the ByteOrder class or the order methods. - // The initial order of a byte buffer is the platform byte order. - return buf; - } + return buf.order(ByteOrder.nativeOrder()); } /** * Returns the size of a single element of this buffer in bytes. */ - public static final int sizeOfBufferElem(Buffer buffer) { + public static int sizeOfBufferElem(Buffer buffer) { if (buffer == null) { return 0; } @@ -273,14 +264,12 @@ public class Buffers { return SIZEOF_SHORT; } else if (buffer instanceof FloatBuffer) { return SIZEOF_FLOAT; - } else if (Platform.isJavaSE()) { - if (buffer instanceof DoubleBuffer) { - return SIZEOF_DOUBLE; - } else if (buffer instanceof LongBuffer) { - return SIZEOF_LONG; - } else if (buffer instanceof CharBuffer) { - return SIZEOF_CHAR; - } + } else if (buffer instanceof DoubleBuffer) { + return SIZEOF_DOUBLE; + } else if (buffer instanceof LongBuffer) { + return SIZEOF_LONG; + } else if (buffer instanceof CharBuffer) { + return SIZEOF_CHAR; } throw new RuntimeException("Unexpected buffer type " + buffer.getClass().getName()); } @@ -306,14 +295,12 @@ public class Buffers { return ((Int64Buffer) buf).isDirect(); } else if (buf instanceof PointerBuffer) { return ((PointerBuffer) buf).isDirect(); - } else if (Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return ((DoubleBuffer) buf).isDirect(); - } else if (buf instanceof LongBuffer) { - return ((LongBuffer) buf).isDirect(); - }else if (buf instanceof CharBuffer) { - return ((CharBuffer) buf).isDirect(); - } + } else if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).isDirect(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).isDirect(); + }else if (buf instanceof CharBuffer) { + return ((CharBuffer) buf).isDirect(); } throw new IllegalArgumentException("Unexpected buffer type " + buf.getClass().getName()); } @@ -337,14 +324,12 @@ public class Buffers { return pos * SIZEOF_INT; } else if (buf instanceof ShortBuffer) { return pos * SIZEOF_SHORT; - }else if(Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return pos * SIZEOF_DOUBLE; - } else if (buf instanceof LongBuffer) { - return pos * SIZEOF_LONG; - } else if (buf instanceof CharBuffer) { - return pos * SIZEOF_CHAR; - } + }else if (buf instanceof DoubleBuffer) { + return pos * SIZEOF_DOUBLE; + } else if (buf instanceof LongBuffer) { + return pos * SIZEOF_LONG; + } else if (buf instanceof CharBuffer) { + return pos * SIZEOF_CHAR; } } else if (buf instanceof Int64Buffer) { Int64Buffer int64Buffer = (Int64Buffer) buf; @@ -377,14 +362,12 @@ public class Buffers { return ((Int64Buffer) buf).array(); } else if (buf instanceof PointerBuffer) { return ((PointerBuffer) buf).array(); - }else if(Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return ((DoubleBuffer) buf).array(); - } else if (buf instanceof LongBuffer) { - return ((LongBuffer) buf).array(); - } else if (buf instanceof CharBuffer) { - return ((CharBuffer) buf).array(); - } + }else if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).array(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).array(); + } else if (buf instanceof CharBuffer) { + return ((CharBuffer) buf).array(); } throw new IllegalArgumentException("Disallowed array backing store type in buffer " + buf.getClass().getName()); @@ -410,14 +393,12 @@ public class Buffers { return (SIZEOF_INT * (((IntBuffer) buf).arrayOffset() + pos)); } else if (buf instanceof ShortBuffer) { return (SIZEOF_SHORT * (((ShortBuffer) buf).arrayOffset() + pos)); - }else if(Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return (SIZEOF_DOUBLE * (((DoubleBuffer) buf).arrayOffset() + pos)); - } else if (buf instanceof LongBuffer) { - return (SIZEOF_LONG * (((LongBuffer) buf).arrayOffset() + pos)); - } else if (buf instanceof CharBuffer) { - return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos)); - } + }else if (buf instanceof DoubleBuffer) { + return (SIZEOF_DOUBLE * (((DoubleBuffer) buf).arrayOffset() + pos)); + } else if (buf instanceof LongBuffer) { + return (SIZEOF_LONG * (((LongBuffer) buf).arrayOffset() + pos)); + } else if (buf instanceof CharBuffer) { + return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos)); } } else if (buf instanceof Int64Buffer) { Int64Buffer int64Buffer = (Int64Buffer) buf; @@ -651,14 +632,12 @@ public class Buffers { return ((IntBuffer) dest).put((IntBuffer) src); } else if ((dest instanceof FloatBuffer) && (src instanceof FloatBuffer)) { return ((FloatBuffer) dest).put((FloatBuffer) src); - } else if (Platform.isJavaSE()) { - if ((dest instanceof LongBuffer) && (src instanceof LongBuffer)) { - return ((LongBuffer) dest).put((LongBuffer) src); - } else if ((dest instanceof DoubleBuffer) && (src instanceof DoubleBuffer)) { - return ((DoubleBuffer) dest).put((DoubleBuffer) src); - } else if ((dest instanceof CharBuffer) && (src instanceof CharBuffer)) { - return ((CharBuffer) dest).put((CharBuffer) src); - } + } else if ((dest instanceof LongBuffer) && (src instanceof LongBuffer)) { + return ((LongBuffer) dest).put((LongBuffer) src); + } else if ((dest instanceof DoubleBuffer) && (src instanceof DoubleBuffer)) { + return ((DoubleBuffer) dest).put((DoubleBuffer) src); + } else if ((dest instanceof CharBuffer) && (src instanceof CharBuffer)) { + return ((CharBuffer) dest).put((CharBuffer) src); } throw new IllegalArgumentException("Incompatible Buffer classes: dest = " + dest.getClass().getName() + ", src = " + src.getClass().getName()); } @@ -808,14 +787,12 @@ public class Buffers { bytesRemaining = elementsRemaining * SIZEOF_INT; } else if (buffer instanceof ShortBuffer) { bytesRemaining = elementsRemaining * SIZEOF_SHORT; - }else if(Platform.isJavaSE()) { - if (buffer instanceof DoubleBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_DOUBLE; - } else if (buffer instanceof LongBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_LONG; - } else if (buffer instanceof CharBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_CHAR; - } + }else if (buffer instanceof DoubleBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_DOUBLE; + } else if (buffer instanceof LongBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_LONG; + } else if (buffer instanceof CharBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_CHAR; } } else if (buffer instanceof Int64Buffer) { Int64Buffer int64Buffer = (Int64Buffer) buffer; diff --git a/src/java/com/jogamp/common/nio/Int64Buffer.java b/src/java/com/jogamp/common/nio/Int64Buffer.java index 32fba03..968e48d 100644 --- a/src/java/com/jogamp/common/nio/Int64Buffer.java +++ b/src/java/com/jogamp/common/nio/Int64Buffer.java @@ -28,7 +28,6 @@ package com.jogamp.common.nio; -import com.jogamp.common.os.*; import java.nio.ByteBuffer; /** @@ -39,35 +38,22 @@ import java.nio.ByteBuffer; * @author Michael Bien * @author Sven Gothel */ -public abstract class Int64Buffer extends AbstractLongBuffer { +public abstract class Int64Buffer extends AbstractLongBuffer<Int64Buffer> { protected Int64Buffer(ByteBuffer bb) { super(bb, elementSize()); } public static Int64Buffer allocate(int size) { - if (Platform.isJavaSE()) { - return new Int64BufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); - } else { - return new Int64BufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); - } + return new Int64BufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); } public static Int64Buffer allocateDirect(int size) { - if (Platform.isJavaSE()) { - return new Int64BufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); - } else { - return new Int64BufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size)); - } + return new Int64BufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); } public static Int64Buffer wrap(ByteBuffer src) { - Int64Buffer res; - if (Platform.isJavaSE()) { - res = new Int64BufferSE(src); - } else { - res = new Int64BufferME_CDC_FP(src); - } + Int64Buffer res = new Int64BufferSE(src); res.updateBackup(); return res; @@ -77,6 +63,7 @@ public abstract class Int64Buffer extends AbstractLongBuffer { return Buffers.SIZEOF_LONG; } + @Override public String toString() { return "Int64Buffer:"+super.toString(); } diff --git a/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java b/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java deleted file mode 100755 index 9621677..0000000 --- a/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.common.nio; - -import com.jogamp.common.os.Platform; -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class Int64BufferME_CDC_FP extends Int64Buffer { - - private IntBuffer pb; - - Int64BufferME_CDC_FP(ByteBuffer bb) { - super(bb); - this.pb = bb.asIntBuffer(); - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; - } - - public final long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - idx = idx << 1; // 8-byte to 4-byte offset - long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); - long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); - if (Platform.isLittleEndian()) { - return hi << 32 | lo; - } - return lo << 32 | hi; - } - - public final AbstractLongBuffer put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - idx = idx << 1; // 8-byte to 4-byte offset - int lo = (int) ((v) & 0x00000000FFFFFFFFL); - int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); - if (Platform.isLittleEndian()) { - pb.put(idx, lo); - pb.put(idx + 1, hi); - } else { - pb.put(idx, hi); - pb.put(idx + 1, lo); - } - return this; - } -} diff --git a/src/java/com/jogamp/common/nio/Int64BufferSE.java b/src/java/com/jogamp/common/nio/Int64BufferSE.java index fc262fd..f9ef026 100755 --- a/src/java/com/jogamp/common/nio/Int64BufferSE.java +++ b/src/java/com/jogamp/common/nio/Int64BufferSE.java @@ -58,7 +58,7 @@ final class Int64BufferSE extends Int64Buffer { return pb.get(idx); } - public final AbstractLongBuffer put(int idx, long v) { + public final Int64BufferSE put(int idx, long v) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java index eeec3e3..ad6bb39 100644 --- a/src/java/com/jogamp/common/nio/NativeBuffer.java +++ b/src/java/com/jogamp/common/nio/NativeBuffer.java @@ -39,7 +39,7 @@ import java.nio.ByteBuffer; * @author Michael Bien * @author Sven Gothel */ -public interface NativeBuffer/*<B extends NativeBuffer>*/ { +public interface NativeBuffer<B extends NativeBuffer> { public int limit(); @@ -47,14 +47,12 @@ public interface NativeBuffer/*<B extends NativeBuffer>*/ { public int position(); - public NativeBuffer position(int newPos); + public B position(int newPos); public int remaining(); public boolean hasRemaining(); - public NativeBuffer rewind(); - public boolean hasArray(); public int arrayOffset(); @@ -63,7 +61,6 @@ public interface NativeBuffer/*<B extends NativeBuffer>*/ { public boolean isDirect(); -/* public long[] array(); public B rewind(); @@ -77,6 +74,5 @@ public interface NativeBuffer/*<B extends NativeBuffer>*/ { public long get(); public long get(int idx); -*/ } diff --git a/src/java/com/jogamp/common/nio/PointerBuffer.java b/src/java/com/jogamp/common/nio/PointerBuffer.java index f43dc20..5f866e1 100644 --- a/src/java/com/jogamp/common/nio/PointerBuffer.java +++ b/src/java/com/jogamp/common/nio/PointerBuffer.java @@ -45,9 +45,9 @@ import java.util.HashMap; * @author Michael Bien * @author Sven Gothel */ -public abstract class PointerBuffer extends AbstractLongBuffer { +public abstract class PointerBuffer extends AbstractLongBuffer<PointerBuffer> { - protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap(); + protected HashMap<Long, Buffer> dataMap = new HashMap<Long, Buffer>(); static { NativeLibrary.ensureNativeLibLoaded(); @@ -58,28 +58,15 @@ public abstract class PointerBuffer extends AbstractLongBuffer { } public static PointerBuffer allocate(int size) { - if (Platform.isJavaSE()) { - return new PointerBufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); - } else { - return new PointerBufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); - } + return new PointerBufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); } public static PointerBuffer allocateDirect(int size) { - if (Platform.isJavaSE()) { - return new PointerBufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); - } else { - return new PointerBufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size)); - } + return new PointerBufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); } public static PointerBuffer wrap(ByteBuffer src) { - PointerBuffer res; - if (Platform.isJavaSE()) { - res = new PointerBufferSE(src); - } else { - res = new PointerBufferME_CDC_FP(src); - } + PointerBuffer res = new PointerBufferSE(src); res.updateBackup(); return res; @@ -89,6 +76,7 @@ public abstract class PointerBuffer extends AbstractLongBuffer { return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG; } + @Override public final PointerBuffer put(PointerBuffer src) { if (remaining() < src.remaining()) { throw new IndexOutOfBoundsException(); @@ -140,7 +128,7 @@ public abstract class PointerBuffer extends AbstractLongBuffer { public final Buffer getReferencedBuffer(int index) { long addr = get(index); - return (Buffer) dataMap.get(new Long(addr)); + return dataMap.get(new Long(addr)); } public final Buffer getReferencedBuffer() { @@ -151,6 +139,7 @@ public abstract class PointerBuffer extends AbstractLongBuffer { private native long getDirectBufferAddressImpl(Object directBuffer); + @Override public String toString() { return "PointerBuffer:"+super.toString(); } diff --git a/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java b/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java deleted file mode 100755 index 5f84ffc..0000000 --- a/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.common.nio; - -import com.jogamp.common.os.Platform; -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class PointerBufferME_CDC_FP extends PointerBuffer { - - private IntBuffer pb; - - PointerBufferME_CDC_FP(ByteBuffer bb) { - super(bb); - this.pb = bb.asIntBuffer(); - } - - public final long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - if (Platform.is32Bit()) { - return (long) pb.get(idx) & 0x00000000FFFFFFFFL; - } else { - idx = idx << 1; // 8-byte to 4-byte offset - long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); - long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); - if (Platform.isLittleEndian()) { - return hi << 32 | lo; - } - return lo << 32 | hi; - } - } - - public final AbstractLongBuffer put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - if (Platform.is32Bit()) { - pb.put(idx, (int) v); - } else { - idx = idx << 1; // 8-byte to 4-byte offset - int lo = (int) ((v) & 0x00000000FFFFFFFFL); - int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); - if (Platform.isLittleEndian()) { - pb.put(idx, lo); - pb.put(idx + 1, hi); - } else { - pb.put(idx, hi); - pb.put(idx + 1, lo); - } - } - return this; - } -} diff --git a/src/java/com/jogamp/common/nio/PointerBufferSE.java b/src/java/com/jogamp/common/nio/PointerBufferSE.java index 04f9ca1..e265b6f 100755 --- a/src/java/com/jogamp/common/nio/PointerBufferSE.java +++ b/src/java/com/jogamp/common/nio/PointerBufferSE.java @@ -67,7 +67,7 @@ final class PointerBufferSE extends PointerBuffer { } } - public final AbstractLongBuffer put(int idx, long v) { + public final PointerBufferSE put(int idx, long v) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java index 117e8de..a586c98 100644 --- a/src/java/com/jogamp/common/nio/StructAccessor.java +++ b/src/java/com/jogamp/common/nio/StructAccessor.java @@ -38,7 +38,6 @@ */ package com.jogamp.common.nio; -import com.jogamp.common.os.Platform; import java.nio.*; /** @@ -51,8 +50,6 @@ public class StructAccessor { private FloatBuffer fb; private IntBuffer ib; private ShortBuffer sb; - - //Java SE only private CharBuffer cb; private DoubleBuffer db; private LongBuffer lb; @@ -60,13 +57,7 @@ public class StructAccessor { public StructAccessor(ByteBuffer bb) { // Setting of byte order is concession to native code which needs // to instantiate these - if(Platform.isJavaSE()) { - this.bb = bb.order(ByteOrder.nativeOrder()); - }else{ - // JSR 239 does not support the ByteOrder class or the order methods. - // The initial order of a byte buffer is the platform byte order. - this.bb = bb; - } + this.bb = bb.order(ByteOrder.nativeOrder()); } public ByteBuffer getBuffer() { @@ -225,53 +216,20 @@ public class StructAccessor { * Retrieves the long at the specified slot (8-byte offset). */ public long getLongAt(int slot) { - if(Platform.isJavaSE()){ - return longBuffer().get(slot); - }else{ - return getLongCDCAt(slot); - } + return longBuffer().get(slot); } /** * Puts a long at the specified slot (8-byte offset). */ public void setLongAt(int slot, long v) { - if(Platform.isJavaSE()){ - longBuffer().put(slot, v); - }else{ - setLongCDCAt(slot, v); - } + longBuffer().put(slot, v); } //---------------------------------------------------------------------- // Internals only below this point // - private final long getLongCDCAt(int slot) { - slot = slot << 1; // 8-byte to 4-byte offset - IntBuffer intBuffer = intBuffer(); - long lo = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot)); - long hi = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot + 1)); - if (Platform.isLittleEndian()) { - return hi << 32 | lo; - } - return lo << 32 | hi; - } - - private final void setLongCDCAt(int slot, long v) { - slot = slot << 1; // 8-byte to 4-byte offset - IntBuffer intBuffer = intBuffer(); - int lo = (int) ((v) & 0x00000000FFFFFFFFL); - int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); - if (Platform.isLittleEndian()) { - intBuffer.put(slot, lo); - intBuffer.put(slot + 1, hi); - } else { - intBuffer.put(slot, hi); - intBuffer.put(slot + 1, lo); - } - } - private final FloatBuffer floatBuffer() { if (fb == null) { fb = bb.asFloatBuffer(); @@ -293,10 +251,7 @@ public class StructAccessor { return sb; } - // - - Java SE only - - - private final LongBuffer longBuffer() { - checkSE(); if (lb == null) { lb = bb.asLongBuffer(); } @@ -304,7 +259,6 @@ public class StructAccessor { } private final DoubleBuffer doubleBuffer() { - checkSE(); if (db == null) { db = bb.asDoubleBuffer(); } @@ -312,16 +266,9 @@ public class StructAccessor { } private final CharBuffer charBuffer() { - checkSE(); if (cb == null) { cb = bb.asCharBuffer(); } return cb; } - - private static void checkSE() { - if (!Platform.isJavaSE()) { - throw new UnsupportedOperationException("I am affraid, this Operation is not supportet on this platform."); - } - } } |