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, Structure.StructureSet
ALIGN_DEFAULT, ALIGN_GNUC, ALIGN_MSVC, ALIGN_NONE, CALCULATE_SIZE, fieldOrder, layoutInfo
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 |
---|---|
protected List |
getFieldOrder()
Unions do not need a field order, so automatically provide a value to
satisfy checking in the Structure superclass.
|
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.
|
Object |
readField(String fieldName)
Force a read of the given field from native memory.
|
protected Object |
readField(Structure.StructField field)
Avoid reading pointer-based fields and structures unless explicitly
selected.
|
void |
setType(Class type)
Indicates by type which field will be used to write to native memory.
|
void |
setType(String fieldName)
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 fieldName)
Write the given field value to native memory.
|
void |
writeField(String fieldName,
Object value)
Write the given field value to the field and native memory.
|
protected void |
writeField(Structure.StructField field)
Only the currently selected field will be written.
|
allocateMemory, allocateMemory, autoAllocate, autoRead, autoRead, autoWrite, autoWrite, busy, cacheTypeInfo, calculateSize, calculateSize, clear, conditionalAutoRead, dataEquals, dataEquals, ensureAllocated, equals, fieldOffset, fields, getAutoRead, getAutoWrite, getFieldList, getFields, getFieldTypeInfo, getFieldValue, getNativeSize, getNativeSize, getPointer, getStringEncoding, getStructAlignment, getTypeInfo, getTypeInfo, getTypeMapper, hashCode, newInstance, newInstance, read, reading, setAlignType, setAutoRead, setAutoSynch, setAutoWrite, setFieldOrder, setFieldValue, setStringEncoding, size, size, size, sortFields, toArray, toArray, toString, toString, typeInfoField, updateStructureByReference, useMemory, useMemory, useMemory, validate, write
protected Union()
protected Union(Pointer p)
protected Union(Pointer p, int alignType)
protected Union(TypeMapper mapper)
protected Union(Pointer p, int alignType, TypeMapper mapper)
protected List getFieldOrder()
getFieldOrder
in class Structure
public void setType(Class type)
setType(String)
instead with the field name.type
- desired active type for the unionIllegalArgumentException
- if the type does not correspond to
any declared union field.public void setType(String fieldName)
fieldName
- desired field to use for the active union typeIllegalArgumentException
- if the name does not correspond to
any declared union field.public Object readField(String fieldName)
readField
in class Structure
fieldName
- field to be readIllegalArgumentException
- if no field exists with the given namepublic void writeField(String fieldName)
writeField
in class Structure
fieldName
- which field to synchIllegalArgumentException
- if no field exists with the given namepublic void writeField(String fieldName, Object value)
writeField
in class Structure
fieldName
- field to writevalue
- value to writeIllegalArgumentException
- if no field exists with the given namepublic Object getTypedValue(Class type)
Union u;
Class type;
u.setType(type);
u.read();
value = u.field;
type
- class type of the Structure field to readpublic Object setTypedValue(Object object)
Union u;
Class type;
u.setType(type);
u.field = value;
object
- instance of a class which is part of the unionprotected void writeField(Structure.StructField field)
writeField
in class Structure
field
- internal field representation to synch to native memoryprotected Object readField(Structure.StructField field)
protected int getNativeAlignment(Class type, Object value, boolean isFirstElement)
getNativeAlignment
in class Structure
type
- field typevalue
- field value, if availableisFirstElement
- is this field the first element in the struct?