Category: Proxy usage
How do I create an array instance?
Let's first discuss how array types differ between the two languages.
You have to use the generated or supplied array proxy type and use parentheses rather than square brackets in the instantiation, for example:
String::array1D arr( 16 );
arr[ 0 ] = "first"; arr[ 15 ] = "last";
C++ proxy types typically contain two typedefs, one for a one-dimensional array of the enclosing type, and one for a two-dimensional array of the enclosing type. If you are generating the proxy classes yourself, you can control the number of dimensions for which you wish to declare typedefs.
There is no implicit conversion path between an instance of a C++ array of the type and the corresponding Java array type, i.e. java::lang::String[] and String::array1D are not type-comptible.
You can explicitly convert between a native array instance and a proxy array instance:
int narr[] = { 0, 1, 2, 3, 4 };
xmog_java_int_array arr( narr, 5 );
The mapping between Java and C++ proxy array types is fairly straightforward:
| Java type | C++ proxy type |
|---|---|
| boolean[ ] | xmog_java_boolean_array |
| byte[ ] | xmog_java_byte_array |
| char[ ] | xmog_java_char_array |
| double[ ] | xmog_java_double_array |
| float[ ] | xmog_java_float_array |
| int[ ] | xmog_java_int_array |
| long[ ] | xmog_java_long_array |
| short[ ] | xmog_java_short_array |
| java.lang.Object[ ] | java::lang::Object::array1D |
| java.lang.Object[ ][ ] | java::lang::Object::array2D |
| Foo[ ][ ][ ] | xmog_java_object_array< Foo::array2D > |
The primitive array types are provided as part of the runtime library; the object array types are provided via typedefs (Dim<=2) and you can create your own typedefs for higher-dimensional array types.
