1 // array.h - Header file for CNI arrays. -*- c++ -*-
3 /* Copyright (C) 1998, 1999 Red Hat, Inc.
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 // FIXME: we'd like this to be `const' but that causes problems with
24 friend jsize
JvGetArrayLength (__JArray
*);
28 class JArray
: public __JArray
32 friend T
* elements
<>(JArray
<T
>& x
);
33 friend T
* elements
<>(JArray
<T
>* x
);
34 // T* getData() { return data; }
35 // T& operator[](jint i) { return data[i]; }
39 T
* elements(JArray
<T
>& x
) { return x
.data
; }
41 T
* elements(JArray
<T
>* x
) { return x
->data
; }
43 }; // end extern "Java"
45 /* These typesdefs match those in JNI. */
46 typedef __JArray
*jarray
;
47 typedef JArray
<jobject
> *jobjectArray
;
48 typedef JArray
<jboolean
> *jbooleanArray
;
49 typedef JArray
<jbyte
> *jbyteArray
;
50 typedef JArray
<jchar
> *jcharArray
;
51 typedef JArray
<jshort
> *jshortArray
;
52 typedef JArray
<jint
> *jintArray
;
53 typedef JArray
<jlong
> *jlongArray
;
54 typedef JArray
<jfloat
> *jfloatArray
;
55 typedef JArray
<jdouble
> *jdoubleArray
;
56 typedef JArray
<jstring
> *jstringArray
;
58 extern class _Jv_PrimClass _Jv_byteClass
, _Jv_shortClass
, _Jv_intClass
,
59 _Jv_longClass
, _Jv_booleanClass
, _Jv_charClass
, _Jv_floatClass
,
60 _Jv_doubleClass
, _Jv_voidClass
;
61 #define JvPrimClass(TYPE) ((jclass) & _Jv_##TYPE##Class)
63 extern "C" jobjectArray
_Jv_NewObjectArray(jsize length
, jclass
, jobject init
);
64 extern "C" jobject
_Jv_NewPrimArray (jclass eltype
, jint count
);
66 extern inline jobjectArray
67 JvNewObjectArray (jsize length
, jclass cls
, jobject init
)
69 return _Jv_NewObjectArray (length
, cls
, init
);
72 extern inline jcharArray
73 JvNewCharArray (jint length
)
75 return (jcharArray
) _Jv_NewPrimArray (JvPrimClass (char), length
);
78 extern inline jbooleanArray
79 JvNewBooleanArray (jint length
)
81 return (jbooleanArray
) _Jv_NewPrimArray (JvPrimClass (boolean
), length
);
84 extern inline jbyteArray
85 JvNewByteArray (jint length
)
87 return (jbyteArray
) _Jv_NewPrimArray (JvPrimClass (byte
), length
);
90 extern inline jshortArray
91 JvNewShortArray (jint length
)
93 return (jshortArray
) _Jv_NewPrimArray (JvPrimClass (short), length
);
96 extern inline jintArray
97 JvNewIntArray (jint length
)
99 return (jintArray
) _Jv_NewPrimArray (JvPrimClass (int), length
);
102 extern inline jlongArray
103 JvNewLongArray (jint length
)
105 return (jlongArray
) _Jv_NewPrimArray (JvPrimClass (long), length
);
108 extern inline jfloatArray
109 JvNewFloatArray (jint length
)
111 return (jfloatArray
) _Jv_NewPrimArray (JvPrimClass (float), length
);
114 extern inline jdoubleArray
115 JvNewDoubleArray (jint length
)
117 return (jdoubleArray
) _Jv_NewPrimArray (JvPrimClass (double), length
);
121 extern "C" jstringArray
JvConvertArgv(int argc
, const char **argv
);
123 inline jsize
JvGetArrayLength (jarray array
) { return array
->length
; }
125 #endif /* __GCJ_ARRAY_H__ */