jnr.ffi.byref
Class AddressByReference

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

public final class AddressByReference
extends AbstractReference<Address>

AddressByReference is used when the address of a primitive pointer value 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 AddressByReference ap);
 }
 
 

and used like this

 AddressByReference ap = new AddressByReference();
 lib.get_a(ap);
 System.out.println("a from lib=" + a.getValue());
 


Constructor Summary
AddressByReference()
          Creates a new reference to an integer value
AddressByReference(Address value)
          Creates a new reference to an address value
 
Method Summary
 void marshal(Pointer memory, long offset)
          Copies the address value to native memory
 int nativeSize(Runtime runtime)
          Gets the native size of type of reference
 void unmarshal(Pointer memory, long offset)
          Copies the address value from 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

AddressByReference

public AddressByReference()
Creates a new reference to an integer value


AddressByReference

public AddressByReference(Address value)
Creates a new reference to an address value

Parameters:
value - the initial native value
Method Detail

marshal

public void marshal(Pointer memory,
                    long offset)
Copies the address value to native memory

Parameters:
memory - the native memory buffer

unmarshal

public void unmarshal(Pointer memory,
                      long offset)
Copies the address value from native memory

Parameters:
memory - the native memory buffer.

nativeSize

public int nativeSize(Runtime runtime)
Gets the native size of type of reference

Returns:
The size of the native type this reference points to


Copyright © 2012. All Rights Reserved.