Top Description Fields Constructors Methods
com.sun.jna

public abstract Class Union

extends Structure
Class Inheritance
Imports
java.util.Iterator

Represents a native union. When writing to native memory, the field corresponding to the type passed to setType 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. 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.

Field Summary

Modifier and TypeField and Description
private Structure.StructField
private Structure.StructField
Inherited from com.sun.jna.Structure:
ALIGN_DEFAULTALIGN_GNUCALIGN_MSVCALIGN_NONECALCULATE_SIZEisPPCisSPARC

Constructor Summary

AccessConstructor and Description
protected
Union()

Create a Union whose size and alignment will be calculated automatically.

protected
Union(int size)

Create a Union of the given size, using default alignment.

protected
Union(int size, int alignType)

Create a Union of the given size and alignment type.

Method Summary

Modifier and TypeMethod and Description
pack-priv int
calculateSize(boolean force)

Overrides com.sun.jna.Structure.calculateSize.

Adjust the size to be the size of the largest element, and ensure all fields begin at offset zero.
protected int
getNativeAlignment(Class<T> type, Object value, boolean isFirstElement)

Overrides com.sun.jna.Structure.getNativeAlignment.

All fields are considered the "first" element.
pack-priv Pointer
getTypeInfo()

Overrides com.sun.jna.Structure.getTypeInfo.

Return type information for the largest field.
pack-priv Object
readField(Structure.StructField field)

Overrides com.sun.jna.Structure.readField.

Avoid reading pointer-based fields and structures unless explicitly selected.
public void
setType(Class<T> type)

Indicates which field will be used to write to native memory.

pack-priv void
writeField(Structure.StructField field)

Overrides com.sun.jna.Structure.writeField.

Only the currently selected field will be written.
Inherited from com.sun.jna.Structure:
allocateMemoryallocateMemorycalculateAlignedSizeclearequalsfieldsgetFieldgetPointergetStructAlignmentgetTypeInfohashCodenewInstancereadreadFieldsetAlignTypesetTypeMappersizetoArraytoArraytoStringupdateStructureByReferenceuseMemoryuseMemorywritewriteField

Field Detail

activeFieldback to summary
private Structure.StructField activeField
biggestFieldback to summary
private Structure.StructField biggestField

Constructor Detail

Unionback to summary
protected Union()

Create a Union whose size and alignment will be calculated automatically.

Unionback to summary
protected Union(int size)

Create a Union of the given size, using default alignment.

Unionback to summary
protected Union(int size, int alignType)

Create a Union of the given size and alignment type.

Method Detail

calculateSizeback to summary
pack-priv int calculateSize(boolean force)

Overrides com.sun.jna.Structure.calculateSize.

Adjust the size to be the size of the largest element, and ensure all fields begin at offset zero.

getNativeAlignmentback to summary
protected int getNativeAlignment(Class<T> type, Object value, boolean isFirstElement)

Overrides com.sun.jna.Structure.getNativeAlignment.

All fields are considered the "first" element.

getTypeInfoback to summary
pack-priv Pointer getTypeInfo()

Overrides com.sun.jna.Structure.getTypeInfo.

Return type information for the largest field.

readFieldback to summary
pack-priv Object readField(Structure.StructField field)

Overrides com.sun.jna.Structure.readField.

Avoid reading pointer-based fields and structures unless explicitly selected. Structures may contain pointer-based fields which can crash the VM if not properly initialized.

setTypeback to summary
public void setType(Class<T> type)

Indicates which field will be used to write to native memory.

Exceptions
IllegalArgumentException:
if the type does not correspond to any declared union field.
writeFieldback to summary
pack-priv void writeField(Structure.StructField field)

Overrides com.sun.jna.Structure.writeField.

Only the currently selected field will be written.