com.jniwrapper
Class Union

java.lang.Object
  |
  +--com.jniwrapper.Parameter
        |
        +--com.jniwrapper.Union

public class Union
extends Parameter

Represents a C union type. This parameter is initialized with several parameters representing union members. Length of this parameter is equal to that of its longest member. A union represents only one of its members at a time. Users should define which member the union represents by calling one of the setActiveMember methods.


Constructor Summary
protected Union()
          Preconstructs a union.
  Union(Parameter[] members)
          Constructs a union with a given set of members.
 
Method Summary
 java.lang.Object clone()
           
 int getLength()
          Returns a length of the parameter in memory.
protected  void init(Parameter[] members)
          Sets union members - order does not matter.
 void read(DataBuffer stackBuffer, int offset)
          Reads this parameter from a specified data source.
 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 setBuffer(DataBuffer newStorage, int newOffset)
          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)
          Writes this parameter to a specified data source.
 
Methods inherited from class com.jniwrapper.Parameter
acceptIOPerformer, asReturnValue, equals, getAlignedLength, getBuffer, getOffset, indent, pop, push, read, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Union

protected Union()
Preconstructs a union. Unions constructed with this constructor should be initialized using init() method.


Union

public Union(Parameter[] members)
Constructs a union with a given set of members. Constructed union initially has no active member - it has to be set using setActiveMember() method.

Parameters:
members - union members - order does not matter.
Method Detail

init

protected void init(Parameter[] members)
Sets union members - order does not matter.


setBuffer

protected void setBuffer(DataBuffer newStorage,
                         int newOffset)
Description copied from class: Parameter
Sets the data buffer this parameter should use to store data and an offset in bytes within that buffer.

Overrides:
setBuffer in class Parameter

setActiveMember

public void setActiveMember(Parameter active)
Defines the member of this union that is currently used. This method should be called before a value is assigned to that member.


setActiveMember

public void setActiveMember(Parameter active,
                            boolean read)
Defines the member of this union that is currently used. This method should be called before a value is assigned to that member. If read is true this member is read from the last value of this union. This is for the case when active member can be determined only after the function call is completed. If the union contains pointers it is recommended to set active member to null before making such calls.

Parameters:
active - new active member
read - if true this member is read from the last value of this union.

clone

public java.lang.Object clone()
Specified by:
clone in class Parameter

getLength

public int getLength()
Description copied from class: Parameter
Returns a length of the parameter in memory. This method is analogous to C sizeof() operator.

Specified by:
getLength in class Parameter

read

public void read(DataBuffer stackBuffer,
                 int offset)
          throws MemoryAccessViolationException
Description copied from class: Parameter
Reads this parameter from a specified data source.

Specified by:
read in class Parameter
MemoryAccessViolationException

write

public void write(DataBuffer stackBuffer,
                  int offset)
           throws MemoryAccessViolationException
Description copied from class: Parameter
Writes this parameter to a specified data source.

Specified by:
write in class Parameter
MemoryAccessViolationException