Commit 403f36ec authored by Brian Panneton's avatar Brian Panneton

ENH: Added Java support for insertValuesAs*() to allow adding of Java arrays.

parent e08245f2
......@@ -79,6 +79,56 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
};
%typemap(javacode) XdmfArray %{
public void insertValuesAsInt8(int index, char[] values) {
for(int i = 0; i < values.length; i++)
this.insertValueAsInt8(index+i, values[i]);
}
public void insertValuesAsInt16(int index, short[] values) {
for(int i = 0; i < values.length; i++)
this.insertValueAsInt16(index+i, values[i]);
}
public void insertValuesAsInt32(int index, int[] values) {
for(int i = 0; i < values.length; i++)
this.insertValueAsInt32(index+i, values[i]);
}
public void insertValuesAsFloat32(int index, float[] values) {
for(int i = 0; i < values.length; i++)
this.insertValueAsFloat32(index+i, values[i]);
}
public void insertValuesAsFloat64(int index, double[] values) {
for(int i = 0; i < values.length; i++)
this.insertValueAsFloat64(index+i, values[i]);
}
%}
%extend XdmfArray {
void insertValueAsInt8(int index, char value) {
$self->insert(index, value);
}
void insertValueAsInt16(int index, short value) {
$self->insert(index, value);
}
void insertValueAsInt32(int index, int value) {
$self->insert(index, value);
}
void insertValueAsFloat32(int index, float value) {
$self->insert(index, value);
}
void insertValueAsFloat64(int index, double value) {
$self->insert(index, value);
}
};
%pragma(java) jniclasscode=%{
static {
try {
......@@ -353,3 +403,4 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(UIntVector) std::vector<unsigned int>;
%template(ItemVector) std::vector<boost::shared_ptr<XdmfItem> >;
......@@ -21,6 +21,7 @@ ADD_TEST_JAVA_PATH("${XDMF_BINARIES}")
# Read UseJavaTest.cmake for more information
# ------------------------
ADD_TEST_JAVA(TestXdmfEquals)
ADD_TEST_JAVA(TestXdmfArray)
# Add any java cleanup here:
# Note: We don't want to use a foreach loop to test the files incase we
......@@ -28,6 +29,7 @@ ADD_TEST_JAVA(TestXdmfEquals)
# Read UseCxxTest.cmake for more information
# ---------------------------------------
CLEAN_TEST_JAVA(TestXdmfEquals)
CLEAN_TEST_JAVA(TestXdmfArray)
# Add a custom target for all java tests
# Note: ${TARGETS} is set in ADD_TEST_JAVA
......
import mil.army.arl.xdmf.*;
public class TestXdmfArray {
static {
System.loadLibrary("XdmfCoreJava");
}
public static void main (String argv[]) {
System.out.println("Hello World");
XdmfArray array = XdmfArray.New();
array.initializeAsFloat64();
array.pushBackAsFloat64(1.0);
array.pushBackAsFloat64(2.0);
array.pushBackAsFloat64(3.0);
if(array.getSize() != 3) {
throw new SecurityException("XdmfArray: pushBack failed");
}
double[] da = {1.0,2.0,3.0};
XdmfArray array2 = XdmfArray.New();
array2.initializeAsFloat64();
array2.insertValuesAsFloat64(0, da);
System.out.println(array2.getSize());
if(array2.getSize() != 3) {
throw new SecurityException("XdmfArray: insert failed");
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment