diff options
Diffstat (limited to 'src/java/com/jogamp/common/nio/PointerBuffer.java')
-rw-r--r-- | src/java/com/jogamp/common/nio/PointerBuffer.java | 117 |
1 files changed, 23 insertions, 94 deletions
diff --git a/src/java/com/jogamp/common/nio/PointerBuffer.java b/src/java/com/jogamp/common/nio/PointerBuffer.java index 9b7232f..26d2e7b 100644 --- a/src/java/com/jogamp/common/nio/PointerBuffer.java +++ b/src/java/com/jogamp/common/nio/PointerBuffer.java @@ -30,8 +30,7 @@ */ package com.jogamp.common.nio; -import com.jogamp.common.os.NativeLibrary; -import com.jogamp.common.os.Platform; +import com.jogamp.common.os.*; import java.nio.ByteBuffer; import java.nio.Buffer; import java.util.HashMap; @@ -45,12 +44,7 @@ import java.util.HashMap; * @author Michael Bien * @author Sven Gothel */ -public abstract class PointerBuffer implements NativeBuffer/*<PointerBuffer>*/ { - - protected final ByteBuffer bb; - protected int capacity; - protected int position; - protected long[] backup; +public abstract class PointerBuffer extends AbstractLongBuffer { protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap(); @@ -59,7 +53,7 @@ public abstract class PointerBuffer implements NativeBuffer/*<PointerBuffer>*/ { } protected PointerBuffer(ByteBuffer bb) { - this.bb = bb; + super(bb, elementSize()); } public static PointerBuffer allocate(int size) { @@ -90,88 +84,33 @@ public abstract class PointerBuffer implements NativeBuffer/*<PointerBuffer>*/ { } - void updateBackup() { - for (int i = 0; i < capacity; i++) { - backup[i] = get(i); - } - } - - int arrayOffset() { - return 0; - } - public static int elementSize() { return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG; } - public int limit() { - return capacity; - } - - public int capacity() { - return capacity; - } - - public int position() { - return position; - } - - public PointerBuffer 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()+"."); + public final PointerBuffer put(PointerBuffer src) { + if (remaining() < src.remaining()) { + 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); + } } - position = newPos; - return this; - } - - public int remaining() { - return capacity - position; - } - - public boolean hasRemaining() { - return position < capacity; - } - - public PointerBuffer rewind() { - position = 0; return this; } - boolean hasArray() { - return true; - } - - public long[] array() { - return backup; - } - - public ByteBuffer getBuffer() { - return bb; - } - - public boolean isDirect() { - return bb.isDirect(); - } - - public long get() { - long r = get(position); - position++; - return r; - } - - public abstract long get(int idx); - - /** put the pointer value at position index */ - public abstract PointerBuffer put(int index, long value); - - /** put the pointer value at the end */ - public abstract PointerBuffer put(long value); - /** 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. */ - public PointerBuffer referenceBuffer(int index, Buffer bb) { + public final PointerBuffer referenceBuffer(int index, Buffer bb) { if(null==bb) { throw new RuntimeException("Buffer is null"); } @@ -191,18 +130,18 @@ public abstract class PointerBuffer implements NativeBuffer/*<PointerBuffer>*/ { /** Put the address of the given direct Buffer at the end of this pointer array. Adding a reference of the given direct Buffer to this object. */ - public PointerBuffer referenceBuffer(Buffer bb) { + public final PointerBuffer referenceBuffer(Buffer bb) { referenceBuffer(position, bb); position++; return this; } - public Buffer getReferencedBuffer(int index) { + public final Buffer getReferencedBuffer(int index) { long addr = get(index); return (Buffer) dataMap.get(new Long(addr)); } - public Buffer getReferencedBuffer() { + public final Buffer getReferencedBuffer() { Buffer bb = getReferencedBuffer(position); position++; return bb; @@ -210,18 +149,8 @@ public abstract class PointerBuffer implements NativeBuffer/*<PointerBuffer>*/ { private native long getDirectBufferAddressImpl(Object directBuffer); - public PointerBuffer put(PointerBuffer src) { - if (remaining() < src.remaining()) { - throw new IndexOutOfBoundsException(); - } - while (src.hasRemaining()) { - put(src.get()); - } - return this; - } - public String toString() { - return "PointerBuffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + return "PointerBuffer:"+super.toString(); } } |