com.jniwrapper
Class Parameter

java.lang.Object
  extended by com.jniwrapper.Parameter
Direct Known Subclasses:
AbstractFloat, AnsiStringArray, Callback, Char, DelegatingParameter, Int16, Int32, Int64, Int8, Pointer, Pointer.Void, PrimitiveArray, Str, StringArray, Structure, UInt16, UInt32, UInt8, Union, WideStringArray, ZeroTerminatedString

public abstract class Parameter
extends java.lang.Object

Common parent class for all types of function parameters.


Field Summary
protected static java.lang.String LICENSE_TYPE
           
protected static java.lang.String V
           
 
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, boolean isReadOperation, boolean invokedByCallback)
          Implementation 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()
           
protected  void dataBufferAssigned()
          Called when new parameter data buffer assigned.
 boolean equals(java.lang.Object obj)
          Compares this Parameter object to a given object.
protected  int getAlignedLength()
          Returns a parameter length in bytes aligned to default alignment.
 int getAlignmentRequirement()
           
protected  DataBuffer getDataBuffer()
          Returns a current data storage.
protected  int getDataBufferOffset()
          Returns a current offset within data storage.
abstract  java.lang.String getDebugInfo()
          Return debug info for JNIWrapper parameter.
abstract  int getLength()
          Returns the length of the parameter in memory.
 int hashCode()
           
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, 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(byte[] arr, int offset)
          Reads the parameter value from a byte array.
 void read(byte[] arr, int offset, boolean invokedByCallback)
          Reads the parameter value from a byte array.
abstract  void read(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Reads this parameter from a specified data source.
protected  void setDataBuffer(DataBuffer newBuffer, int newOffset, boolean shouldRead)
          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, boolean invokedByCallback)
          Writes this parameter to a specified data source.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

V

protected static final java.lang.String V
See Also:
Constant Field Values

LICENSE_TYPE

protected static final java.lang.String LICENSE_TYPE
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

dataBufferAssigned

protected void dataBufferAssigned()
Called when new parameter data buffer assigned.


getLength

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


write

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

Throws:
MemoryAccessViolationException

read

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

Throws:
MemoryAccessViolationException

setDataBuffer

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


getDataBuffer

protected DataBuffer getDataBuffer()
Returns a current data storage.


getDataBufferOffset

protected int getDataBufferOffset()
Returns a 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 - a value to compare this object to.
Returns:
true if two objects are equal.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clone

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

getAlignedLength

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


getAlignmentRequirement

public int getAlignmentRequirement()
Returns:
required alignment within a structure or an array

push

public void push(DataBuffer stackBuffer,
                 int offset,
                 boolean invokedByCallback)
          throws MemoryAccessViolationException
Writes a parameter to a function stacks.

Throws:
MemoryAccessViolationException

pop

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

Throws:
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,
                                 boolean isReadOperation,
                                 boolean invokedByCallback)
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.

Parameters:
performer - a 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.


read

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


toByteArray

public static byte[] toByteArray(Parameter param)
Converts a parameter to a byte array. Constructs a byte array and writes a 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 paramater. Lines are identified by "\n" character.


getDebugInfo

public abstract java.lang.String getDebugInfo()
Return debug info for JNIWrapper parameter.

Returns:
debug info