com.jniwrapper
Class PrimitiveArray

java.lang.Object
  extended by com.jniwrapper.Parameter
      extended by com.jniwrapper.PrimitiveArray
All Implemented Interfaces:
AlignmentAwareParameter, ArrayParameter

public class PrimitiveArray
extends Parameter
implements ArrayParameter, AlignmentAwareParameter

Represents an array of primitive types such as array of bytes or array of integer values. All array items are instances of the same class.


Field Summary
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Constructor Summary
PrimitiveArray(byte[] data)
          Constructs a byte array and fills it with specified data.
PrimitiveArray(byte[] buf, java.lang.Class entriesClass)
          Constructs an array of objects of a specified class and fills it with corresponding data.
PrimitiveArray(java.lang.Class entriesClass, int count)
          Constructs an array and fills it with instances of a specified class.
PrimitiveArray(Parameter[] params)
          Constructs an array object taking a specified Parameter array.
PrimitiveArray(Parameter sample, int count)
          Constructs an array object.
PrimitiveArray(PrimitiveArray t)
          Constructs a copy of a specified array.
 
Method Summary
protected  Parameter asReturnValue()
          Returns a parameter that represents this one as a return value.
 java.lang.Object clone()
           
 void forceElementCount(int elementCount)
          Sets a new array size without memory reallocation.
 void fromParameterArray(Parameter[] params)
          Sets array contents to the given values.
protected  int getAlignedLength()
          Returns a parameter length in bytes aligned to default alignment.
 int getAlignmentRequirement()
           
 byte[] getBytes()
          Returns byte data of an array.
 java.lang.String getDebugInfo()
          Return debug info for JNIWrapper parameter.
 Parameter getElement(int i)
          Returns an array item specified by an index.
 int getElementCount()
          Returns the number of elements in the array.
 java.lang.Class getEntryClass()
          Returns a class of array items.
 int getFirstMemberSize()
          Should return first member size.
 int getLength()
          Returns the length of the array data in bytes.
 void read(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Reads this parameter from a specified data source.
 void readPartially(byte[] arr, int offset)
          Reads raw data from a given array into this object's data source.
 void resizeAndRead(byte[] arr, int offset, int dataLength)
          Sets a new size of this array and reads it from a given byte array.
 void setElement(int i, Parameter elem)
          Replaces an array item with the specified object.
 void setElementCount(int elementCount)
          Resizes this array to a given size.
 Parameter[] toParameterArray()
          Returns items as Java array.
 void write(DataBuffer stackBuffer, int offset, boolean invokedByCallback)
          Writes this parameter to a specified data source.
 
Methods inherited from class com.jniwrapper.Parameter
acceptIOPerformer, dataBufferAssigned, equals, getDataBuffer, getDataBufferOffset, hashCode, indent, pop, push, read, read, setDataBuffer, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrimitiveArray

public PrimitiveArray(PrimitiveArray t)
Constructs a copy of a specified array.


PrimitiveArray

public PrimitiveArray(java.lang.Class entriesClass,
                      int count)
Constructs an array and fills it with instances of a specified class.

Parameters:
entriesClass - Class of array items
count - Count of array items

PrimitiveArray

public PrimitiveArray(byte[] data)
Constructs a byte array and fills it with specified data.


PrimitiveArray

public PrimitiveArray(Parameter sample,
                      int count)
Constructs an array object. Fills it with copies of the sample object.

Parameters:
sample - a sample for items in the constructed array.
count - count of items in the constructed array.

PrimitiveArray

public PrimitiveArray(byte[] buf,
                      java.lang.Class entriesClass)
Constructs an array of objects of a specified class and fills it with corresponding data.


PrimitiveArray

public PrimitiveArray(Parameter[] params)
Constructs an array object taking a specified Parameter array.

Method Detail

getEntryClass

public java.lang.Class getEntryClass()
Returns a class of array items.


getLength

public int getLength()
Returns the length of the array data in bytes.

Specified by:
getLength in class Parameter

getBytes

public byte[] getBytes()
Returns byte data of an array.


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

getElement

public Parameter getElement(int i)
Description copied from interface: ArrayParameter
Returns an array item specified by an index.

Specified by:
getElement in interface ArrayParameter
Parameters:
i - index of a requested array item

setElement

public void setElement(int i,
                       Parameter elem)
Description copied from interface: ArrayParameter
Replaces an array item with the specified object.

Specified by:
setElement in interface ArrayParameter
Parameters:
i - index of an item to be replaced
elem - object to be set as array item

getElementCount

public int getElementCount()
Description copied from interface: ArrayParameter
Returns the number of elements in the array.

Specified by:
getElementCount in interface ArrayParameter

toParameterArray

public Parameter[] toParameterArray()
Description copied from interface: ArrayParameter
Returns items as Java array.

Specified by:
toParameterArray in interface ArrayParameter

fromParameterArray

public void fromParameterArray(Parameter[] params)
Description copied from interface: ArrayParameter
Sets array contents to the given values.

Specified by:
fromParameterArray in interface ArrayParameter

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

readPartially

public void readPartially(byte[] arr,
                          int offset)
Reads raw data from a given array into this object's data source. This is equal to a read(byte[] arr, int offset), where data beyond a given array length in the source array is unspecified.


resizeAndRead

public void resizeAndRead(byte[] arr,
                          int offset,
                          int dataLength)
Sets a new size of this array and reads it from a given byte array.

Parameters:
arr - new array raw (as in memory) content.
offset - where this parameter starts in arr
dataLength - raw length of this array (sizeof(element) * elementCount)

forceElementCount

public void forceElementCount(int elementCount)
Description copied from interface: ArrayParameter
Sets a new array size without memory reallocation. This method should be used with caution as the array may access invalid memory area if an incorrect value is passed in the argument.

Specified by:
forceElementCount in interface ArrayParameter

setElementCount

public void setElementCount(int elementCount)
Description copied from interface: ArrayParameter
Resizes this array to a given size.

Specified by:
setElementCount in interface ArrayParameter

getAlignedLength

protected int getAlignedLength()
Description copied from class: Parameter
Returns a parameter length in bytes aligned to default alignment.

Overrides:
getAlignedLength in class Parameter

getAlignmentRequirement

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

asReturnValue

protected Parameter asReturnValue()
Description copied from class: Parameter
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.

Overrides:
asReturnValue in class Parameter
Returns:
this

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