Class PointerPointer<P extends Pointer>

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    @Properties(inherit=javacpp.class)
    public class PointerPointer<P extends Pointer>
    extends Pointer
    The peer class to native pointers and arrays of void*. All operations take into account the position and limit, when appropriate.

    To support higher levels of indirection, we can create out of the Pointer objects returned by get(long) additional PointerPointer objects.

    • Field Detail

      • logger

        private static final Logger logger
      • pointerArray

        private P extends Pointer[] pointerArray
        This is just to keep references to Pointer objects and prevent premature deallocation.
    • Constructor Detail

      • PointerPointer

        public PointerPointer​(java.lang.String... array)
        Allocates enough memory for the array of strings and copies it.
        Parameters:
        array - the array of strings to copy
        See Also:
        putString(String[])
      • PointerPointer

        public PointerPointer​(java.lang.String[] array,
                              java.lang.String charsetName)
                       throws java.io.UnsupportedEncodingException
        Allocates enough memory for the array of strings and copies it.
        Parameters:
        array - the array of strings to copy
        charsetName - the charset in which the bytes are encoded
        Throws:
        java.io.UnsupportedEncodingException
        See Also:
        putString(String[], String)
      • PointerPointer

        public PointerPointer​(java.lang.String[] array,
                              java.nio.charset.Charset charset)
        Allocates enough memory for the array of strings and copies it.
        Parameters:
        array - the array of strings to copy
        charset - the charset in which the bytes are encoded
        See Also:
        putString(String[], String)
      • PointerPointer

        public PointerPointer​(P... array)
        Allocates enough memory for the array and copies it.
        Parameters:
        array - the array to copy
        See Also:
        put(Pointer[])
      • PointerPointer

        public PointerPointer​(byte[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(byte[][])
      • PointerPointer

        public PointerPointer​(short[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(short[][])
      • PointerPointer

        public PointerPointer​(int[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(int[][])
      • PointerPointer

        public PointerPointer​(long[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(long[][])
      • PointerPointer

        public PointerPointer​(float[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(float[][])
      • PointerPointer

        public PointerPointer​(double[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(double[][])
      • PointerPointer

        public PointerPointer​(char[]... array)
        Allocates enough memory for the array of arrays and copies it.
        Parameters:
        array - the array of arrays to copy
        See Also:
        put(char[][])
      • PointerPointer

        public PointerPointer​(long size)
        Allocates a native array of void* of the given size.
        Parameters:
        size - the number of void* elements to allocate
      • PointerPointer

        public PointerPointer()
        See Also:
        Pointer()
    • Method Detail

      • allocateArray

        private void allocateArray​(long size)
      • position

        public PointerPointer<P> position​(long position)
        Description copied from class: Pointer
        Sets the position and returns this. That makes the array.position(i) statement sort of equivalent to the array[i] statement in C++.
        Overrides:
        position in class Pointer
        Parameters:
        position - the new position
        Returns:
        this
        See Also:
        Pointer.position(long)
      • limit

        public PointerPointer<P> limit​(long limit)
        Description copied from class: Pointer
        Sets the limit and returns this. Used to limit the size of an operation on this object.
        Overrides:
        limit in class Pointer
        Parameters:
        limit - the new limit
        Returns:
        this
        See Also:
        Pointer.limit(long)
      • capacity

        public PointerPointer<P> capacity​(long capacity)
        Description copied from class: Pointer
        Sets the capacity and returns this. Should not be called more than once after allocation.
        Overrides:
        capacity in class Pointer
        Parameters:
        capacity - the new capacity
        Returns:
        this
        See Also:
        Pointer.capacity(long)
      • getString

        public java.lang.String getString​(long i)
        Returns:
        get(BytePointer.class, i).getString()
        See Also:
        BytePointer.getString()
      • getString

        public java.lang.String getString​(long i,
                                          java.lang.String charsetName)
                                   throws java.io.UnsupportedEncodingException
        Returns:
        get(BytePointer.class, i).getString(charsetName)
        Throws:
        java.io.UnsupportedEncodingException
        See Also:
        BytePointer.getString(String)
      • getString

        public java.lang.String getString​(long i,
                                          java.nio.charset.Charset charset)
        Returns:
        get(BytePointer.class, i).getString(charset)
        See Also:
        BytePointer.getString(Charset)
      • putString

        public PointerPointer<P> putString​(java.lang.String... array)
        Creates one by one a new BytePointer for each String, and writes them into the native void* array.
        Parameters:
        array - the array of String to read from
        Returns:
        this
      • putString

        public PointerPointer<P> putString​(java.lang.String[] array,
                                           java.lang.String charsetName)
                                    throws java.io.UnsupportedEncodingException
        Creates one by one a new BytePointer for each String, and writes them into the native void* array.
        Parameters:
        array - the array of String to read from
        charsetName - the charset in which the bytes are encoded
        Returns:
        this
        Throws:
        java.io.UnsupportedEncodingException
      • putString

        public PointerPointer<P> putString​(java.lang.String[] array,
                                           java.nio.charset.Charset charset)
        Creates one by one a new BytePointer for each String, and writes them into the native void* array.
        Parameters:
        array - the array of String to read from
        charset - the charset in which the bytes are encoded
        Returns:
        this
      • put

        public PointerPointer<P> put​(P... array)
        Writes the Pointer values into the native void* array.
        Parameters:
        array - the array of Pointer values to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(byte[]... array)
        Creates one by one a new BytePointer for each byte[], and writes them into the native void* array.
        Parameters:
        array - the array of byte[] to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(short[]... array)
        Creates one by one a new ShortPointer for each short[], and writes them into the native void* array.
        Parameters:
        array - the array of short[] to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(int[]... array)
        Creates one by one a new IntPointer for each int[], and writes them into the native void* array.
        Parameters:
        array - the array of int[] to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(long[]... array)
        Creates one by one a new LongPointer for each long[], and writes them into the native void* array.
        Parameters:
        array - the array of long[] to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(float[]... array)
        Creates one by one a new FloatPointer for each float[], and writes them into the native void* array.
        Parameters:
        array - the array of float[] to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(double[]... array)
        Creates one by one a new DoublePointer for each double[], and writes them into the native void* array.
        Parameters:
        array - the array of double[] to read from
        Returns:
        this
      • put

        public PointerPointer<P> put​(char[]... array)
        Creates one by one a new CharPointer for each char[], and writes them into the native void* array.
        Parameters:
        array - the array of char[] to read from
        Returns:
        this
      • get

        public Pointer get()
        Returns:
        get(0)
      • get

        public P get​(java.lang.Class<P> cls)
        Returns:
        get(cls, 0)
      • get

        public Pointer get​(long i)
        Returns:
        the i-th Pointer value of a native array
      • get

        public P get​(java.lang.Class<P> cls,
                     long i)
        Returns:
        in the given class the i-th Pointer value of a native array
      • put

        public PointerPointer<P> put​(Pointer p)
        Description copied from class: Pointer
        Calls in effect memcpy(this.address + this.position, p.address + p.position, length), where length = sizeof(p) * (p.limit - p.position). If limit == 0, it uses position + 1 instead. The way the methods were designed allows constructs such as this.position(0).put(p.position(13).limit(42)).
        Overrides:
        put in class Pointer
        Parameters:
        p - the Pointer from which to copy memory
        Returns:
        put(0, p)
      • put

        public PointerPointer<P> put​(long i,
                                     Pointer p)
        Copies the Pointer value to the i-th element of a native array.
        Parameters:
        i - the index into the array
        p - the Pointer value to copy
        Returns:
        this