1 // array.h - Header file for CNI arrays. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 #ifndef __GCJ_ARRAY_H__
12 #define __GCJ_ARRAY_H__
14 #include <java/lang/Object.h>
18 class __JArray
: public java::lang::Object
21 // This is just a hack to work around a warning emitted by the C++
22 // compiler. We initialize `length' evilly, but it doesn't know
24 __JArray () : length (0)
29 friend jsize
JvGetArrayLength (__JArray
*);
36 inline T
* elements(JArray
<T
>& x
);
38 inline T
* elements(JArray
<T
>* x
);
41 class JArray
: public __JArray
45 friend T
* elements
<>(JArray
<T
>& x
);
46 friend T
* elements
<>(JArray
<T
>* x
);
47 // T* getData() { return data; }
48 // T& operator[](jint i) { return data[i]; }
52 inline T
* elements(JArray
<T
>& x
) { return x
.data
; }
54 inline T
* elements(JArray
<T
>* x
) { return x
->data
; }
56 } // end extern "Java"
58 /* These typesdefs match those in JNI. */
59 typedef __JArray
*jarray
;
60 typedef JArray
<jobject
> *jobjectArray
;
61 typedef JArray
<jboolean
> *jbooleanArray
;
62 typedef JArray
<jbyte
> *jbyteArray
;
63 typedef JArray
<jchar
> *jcharArray
;
64 typedef JArray
<jshort
> *jshortArray
;
65 typedef JArray
<jint
> *jintArray
;
66 typedef JArray
<jlong
> *jlongArray
;
67 typedef JArray
<jfloat
> *jfloatArray
;
68 typedef JArray
<jdouble
> *jdoubleArray
;
69 typedef JArray
<jstring
> *jstringArray
;
71 extern java::lang::Class _Jv_byteClass
, _Jv_shortClass
, _Jv_intClass
,
72 _Jv_longClass
, _Jv_booleanClass
, _Jv_charClass
, _Jv_floatClass
,
73 _Jv_doubleClass
, _Jv_voidClass
;
74 /* The definition of this macro cannot be enclosed in parentheses
75 because "JvPrimClass(x)" is used as a template argument. */
76 #define JvPrimClass(TYPE) & _Jv_##TYPE##Class
78 extern "C" jobjectArray
_Jv_NewObjectArray(jsize length
, jclass
, jobject init
);
79 extern "C" jobject
_Jv_NewPrimArray (jclass eltype
, jint count
);
81 extern inline jobjectArray
82 JvNewObjectArray (jsize length
, jclass cls
, jobject init
)
84 return _Jv_NewObjectArray (length
, cls
, init
);
87 extern inline jcharArray
88 JvNewCharArray (jint length
)
90 return (jcharArray
) _Jv_NewPrimArray (JvPrimClass (char), length
);
93 extern inline jbooleanArray
94 JvNewBooleanArray (jint length
)
96 return (jbooleanArray
) _Jv_NewPrimArray (JvPrimClass (boolean
), length
);
99 extern inline jbyteArray
100 JvNewByteArray (jint length
)
102 return (jbyteArray
) _Jv_NewPrimArray (JvPrimClass (byte
), length
);
105 extern inline jshortArray
106 JvNewShortArray (jint length
)
108 return (jshortArray
) _Jv_NewPrimArray (JvPrimClass (short), length
);
111 extern inline jintArray
112 JvNewIntArray (jint length
)
114 return (jintArray
) _Jv_NewPrimArray (JvPrimClass (int), length
);
117 extern inline jlongArray
118 JvNewLongArray (jint length
)
120 return (jlongArray
) _Jv_NewPrimArray (JvPrimClass (long), length
);
123 extern inline jfloatArray
124 JvNewFloatArray (jint length
)
126 return (jfloatArray
) _Jv_NewPrimArray (JvPrimClass (float), length
);
129 extern inline jdoubleArray
130 JvNewDoubleArray (jint length
)
132 return (jdoubleArray
) _Jv_NewPrimArray (JvPrimClass (double), length
);
136 extern "C" jstringArray
JvConvertArgv(int argc
, const char **argv
);
138 inline jsize
JvGetArrayLength (jarray array
) { return array
->length
; }
140 #endif /* __GCJ_ARRAY_H__ */