org.bridj
Class StructIO

java.lang.Object
  extended by org.bridj.StructIO

public class StructIO
extends Object

Representation of a C struct's memory layout, built thanks to the annotations found in the Java bindings.
End-users should not use this class, it's used by runtimes.
Annotations currently used are Virtual, Array, Bits, Field, Alignment and soon Struct

Author:
ochafik

Nested Class Summary
static class StructIO.AggregatedFieldDesc
           
static interface StructIO.Customizer
          Deprecated. The StructIO API is subject to future changes. Use this with care and be prepared to migrate your code...
static class StructIO.DefaultCustomizer
           
static class StructIO.FieldDecl
           
static class StructIO.FieldDesc
          Internal metadata on a struct field
 
Field Summary
protected  StructIO.FieldDesc[] fields
           
protected  boolean hasFieldFields
           
protected  PointerIO<?> pointerIO
           
protected  Class<?> structClass
           
protected  Type structType
           
 
Constructor Summary
StructIO(Class<?> structClass, Type structType)
           
 
Method Summary
protected  boolean acceptFieldGetter(Member member, boolean getter)
           
protected  StructIO.AggregatedFieldDesc aggregateFields(List<StructIO.FieldDecl> fieldGroup)
           
protected  long alignSize(long size, long alignment)
           
 void appendBytes(long bytes)
           
 int compare(StructObject a, StructObject b)
           
protected  StructIO.FieldDesc[] computeStructLayout()
           
protected  StructIO.FieldDecl createFieldDecl(Field getter)
           
protected  StructIO.FieldDecl createFieldDecl(Member member)
           
protected  StructIO.FieldDecl createFieldDecl(Method getter)
           
 String describe()
           
 String describe(StructObject struct)
           
 boolean equal(StructObject a, StructObject b)
           
 List<StructIO.AggregatedFieldDesc> getAggregatedFields()
           
 boolean getBooleanField(StructObject struct, int fieldIndex)
           
 byte getByteField(StructObject struct, int fieldIndex)
           
 char getCharField(StructObject struct, int fieldIndex)
           
 long getCLongField(StructObject struct, int fieldIndex)
           
 double getDoubleField(StructObject struct, int fieldIndex)
           
<E extends Enum<E>>
IntValuedEnum<E>
getEnumField(StructObject struct, int fieldIndex)
           
 float getFloatField(StructObject struct, int fieldIndex)
           
static StructIO getInstance(Class structClass, Type structType)
           
static StructIO getInstance(Type structType)
           
 int getIntField(StructObject struct, int fieldIndex)
           
 long getLongField(StructObject struct, int fieldIndex)
           
<O extends NativeObject>
O
getNativeObjectField(StructObject struct, int fieldIndex)
           
<T> Pointer<T>
getPointerField(StructObject struct, int fieldIndex)
           
 PointerIO<?> getPointerIO()
           
 short getShortField(StructObject struct, int fieldIndex)
           
 long getSizeTField(StructObject struct, int fieldIndex)
           
 long getStructAlignment()
           
 Class<?> getStructClass()
           
 long getStructSize()
           
 Type getStructType()
           
<T extends TypedPointer>
T
getTypedPointerField(StructObject struct, int fieldIndex)
           
protected  List<StructIO.FieldDecl> listFields()
          Creates a list of structure fields
protected  void orderFields(List<StructIO.FieldDecl> fields)
          Orders the fields to match the actual structure layout
protected  void performLayout(Iterable<StructIO.AggregatedFieldDesc> aggregatedFields)
           
 void prependBytes(long bytes)
           
protected static int primTypeLength(Class<?> primType)
           
 void readFieldsFromNative(StructObject struct)
          Read struct fields implemented as Java fields from the corresponding native memory (Java fields are read from native memory).
static StructIO registerStructIO(Class structClass, Type structType, StructIO io)
           
 void setBooleanField(StructObject struct, int fieldIndex, boolean value)
           
 void setByteField(StructObject struct, int fieldIndex, byte value)
           
 void setCharField(StructObject struct, int fieldIndex, char value)
           
 void setCLongField(StructObject struct, int fieldIndex, long value)
           
 void setDoubleField(StructObject struct, int fieldIndex, double value)
           
 void setEnumField(StructObject struct, int fieldIndex, ValuedEnum<?> value)
           
 void setFieldOffset(String fieldName, long fieldOffset, boolean propagateChanges)
           
 void setFloatField(StructObject struct, int fieldIndex, float value)
           
 void setIntField(StructObject struct, int fieldIndex, int value)
           
 void setLongField(StructObject struct, int fieldIndex, long value)
           
<O extends NativeObject>
void
setNativeObjectField(StructObject struct, int fieldIndex, O value)
           
<T> void
setPointerField(StructObject struct, int fieldIndex, Pointer<T> value)
           
 void setShortField(StructObject struct, int fieldIndex, short value)
           
 void setSizeTField(StructObject struct, int fieldIndex, long value)
           
 String toString()
           
 void writeFieldsToNative(StructObject struct)
          Write struct fields implemented as Java fields to the corresponding native memory (Java fields are written to native memory).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pointerIO

protected PointerIO<?> pointerIO

fields

protected volatile StructIO.FieldDesc[] fields

structClass

protected final Class<?> structClass

structType

protected final Type structType

hasFieldFields

protected boolean hasFieldFields
Constructor Detail

StructIO

public StructIO(Class<?> structClass,
                Type structType)
Method Detail

getInstance

public static StructIO getInstance(Type structType)

