|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.smardec.j2native.Argument | +--com.smardec.j2native.Union
The Union
class represents a C union type. Function arguments 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.
Field Summary |
Fields inherited from class com.smardec.j2native.Argument |
JAVA_SIDE, NATIVE_SIDE |
Constructor Summary | |
protected |
Union()
Preconstructs a union. |
protected |
Union(Argument[] members)
Constructs a union with a given set of members. |
Method Summary | |
java.lang.Object |
clone()
Creates and returns a copy of this object. |
void |
fromBytesValue(byte[] bytes,
int offset)
Restores itself from provided array of bytes. |
Argument |
getActiveMember()
Returns currently active member. |
int |
getLength()
Returns length in bytes. |
Argument[] |
getMembers()
Returns union members. |
protected void |
initialize(Argument[] members)
Initialize union and sets union members. |
protected boolean |
isFixedLength()
Identify if Argument is a fixed length variable. |
protected void |
read(long handle,
int offset)
Reads itself from the memory. |
protected void |
readFromStack(byte[] stack,
int offset)
Read itself from stack. |
void |
setActiveMember(Argument active)
Defines the member of this union that is currently used. |
void |
setActiveMember(Argument active,
boolean update)
Defines the member of this union that is currently used. |
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 update)
Selects a new active member of the union by its index in the array passed on the initialization. |
byte[] |
toBytesValue()
Encodes itself and returns it's representation as array of bytes. |
protected void |
toBytesValue(byte[] bytes,
int offset)
Encodes itself to the provided array of bytes. |
java.lang.String |
toString()
|
protected void |
update(byte side)
This method is used to synchronize Java side and native part. |
protected void |
write(long handle,
int offset)
Writes itself to the memory. |
protected void |
writeToStack(byte[] stack,
int offset)
Writes itself to stack. |
Methods inherited from class com.smardec.j2native.Argument |
finalize, free, getAlignedLength, readFromRAM, restoreFromRAM, storeToRAM, writeToRAM |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Union()
initialize()
method
protected Union(Argument[] members)
Method Detail |
protected void initialize(Argument[] members)
members
- union memberspublic Argument[] getMembers()
public void setActiveMember(Argument active)
active
- a new active memberpublic void setActiveMember(Argument active, boolean update) throws java.lang.IllegalStateException
update
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.
active
- a new active memberupdate
- if true, this member is read from the last value of this union
java.lang.IllegalStateException
- if internal structure is wrongpublic void setActiveMember(int index)
index
- the index of the new active member.public void setActiveMember(int index, boolean update)
update
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.
index
- the index of the new active member.update
- if true, this member is read from the last value of this union
java.lang.IllegalStateException
- if internal structure is wrongpublic Argument getActiveMember()
protected void update(byte side)
Argument
update
in class Argument
side
- identifies part that should be updatedprotected void write(long handle, int offset)
Argument
write
in class Argument
handle
- identifies location in memory where Argument
will be writtenoffset
- memory address offsetprotected void read(long handle, int offset)
Argument
read
in class Argument
handle
- identifies location in memory from which Argument
will be readoffset
- memory address offsetprotected void writeToStack(byte[] stack, int offset)
Argument
writeToStack
in class Argument
stack
- it's byte array, where Argument
will be writtenoffset
- offset in stackprotected void readFromStack(byte[] stack, int offset)
Argument
readFromStack
in class Argument
stack
- it's byte array, from which Argument
will be restoredoffset
- offset in stackprotected boolean isFixedLength()
Argument
Argument
is a fixed length variable.
isFixedLength
in class Argument
true
if it is so, and false
otherwisepublic byte[] toBytesValue()
Argument
toBytesValue
in class Argument
Argument
protected void toBytesValue(byte[] bytes, int offset)
Argument
toBytesValue
in class Argument
bytes
- array of bytes to which Argument
will be writtenoffset
- offset in arraypublic void fromBytesValue(byte[] bytes, int offset)
Argument
fromBytesValue
in class Argument
bytes
- array of bytes from which Argument
will be restoredoffset
- offset in arraypublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone()
Argument
clone
in class Argument
public int getLength()
Argument
getLength
in class Argument
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |