com.smardec.j2native
Class Structure
java.lang.Object
|
+--com.smardec.j2native.Argument
|
+--com.smardec.j2native.Structure
- All Implemented Interfaces:
- java.lang.Cloneable
- public abstract class Structure
- extends Argument
The Structure class represents structures in tems of C language.
Structure is a superclass for classes representing specific structures.
Example of usage:
final public class RECT extends Structure{
public UInt32 left;
public UInt32 top;
public UInt32 right;
public UInt32 bottom;
public RECT(){
left = new UInt32();
top = new UInt32();
right = new UInt32();
bottom = new UInt32();
initialize(new Argument[]{left, top, right, bottom});
}
}
You are not forced to derive another class from Struct.
A needed structure can be constructed using constructor taking
array of Argument s.
Constructor Summary |
Structure()
Constructs a new structure. |
Structure(Argument[] members)
Constructs a new structure that consists of a given set
of members with default alignment. |
Structure(Argument[] members,
int align)
Constructs a new structure that consists of a given set
of members with specified alignment. |
Method Summary |
void |
free()
To avoid memory leaks in native memory should be used this method. |
void |
fromBytesValue(byte[] bytes,
int offset)
Restores itself from provided array of bytes. |
int |
getLength()
Returns length in bytes. |
Argument[] |
getMembers()
Returns structure members. |
protected void |
initialize(Argument[] members)
Initializes the Structure instance with specified
structure 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. |
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. |
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 java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Structure
public Structure()
- Constructs a new structure. Initial contents are undefined.
When using this constructor, subclass should then call the
initialize() method to define structure members
and alignment
Structure
public Structure(Argument[] members)
- Constructs a new structure that consists of a given set
of members with default alignment.
- Parameters:
- members - structure members as appear in structure definition
Structure
public Structure(Argument[] members,
int align)
- Constructs a new structure that consists of a given set
of members with specified alignment.
NOTE: Alignment should be 1 for Delphi packed record
- Parameters:
- members - structure members as appear in structure definition
- align - alignment in bytes
initialize
protected void initialize(Argument[] members)
- Initializes the
Structure instance with specified
structure members.
- Parameters:
- members - members of structure. Order of members in array
is order of members in native structure.
getMembers
public Argument[] getMembers()
- Returns structure members.
WARNING: Do not modify contents of the returned array.
getLength
public int getLength()
- Description copied from class: Argument
- Returns length in bytes.
- Specified by:
- getLength in class Argument
- Returns:
- an int
writeToStack
protected void writeToStack(byte[] stack,
int offset)
- Description copied from class: Argument
- Writes itself to stack.
- Specified by:
- writeToStack in class Argument
- Parameters:
- stack - it's byte array, where
Argument will be written- offset - offset in stack
readFromStack
protected void readFromStack(byte[] stack,
int offset)
- Description copied from class: Argument
- Read itself from stack.
- Specified by:
- readFromStack in class Argument
- Parameters:
- stack - it's byte array, from which
Argument will be restored- offset - offset in stack
toBytesValue
public byte[] toBytesValue()
- Description copied from class: Argument
- Encodes itself and returns it's representation as array of bytes.
- Specified by:
- toBytesValue in class Argument
- Returns:
- byte[] representation of
Argument
toBytesValue
protected void toBytesValue(byte[] bytes,
int offset)
- Description copied from class: Argument
- Encodes itself to the provided array of bytes.
- Specified by:
- toBytesValue in class Argument
- Parameters:
- bytes - array of bytes to which
Argument will be written- offset - offset in array
fromBytesValue
public void fromBytesValue(byte[] bytes,
int offset)
- Description copied from class: Argument
- Restores itself from provided array of bytes.
- Specified by:
- fromBytesValue in class Argument
- Parameters:
- bytes - array of bytes from which
Argument will be restored- offset - offset in array
write
protected void write(long handle,
int offset)
- Description copied from class: Argument
- Writes itself to the memory. Exact memory address specified by params.
- Specified by:
- write in class Argument
- Parameters:
- handle - identifies location in memory where
Argument
will be written- offset - memory address offset
read
protected void read(long handle,
int offset)
- Description copied from class: Argument
- Reads itself from the memory. Exact memory address specified by params.
- Specified by:
- read in class Argument
- Parameters:
- handle - identifies location in memory from which
Argument
will be read- offset - memory address offset
update
protected void update(byte side)
- Description copied from class: Argument
- This method is used to synchronize Java side and native part.
- Overrides:
- update in class Argument
- Parameters:
- side - identifies part that should be updated
isFixedLength
protected boolean isFixedLength()
- Description copied from class: Argument
- Identify if
Argument is a fixed length variable.
- Specified by:
- isFixedLength in class Argument
- Returns:
true if it is so, and false otherwise
free
public void free()
- Description copied from class: Argument
- To avoid memory leaks in native memory should be used this method.
- Overrides:
- free in class Argument
|