public abstract class Union extends Structure
setType(java.lang.Class)
will be written
to native memory. Upon reading from native memory, Structure, String,
or WString fields will not be initialized unless they are
the current field as identified by a call to setType(java.lang.Class)
. The current
field is always unset by default to avoid accidentally attempting to read
a field that is not valid. In the case of a String, for instance, an
invalid pointer may result in a memory fault when attempting to initialize
the String.Structure.ByReference, Structure.ByValue, Structure.FFIType, Structure.StructField
Modifier and Type | Field and Description |
---|---|
(package private) Structure.StructField |
biggestField |
ALIGN_DEFAULT, ALIGN_GNUC, ALIGN_MSVC, ALIGN_NONE, CALCULATE_SIZE, isPPC, isSPARC
Modifier | Constructor and Description |
---|---|
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(Pointer p,
int alignType,
TypeMapper mapper)
Create a Union of the given size and alignment type.
|
protected |
Union(TypeMapper mapper)
Create a Union of the given size and alignment type.
|
Modifier and Type | Method and Description |
---|---|
(package private) 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(java.lang.Class type,
java.lang.Object value,
boolean isFirstElement)
All fields are considered the "first" element.
|
java.lang.Object |
getTypedValue(java.lang.Class type)
Reads the Structure field of the given type from memory, sets it as
the active type and returns it.
|
(package private) Pointer |
getTypeInfo()
Avoid calculating type information until we know our biggest field.
|
java.lang.Object |
readField(java.lang.String name)
Force a read of the given field from native memory.
|
(package private) java.lang.Object |
readField(Structure.StructField field)
Avoid reading pointer-based fields and structures unless explicitly
selected.
|
void |
setType(java.lang.Class type)
Indicates which field will be used to write to native memory.
|
java.lang.Object |
setTypedValue(java.lang.Object object)
Set the active type and its value.
|
void |
writeField(java.lang.String name)
Write the given field value to native memory.
|
void |
writeField(java.lang.String name,
java.lang.Object value)
Write the given field value to the field and native memory.
|
(package private) void |
writeField(Structure.StructField field)
Only the currently selected field will be written.
|
allocateMemory, allocateMemory, autoAllocate, autoRead, autoRead, autoWrite, autoWrite, busy, cacheTypeInfo, calculateAlignedSize, clear, ensureAllocated, equals, fields, getAutoRead, getAutoWrite, getField, getFieldOrder, getFields, getPointer, getStructAlignment, getTypeInfo, hashCode, newInstance, read, reading, setAlignType, setAutoRead, setAutoSynch, setAutoWrite, setField, setFieldOrder, setTypeMapper, size, sortFields, toArray, toArray, toString, updateStructureByReference, useMemory, useMemory, write
Structure.StructField biggestField
protected Union()
protected Union(Pointer p)
protected Union(Pointer p, int alignType)
protected Union(TypeMapper mapper)
protected Union(Pointer p, int alignType, TypeMapper mapper)
public void setType(java.lang.Class type)
java.lang.IllegalArgumentException
- if the type does not correspond to
any declared union field.public java.lang.Object readField(java.lang.String name)
public void writeField(java.lang.String name)
writeField
in class Structure
java.lang.IllegalArgumentException
- if no field exists with the given namepublic void writeField(java.lang.String name, java.lang.Object value)
writeField
in class Structure
java.lang.IllegalArgumentException
- if no field exists with the given namepublic java.lang.Object getTypedValue(java.lang.Class type)
Union u;
Class type;
u.setType(type);
u.read();
value = u.field;
type
- class type of the Structure field to readpublic java.lang.Object setTypedValue(java.lang.Object object)
Union u;
Class type;
u.setType(type);
u.field = value;
object
- instance of a class which is part of the unionvoid writeField(Structure.StructField field)
writeField
in class Structure
java.lang.Object readField(Structure.StructField field)
int calculateSize(boolean force)
calculateSize
in class Structure
protected int getNativeAlignment(java.lang.Class type, java.lang.Object value, boolean isFirstElement)
getNativeAlignment
in class Structure
Pointer getTypeInfo()
getTypeInfo
in class Structure