getInstance

public static StructIO getInstance(Class structClass,
                                   Type structType)

registerStructIO

public static StructIO registerStructIO(Class structClass,
                                        Type structType,
                                        StructIO io)

prependBytes

public void prependBytes(long bytes)

appendBytes

public void appendBytes(long bytes)

setFieldOffset

public void setFieldOffset(String fieldName,
                           long fieldOffset,
                           boolean propagateChanges)

getStructClass

public Class<?> getStructClass()

getStructType

public Type getStructType()

toString

public String toString()
Overrides:
toString in class Object

getPointerIO

public PointerIO<?> getPointerIO()

alignSize

protected long alignSize(long size,
                         long alignment)

getStructSize

public final long getStructSize()

getStructAlignment

public final long getStructAlignment()

orderFields

protected void orderFields(List<StructIO.FieldDecl> fields)
Orders the fields to match the actual structure layout


acceptFieldGetter

protected boolean acceptFieldGetter(Member member,
                                    boolean getter)

createFieldDecl

protected StructIO.FieldDecl createFieldDecl(Field getter)

createFieldDecl

protected StructIO.FieldDecl createFieldDecl(Method getter)

createFieldDecl

protected StructIO.FieldDecl createFieldDecl(Member member)

listFields

protected List<StructIO.FieldDecl> listFields()
Creates a list of structure fields


primTypeLength

protected static int primTypeLength(Class<?> primType)

getAggregatedFields

public List<StructIO.AggregatedFieldDesc> getAggregatedFields()

computeStructLayout

protected StructIO.FieldDesc[] computeStructLayout()

aggregateFields

protected StructIO.AggregatedFieldDesc aggregateFields(List<StructIO.FieldDecl> fieldGroup)

performLayout

protected void performLayout(Iterable<StructIO.AggregatedFieldDesc> aggregatedFields)

equal

public boolean equal(StructObject a,
                     StructObject b)

compare

public int compare(StructObject a,
                   StructObject b)

describe

public final String describe(StructObject struct)

describe

public final String describe()

writeFieldsToNative

public final void writeFieldsToNative(StructObject struct)
Write struct fields implemented as Java fields to the corresponding native memory (Java fields are written to native memory).
This does not concern normal structs as generated by JNAerator (which use getters and setters methods that read and write the fields directly from / to the native memory), but rather structs that are in the JNA style.


readFieldsFromNative

public final void readFieldsFromNative(StructObject struct)
Read struct fields implemented as Java fields from the corresponding native memory (Java fields are read from native memory).
This does not concern normal structs as generated by JNAerator (which use getters and setters methods that read and write the fields directly from / to the native memory), but rather structs that are in the JNA style.


getPointerField

public final <T> Pointer<T> getPointerField(StructObject struct,
                                            int fieldIndex)

setPointerField

public final <T> void setPointerField(StructObject struct,
                                      int fieldIndex,
                                      Pointer<T> value)

getTypedPointerField

public final <T extends TypedPointer> T getTypedPointerField(StructObject struct,
                                                             int fieldIndex)

getNativeObjectField

public final <O extends NativeObject> O getNativeObjectField(StructObject struct,
                                                             int fieldIndex)

setNativeObjectField

public final <O extends NativeObject> void setNativeObjectField(StructObject struct,
                                                                int fieldIndex,
                                                                O value)

getEnumField

public final <E extends Enum<E>> IntValuedEnum<E> getEnumField(StructObject struct,
                                                               int fieldIndex)

setEnumField

public final void setEnumField(StructObject struct,
                               int fieldIndex,
                               ValuedEnum<?> value)

setIntField

public final void setIntField(StructObject struct,
                              int fieldIndex,
                              int value)

getIntField

public final int getIntField(StructObject struct,
                             int fieldIndex)

setLongField

public final void setLongField(StructObject struct,
                               int fieldIndex,
                               long value)

getLongField

public final long getLongField(StructObject struct,
                               int fieldIndex)

setShortField

public final void setShortField(StructObject struct,
                                int fieldIndex,
                                short value)

getShortField

public final short getShortField(StructObject struct,
                                 int fieldIndex)

setByteField

public final void setByteField(StructObject struct,
                               int fieldIndex,
                               byte value)

getByteField

public final byte getByteField(StructObject struct,
                               int fieldIndex)

setCharField

public final void setCharField(StructObject struct,
                               int fieldIndex,
                               char value)

getCharField

public final char getCharField(StructObject struct,
                               int fieldIndex)

setFloatField

public final void setFloatField(StructObject struct,
                                int fieldIndex,
                                float value)

getFloatField

public final float getFloatField(StructObject struct,
                                 int fieldIndex)

setDoubleField

public final void setDoubleField(StructObject struct,
                                 int fieldIndex,
                                 double value)

getDoubleField

public final double getDoubleField(StructObject struct,
                                   int fieldIndex)

setBooleanField

public final void setBooleanField(StructObject struct,
                                  int fieldIndex,
                                  boolean value)

getBooleanField

public final boolean getBooleanField(StructObject struct,
                                     int fieldIndex)

setSizeTField

public final void setSizeTField(StructObject struct,
                                int fieldIndex,
                                long value)

getSizeTField

public final long getSizeTField(StructObject struct,
                                int fieldIndex)

setCLongField

public final void setCLongField(StructObject struct,
                                int fieldIndex,
                                long value)

getCLongField

public final long getCLongField(StructObject struct,
                                int fieldIndex)


Copyright © 2009-2012. All Rights Reserved.