Package org.bytedeco.javacpp
Class PointerPointer<P extends Pointer>
- java.lang.Object
-
- org.bytedeco.javacpp.Pointer
-
- org.bytedeco.javacpp.PointerPointer<P>
-
- 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 ofvoid*
. 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.bytedeco.javacpp.Pointer
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.DeallocatorReference, Pointer.DeallocatorThread, Pointer.NativeDeallocator, Pointer.ProxyDeallocator, Pointer.ReferenceCounter
-
-
Field Summary
Fields Modifier and Type Field Description private static Logger
logger
private P[]
pointerArray
This is just to keep references to Pointer objects and prevent premature deallocation.-
Fields inherited from class org.bytedeco.javacpp.Pointer
address, capacity, deallocatorThread, limit, maxBytes, maxPhysicalBytes, maxRetries, position
-
-
Constructor Summary
Constructors Constructor Description PointerPointer()
PointerPointer(byte[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(char[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(double[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(float[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(int[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(long size)
Allocates a native array ofvoid*
of the given size.PointerPointer(long[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(short[]... array)
Allocates enough memory for the array of arrays and copies it.PointerPointer(java.lang.String... array)
Allocates enough memory for the array of strings and copies it.PointerPointer(java.lang.String[] array, java.lang.String charsetName)
Allocates enough memory for the array of strings and copies it.PointerPointer(java.lang.String[] array, java.nio.charset.Charset charset)
Allocates enough memory for the array of strings and copies it.PointerPointer(Pointer p)
PointerPointer(P... array)
Allocates enough memory for the array and copies it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
allocateArray(long size)
PointerPointer<P>
capacity(long capacity)
Sets the capacity and returns this.Pointer
get()
Pointer
get(long i)
P
get(java.lang.Class<P> cls)
P
get(java.lang.Class<P> cls, long i)
PointerPointer<P>
getPointer(long i)
ReturnsgetPointer(getClass(), i)
.java.lang.String
getString(long i)
java.lang.String
getString(long i, java.lang.String charsetName)
java.lang.String
getString(long i, java.nio.charset.Charset charset)
PointerPointer<P>
limit(long limit)
Sets the limit and returns this.PointerPointer<P>
position(long position)
Sets the position and returns this.PointerPointer<P>
put(byte[]... array)
PointerPointer<P>
put(char[]... array)
PointerPointer<P>
put(double[]... array)
Creates one by one a newDoublePointer
for eachdouble[]
, and writes them into the nativevoid*
array.PointerPointer<P>
put(float[]... array)
Creates one by one a newFloatPointer
for eachfloat[]
, and writes them into the nativevoid*
array.PointerPointer<P>
put(int[]... array)
PointerPointer<P>
put(long[]... array)
PointerPointer<P>
put(long i, Pointer p)
Copies the Pointer value to the i-th element of a native array.PointerPointer<P>
put(short[]... array)
Creates one by one a newShortPointer
for eachshort[]
, and writes them into the nativevoid*
array.PointerPointer<P>
put(Pointer p)
Calls in effectmemcpy(this.address + this.position, p.address + p.position, length)
, wherelength = sizeof(p) * (p.limit - p.position)
.PointerPointer<P>
put(P... array)
Writes the Pointer values into the nativevoid*
array.PointerPointer<P>
putString(java.lang.String... array)
PointerPointer<P>
putString(java.lang.String[] array, java.lang.String charsetName)
PointerPointer<P>
putString(java.lang.String[] array, java.nio.charset.Charset charset)
-
Methods inherited from class org.bytedeco.javacpp.Pointer
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, hashCode, init, interruptDeallocatorThread, isNull, isNull, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
-
-
-
-
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 copycharsetName
- 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 copycharset
- 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 ofvoid*
of the given size.- Parameters:
size
- the number ofvoid*
elements to allocate
-
PointerPointer
public PointerPointer()
- See Also:
Pointer()
-
PointerPointer
public PointerPointer(Pointer p)
- See Also:
Pointer(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 thearray.position(i)
statement sort of equivalent to thearray[i]
statement in C++.- Overrides:
position
in classPointer
- 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 classPointer
- 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 classPointer
- Parameters:
capacity
- the new capacity- Returns:
- this
- See Also:
Pointer.capacity(long)
-
getPointer
public PointerPointer<P> getPointer(long i)
Description copied from class:Pointer
ReturnsgetPointer(getClass(), i)
.- Overrides:
getPointer
in classPointer
-
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)
- Parameters:
array
- the array ofString
to read from- Returns:
- this
-
putString
public PointerPointer<P> putString(java.lang.String[] array, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
- Parameters:
array
- the array ofString
to read fromcharsetName
- 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)
- Parameters:
array
- the array ofString
to read fromcharset
- the charset in which the bytes are encoded- Returns:
- this
-
put
public PointerPointer<P> put(P... array)
Writes the Pointer values into the nativevoid*
array.- Parameters:
array
- the array of Pointer values to read from- Returns:
- this
-
put
public PointerPointer<P> put(byte[]... array)
- Parameters:
array
- the array ofbyte[]
to read from- Returns:
- this
-
put
public PointerPointer<P> put(short[]... array)
Creates one by one a newShortPointer
for eachshort[]
, and writes them into the nativevoid*
array.- Parameters:
array
- the array ofshort[]
to read from- Returns:
- this
-
put
public PointerPointer<P> put(int[]... array)
- Parameters:
array
- the array ofint[]
to read from- Returns:
- this
-
put
public PointerPointer<P> put(long[]... array)
- Parameters:
array
- the array oflong[]
to read from- Returns:
- this
-
put
public PointerPointer<P> put(float[]... array)
Creates one by one a newFloatPointer
for eachfloat[]
, and writes them into the nativevoid*
array.- Parameters:
array
- the array offloat[]
to read from- Returns:
- this
-
put
public PointerPointer<P> put(double[]... array)
Creates one by one a newDoublePointer
for eachdouble[]
, and writes them into the nativevoid*
array.- Parameters:
array
- the array ofdouble[]
to read from- Returns:
- this
-
put
public PointerPointer<P> put(char[]... array)
- Parameters:
array
- the array ofchar[]
to read from- Returns:
- this
-
get
public Pointer get()
- Returns:
get(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 effectmemcpy(this.address + this.position, p.address + p.position, length)
, wherelength = sizeof(p) * (p.limit - p.position)
. If limit == 0, it uses position + 1 instead. The way the methods were designed allows constructs such asthis.position(0).put(p.position(13).limit(42))
.
-
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 arrayp
- the Pointer value to copy- Returns:
- this
-
-