public class Union extends Parameter implements CompositeParameter, AlignmentAwareParameter
union type. Function parameters of this type are
initialized with several parameters representing the union members. The
length of the union is equal to that of its longest member. A union
represents only one of its members at a time. Users of this class should
define which member the union represents by calling one of the
setActiveMember methods.LICENSE_TYPE, V| Modifier | Constructor and Description |
|---|---|
protected |
Union()
Preconstructs a union.
|
|
Union(Parameter[] members)
Constructs a union with a given set of members.
|
protected |
Union(Union that) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
acceptIOPerformer(IOPerformer performer,
DataBuffer buffer,
int initialOffset,
boolean isReadOperation,
boolean invokedByCallback)
Implementation of a Visitor pattern for parameter IO.
|
java.lang.Object |
clone()
This method is not supported and throws exception to designate that.
|
Parameter |
getActiveMember() |
int |
getAlignmentRequirement() |
protected boolean |
getCheckMembers() |
java.lang.String |
getDebugInfo()
Return debug info for JNIWrapper parameter.
|
int |
getFirstMemberSize()
Should return first member size.
|
int |
getLength()
Returns the length of the parameter in memory.
|
Parameter[] |
getMembers() |
protected void |
init(Parameter[] members)
Sets union members.
|
void |
pop(DataBuffer stackBuffer,
int offset,
boolean invokedByCallback)
Default implementation that does nothing because most primitive types do
nothing on pop.
|
void |
push(DataBuffer stackBuffer,
int offset,
boolean invokedByCallback)
Writes a parameter to a function stacks.
|
void |
read(DataBuffer stackBuffer,
int offset,
boolean invokedByCallback)
Reads this parameter from a specified data source.
|
protected void |
readPerformed() |
void |
setActiveMember(int index)
Selects a new active member of the union by its index in the array passed
on the initialization.
|
void |
setActiveMember(int index,
boolean read)
Selects a new active member of the union by its index in the array passed
on the initialization.
|
void |
setActiveMember(Parameter active)
Defines the member of this union that is currently used.
|
void |
setActiveMember(Parameter active,
boolean read)
Defines the member of this union that is currently used.
|
protected void |
setCheckMembers(boolean value) |
protected void |
setDataBuffer(DataBuffer newStorage,
int newOffset,
boolean shouldRead)
Sets the data buffer this parameter should use to store data and an
offset in bytes within that buffer.
|
void |
write(DataBuffer stackBuffer,
int offset,
boolean invokedByCallback)
Writes this parameter to a specified data source.
|
asReturnValue, dataBufferAssigned, equals, getAlignedLength, getDataBuffer, getDataBufferOffset, hashCode, indent, read, read, toByteArray, writeprotected Union()
init() method.protected Union(Union that)
public Union(Parameter[] members)
setActiveMember() method.members - union members - the order does not matter.protected void init(Parameter[] members)
members - union memberspublic Parameter[] getMembers()
protected void setDataBuffer(DataBuffer newStorage, int newOffset, boolean shouldRead)
ParametersetDataBuffer in class Parameterpublic Parameter getActiveMember()
public void setActiveMember(Parameter active)
active - a new active memberpublic void setActiveMember(Parameter active, boolean read)
read parameter is true, this member is read
from the last value of this union. This is for the case when an active
member can be determined only after the function call is completed.
If the union contains pointers, it is recommended to set an active
member to null before making such calls.
Because of performance considerations, the method does not check that
the passed Parameter instance actually belongs to the union.
active - a new active memberread - if true, this member is read from the last value
of this union.public void setActiveMember(int index)
index - the index of the new active member.init(Parameter[])public void setActiveMember(int index,
boolean read)
index - the index of a new active member.read - if true, a new active member is read from the
last value of the union.init(Parameter[])public java.lang.Object clone()
public int getLength()
Parametersizeof() operator.public void read(DataBuffer stackBuffer, int offset, boolean invokedByCallback) throws MemoryAccessViolationException
Parameterread in class ParameterMemoryAccessViolationExceptionprotected void readPerformed()
protected boolean getCheckMembers()
protected void setCheckMembers(boolean value)
public void write(DataBuffer stackBuffer, int offset, boolean invokedByCallback) throws MemoryAccessViolationException
Parameterwrite in class ParameterMemoryAccessViolationExceptionpublic void push(DataBuffer stackBuffer, int offset, boolean invokedByCallback) throws MemoryAccessViolationException
Parameterpush in class ParameterMemoryAccessViolationExceptionpublic void pop(DataBuffer stackBuffer, int offset, boolean invokedByCallback) throws MemoryAccessViolationException
Parameterpop in class ParameterMemoryAccessViolationExceptionprotected void acceptIOPerformer(IOPerformer performer, DataBuffer buffer, int initialOffset, boolean isReadOperation, boolean invokedByCallback)
Parameterperformer is responsible for reading and writing the
parameter. Users implementing a complex parameter from scratch (i.e. not
by extending a pre-existing class such as Structure or
Pointer) may wish to override this method to make a
performer visit object internal parts.acceptIOPerformer in class Parameterperformer - a visitor responsible for I/Oing the parameter.buffer - data buffer for I/O operation.initialOffset - I/O operation offset of this parameter in the
buffer.public int getAlignmentRequirement()
getAlignmentRequirement in class Parameterpublic java.lang.String getDebugInfo()
ParametergetDebugInfo in class Parameterpublic int getFirstMemberSize()
AlignmentAwareParametergetFirstMemberSize in interface AlignmentAwareParameter