public class PointerBuffer
extends java.lang.Object
implements java.lang.Comparable
Modifier and Type | Field and Description |
---|---|
protected java.nio.ByteBuffer |
pointers |
protected java.nio.Buffer |
view |
protected java.nio.IntBuffer |
view32 |
protected java.nio.LongBuffer |
view64 |
Constructor and Description |
---|
PointerBuffer(java.nio.ByteBuffer source)
Creates a new PointerBuffer using the specified ByteBuffer as its pointer
data source.
|
PointerBuffer(int capacity)
Creates a new PointerBuffer with the specified capacity.
|
Modifier and Type | Method and Description |
---|---|
static PointerBuffer |
allocateDirect(int capacity)
Allocates a new pointer buffer.
|
PointerBuffer |
asReadOnlyBuffer()
Creates a new, read-only pointer buffer that shares this buffer's
content.
|
int |
capacity()
Returns this buffer's capacity.
|
PointerBuffer |
clear()
Clears this buffer.
|
PointerBuffer |
compact()
Compacts this buffer (optional operation).
|
int |
compareTo(java.lang.Object o)
Compares this buffer to another.
|
PointerBuffer |
duplicate()
Creates a new pointer buffer that shares this buffer's content.
|
boolean |
equals(java.lang.Object ob)
Tells whether or not this buffer is equal to another object.
|
PointerBuffer |
flip()
Flips this buffer.
|
long |
get()
Relative get method.
|
long |
get(int index)
Absolute get method.
|
PointerBuffer |
get(long[] dst)
Relative bulk get method.
|
PointerBuffer |
get(long[] dst,
int offset,
int length)
Relative bulk get method.
|
java.nio.ByteBuffer |
getBuffer()
Returns the ByteBuffer that backs this PointerBuffer.
|
static int |
getPointerSize()
Returns the pointer size in bytes, based on the underlying architecture.
|
int |
hashCode()
Returns the current hash code of this buffer.
|
boolean |
hasRemaining()
Tells whether there are any elements between the current position and
the limit.
|
static boolean |
is64Bit()
Returns true if the underlying architecture is 64bit.
|
boolean |
isReadOnly() |
int |
limit()
Returns this buffer's limit.
|
PointerBuffer |
limit(int newLimit)
Sets this buffer's limit.
|
PointerBuffer |
mark()
Sets this buffer's mark at its position.
|
protected PointerBuffer |
newInstance(java.nio.ByteBuffer source)
This method is used in slice and duplicate instead of normal object construction,
so that subclasses can return themselves.
|
java.nio.ByteOrder |
order()
Retrieves this buffer's byte order.
|
int |
position()
Returns this buffer's position.
|
PointerBuffer |
position(int newPosition)
Sets this buffer's position.
|
int |
positionByte()
Returns this buffer's position, in bytes.
|
static void |
put(java.nio.ByteBuffer target,
int index,
long l)
Convenience put on a target ByteBuffer.
|
static void |
put(java.nio.ByteBuffer target,
long l)
Convenience put on a target ByteBuffer.
|
PointerBuffer |
put(int index,
long l)
Absolute put method (optional operation).
|
PointerBuffer |
put(int index,
PointerWrapper pointer)
Convenience put that accepts PointerWrapper objects.
|
PointerBuffer |
put(long l)
Relative put method (optional operation).
|
PointerBuffer |
put(long[] src)
Relative bulk put method (optional operation).
|
PointerBuffer |
put(long[] src,
int offset,
int length)
Relative bulk put method (optional operation).
|
PointerBuffer |
put(PointerBuffer src)
Relative bulk put method (optional operation).
|
PointerBuffer |
put(PointerWrapper pointer)
Convenience put that accepts PointerWrapper objects.
|
int |
remaining()
Returns the number of elements between the current position and the
limit.
|
int |
remainingByte()
Returns the number of bytes between the current position and the
limit.
|
PointerBuffer |
reset()
Resets this buffer's position to the previously-marked position.
|
PointerBuffer |
rewind()
Rewinds this buffer.
|
PointerBuffer |
slice()
Creates a new pointer buffer whose content is a shared subsequence of
this buffer's content.
|
java.lang.String |
toString()
Returns a string summarizing the state of this buffer.
|
protected final java.nio.ByteBuffer pointers
protected final java.nio.Buffer view
protected final java.nio.IntBuffer view32
protected final java.nio.LongBuffer view64
public PointerBuffer(int capacity)
capacity
- the PointerBuffer size, in number of pointerspublic PointerBuffer(java.nio.ByteBuffer source)
source
- the source bufferpublic java.nio.ByteBuffer getBuffer()
public static boolean is64Bit()
public static int getPointerSize()
public final int capacity()
public final int position()
public final int positionByte()
public final PointerBuffer position(int newPosition)
newPosition
- The new position value; must be non-negative
and no larger than the current limitjava.lang.IllegalArgumentException
- If the preconditions on newPosition do not holdpublic final int limit()
public final PointerBuffer limit(int newLimit)
newLimit
- The new limit value; must be non-negative
and no larger than this buffer's capacityjava.lang.IllegalArgumentException
- If the preconditions on newLimit do not holdpublic final PointerBuffer mark()
public final PointerBuffer reset()
Invoking this method neither changes nor discards the mark's value.
java.nio.InvalidMarkException
- If the mark has not been setpublic final PointerBuffer clear()
Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
public final PointerBuffer flip()
After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.put(magic); // Prepend header in.read(buf); // Read data into rest of buffer buf.flip(); // Flip buffer out.write(buf); // Write header + data to channel
This method is often used in conjunction with the compact
method when transferring data from
one place to another.
public final PointerBuffer rewind()
Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately. For example:
out.write(buf); // Write remaining data buf.rewind(); // Rewind buffer buf.get(array); // Copy data into array
public final int remaining()
public final int remainingByte()
public final boolean hasRemaining()
public static PointerBuffer allocateDirect(int capacity)
The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined.
capacity
- The new buffer's capacity, in pointersjava.lang.IllegalArgumentException
- If the capacity is a negative integerprotected PointerBuffer newInstance(java.nio.ByteBuffer source)
source
- public PointerBuffer slice()
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of longs remaining in this buffer, and its mark will be undefined. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
public PointerBuffer duplicate()
The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's capacity, limit and position will be identical to those of this buffer. The new buffer will be direct if, and only if, this buffer is direct, and it will be read-only if, and only if, this buffer is read-only.
public PointerBuffer asReadOnlyBuffer()
The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer; the new buffer itself, however, will be read-only and will not allow the shared content to be modified. The two buffers' position, limit, and mark values will be independent.
The new buffer's capacity, limit and position will be identical to those of this buffer.
If this buffer is itself read-only then this method behaves in
exactly the same way as the duplicate
method.
public boolean isReadOnly()
public long get()
java.nio.BufferUnderflowException
- If the buffer's current position is not smaller than its limitpublic PointerBuffer put(long l)
Writes the given long into this buffer at the current position, and then increments the position.
l
- The long to be writtenjava.nio.BufferOverflowException
- If this buffer's current position is not smaller than its limitjava.nio.ReadOnlyBufferException
- If this buffer is read-onlypublic PointerBuffer put(PointerWrapper pointer)
put(long)
public static void put(java.nio.ByteBuffer target, long l)
target
- the target ByteBufferl
- the long value to be writtenpublic long get(int index)
index
- The index from which the long will be readjava.lang.IndexOutOfBoundsException
- If index is negative
or not smaller than the buffer's limitpublic PointerBuffer put(int index, long l)
Writes the given long into this buffer at the given index.
index
- The index at which the long will be writtenl
- The long value to be writtenjava.lang.IndexOutOfBoundsException
- If index is negative
or not smaller than the buffer's limitjava.nio.ReadOnlyBufferException
- If this buffer is read-onlypublic PointerBuffer put(int index, PointerWrapper pointer)
put(int, long)
public static void put(java.nio.ByteBuffer target, int index, long l)
target
- the target ByteBufferindex
- the index at which the long will be writtenl
- the long value to be writtenpublic PointerBuffer get(long[] dst, int offset, int length)
This method transfers longs from this buffer into the given
destination array. If there are fewer longs remaining in the
buffer than are required to satisfy the request, that is, if
length > remaining(), then no
longs are transferred and a BufferUnderflowException
is
thrown.
Otherwise, this method copies length longs from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length.
In other words, an invocation of this method of the form src.get(dst, off, len) has exactly the same effect as the loop
for (int i = off; i < off + len; i++) dst[i] = src.get();except that it first checks that there are sufficient longs in this buffer and it is potentially much more efficient.
dst
- The array into which longs are to be writtenoffset
- The offset within the array of the first long to be
written; must be non-negative and no larger than
dst.lengthlength
- The maximum number of longs to be written to the given
array; must be non-negative and no larger than
dst.length - offsetjava.nio.BufferUnderflowException
- If there are fewer than length longs
remaining in this bufferjava.lang.IndexOutOfBoundsException
- If the preconditions on the offset and length
parameters do not holdpublic PointerBuffer get(long[] dst)
This method transfers longs from this buffer into the given destination array. An invocation of this method of the form src.get(a) behaves in exactly the same way as the invocation
src.get(a, 0, a.length)
java.nio.BufferUnderflowException
- If there are fewer than length longs
remaining in this bufferpublic PointerBuffer put(PointerBuffer src)
This method transfers the longs remaining in the given source
buffer into this buffer. If there are more longs remaining in the
source buffer than in this buffer, that is, if
src.remaining() > remaining(),
then no longs are transferred and a BufferOverflowException
is thrown.
Otherwise, this method copies n = src.remaining() longs from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop
while (src.hasRemaining()) dst.put(src.get());except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.
src
- The source buffer from which longs are to be read;
must not be this bufferjava.nio.BufferOverflowException
- If there is insufficient space in this buffer
for the remaining longs in the source bufferjava.lang.IllegalArgumentException
- If the source buffer is this bufferjava.nio.ReadOnlyBufferException
- If this buffer is read-onlypublic PointerBuffer put(long[] src, int offset, int length)
This method transfers longs into this buffer from the given
source array. If there are more longs to be copied from the array
than remain in this buffer, that is, if
length > remaining(), then no
longs are transferred and a BufferOverflowException
is
thrown.
Otherwise, this method copies length longs from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.
In other words, an invocation of this method of the form dst.put(src, off, len) has exactly the same effect as the loop
for (int i = off; i < off + len; i++) dst.put(a[i]);except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.
src
- The array from which longs are to be readoffset
- The offset within the array of the first long to be read;
must be non-negative and no larger than array.lengthlength
- The number of longs to be read from the given array;
must be non-negative and no larger than
array.length - offsetjava.nio.BufferOverflowException
- If there is insufficient space in this bufferjava.lang.IndexOutOfBoundsException
- If the preconditions on the offset and length
parameters do not holdjava.nio.ReadOnlyBufferException
- If this buffer is read-onlypublic final PointerBuffer put(long[] src)
This method transfers the entire content of the given source long array into this buffer. An invocation of this method of the form dst.put(a) behaves in exactly the same way as the invocation
dst.put(a, 0, a.length)
java.nio.BufferOverflowException
- If there is insufficient space in this bufferjava.nio.ReadOnlyBufferException
- If this buffer is read-onlypublic PointerBuffer compact()
The longs between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the long at index p = position() is copied to index zero, the long at index p + 1 is copied to index one, and so forth until the long at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.
The buffer's position is set to the number of longs copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.
java.nio.ReadOnlyBufferException
- If this buffer is read-onlypublic java.nio.ByteOrder order()
The byte order of a pointer buffer created by allocation or by
wrapping an existing long array is the native order
of the underlying
hardware. The byte order of a pointer buffer created as a view of a byte buffer is that of the
byte buffer at the moment that the view is created.
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
The hash code of a pointer buffer depends only upon its remaining elements; that is, upon the elements from position() up to, and including, the element at limit() - 1.
Because buffer hash codes are content-dependent, it is inadvisable to use buffers as keys in hash maps or similar data structures unless it is known that their contents will not change.
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object ob)
Two pointer buffers are equal if, and only if,
They have the same element type,
They have the same number of remaining elements, and
The two sequences of remaining elements, considered independently of their starting positions, are pointwise equal.
A pointer buffer is not equal to any other type of object.
equals
in class java.lang.Object
ob
- The object to which this buffer is to be comparedpublic int compareTo(java.lang.Object o)
Two pointer buffers are compared by comparing their sequences of remaining elements lexicographically, without regard to the starting position of each sequence within its corresponding buffer.
A pointer buffer is not comparable to any other type of object.
compareTo
in interface java.lang.Comparable
Copyright © 2002-2009 lwjgl.org. All Rights Reserved.