jnr.ffi.byref
Class PointerByReference

java.lang.Object
  extended by jnr.ffi.byref.AbstractReference<Pointer>
      extended by jnr.ffi.byref.PointerByReference
All Implemented Interfaces:
ByReference<Pointer>

public final class PointerByReference
extends AbstractReference<Pointer>

AddressByReference is used when the address of a pointer must be passed as a parameter to a function.

For example, the following C code,

 extern void get_a(void** ap);

 void* foo(void) {
     void* a;
     // pass a reference to 'a' so get_a() can fill it out
     get_a(&a);

     return a;
 }
 
 

Would be declared in java as

 interface Lib {
     void get_a(@Out PointerByReference ap);
 }
 
 

and used like this

 PointerByReference ap = new PointerByReference();
 lib.get_a(ap);
 Pointer ptr = ap.getValue();
 System.out.println("ptr from lib=" + a.getValue());
 System.out.println("ptr contents=" + ptr.getInt(0));
 


Constructor Summary
PointerByReference()
          Creates a new reference to a pointer value with a null default value.
PointerByReference(Pointer value)
          Creates a new reference to a pointer value
 
Method Summary
 void fromNative(Runtime runtime, Pointer memory, long offset)
          Copies the java value from native memory
 int nativeSize(Runtime runtime)
          Gets the size of the native buffer required to store the value
 void toNative(Runtime runtime, Pointer memory, long offset)
          Copies the java value to native memory
 
Methods inherited from class jnr.ffi.byref.AbstractReference
checkNull, getValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PointerByReference

public PointerByReference()
Creates a new reference to a pointer value with a null default value.


PointerByReference

public PointerByReference(Pointer value)
Creates a new reference to a pointer value

Parameters:
value - the initial pointer value
Method Detail

toNative

public final void toNative(Runtime runtime,
                           Pointer memory,
                           long offset)
Description copied from interface: ByReference
Copies the java value to native memory

memory - the native memory buffer.

fromNative

public final void fromNative(Runtime runtime,
                             Pointer memory,
                             long offset)
Description copied from interface: ByReference
Copies the java value from native memory

memory - the native memory buffer.

nativeSize

public final int nativeSize(Runtime runtime)
Description copied from interface: ByReference
Gets the size of the native buffer required to store the value

Returns:
the size in bytes of the native type


Copyright © 2013. All Rights Reserved.