T
- Component type of the array.public class CArrayFacade<T> extends CPointer<T> implements java.lang.Iterable<T>
Arrays provide common array functionality and conversion between underlying data and corresponding Java arrays (see various toArray and fromArray methods).
Since arrays in C are interchangable with pointers, the class inherits
the capabilities of CPointer
. This way, an array can
always be assigned to a pointer variable. To turn a pointer in
an instance of CArrayFacade
use its CPointer.toCArrayFacade(int)
.
Arrays have a component type and an elementary type. This is important when dealing with multi-dimensional arrays. The elementary type is the most basic type contained in the array. If the array is an array of arrays of int (i.e. CArrayFacade<CArrayFacade<int>>), then the elementary type is 'int' but it's component type is CArrayFacade<int>. In case the array has just one dimension, the component type and the elementary type are the same.
Arrays need runtime information about their component type. If the component type is an array or a pointer then the array needs the information about those contained types, too. Thus, arrays are instanciated with a list of types as type specification, where each element in the type list corresponds to a component type of the component type.
CArrayFacade<CArrayFacade<CPointer<Integer>>> array;To instantiate such an array, we need to specify the list of types for each component.
Class[] typeList = new Class[]{ CArrayFacade.class, CArrayFacade.class, CPointer.class, Integer.class };
You will note, that we just read out the template parameters
and put them in an array. The array also needs to know the length
of each dimension beforehand. Thus, we create another array which holds
the length for each dimension. Let's say we want an array which
corresponds to the C type declaration int* array[2][8]
.
int[] dimensions = new int[]{2,8};
Finally we can create an instance of that array (given that we have an open blender file and a blockTable and the address of that array).
array = new CArrayFacade<CArrayFacade<CPointer<Integer>>>( address, typeList, dimensions, blockTable );
Remember, that arrays are just facades and the actual data is stored in
a block of the blender file. Thus, the address (first parameter of
the constructor) is either received from CFacade.__io__addressof(long[])
or
from a pointer or by allocating a new block.
To allocate a block for an entirely new array, refer to the block
allocation methods in either BlenderFactoryBase
or the derived class BlenderFactory
in the generated code
or even directly to BlenderFile
and BlockTable
.
Modifier and Type | Field and Description |
---|---|
protected long |
componentSize
Component size is the size in bytes of one element of this array.
|
protected int[] |
dimensions
This list contains the length of each dimension of the array.
|
protected java.lang.Class<?>[] |
targetTypeList |
targetSize
__io__address, __io__arch_index, __io__block, __io__blockTable, __io__pointersize
Constructor and Description |
---|
CArrayFacade(CArrayFacade<T> other)
Copy constructor.
|
CArrayFacade(long baseAddress,
java.lang.Class<?>[] targetTypeList,
int[] dimensions,
Block block,
BlockTable __blockTable)
This is the constructor to attach an array facade to existing
data in a block of a blender file.
|
Modifier and Type | Method and Description |
---|---|
protected void |
__io__generic__copy(CFacade sourceArray)
This method does a highlevel copy of the given source to this object.
|
static long |
__io__sizeof(java.lang.Class<?> elementaryType,
int[] dimensions,
Encoding encoding)
Calculates the total size of an array based on the given parameters.
|
java.lang.String |
asString()
Converts the array into a string.
|
void |
fromArray(T[] data)
Copyies all elements of the given array to this array.
|
void |
fromByteArray(byte[] data)
Copies all values of the given Java array to this array.
|
void |
fromString(java.lang.String str)
Fills the underlying buffer with a null-terminated string
from the given string using the default charset (see
Charset.defaultCharset() ). |
void |
fromString(java.lang.String str,
boolean addNullTermination)
Fills the underlying buffer with the bytes of the given string str using the default charset (see
Charset.defaultCharset() ). |
void |
fromString(java.lang.String str,
java.nio.charset.Charset charset,
boolean addNullTermination)
Fills the underlying buffer with the bytes of the given string str using the given charset (see
Charset ). |
T |
get(int index)
Returns the element with the given 'index'.
|
java.util.Iterator<T> |
iterator()
For convienient iteration over this array's elements.
|
int |
length() |
void |
set(int index,
T value)
Set the value of the array element with given 'index'.
|
long |
sizeof()
Delivers the native size of this array considering
its architecture specific encoding.
|
T[] |
toArray()
Converts the underlying data into a Java array with
component type T.
|
byte[] |
toByteArray()
Converts the underlying data into an array of the given native type.
|
double[] |
toDoubleArray()
Converts the underlying data into an array of the given native type.
|
float[] |
toFloatArray()
Converts the underlying data into an array of the given native type.
|
long[] |
toInt64Array()
Converts the underlying data into an array of the given native type.
|
int[] |
toIntArray()
Converts the underlying data into an array of the given native type.
|
long[] |
toLongArray()
Converts the underlying data into an array of the given native type.
|
short[] |
toShortArray()
Converts the underlying data into an array of the given native type.
|
__get, __set, cast, cast, cast, equals, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromArray, fromInt64Array, fromInt64Array, get, getAddress, getCFacade, getScalar, hashCode, isNull, isPrimitive, isValid, mutable, plus, set, setScalar, toArray, toArray, toArray, toArray, toArray, toArray, toArray, toArrayInt64, toByteArray, toCArrayFacade, toDoubleArray, toFloatArray, toInt64Array, toIntArray, toLongArray, toShortArray
__io__addressof, __io__addressof, __io__equals, __io__generic__copy, __io__instanceof, __io__native__copy, __io__newInstance, __io__same__encoding, __io__sizeof, __io__sizeof, __io__subclassof
protected java.lang.Class<?>[] targetTypeList
protected int[] dimensions
protected long componentSize
public CArrayFacade(CArrayFacade<T> other)
other
- public CArrayFacade(long baseAddress, java.lang.Class<?>[] targetTypeList, int[] dimensions, Block block, BlockTable __blockTable)
To allocate a block for an entirely new array, refer to the block
allocation methods in either BlenderFactoryBase
or the derived class BlenderFactory
in the generated code.
baseAddress
- virtual start address of the array (file specific).targetTypeList
- Type specification of the component type (see class documentation).dimensions
- Length of each dimension (see class documentation)__blockTable
- Block table of the associated blender file.public int length()
public long sizeof()
public T get(int index) throws java.io.IOException
index
- java.io.IOException
public void set(int index, T value) throws java.io.IOException
array[index] = value;
index
- index of the array element.value
- New value for that element.java.io.IOException
public T[] toArray() throws java.io.IOException
java.io.IOException
public void fromArray(T[] data) throws java.io.IOException
data
- java.io.IOException
public java.lang.String asString() throws java.io.IOException
java.io.IOException
public void fromString(java.lang.String str) throws java.io.IOException
Charset.defaultCharset()
).str
- string to write into the array.java.io.IOException
public void fromString(java.lang.String str, boolean addNullTermination) throws java.io.IOException
Charset.defaultCharset()
).
The parameter addNullTermination controls, whether the method adds a 0 to terminate the string or not.str
- string to write into the array.addNullTermination
- Adds a '\0' if true.java.io.IOException
public void fromString(java.lang.String str, java.nio.charset.Charset charset, boolean addNullTermination) throws java.io.IOException
Charset
).
The parameter addNullTermination controls, whether the method adds a 0 to terminate the string or not.str
- string to write into the array.charset
- Charset to use when converting into a byte array.addNullTermination
- Adds a '\0' if true.java.io.IOException
public byte[] toByteArray() throws java.io.IOException
java.io.IOException
public void fromByteArray(byte[] data) throws java.io.IOException
data
- Array of data to be copied to this array.java.io.IOException
public short[] toShortArray() throws java.io.IOException
java.io.IOException
public int[] toIntArray() throws java.io.IOException
java.io.IOException
public long[] toLongArray() throws java.io.IOException
java.io.IOException
public long[] toInt64Array() throws java.io.IOException
java.io.IOException
public float[] toFloatArray() throws java.io.IOException
java.io.IOException
public double[] toDoubleArray() throws java.io.IOException
java.io.IOException
public static long __io__sizeof(java.lang.Class<?> elementaryType, int[] dimensions, Encoding encoding)
elementaryType
- The elementary type, i.e. the scalar type.dimensions
- encoding
- protected void __io__generic__copy(CFacade sourceArray) throws java.io.IOException
The method is used in case a lowlevel copy (see CFacade.__io__native__copy(Block, long, CFacade)
)
is not possible due to different encodings of the underlying blocks
(see CFacade.__io__same__encoding(CFacade, CFacade)
.
The method is overridden by CArrayFacade.
This is for arrays only. Behaviour is unspecified if the given parameter source is not an array!__io__generic__copy
in class CFacade
sourceArray
- java.io.IOException