Package org.lwjgl

Class PointerBuffer

  • All Implemented Interfaces:
    java.lang.Comparable<PointerBuffer>, Pointer

    public class PointerBuffer
    extends CustomBuffer<PointerBuffer>
    implements java.lang.Comparable<PointerBuffer>
    This class is a container for architecture-independent pointer data. Its interface mirrors the LongBuffer API for convenience.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PointerBuffer allocateDirect​(int capacity)
      Allocates a new pointer buffer.
      int compareTo​(PointerBuffer that)
      Compares this buffer to another.
      static PointerBuffer create​(long address, int capacity)
      Creates a new PointerBuffer that starts at the specified memory address and has the specified capacity.
      static PointerBuffer create​(java.nio.ByteBuffer source)
      Creates a new PointerBuffer using the specified ByteBuffer as its pointer data source.
      boolean equals​(java.lang.Object ob)
      Tells whether or not this buffer is equal to another object.
      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.
      static long get​(java.nio.ByteBuffer source)
      Convenience relative get from a source ByteBuffer.
      static long get​(java.nio.ByteBuffer source, int index)
      Convenience absolute get from a source ByteBuffer.
      java.nio.ByteBuffer getByteBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      java.nio.ByteBuffer getByteBuffer​(int index, int size)
      Returns a ByteBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      java.nio.DoubleBuffer getDoubleBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      java.nio.DoubleBuffer getDoubleBuffer​(int index, int size)
      Returns a DoubleBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      java.nio.FloatBuffer getFloatBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      java.nio.FloatBuffer getFloatBuffer​(int index, int size)
      Returns a FloatBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      java.nio.IntBuffer getIntBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      java.nio.IntBuffer getIntBuffer​(int index, int size)
      Returns a IntBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      java.nio.LongBuffer getLongBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      java.nio.LongBuffer getLongBuffer​(int index, int size)
      Returns a LongBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      PointerBuffer getPointerBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      PointerBuffer getPointerBuffer​(int index, int size)
      Returns a PointerBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      java.nio.ShortBuffer getShortBuffer​(int size)
      Reads the pointer at this buffer's current position, and then increments the position.
      java.nio.ShortBuffer getShortBuffer​(int index, int size)
      Returns a ShortBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      java.lang.String getStringASCII()
      Reads the pointer at this buffer's current position, and then increments the position.
      java.lang.String getStringASCII​(int index)
      Decodes the ASCII string that starts at the address found at the specified index.
      java.lang.String getStringUTF16()
      Reads the pointer at this buffer's current position, and then increments the position.
      java.lang.String getStringUTF16​(int index)
      Decodes the UTF-16 string that starts at the address found at the specified index.
      java.lang.String getStringUTF8()
      Reads the pointer at this buffer's current position, and then increments the position.
      java.lang.String getStringUTF8​(int index)
      Decodes the UTF-8 string that starts at the address found at the specified index.
      int hashCode()
      Returns the current hash code of this buffer.
      PointerBuffer put​(int index, long p)
      Absolute put method  (optional operation).
      PointerBuffer put​(int index, java.nio.ByteBuffer buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer put​(int index, java.nio.DoubleBuffer buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer put​(int index, java.nio.FloatBuffer buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer put​(int index, java.nio.IntBuffer buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer put​(int index, java.nio.LongBuffer buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer put​(int index, java.nio.ShortBuffer buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer put​(int index, Pointer pointer)
      Puts the pointer value of the specified Pointer at the specified index.
      PointerBuffer put​(long p)
      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​(java.nio.ByteBuffer buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      static void put​(java.nio.ByteBuffer target, int index, long p)
      Convenience absolute put on a target ByteBuffer.
      static void put​(java.nio.ByteBuffer target, long p)
      Convenience relative put on a target ByteBuffer.
      PointerBuffer put​(java.nio.DoubleBuffer buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      PointerBuffer put​(java.nio.FloatBuffer buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      PointerBuffer put​(java.nio.IntBuffer buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      PointerBuffer put​(java.nio.LongBuffer buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      PointerBuffer put​(java.nio.ShortBuffer buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      PointerBuffer put​(Pointer pointer)
      Puts the pointer value of the specified Pointer at the current position and then increments the position.
      PointerBuffer putAddressOf​(int index, CustomBuffer<?> buffer)
      Puts the address of the specified buffer at the specified index.
      PointerBuffer putAddressOf​(CustomBuffer<?> buffer)
      Writes the address of the specified buffer into this buffer at the current position, and then increments the position.
      int sizeof()
      Returns the sizeof a single element in the buffer.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • allocateDirect

        public static PointerBuffer allocateDirect​(int capacity)
        Allocates a new pointer buffer.

        The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined.

        Parameters:
        capacity - the new buffer's capacity, in pointers
        Returns:
        the new pointer buffer
        Throws:
        java.lang.IllegalArgumentException - If the capacity is a negative integer
      • create

        public static PointerBuffer create​(long address,
                                           int capacity)
        Creates a new PointerBuffer that starts at the specified memory address and has the specified capacity.
        Parameters:
        address - the starting memory address
        capacity - the buffer capacity, in number of pointers
      • create

        public static PointerBuffer create​(java.nio.ByteBuffer source)
        Creates a new PointerBuffer using the specified ByteBuffer as its pointer data source.
        Parameters:
        source - the source buffer
      • get

        public long get()
        Relative get method. Reads the pointer at this buffer's current position, and then increments the position.
        Returns:
        the pointer at the buffer's current position
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • get

        public static long get​(java.nio.ByteBuffer source)
        Convenience relative get from a source ByteBuffer.
        Parameters:
        source - the source ByteBuffer
      • put

        public PointerBuffer put​(long p)
        Relative put method  (optional operation).

        Writes the specified pointer into this buffer at the current position, and then increments the position.

        Parameters:
        p - the pointer to be written
        Returns:
        This buffer
        Throws:
        java.nio.BufferOverflowException - If this buffer's current position is not smaller than its limit
      • put

        public static void put​(java.nio.ByteBuffer target,
                               long p)
        Convenience relative put on a target ByteBuffer.
        Parameters:
        target - the target ByteBuffer
        p - the pointer value to be written
      • get

        public long get​(int index)
        Absolute get method. Reads the pointer at the specified index.
        Parameters:
        index - the index from which the pointer will be read
        Returns:
        the pointer at the specified index
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit
      • get

        public static long get​(java.nio.ByteBuffer source,
                               int index)
        Convenience absolute get from a source ByteBuffer.
        Parameters:
        source - the source ByteBuffer
        index - the index at which the pointer will be read
      • put

        public PointerBuffer put​(int index,
                                 long p)
        Absolute put method  (optional operation).

        Writes the specified pointer into this buffer at the specified index.

        Parameters:
        index - the index at which the pointer will be written
        p - the pointer value to be written
        Returns:
        This buffer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit
      • put

        public static void put​(java.nio.ByteBuffer target,
                               int index,
                               long p)
        Convenience absolute put on a target ByteBuffer.
        Parameters:
        target - the target ByteBuffer
        index - the index at which the pointer will be written
        p - the pointer value to be written
      • put

        public PointerBuffer put​(Pointer pointer)
        Puts the pointer value of the specified Pointer at the current position and then increments the position.
      • put

        public PointerBuffer put​(int index,
                                 Pointer pointer)
        Puts the pointer value of the specified Pointer at the specified index.
      • put, putAddressOf

        public PointerBuffer put​(java.nio.ByteBuffer buffer)
        
        public PointerBuffer put​(java.nio.ShortBuffer buffer)
        
        public PointerBuffer put​(java.nio.IntBuffer buffer)
        
        public PointerBuffer put​(java.nio.LongBuffer buffer)
        
        public PointerBuffer put​(java.nio.FloatBuffer buffer)
        
        public PointerBuffer put​(java.nio.DoubleBuffer buffer)
        
        public PointerBuffer putAddressOf​(CustomBuffer<?> buffer)
        

        Writes the address of the specified buffer into this buffer at the current position, and then increments the position.

        Parameters:
        buffer - the pointer to be written
        Returns:
        this buffer
        Throws:
        java.nio.BufferOverflowException - If this buffer's current position is not smaller than its limit
      • put, putAddressOf

        public PointerBuffer put​(int index,
                                 java.nio.ByteBuffer buffer)
        
        public PointerBuffer put​(int index,
                                 java.nio.ShortBuffer buffer)
        
        public PointerBuffer put​(int index,
                                 java.nio.IntBuffer buffer)
        
        public PointerBuffer put​(int index,
                                 java.nio.LongBuffer buffer)
        
        public PointerBuffer put​(int index,
                                 java.nio.FloatBuffer buffer)
        
        public PointerBuffer put​(int index,
                                 java.nio.DoubleBuffer buffer)
        
        public PointerBuffer putAddressOf​(int index,
                                          CustomBuffer<?> buffer)
        
        Puts the address of the specified buffer at the specified index.
      • getByteBuffer

        public java.nio.ByteBuffer getByteBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a ByteBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getShortBuffer

        public java.nio.ShortBuffer getShortBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a ShortBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getIntBuffer

        public java.nio.IntBuffer getIntBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a IntBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getLongBuffer

        public java.nio.LongBuffer getLongBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a LongBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getFloatBuffer

        public java.nio.FloatBuffer getFloatBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a FloatBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getDoubleBuffer

        public java.nio.DoubleBuffer getDoubleBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a DoubleBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getPointerBuffer

        public PointerBuffer getPointerBuffer​(int size)
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is returned as a PointerBuffer instance that starts at the pointer address and has capacity equal to the specified size.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getStringASCII

        public java.lang.String getStringASCII()
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is evaluated as a null-terminated ASCII string, which is decoded and returned as a String instance.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getStringUTF8

        public java.lang.String getStringUTF8()
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is evaluated as a null-terminated UTF-8 string, which is decoded and returned as a String instance.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getStringUTF16

        public java.lang.String getStringUTF16()
        Reads the pointer at this buffer's current position, and then increments the position. The pointer is evaluated as a null-terminated UTF-16 string, which is decoded and returned as a String instance.
        Throws:
        java.nio.BufferUnderflowException - If the buffer's current position is not smaller than its limit
      • getByteBuffer

        public java.nio.ByteBuffer getByteBuffer​(int index,
                                                 int size)
        Returns a ByteBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getShortBuffer

        public java.nio.ShortBuffer getShortBuffer​(int index,
                                                   int size)
        Returns a ShortBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getIntBuffer

        public java.nio.IntBuffer getIntBuffer​(int index,
                                               int size)
        Returns a IntBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getLongBuffer

        public java.nio.LongBuffer getLongBuffer​(int index,
                                                 int size)
        Returns a LongBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getFloatBuffer

        public java.nio.FloatBuffer getFloatBuffer​(int index,
                                                   int size)
        Returns a FloatBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getDoubleBuffer

        public java.nio.DoubleBuffer getDoubleBuffer​(int index,
                                                     int size)
        Returns a DoubleBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getPointerBuffer

        public PointerBuffer getPointerBuffer​(int index,
                                              int size)
        Returns a PointerBuffer instance that starts at the address found at the specified index and has capacity equal to the specified size.
      • getStringASCII

        public java.lang.String getStringASCII​(int index)
        Decodes the ASCII string that starts at the address found at the specified index.
      • getStringUTF8

        public java.lang.String getStringUTF8​(int index)
        Decodes the UTF-8 string that starts at the address found at the specified index.
      • getStringUTF16

        public java.lang.String getStringUTF16​(int index)
        Decodes the UTF-16 string that starts at the address found at the specified index.
      • get

        public PointerBuffer get​(long[] dst)
        Relative bulk get method.

        This method transfers pointers from this buffer into the specified 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) 
        Returns:
        This buffer
        Throws:
        java.nio.BufferUnderflowException - If there are fewer than length pointers remaining in this buffer
      • get

        public PointerBuffer get​(long[] dst,
                                 int offset,
                                 int length)
        Relative bulk get method.

        This method transfers pointers from this buffer into the specified destination array. If there are fewer pointers remaining in the buffer than are required to satisfy the request, that is, if length &gt; remaining(), then no pointers are transferred and a BufferUnderflowException is thrown.

        Otherwise, this method copies length pointers from this buffer into the specified array, starting at the current position of this buffer and at the specified 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,&nbsp;off,&nbsp;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 pointers in this buffer and it is potentially much more efficient.

        Parameters:
        dst - the array into which pointers are to be written
        offset - the offset within the array of the first pointer to be written; must be non-negative and no larger than dst.length
        length - the maximum number of pointers to be written to the specified array; must be non-negative and no larger than dst.length - offset
        Returns:
        This buffer
        Throws:
        java.nio.BufferUnderflowException - If there are fewer than length pointers remaining in this buffer
        java.lang.IndexOutOfBoundsException - If the preconditions on the offset and length parameters do not hold
      • put

        public PointerBuffer put​(long[] src)
        Relative bulk put method  (optional operation).

        This method transfers the entire content of the specified source pointer 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) 
        Returns:
        This buffer
        Throws:
        java.nio.BufferOverflowException - If there is insufficient space in this buffer
      • put

        public PointerBuffer put​(long[] src,
                                 int offset,
                                 int length)
        Relative bulk put method  (optional operation).

        This method transfers pointers into this buffer from the specified source array. If there are more pointers to be copied from the array than remain in this buffer, that is, if length &gt; remaining(), then no pointers are transferred and a BufferOverflowException is thrown.

        Otherwise, this method copies length pointers from the specified array into this buffer, starting at the specified 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,&nbsp;off,&nbsp;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.

        Parameters:
        src - the array from which pointers are to be read
        offset - the offset within the array of the first pointer to be read; must be non-negative and no larger than array.length
        length - the number of pointers to be read from the specified array; must be non-negative and no larger than array.length - offset
        Returns:
        This buffer
        Throws:
        java.nio.BufferOverflowException - If there is insufficient space in this buffer
        java.lang.IndexOutOfBoundsException - If the preconditions on the offset and length parameters do not hold
      • hashCode

        public int hashCode()
        Returns the current hash code of this buffer.

        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.

        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the current hash code of this buffer
      • equals

        public boolean equals​(java.lang.Object ob)
        Tells whether or not this buffer is equal to another object.

        Two pointer buffers are equal if, and only if,

        1. They have the same element type,
        2. They have the same number of remaining elements, and
        3. 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.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        ob - the object to which this buffer is to be compared
        Returns:
        true if, and only if, this buffer is equal to the given object
      • compareTo

        public int compareTo​(PointerBuffer that)
        Compares this buffer to another.

        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.

        Specified by:
        compareTo in interface java.lang.Comparable<PointerBuffer>
        Returns:
        A negative integer, zero, or a positive integer as this buffer is less than, equal to, or greater than the specified buffer