com.jniwrapper
Class Parameter

java.lang.Object
  |
  +--com.jniwrapper.Parameter
Direct Known Subclasses:
AbstractFloat, com.jniwrapper.AbstractInteger, Bool, Callback, Char, com.jniwrapper.DelegatingParameter, Pointer, Pointer.Void, PrimitiveArray, Structure, Union, ZeroTerminatedString

public abstract class Parameter
extends java.lang.Object

Common parent class for all types of function parameters.


Constructor Summary
Parameter(DataBuffer dataBuffer, int offset)
          Constructs a new Parameter object that is initially stored in a given buffer at a given offset.
 
Method Summary
protected  void acceptIOPerformer(IOPerformer performer, DataBuffer buffer, int initialOffset)
          Realization of a Visitor pattern for parameter IO.
protected  Parameter asReturnValue()
          Returns a parameter that represents this one as a return value.
abstract  java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Compares this Parameter object to a given object.
protected  int getAlignedLength()
          Returns parameter length in bytes aligned to default alignment.
protected  DataBuffer getBuffer()
          Returns current data storage.
abstract  int getLength()
          Returns a length of the parameter in memory.
protected  int getOffset()
          Returns current offset within data storage.
protected static java.lang.String indent(java.lang.String param, int size)
          Utility method used for readable output in toString().
 void pop(DataBuffer stackBuffer, int offset)
          Default implementation, which does nothing as most primitive types do nothing on pop.
 void push(DataBuffer stackBuffer, int offset)
          Writes a parameter to a function stacks
 void read(byte[] arr, int offset)
          Reads the parameter value from a byte array.
abstract  void read(DataBuffer stackBuffer, int offset)
          Reads this parameter from a specified data source.
protected  void setBuffer(DataBuffer newBuffer, int newOffset)
          Sets the data buffer this parameter should use to store data and an offset in bytes within that buffer.
static byte[] toByteArray(Parameter param)
          Converts a parameter to a byte array.
 void write(byte[] arr, int offset)
          Writes the parameter value to a byte array.
abstract  void write(DataBuffer stackBuffer, int offset)
          Writes this parameter to a specified data source.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parameter

public Parameter(DataBuffer dataBuffer,
                 int offset)
Constructs a new Parameter object that is initially stored in a given buffer at a given offset.

Parameters:
dataBuffer - initial data buffer where this parameter should be stored.
offset - offset in the given data buffer where this parameter should be stored.
Method Detail

getLength

public abstract int getLength()
Returns a length of the parameter in memory. This method is analogous to C sizeof() operator.


write

public abstract void write(DataBuffer stackBuffer,
                           int offset)
                    throws MemoryAccessViolationException
Writes this parameter to a specified data source.

MemoryAccessViolationException

read

public abstract void read(DataBuffer stackBuffer,
                          int offset)
                   throws MemoryAccessViolationException
Reads this parameter from a specified data source.

MemoryAccessViolationException

setBuffer

protected void setBuffer(DataBuffer newBuffer,
                         int newOffset)
Sets the data buffer this parameter should use to store data and an offset in bytes within that buffer.


getBuffer

protected DataBuffer getBuffer()
Returns current data storage.


getOffset

protected int getOffset()
Returns current offset within data storage.


equals

public boolean equals(java.lang.Object obj)
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 java.lang.Object
Parameters:
obj - value to compare this object to
Returns:
true if two objects are equal.

clone

public abstract java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getAlignedLength

protected int getAlignedLength()
Returns parameter length in bytes aligned to default alignment.


push

public void push(DataBuffer stackBuffer,
                 int offset)
Writes a parameter to a function stacks


pop

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

MemoryAccessViolationException

asReturnValue

protected Parameter asReturnValue()
Returns a parameter that represents this one as a return value. Implementors may use this as a convenience shortcut for users when implementing such objects as strings or arrays to allow users to specify an object as a return value instead of requiring a pointer to it. For general use the default implementation should suffice.

Returns:
this

acceptIOPerformer

protected void acceptIOPerformer(IOPerformer performer,
                                 DataBuffer buffer,
                                 int initialOffset)
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.

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

write

public void write(byte[] arr,
                  int offset)
Writes the parameter value to a byte array.


read

public void read(byte[] arr,
                 int offset)
Reads the parameter value from a byte array.


toByteArray

public static final byte[] toByteArray(Parameter param)
Converts a parameter to a byte array. Constructs a byte array and writes specified parameter to the array.


indent

protected static java.lang.String indent(java.lang.String param,
                                         int size)
Utility method used for readable output in toString(). Adds an indentation at the start of each line into param. Lines are identified by "\n" character.