Package org.bytedeco.javacpp
Class CharPointer
- java.lang.Object
-
- org.bytedeco.javacpp.Pointer
-
- org.bytedeco.javacpp.CharPointer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
@Properties(inherit=javacpp.class) public class CharPointer extends Pointer
The peer class to native pointers and arrays ofshortfor UTF-16. All operations take into account the position and limit, when appropriate.
-
-
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 Loggerlogger-
Fields inherited from class org.bytedeco.javacpp.Pointer
address, capacity, deallocatorThread, limit, maxBytes, maxPhysicalBytes, maxRetries, position
-
-
Constructor Summary
Constructors Constructor Description CharPointer()CharPointer(char... array)Allocates enough memory for the array and copies it.CharPointer(long size)Allocates a nativeshortarray of the given size.CharPointer(java.lang.String s)Allocates enough memory for the String and copies it.CharPointer(java.nio.CharBuffer buffer)For direct buffers, callsPointer(Buffer), while for buffers backed with an array, allocates enough memory for the array and copies it.CharPointer(Pointer p)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidallocateArray(long size)java.nio.CharBufferasBuffer()Same asPointer.asByteBuffer(), but can be overridden to return subclasses of Buffer.CharPointercapacity(long capacity)Sets the capacity and returns this.charget()CharPointerget(char[] array)CharPointerget(char[] array, int offset, int length)Reads a portion of the native array into a Java array.charget(long i)CharPointergetPointer(long i)ReturnsgetPointer(getClass(), i).java.lang.StringgetString()Returns the String, assuming a null-terminated string iflimit <= position.char[]getStringChars()Returns the chars, assuming a null-terminated string iflimit <= position.CharPointerlimit(long limit)Sets the limit and returns this.CharPointerposition(long position)Sets the position and returns this.CharPointerput(char c)CharPointerput(char... array)CharPointerput(char[] array, int offset, int length)Writes a portion of a Java array into the native array.CharPointerput(long i, char c)Copies thecharvalue to the i-th element of a native array.CharPointerputString(java.lang.String s)Copies the String chars into native memory, including a terminating null char.intsizeof()Returns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())or -1 on error.-
Methods inherited from class org.bytedeco.javacpp.Pointer
address, 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, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
-
-
-
-
Field Detail
-
logger
private static final Logger logger
-
-
Constructor Detail
-
CharPointer
public CharPointer(java.lang.String s)
Allocates enough memory for the String and copies it.- Parameters:
s- the String to copy- See Also:
putString(String)
-
CharPointer
public CharPointer(char... array)
Allocates enough memory for the array and copies it.- Parameters:
array- the array to copy- See Also:
put(char[])
-
CharPointer
public CharPointer(java.nio.CharBuffer buffer)
For direct buffers, callsPointer(Buffer), while for buffers backed with an array, allocates enough memory for the array and copies it.- Parameters:
buffer- the Buffer to reference or copy- See Also:
put(char[])
-
CharPointer
public CharPointer(long size)
Allocates a nativeshortarray of the given size.- Parameters:
size- the number ofshortelements to allocate
-
CharPointer
public CharPointer()
- See Also:
Pointer()
-
CharPointer
public CharPointer(Pointer p)
- See Also:
Pointer(Pointer)
-
-
Method Detail
-
allocateArray
private void allocateArray(long size)
-
position
public CharPointer position(long position)
Description copied from class:PointerSets the position and returns this. That makes thearray.position(i)statement sort of equivalent to thearray[i]statement in C++.- Overrides:
positionin classPointer- Parameters:
position- the new position- Returns:
- this
- See Also:
Pointer.position(long)
-
limit
public CharPointer limit(long limit)
Description copied from class:PointerSets the limit and returns this. Used to limit the size of an operation on this object.- Overrides:
limitin classPointer- Parameters:
limit- the new limit- Returns:
- this
- See Also:
Pointer.limit(long)
-
capacity
public CharPointer capacity(long capacity)
Description copied from class:PointerSets the capacity and returns this. Should not be called more than once after allocation.- Overrides:
capacityin classPointer- Parameters:
capacity- the new capacity- Returns:
- this
- See Also:
Pointer.capacity(long)
-
sizeof
public int sizeof()
Description copied from class:PointerReturns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())or -1 on error.
-
getPointer
public CharPointer getPointer(long i)
Description copied from class:PointerReturnsgetPointer(getClass(), i).- Overrides:
getPointerin classPointer
-
getStringChars
public char[] getStringChars()
Returns the chars, assuming a null-terminated string iflimit <= position.
-
getString
public java.lang.String getString()
Returns the String, assuming a null-terminated string iflimit <= position.
-
putString
public CharPointer putString(java.lang.String s)
Copies the String chars into native memory, including a terminating null char. Sets the limit to just before the terminating null character.- Parameters:
s- the String to copy- Returns:
- this
- See Also:
String.toCharArray(),put(char[])
-
get
public char get()
- Returns:
get(0)
-
get
public char get(long i)
- Returns:
- the i-th
charvalue of a native array
-
put
public CharPointer put(char c)
- Returns:
put(0, c)
-
put
public CharPointer put(long i, char c)
Copies thecharvalue to the i-th element of a native array.- Parameters:
i- the index into the arrayc- thecharvalue to copy- Returns:
- this
-
get
public CharPointer get(char[] array)
- Returns:
get(array, 0, array.length)
-
put
public CharPointer put(char... array)
- Returns:
put(array, 0, array.length)
-
get
public CharPointer get(char[] array, int offset, int length)
Reads a portion of the native array into a Java array.- Parameters:
array- the array to write tooffset- the offset into the array where to start writinglength- the length of data to read and write- Returns:
- this
-
put
public CharPointer put(char[] array, int offset, int length)
Writes a portion of a Java array into the native array.- Parameters:
array- the array to read fromoffset- the offset into the array where to start readinglength- the length of data to read and write- Returns:
- this
-
asBuffer
public final java.nio.CharBuffer asBuffer()
Description copied from class:PointerSame asPointer.asByteBuffer(), but can be overridden to return subclasses of Buffer.- Overrides:
asBufferin classPointer- Returns:
asByteBuffer().asCharBuffer()- See Also:
BytePointer.asBuffer(),ShortPointer.asBuffer(),IntPointer.asBuffer(),LongPointer.asBuffer(),FloatPointer.asBuffer(),DoublePointer.asBuffer(),asBuffer()
-
-