/** * Copies {@code n} {@code boolean}s from the memory pointed to by this * {@link BooleanPtr} to a new {@code boolean[]} instance. * * @param n the number of {@code boolean}s to copy. * @return the {@code boolean[]}. */ public boolean[] toBooleanArray(int n) { boolean[] result = new boolean[n]; get(result); return result; }
/** * Copies {@code n} doubles from the memory pointed to by this {@link DoublePtr} * to a new {@code double[]} instance. * * @param n the number of doubles to copy. * @return the {@code double[]}. */ public double[] toDoubleArray(int n) { double[] result = new double[n]; get(result); return result; }
/** * Copies {@code n} longs from the memory pointed to by this {@link LongPtr} * to a new {@code long[]} instance. * * @param n the number of longs to copy. * @return the {@code long[]}. */ public long[] toLongArray(int n) { long[] result = new long[n]; get(result); return result; }
public static String getMachineString () { BytePtr name = BytePtr.toBytePtrAsciiZ("hw.machine"); MachineSizedUIntPtr size = new MachineSizedUIntPtr(); sysctlbyname(name, null, size, null, 0); BytePtr machine = Struct.allocate(BytePtr.class, (int) size.get()); sysctlbyname(name, machine.as(VoidPtr.class), size, null, 0); return machine.toStringAsciiZ(); }
/** * Copies {@code n} bytes from the memory pointed to by this {@link BytePtr} * to a new {@code byte[]} instance. * * @param n the number of bytes to copy. * @return the {@code byte[]}. */ public byte[] toByteArray(int n) { byte[] result = new byte[n]; get(result); return result; }
/** * 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 src.length} ints from {@code src} to the memory pointed to by * this {@link IntPtr}. * * @param src the source. */ public void set(int[] src) { set(src, 0, src.length); }
/** * Copies {@code dst.length} doubles from the memory pointed to by this * {@link MachineSizedFloatPtr} to {@code dst}. Does {@code float} to * {@code double} conversion if running on a 32-bit platform. * * @param dst the destination. */ public void get(double[] dst) { get(dst, 0, dst.length); }
/** * Creates a new {@link FloatPtr} and initializes it with the specified value. * * @param value the value. */ public FloatPtr(float value) { set(value); }
/** * Copies {@code n} floats from the memory pointed to by this {@link FloatPtr} * to a new {@code float[]} instance. * * @param n the number of floats to copy. * @return the {@code float[]}. */ public float[] toFloatArray(int n) { float[] result = new float[n]; get(result); return result; }
/** * Copies {@code dst.length} shorts from the memory pointed to by this * {@link ShortPtr} to {@code dst}. * * @param dst the destination. */ public void get(short[] dst) { get(dst, 0, dst.length); }
/** * Copies {@code src.length} {@code boolean}s from {@code src} to the memory * pointed to by this {@link BooleanPtr}. * * @param src the source. */ public void set(boolean[] src) { set(src, 0, src.length); }
/** * 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); }
/** * Creates a new {@link LongPtr} and initializes it with the specified value. * * @param value the value. */ public LongPtr(long value) { set(value); }
/** * Returns the current value. * * @return the value. */ public boolean get() { return getByte() != 0; }
/** * Creates a new {@link DoublePtr} and initializes it with the specified value. * * @param value the value. */ public DoublePtr(double value) { set(value); }
public static String getMachineString () { BytePtr name = BytePtr.toBytePtrAsciiZ("hw.machine"); MachineSizedUIntPtr size = new MachineSizedUIntPtr(); sysctlbyname(name, null, size, null, 0); BytePtr machine = Struct.allocate(BytePtr.class, (int) size.get()); sysctlbyname(name, machine.as(VoidPtr.class), size, null, 0); return machine.toStringAsciiZ(); }
/** * Copies {@code dst.length} bytes from the memory pointed to by this * {@link BooleanPtr} to {@code dst}. * * @param dst the destination. */ public void get(boolean[] dst) { get(dst, 0, dst.length); }
/** * Copies {@code dst.length} doubles from the memory pointed to by this * {@link DoublePtr} to {@code dst}. * * @param dst the destination. */ public void get(double[] dst) { get(dst, 0, dst.length); }
/** * Copies {@code dst.length} bytes from the memory pointed to by this * {@link BytePtr} to {@code dst}. * * @param dst the destination. */ public void get(byte[] dst) { get(dst, 0, dst.length); }