com.jniwrapper
Class Structure

java.lang.Object
  |
  +--com.jniwrapper.Parameter
        |
        +--com.jniwrapper.Structure
Direct Known Subclasses:
ComplexArray, FileTime, JAWT_DrawingSurface, JAWT_DrawingSurfaceInfo, JAWT_Rectangle, LogPalette, PaletteEntry, Point, Rect, Size, VersionInfo

public class Structure
extends Parameter

The class represents structures in tems of C language.

Struct is superclass for classes representing specific structures.

Example of usage:

  final public class CPoint extends Structure {
    public Int x = new Int();
    public Int y = new Int();
    public CPoint() {
      init(new Parameter[] {x, y});
    }
  }
 

Nevertheless you are not forced to derive another class from Struct. Needed structure can be constructed using constructor taking array of CParameters.


Constructor Summary
protected Structure()
          Preconstructs a new structure.
  Structure(Parameter[] members)
          Construct a new structure that consists of given set of members with default alignment.
  Structure(Parameter[] members, short alignment)
          Construct a new structure that consists of given set of members with given alignment.
 
Method Summary
protected  void acceptIOPerformer(IOPerformer performer, DataBuffer source, int initialOffset, boolean isReadOperation, boolean invokedByCallback)
          Realization of a Visitor pattern for parameter IO.
protected  void addMembers(Parameter[] additionalMembers)
          Adds structure members (for example, in a case of structure inheritance)
 java.lang.Object clone()
           
protected  void computeLength()
          Subclasses should call this method if any member changes its length.
 int getAlignmentRequirement()
           
 int getLength()
          Returns a length of the parameter in memory.
 Parameter getMember(int i)
          Returns a copy (clone) of a member with index i.
 Parameter[] getMembers()
          Returns structure members.
protected  void init(Parameter[] members)
          Initializes the instance with specified structure members and default alignment.
protected  void init(Parameter[] members, short alignment)
          Initializes the instance with specified structure members and alignment.
 void pop(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Default implementation, which does nothing as 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 setDataBuffer(DataBuffer newSource, int newOffset)
          Sets the data buffer this parameter should use to store data and an offset in bytes within that buffer.
 java.lang.String toString()
           
 void write(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Writes this parameter to a specified data source.
 
Methods inherited from class com.jniwrapper.Parameter
asReturnValue, equals, getAlignedLength, getDataBuffer, getDataBufferOffset, indent, read, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Structure

protected Structure()
Preconstructs a new structure. Initial contents are undefined. When using this constructor subclass should then call init() method to define structure members and alignment.


Structure

public Structure(Parameter[] members)
Construct a new structure that consists of given set of members with default alignment.

Parameters:
members - structure members as appear in structure definition.

Structure

public Structure(Parameter[] members,
                 short alignment)
Construct a new structure that consists of given set of members with given alignment.

Parameters:
members - structure members as appear in structure definition.
alignment - alignment in bytes.
Method Detail

init

protected void init(Parameter[] members,
                    short alignment)
Initializes the instance with specified structure members and alignment.


init

protected void init(Parameter[] members)
Initializes the instance with specified structure members and default alignment.


addMembers

protected void addMembers(Parameter[] additionalMembers)
Adds structure members (for example, in a case of structure inheritance)


getAlignmentRequirement

public int getAlignmentRequirement()
Overrides:
getAlignmentRequirement in class Parameter

computeLength

protected void computeLength()
Subclasses should call this method if any member changes its length. This method should only be used in very special cases - the preferred way is to call init.


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

clone

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getMembers

public Parameter[] getMembers()
Returns structure members.
WARNING: Do not modify contents of the returned array.


getMember

public Parameter getMember(int i)
Returns a copy (clone) of a member with index i. To get the actual member element use getMembers()[i]

Parameters:
i - index of member to return
Returns:
copy of the requested member

setDataBuffer

protected void setDataBuffer(DataBuffer newSource,
                             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:
setDataBuffer in class Parameter

acceptIOPerformer

protected void acceptIOPerformer(IOPerformer performer,
                                 DataBuffer source,
                                 int initialOffset,
                                 boolean isReadOperation,
                                 boolean invokedByCallback)
Description copied from class: Parameter
Realization of a Visitor pattern for parameter IO. A performer is responsible for I/Oing 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.

Overrides:
acceptIOPerformer in class Parameter
Parameters:
performer - visitor responsible for I/Oing the parameter
source - data buffer for I/O operation
initialOffset - I/O operation offset of this parameter in the buffer

write

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

Specified by:
write in class Parameter
MemoryAccessViolationException

read

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

Specified by:
read in class Parameter
MemoryAccessViolationException

push

public void push(DataBuffer stackBuffer,
                 int offset,
                 boolean invokedByCallback)
          throws MemoryAccessViolationException
Description copied from class: Parameter
Writes a parameter to a function stacks

Overrides:
push in class Parameter
MemoryAccessViolationException

pop

public void pop(DataBuffer stackBuffer,
                int offset,
                boolean invokedByCallback)
         throws MemoryAccessViolationException
Description copied from class: Parameter
Default implementation, which does nothing as most primitive types do nothing on pop. Reads a parameter from a function stack.

Overrides:
pop in class Parameter
MemoryAccessViolationException