com.jniwrapper
Class Structure

java.lang.Object
  extended by com.jniwrapper.Parameter
      extended by com.jniwrapper.Structure
All Implemented Interfaces:
AlignmentAwareParameter, CompositeParameter
Direct Known Subclasses:
ComplexArray, JAWT_DrawingSurface, JAWT_DrawingSurfaceInfo, JAWT_Rectangle

public class Structure
extends Parameter
implements CompositeParameter, AlignmentAwareParameter

The class represents structures in terms of C language.

Structure is a 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 Structure. A needed structure can be instanciated using constructor taking array of Parameters.


Field Summary
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Constructor Summary
protected Structure()
          Preconstructs a new structure.
  Structure(Parameter[] members)
          Constructs a new structure that consists of a given set of members with default alignment.
  Structure(Parameter[] members, short alignment)
          Constructs a new structure that consists of a given set of members with given alignment.
  Structure(Structure t)
          Deprecated. This medhod does nothing. Use new initFrom(Structure) method instead.
 
Method Summary
protected  void acceptIOPerformer(IOPerformer performer, DataBuffer source, int initialOffset, boolean isReadOperation, boolean invokedByCallback)
          Implementation of a Visitor pattern for parameter IO.
protected  void addMembers(Parameter[] additionalMembers)
          Adds structure members (for example, in the case of structure inheritance).
 java.lang.Object clone()
           
protected  void computeLength()
          Subclasses should call this method if any member changes its length.
 boolean equals(java.lang.Object obj)
          Compares this Parameter object to a given object.
 int getAlignmentRequirement()
           
 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 getMember(int i)
          Returns a copy (clone) of a member with index i.
 Parameter[] getMembers()
          Returns structure members.
protected  int[] getOffsets()
          Required for alignment tests
protected  void init(Parameter[] members)
          Initializes the instance with specified structure members and default alignment for current Platform.
protected  void init(Parameter[] members, short alignment)
          Initializes the instance with specified structure members and alignment.
 void initFrom(Structure source)
          Copies data of source structure to this structure.
 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 setDataBuffer(DataBuffer newSource, 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.
 
Methods inherited from class com.jniwrapper.Parameter
asReturnValue, dataBufferAssigned, getAlignedLength, getDataBuffer, getDataBufferOffset, hashCode, indent, read, read, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Structure

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


Structure

public Structure(Parameter[] 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(Parameter[] members,
                 short alignment)
Constructs a new structure that consists of a given set of members with given alignment.

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

Note.Alignment should be 1 for Delphi packed record and 8 for non-packed.


Structure

public Structure(Structure t)
Deprecated. This medhod does nothing. Use new initFrom(Structure) method instead.

Copy constructor.

Method Detail

initFrom

public void initFrom(Structure source)
Copies data of source structure to this structure.

Parameters:
source - source structure which values will be copied to this structure
Since:
3.3

init

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

Parameters:
members - members of structure. Order of members in array is order of members in native structure.
alignment - alignment in bytes.

Note.Alignment should be 1 for Delphi packed record.


init

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


addMembers

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


getAlignmentRequirement

public int getAlignmentRequirement()
Overrides:
getAlignmentRequirement in class Parameter
Returns:
required alignment within a structure or an array

getOffsets

protected int[] getOffsets()
Required for alignment tests

Returns:
Array of offsets in memory

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 setBuffer.


getLength

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

Specified by:
getLength in class Parameter

clone

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

getDebugInfo

public java.lang.String getDebugInfo()
Description copied from class: Parameter
Return debug info for JNIWrapper parameter.

Specified by:
getDebugInfo in class Parameter
Returns:
debug info

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,
                             boolean shouldRead)
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
Implementation of a Visitor pattern for parameter IO. A performer 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.

Overrides:
acceptIOPerformer in class Parameter
Parameters:
performer - a 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
Throws:
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
Throws:
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
Throws:
MemoryAccessViolationException

pop

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

Overrides:
pop in class Parameter
Throws:
MemoryAccessViolationException

equals

public boolean equals(java.lang.Object obj)
Description copied from class: Parameter
Compares this Parameter object to a given object. Two Parameter objects are considered equal if their byte representations are equal and they are of the same type. Subclasses may override this method as appropriate.

Overrides:
equals in class Parameter
Parameters:
obj - a value to compare this object to.
Returns:
true if two objects are equal.

getFirstMemberSize

public int getFirstMemberSize()
Description copied from interface: AlignmentAwareParameter
Should return first member size. If first member is structure, should return it's first parameter (in recursive manner). Unions should return their full size.

Specified by:
getFirstMemberSize in interface AlignmentAwareParameter
Returns:
first structure member size