summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/common')
-rw-r--r--src/java/com/jogamp/common/nio/AbstractBuffer.java49
-rw-r--r--src/java/com/jogamp/common/nio/AbstractLongBuffer.java142
-rwxr-xr-xsrc/java/com/jogamp/common/nio/Buffers.java26
-rw-r--r--src/java/com/jogamp/common/nio/NativeBuffer.java28
-rw-r--r--src/java/com/jogamp/common/nio/PointerBuffer.java190
-rwxr-xr-xsrc/java/com/jogamp/common/nio/PointerBufferSE.java84
6 files changed, 221 insertions, 298 deletions
diff --git a/src/java/com/jogamp/common/nio/AbstractBuffer.java b/src/java/com/jogamp/common/nio/AbstractBuffer.java
index 870f3c0..58bab65 100644
--- a/src/java/com/jogamp/common/nio/AbstractBuffer.java
+++ b/src/java/com/jogamp/common/nio/AbstractBuffer.java
@@ -33,15 +33,17 @@ package com.jogamp.common.nio;
import com.jogamp.common.os.*;
+import java.nio.Buffer;
import java.nio.ByteBuffer;
/**
- * @author Michael Bien
* @author Sven Gothel
+ * @author Michael Bien
*/
public abstract class AbstractBuffer<B extends AbstractBuffer> implements NativeBuffer<B> {
- protected final ByteBuffer bb;
+ protected final int elementSize;
+ protected final Buffer buffer;
protected int capacity;
protected int position;
@@ -49,13 +51,22 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
NativeLibrary.ensureNativeLibLoaded();
}
- protected AbstractBuffer(ByteBuffer bb, int elementSize) {
- this.bb = bb;
+ /**
+ * @param buffer expected in target format
+ * @param elementSize the target element size in bytes
+ */
+ protected AbstractBuffer(Buffer buffer, int elementSize) {
+ this.elementSize = elementSize;
+ this.buffer = buffer;
- capacity = bb.capacity() / elementSize;
+ capacity = buffer.capacity() /* / elementSize */;
position = 0;
}
+ public final int elementSize() {
+ return elementSize;
+ }
+
public final int limit() {
return capacity;
}
@@ -90,25 +101,33 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
return (B) this;
}
- public boolean hasArray() {
- return false;
+ public final Buffer getBuffer() {
+ return buffer;
}
- public int arrayOffset() {
- return 0;
+ public final boolean isDirect() {
+ return buffer.isDirect();
}
-
- public final ByteBuffer getBuffer() {
- return bb;
+
+ public final boolean hasArray() {
+ return buffer.hasArray();
}
- public final boolean isDirect() {
- return bb.isDirect();
+ public final int arrayOffset() {
+ if(hasArray()) {
+ return buffer.arrayOffset();
+ } else {
+ return 0;
+ }
}
+ public Object array() throws UnsupportedOperationException {
+ return buffer.array();
+ }
+
@Override
public String toString() {
- return "AbstractBuffer[capacity "+capacity+", position "+position+", elementSize "+(bb.capacity()/capacity)+", ByteBuffer.capacity "+bb.capacity()+"]";
+ return "AbstractBuffer[direct "+isDirect()+", hasArray "+hasArray()+", capacity "+capacity+", position "+position+", elementSize "+elementSize+", buffer[capacity "+buffer.capacity()+", lim "+buffer.limit()+", pos "+buffer.position()+"]]";
}
}
diff --git a/src/java/com/jogamp/common/nio/AbstractLongBuffer.java b/src/java/com/jogamp/common/nio/AbstractLongBuffer.java
deleted file mode 100644
index c097e2e..0000000
--- a/src/java/com/jogamp/common/nio/AbstractLongBuffer.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions 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.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-
-/*
- * Created on Saturday, March 27 2010 11:55
- */
-package com.jogamp.common.nio;
-
-import com.jogamp.common.os.*;
-import java.nio.ByteBuffer;
-
-/**
- * Hardware independent container for native pointer arrays.
- *
- * The native values (NIO direct ByteBuffer) might be 32bit or 64bit wide,
- * depending of the CPU pointer width.
- *
- * @author Michael Bien
- * @author Sven Gothel
- */
-public abstract class AbstractLongBuffer<B extends AbstractLongBuffer> extends AbstractBuffer<B> {
-
- protected long[] backup;
-
- static {
- NativeLibrary.ensureNativeLibLoaded();
- }
-
- protected AbstractLongBuffer(ByteBuffer bb, int elementSize) {
- super(bb, elementSize);
-
- backup = new long[capacity];
- }
-
- final void updateBackup() {
- for (int i = 0; i < capacity; i++) {
- backup[i] = get(i);
- }
- }
-
- @Override
- public final boolean hasArray() {
- return true;
- }
-
- public final long[] array() {
- return backup;
- }
-
- /** Absolute get method. Get the pointer value at the given index */
- public abstract long get(int idx);
-
- /** Relative get method. Get the pointer value at the current position and increment the position by one. */
- public final long get() {
- long r = get(position);
- position++;
- return r;
- }
-
- /**
- * Relative bulk get method. Copy the pointer values <code> [ position .. position+length [</code>
- * to the destination array <code> [ dest[offset] .. dest[offset+length] [ </code>
- * and increment the position by <code>length</code>. */
- public final AbstractLongBuffer get(long[] dest, int offset, int length) {
- if (dest.length<offset+length) {
- throw new IndexOutOfBoundsException();
- }
- if (remaining() < length) {
- throw new IndexOutOfBoundsException();
- }
- while(length>0) {
- dest[offset++] = get(position++);
- length--;
- }
- return this;
- }
-
- /** Absolute put method. Put the pointer value at the given index */
- 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 B put(long value) {
- put(position, value);
- position++;
- return (B) this;
- }
-
- /**
- * Relative bulk put method. Put the pointer values <code> [ src[offset] .. src[offset+length] [</code>
- * at the current position and increment the position by <code>length</code>. */
- public final AbstractLongBuffer put(long[] src, int offset, int length) {
- if (src.length<offset+length) {
- throw new IndexOutOfBoundsException();
- }
- if (remaining() < length) {
- throw new IndexOutOfBoundsException();
- }
- while(length>0) {
- put(position++, src[offset++]);
- length--;
- }
- return this;
- }
-
- /**
- * 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 B put(B src) {
- if (remaining() < src.remaining()) {
- throw new IndexOutOfBoundsException();
- }
- while (src.hasRemaining()) {
- put(src.get());
- }
- return (B) this;
- }
-}
diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java
index ed9323e..0d30026 100755
--- a/src/java/com/jogamp/common/nio/Buffers.java
+++ b/src/java/com/jogamp/common/nio/Buffers.java
@@ -329,9 +329,9 @@ public class Buffers {
} else if (buf instanceof CharBuffer) {
return pos * SIZEOF_CHAR;
}
- } else if (buf instanceof PointerBuffer) {
- PointerBuffer pointerBuffer = (PointerBuffer) buf;
- return pointerBuffer.position() * PointerBuffer.elementSize();
+ } else if (buf instanceof NativeBuffer) {
+ final NativeBuffer nb = (NativeBuffer) buf;
+ return nb.position() * nb.elementSize() ;
}
throw new IllegalArgumentException("Disallowed array backing store type in buffer " + buf.getClass().getName());
@@ -340,15 +340,17 @@ public class Buffers {
/**
* Helper routine to return the array backing store reference from
* a Buffer object.
+ * @throws UnsupportedOperationException if the passed Object does not have an array backing store
+ * @throws IllegalArgumentException if the passed Object is neither of type {@link java.nio.Buffer} or {@link NativeBuffer}.
*/
- public static Object getArray(Object buf) {
+ public static Object getArray(Object buf) throws UnsupportedOperationException, IllegalArgumentException {
if (buf == null) {
return null;
}
if (buf instanceof Buffer) {
return ((Buffer) buf).array();
- } else if (buf instanceof PointerBuffer) {
- return ((PointerBuffer) buf).array();
+ } else if (buf instanceof NativeBuffer) {
+ return ((NativeBuffer) buf).array();
}
throw new IllegalArgumentException("Disallowed array backing store type in buffer " + buf.getClass().getName());
@@ -381,9 +383,9 @@ public class Buffers {
} else if (buf instanceof CharBuffer) {
return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos));
}
- } else if (buf instanceof PointerBuffer) {
- PointerBuffer pointerBuffer = (PointerBuffer) buf;
- return PointerBuffer.elementSize() * (pointerBuffer.arrayOffset() + pointerBuffer.position());
+ } else if (buf instanceof NativeBuffer) {
+ final NativeBuffer nb = (NativeBuffer) buf;
+ return nb.elementSize() * ( nb.arrayOffset() + nb.position() );
}
throw new IllegalArgumentException("Unknown buffer type " + buf.getClass().getName());
@@ -772,9 +774,9 @@ public class Buffers {
} else if (buffer instanceof CharBuffer) {
bytesRemaining = elementsRemaining * SIZEOF_CHAR;
}
- } else if (buffer instanceof PointerBuffer) {
- PointerBuffer pointerBuffer = (PointerBuffer) buffer;
- bytesRemaining = pointerBuffer.remaining() * PointerBuffer.elementSize();
+ } else if (buffer instanceof NativeBuffer) {
+ final NativeBuffer nb = (NativeBuffer) buffer;
+ bytesRemaining = nb.remaining() * nb.elementSize();
}
if (bytesRemaining < minBytesRemaining) {
throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining);
diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java
index ad6bb39..666907f 100644
--- a/src/java/com/jogamp/common/nio/NativeBuffer.java
+++ b/src/java/com/jogamp/common/nio/NativeBuffer.java
@@ -31,16 +31,19 @@
*/
package com.jogamp.common.nio;
+import java.nio.Buffer;
import java.nio.ByteBuffer;
/**
* Hardware independent container for various kinds of buffers.
*
- * @author Michael Bien
* @author Sven Gothel
+ * @author Michael Bien
*/
public interface NativeBuffer<B extends NativeBuffer> {
+ public int elementSize();
+
public int limit();
public int capacity();
@@ -53,16 +56,30 @@ public interface NativeBuffer<B extends NativeBuffer> {
public boolean hasRemaining();
+ /**
+ * @return true if this buffer has a primitive backup array, otherwise false
+ */
public boolean hasArray();
+ /**
+ * @return the array offset of the optional primitive backup array of the buffer if {@link #hasArray()} is true,
+ * otherwise 0.
+ */
public int arrayOffset();
-
- public ByteBuffer getBuffer();
+
+ /**
+ * @return the primitive backup array of the buffer if {@link #hasArray()} is true,
+ * otherwise it throws {@link java.lang.UnsupportedOperationException}.
+ * The returned primitive array maybe of type <code>int[]</code> or <code>long[]</code>, etc ..
+ * @throws UnsupportedOperationException if this object has no backup array
+ * @see #hasArray()
+ */
+ public Object array() throws UnsupportedOperationException ;
+
+ public Buffer getBuffer();
public boolean isDirect();
- public long[] array();
-
public B rewind();
public B put(int index, long value);
@@ -74,5 +91,4 @@ 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 5f866e1..69f8bbd 100644
--- a/src/java/com/jogamp/common/nio/PointerBuffer.java
+++ b/src/java/com/jogamp/common/nio/PointerBuffer.java
@@ -31,10 +31,14 @@
*/
package com.jogamp.common.nio;
-import com.jogamp.common.os.*;
-import java.nio.ByteBuffer;
import java.nio.Buffer;
-import java.util.HashMap;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+
+import com.jogamp.common.os.NativeLibrary;
+import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.LongObjectHashMap;
/**
* Hardware independent container for native pointer arrays.
@@ -42,78 +46,184 @@ import java.util.HashMap;
* The native values (NIO direct ByteBuffer) might be 32bit or 64bit wide,
* depending of the CPU pointer width.
*
- * @author Michael Bien
* @author Sven Gothel
+ * @author Michael Bien
*/
-public abstract class PointerBuffer extends AbstractLongBuffer<PointerBuffer> {
-
- protected HashMap<Long, Buffer> dataMap = new HashMap<Long, Buffer>();
+public class PointerBuffer extends AbstractBuffer<PointerBuffer> {
+ public static final int ELEMENT_SIZE = Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG ;
+ protected LongObjectHashMap dataMap = null;
static {
NativeLibrary.ensureNativeLibLoaded();
}
- protected PointerBuffer(ByteBuffer bb) {
- super(bb, elementSize());
+ /** no backup array, use for direct usage only */
+ PointerBuffer(ByteBuffer bb) {
+ super(Platform.is32Bit() ? bb.asIntBuffer() : bb.asLongBuffer(), ELEMENT_SIZE);
+ }
+
+ /** supports backup array */
+ PointerBuffer(IntBuffer b) {
+ super(b, ELEMENT_SIZE);
+ }
+
+ /** supports backup array */
+ PointerBuffer(LongBuffer b) {
+ super(b, ELEMENT_SIZE);
+ }
+
+ private final void validateDataMap() {
+ if(null == dataMap) {
+ dataMap = new LongObjectHashMap();
+ dataMap.setKeyNotFoundValue(null);
+ }
}
+ /** Returns a non direct PointerBuffer in native order, having a backup array */
public static PointerBuffer allocate(int size) {
- return new PointerBufferSE(ByteBuffer.wrap(new byte[elementSize() * size]));
+ if (Platform.is32Bit()) {
+ return new PointerBuffer(IntBuffer.wrap(new int[size]));
+ } else {
+ return new PointerBuffer(LongBuffer.wrap(new long[size]));
+ }
}
+ /** Returns a direct PointerBuffer in native order, w/o backup array */
public static PointerBuffer allocateDirect(int size) {
- return new PointerBufferSE(Buffers.newDirectByteBuffer(elementSize() * size));
+ return new PointerBuffer(Buffers.newDirectByteBuffer(ELEMENT_SIZE * size));
}
public static PointerBuffer wrap(ByteBuffer src) {
- PointerBuffer res = new PointerBufferSE(src);
- res.updateBackup();
- return res;
+ return new PointerBuffer(src);
+ }
+ /**
+ * 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 final PointerBuffer put(PointerBuffer src) {
+ if (remaining() < src.remaining()) {
+ throw new IndexOutOfBoundsException();
+ }
+ if( null == src.dataMap && null == dataMap ) {
+ // fast path no dataMap usage on both
+ while (src.hasRemaining()) {
+ put(src.get());
+ }
+ } else {
+ while (src.hasRemaining()) {
+ final long addr = src.get();
+ put(addr);
+ if( null != src.dataMap) {
+ Buffer bb = (Buffer) src.dataMap.get(addr);
+ if(null!=bb) {
+ validateDataMap();
+ dataMap.put(addr, bb);
+ } else if( null != dataMap ) {
+ dataMap.remove(addr);
+ }
+ } else if( null != dataMap ) {
+ dataMap.remove(addr);
+ }
+ }
+ }
+ return this;
+ }
+
+ /** Relative get method. Get the pointer value at the current position and increment the position by one. */
+ public final long get() {
+ long r = get(position);
+ position++;
+ return r;
}
- public static int elementSize() {
- return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG;
+ /** Absolute get method. Get the pointer value at the given index */
+ public final long get(int idx) {
+ if (0 > idx || idx >= capacity) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (Platform.is32Bit()) {
+ return (long) ((IntBuffer) buffer).get(idx) & 0x00000000FFFFFFFFL;
+ } else {
+ return ((LongBuffer) buffer).get(idx);
+ }
+ }
+
+ /**
+ * Relative bulk get method. Copy the pointer values <code> [ position .. position+length [</code>
+ * to the destination array <code> [ dest[offset] .. dest[offset+length] [ </code>
+ * and increment the position by <code>length</code>. */
+ public final PointerBuffer get(long[] dest, int offset, int length) {
+ if (dest.length<offset+length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (remaining() < length) {
+ throw new IndexOutOfBoundsException();
+ }
+ while(length>0) {
+ dest[offset++] = get(position++);
+ length--;
+ }
+ return this;
}
- @Override
- public final PointerBuffer put(PointerBuffer src) {
- if (remaining() < src.remaining()) {
+ /** Absolute put method. Put the pointer value at the given index */
+ public final PointerBuffer put(int idx, long v) {
+ if (0 > idx || idx >= capacity) {
throw new IndexOutOfBoundsException();
}
- long addr;
- while (src.hasRemaining()) {
- addr = src.get();
- put(addr);
- Long addrL = new Long(addr);
- Buffer bb = (Buffer) dataMap.get(addrL);
- if(null!=bb) {
- dataMap.put(addrL, bb);
- } else {
- dataMap.remove(addrL);
- }
+ if (Platform.is32Bit()) {
+ ((IntBuffer) buffer).put(idx, (int) v);
+ } else {
+ ((LongBuffer) buffer).put(idx, v);
+ }
+ return this;
+ }
+
+ /** Relative put method. Put the pointer value at the current position and increment the position by one. */
+ public final PointerBuffer put(long value) {
+ put(position, value);
+ position++;
+ return this;
+ }
+
+ /**
+ * Relative bulk put method. Put the pointer values <code> [ src[offset] .. src[offset+length] [</code>
+ * at the current position and increment the position by <code>length</code>. */
+ public final PointerBuffer put(long[] src, int offset, int length) {
+ if (src.length<offset+length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (remaining() < length) {
+ throw new IndexOutOfBoundsException();
+ }
+ while(length>0) {
+ put(position++, src[offset++]);
+ length--;
}
return this;
}
/** Put the address of the given direct Buffer at the given position
of this pointer array.
- Adding a reference of the given direct Buffer to this object. */
+ Adding a reference of the given direct Buffer to this object.
+
+ @throws IllegalArgumentException if bb is null or not a direct buffer
+ */
public final PointerBuffer referenceBuffer(int index, Buffer bb) {
if(null==bb) {
- throw new RuntimeException("Buffer is null");
+ throw new IllegalArgumentException("Buffer is null");
}
if(!Buffers.isDirect(bb)) {
- throw new RuntimeException("Buffer is not direct");
+ throw new IllegalArgumentException("Buffer is not direct");
}
long mask = Platform.is32Bit() ? 0x00000000FFFFFFFFL : 0xFFFFFFFFFFFFFFFFL ;
long bbAddr = getDirectBufferAddressImpl(bb) & mask;
if(0==bbAddr) {
throw new RuntimeException("Couldn't determine native address of given Buffer: "+bb);
}
-
- put(index, bbAddr);
- dataMap.put(new Long(bbAddr), bb);
+ validateDataMap();
+ put(index, bbAddr);
+ dataMap.put(bbAddr, bb);
return this;
}
@@ -127,8 +237,11 @@ public abstract class PointerBuffer extends AbstractLongBuffer<PointerBuffer> {
}
public final Buffer getReferencedBuffer(int index) {
- long addr = get(index);
- return dataMap.get(new Long(addr));
+ if(null != dataMap) {
+ long addr = get(index);
+ return (Buffer) dataMap.get(addr);
+ }
+ return null;
}
public final Buffer getReferencedBuffer() {
@@ -143,5 +256,4 @@ public abstract class PointerBuffer extends AbstractLongBuffer<PointerBuffer> {
public String toString() {
return "PointerBuffer:"+super.toString();
}
-
}
diff --git a/src/java/com/jogamp/common/nio/PointerBufferSE.java b/src/java/com/jogamp/common/nio/PointerBufferSE.java
deleted file mode 100755
index f3fdc68..0000000
--- a/src/java/com/jogamp/common/nio/PointerBufferSE.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. 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 PointerBufferSE extends PointerBuffer {
-
- private Buffer pb;
-
- PointerBufferSE(ByteBuffer bb) {
- super(bb);
-
- if (Platform.is32Bit()) {
- this.pb = bb.asIntBuffer();
- } else {
- this.pb = bb.asLongBuffer();
- }
- }
-
- public final long get(int idx) {
- if (0 > idx || idx >= capacity) {
- throw new IndexOutOfBoundsException();
- }
- if (Platform.is32Bit()) {
- return (long) ((IntBuffer) pb).get(idx) & 0x00000000FFFFFFFFL;
- } else {
- return ((LongBuffer) pb).get(idx);
- }
- }
-
- public final PointerBufferSE put(int idx, long v) {
- if (0 > idx || idx >= capacity) {
- throw new IndexOutOfBoundsException();
- }
- backup[idx] = v;
- if (Platform.is32Bit()) {
- ((IntBuffer) pb).put(idx, (int) v);
- } else {
- ((LongBuffer) pb).put(idx, v);
- }
- return this;
- }
-
-}