Package com.jogamp.common.nio
Class AbstractBuffer<B extends AbstractBuffer>
- java.lang.Object
-
- com.jogamp.common.nio.AbstractBuffer<B>
-
- All Implemented Interfaces:
NativeBuffer<B>
- Direct Known Subclasses:
ElementBuffer
,PointerBuffer
public abstract class AbstractBuffer<B extends AbstractBuffer> extends Object implements NativeBuffer<B>
- Author:
- Sven Gothel, Michael Bien
-
-
Field Summary
Fields Modifier and Type Field Description protected Buffer
buffer
protected int
capacity
protected int
elementSize
protected int
limit
static int
POINTER_SIZE
Platform dependent pointer size in bytes, i.e.protected int
position
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractBuffer(Buffer buffer, int elementSize, int capacity)
capacity and elementSize should be match the equation w/ target buffer type
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
array()
int
arrayOffset()
int
capacity()
Returns this buffer's element capacity.B
clear()
Sets the limit to the capacity and the position to zero.int
elementSize()
Returns byte size of one elementB
flip()
Sets the limit to the current position and the position to zero.Buffer
getBuffer()
Returns the underlying buffer object.long
getDirectBufferAddress()
Returns the native address of the underlying buffer ifNativeBuffer.isDirect()
, otherwise0
.boolean
hasArray()
boolean
hasRemaining()
ReturnsNativeBuffer.remaining()
> 0boolean
isDirect()
Return true if the underlying buffer is NIO direct, otherwise false.int
limit()
Returns this buffer's element limit.B
limit(int newLim)
Sets this buffer's element limit.int
position()
Returns this buffer's element position.B
position(int newPos)
Sets this buffer's element position.int
remaining()
Returns this buffer's remaining element, i.e.B
rewind()
Sets the position to zero.void
storeDirectAddress(ByteBuffer directDest)
Store theNativeBuffer.getDirectBufferAddress()
into the givenByteBuffer
using relative put.void
storeDirectAddress(ByteBuffer directDest, int destBytePos)
Store theNativeBuffer.getDirectBufferAddress()
into the givenByteBuffer
using absolute put.String
toString()
protected String
toSubString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.jogamp.common.nio.NativeBuffer
put
-
-
-
-
Field Detail
-
POINTER_SIZE
public static final int POINTER_SIZE
Platform dependent pointer size in bytes, i.e. 32bit or 64bit wide, depending of the CPU pointer width.
-
buffer
protected final Buffer buffer
-
elementSize
protected final int elementSize
-
capacity
protected final int capacity
-
limit
protected int limit
-
position
protected int position
-
-
Constructor Detail
-
AbstractBuffer
protected AbstractBuffer(Buffer buffer, int elementSize, int capacity)
capacity and elementSize should be match the equation w/ target buffer typecapacity = elementSizeInBytes(buffer) * buffer.capacity() ) / elementSize
- Parameters:
buffer
- shall be in target format.elementSize
- the target element size in bytes.capacity
- the target capacity in elements of sizeelementSize
.
-
-
Method Detail
-
elementSize
public final int elementSize()
Description copied from interface:NativeBuffer
Returns byte size of one element- Specified by:
elementSize
in interfaceNativeBuffer<B extends AbstractBuffer>
-
limit
public final int limit()
Description copied from interface:NativeBuffer
Returns this buffer's element limit.- Specified by:
limit
in interfaceNativeBuffer<B extends AbstractBuffer>
-
limit
public final B limit(int newLim)
Description copied from interface:NativeBuffer
Sets this buffer's element limit.- Specified by:
limit
in interfaceNativeBuffer<B extends AbstractBuffer>
-
capacity
public final int capacity()
Description copied from interface:NativeBuffer
Returns this buffer's element capacity.- Specified by:
capacity
in interfaceNativeBuffer<B extends AbstractBuffer>
-
position
public final int position()
Description copied from interface:NativeBuffer
Returns this buffer's element position.- Specified by:
position
in interfaceNativeBuffer<B extends AbstractBuffer>
-
position
public final B position(int newPos)
Description copied from interface:NativeBuffer
Sets this buffer's element position.- Specified by:
position
in interfaceNativeBuffer<B extends AbstractBuffer>
-
remaining
public final int remaining()
Description copied from interface:NativeBuffer
Returns this buffer's remaining element, i.e. limit - position.- Specified by:
remaining
in interfaceNativeBuffer<B extends AbstractBuffer>
-
hasRemaining
public final boolean hasRemaining()
Description copied from interface:NativeBuffer
ReturnsNativeBuffer.remaining()
> 0- Specified by:
hasRemaining
in interfaceNativeBuffer<B extends AbstractBuffer>
-
clear
public final B clear()
Description copied from interface:NativeBuffer
Sets the limit to the capacity and the position to zero.- Specified by:
clear
in interfaceNativeBuffer<B extends AbstractBuffer>
-
flip
public final B flip()
Description copied from interface:NativeBuffer
Sets the limit to the current position and the position to zero.- Specified by:
flip
in interfaceNativeBuffer<B extends AbstractBuffer>
-
rewind
public final B rewind()
Description copied from interface:NativeBuffer
Sets the position to zero.- Specified by:
rewind
in interfaceNativeBuffer<B extends AbstractBuffer>
-
getBuffer
public final Buffer getBuffer()
Description copied from interface:NativeBuffer
Returns the underlying buffer object.- Specified by:
getBuffer
in interfaceNativeBuffer<B extends AbstractBuffer>
-
isDirect
public final boolean isDirect()
Description copied from interface:NativeBuffer
Return true if the underlying buffer is NIO direct, otherwise false.- Specified by:
isDirect
in interfaceNativeBuffer<B extends AbstractBuffer>
-
getDirectBufferAddress
public long getDirectBufferAddress()
Description copied from interface:NativeBuffer
Returns the native address of the underlying buffer ifNativeBuffer.isDirect()
, otherwise0
.- Specified by:
getDirectBufferAddress
in interfaceNativeBuffer<B extends AbstractBuffer>
-
storeDirectAddress
public void storeDirectAddress(ByteBuffer directDest)
Description copied from interface:NativeBuffer
Store theNativeBuffer.getDirectBufferAddress()
into the givenByteBuffer
using relative put.The native pointer value is stored either as a 32bit (int) or 64bit (long) wide value, depending of the CPU pointer width.
- Specified by:
storeDirectAddress
in interfaceNativeBuffer<B extends AbstractBuffer>
-
storeDirectAddress
public void storeDirectAddress(ByteBuffer directDest, int destBytePos)
Description copied from interface:NativeBuffer
Store theNativeBuffer.getDirectBufferAddress()
into the givenByteBuffer
using absolute put.The native pointer value is stored either as a 32bit (int) or 64bit (long) wide value, depending of the CPU pointer width.
- Specified by:
storeDirectAddress
in interfaceNativeBuffer<B extends AbstractBuffer>
-
hasArray
public final boolean hasArray()
- Specified by:
hasArray
in interfaceNativeBuffer<B extends AbstractBuffer>
- Returns:
- true if this buffer has a primitive backup array, otherwise false
-
arrayOffset
public final int arrayOffset()
- Specified by:
arrayOffset
in interfaceNativeBuffer<B extends AbstractBuffer>
- Returns:
- the array offset of the optional primitive backup array of the buffer if
NativeBuffer.hasArray()
is true, otherwise 0.
-
array
public Object array() throws UnsupportedOperationException
- Specified by:
array
in interfaceNativeBuffer<B extends AbstractBuffer>
- Returns:
- the primitive backup array of the buffer if
NativeBuffer.hasArray()
is true, otherwise it throwsUnsupportedOperationException
. The returned primitive array maybe of typeint[]
orlong[]
, etc .. - Throws:
UnsupportedOperationException
- if this object has no backup array- See Also:
NativeBuffer.hasArray()
-
toSubString
protected String toSubString()
-
-