com.sun.jna
public abstract class Union extends Structure
Field Summary | |
---|---|
StructField | biggestField |
Constructor Summary | |
---|---|
protected | Union() Create a Union whose size and alignment will be calculated
automatically. |
protected | Union(Pointer p) Create a Union of the given size, using default alignment. |
protected | Union(Pointer p, int alignType) Create a Union of the given size and alignment type. |
protected | Union(TypeMapper mapper) Create a Union of the given size and alignment type. |
protected | Union(Pointer p, int alignType, TypeMapper mapper) Create a Union of the given size and alignment type. |
Method Summary | |
---|---|
int | calculateSize(boolean force) Adjust the size to be the size of the largest element, and ensure
all fields begin at offset zero. |
protected int | getNativeAlignment(Class type, Object value, boolean isFirstElement) All fields are considered the "first" element. |
Object | getTypedValue(Class type) Reads the Structure field of the given type from memory, sets it as
the active type and returns it. |
Pointer | getTypeInfo() Avoid calculating type information until we know our biggest field.
|
Object | readField(String name) Force a read of the given field from native memory. |
Object | readField(StructField field) Avoid reading pointer-based fields and structures unless explicitly
selected. |
void | setType(Class type) Indicates which field will be used to write to native memory. |
Object | setTypedValue(Object object) Set the active type and its value. |
void | writeField(String name) Write the given field value to native memory.
|
void | writeField(String name, Object value) Write the given field value to the field and native memory.
|
void | writeField(StructField field) Only the currently selected field will be written. |
Union u;
Class type;
u.setType(type);
u.read();
value = u.field;
Parameters: type class type of the Structure field to read
Returns: the Structure field with the given type
Returns: the new field value, after updating
Throws: IllegalArgumentException if no field exists with the given name
Throws: IllegalArgumentException if the type does not correspond to any declared union field.
Union u;
Class type;
u.setType(type);
u.field = value;
Parameters: object instance of a class which is part of the union
Returns: this Union object
Throws: IllegalArgumentException if no field exists with the given name
Throws: IllegalArgumentException if no field exists with the given name