/** * Returns a {@link CharBuffer} which reads and writes to the same memory * location pointed to by this {@link CharPtr}. * * @param n the maximum number of chars the {@link CharBuffer} can * read/write. This will be the {@link CharBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public CharBuffer asCharBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asCharBuffer(); }
/** * Copies {@code count} chars from the memory pointed to by this * {@link CharPtr} to {@code dst} starting at offset {@code offset}. * * @param dst the destination. * @param offset the offset within the destination array to start copying to. * @param count the number of elements to copy. */ public void get(char[] dst, int offset, int count) { asCharBuffer(count).get(dst, offset, count); }
/** * Copies {@code n} chars from the memory pointed to by this {@link CharPtr} * to a new {@code char[]} instance. * * @param n the number of chars to copy. * @return the {@code char[]}. */ public char[] toCharArray(int n) { char[] result = new char[n]; get(result); return result; }
/** * Creates a new {@link CharPtr} and initializes it with the specified value. * * @param value the value. */ public CharPtr(char value) { set(value); }
public char[] getOutputDataAsCharArray() { CharPtr ptr = getOutputDataPointer().as(CharPtr.class); return ptr.toCharArray(getOutputDataSize()); } public int[] getOutputDataAsIntArray() {
/** * Copies {@code src.length} chars from {@code src} to the memory pointed to by * this {@link CharPtr}. * * @param src the source. */ public void set(char[] src) { set(src, 0, src.length); }
public char[] getOutputDataAsCharArray() { CharPtr ptr = getOutputDataPointer().as(CharPtr.class); return ptr.toCharArray(getOutputDataSize()); } public int[] getOutputDataAsIntArray() {
/** * Copies {@code dst.length} chars from the memory pointed to by this * {@link CharPtr} to {@code dst}. * * @param dst the destination. */ public void get(char[] dst) { get(dst, 0, dst.length); }
/** * Copies {@code count} chars from {@code src} starting at offset {@code offset} * to the memory pointed to by this {@link CharPtr}. * * @param src the source. * @param offset the offset within the source array to start copying from. * @param count the number of elements to copy. */ public void set(char[] src, int offset, int count) { asCharBuffer(count).put(src, offset, count); } }
/** * Creates a new {@link CharPtr} and initializes it with the specified value. * * @param value the value. */ public CharPtr(char value) { set(value); }
/** * Returns a {@link CharBuffer} which reads and writes to the same memory * location pointed to by this {@link CharPtr}. * * @param n the maximum number of chars the {@link CharBuffer} can * read/write. This will be the {@link CharBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public CharBuffer asCharBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asCharBuffer(); }
public char[] getOutputDataAsCharArray() { CharPtr ptr = getOutputDataPointer().as(CharPtr.class); return ptr.toCharArray(getOutputDataSize()); } public int[] getOutputDataAsIntArray() {
public char charValue() { VoidPtr ptr = new VoidPtr(); getValue(CFNumberType.SInt16Type, ptr); return ptr.as(CharPtr.class).get(); } public int intValue() {
@SuppressWarnings("unchecked") public <T extends Buffer> T getOutputDataAsBuffer(Class<T> bufferType) { VoidPtr ptr = getOutputDataPointer(); if (bufferType == ByteBuffer.class) { return (T) ptr.as(BytePtr.class).asByteBuffer(getOutputDataSize()); } else if (bufferType == CharBuffer.class) { return (T) ptr.as(CharPtr.class).asCharBuffer(getOutputDataSize()); } else if (bufferType == ShortBuffer.class) { return (T) ptr.as(ShortPtr.class).asShortBuffer(getOutputDataSize()); } else if (bufferType == IntBuffer.class) { return (T) ptr.as(IntPtr.class).asIntBuffer(getOutputDataSize()); } else if (bufferType == LongBuffer.class) { return (T) ptr.as(LongPtr.class).asLongBuffer(getOutputDataSize()); } else if (bufferType == FloatBuffer.class) { return (T) ptr.as(FloatPtr.class).asFloatBuffer(getOutputDataSize()); } else if (bufferType == DoubleBuffer.class) { return (T) ptr.as(DoublePtr.class).asDoubleBuffer(getOutputDataSize()); } else { throw new UnsupportedOperationException("Buffer type not supported: " + bufferType); } }