1 // array.h - Header file for CNI arrays. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000 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 // FIXME: this is a hack to work around a bug in the g++ Java
22 // support. If we add a constructor with a jsize argument to
23 // JArray<T>, then g++ complains.
24 __JArray () : length (0)
29 friend jsize
JvGetArrayLength (__JArray
*);
31 // This probably shouldn't be public.
32 __JArray (jsize l
) : length (l
)
38 class JArray
: public __JArray
42 friend T
* elements
<>(JArray
<T
>& x
);
43 friend T
* elements
<>(JArray
<T
>* x
);
44 // T* getData() { return data; }
45 // T& operator[](jint i) { return data[i]; }
49 inline T
* elements(JArray
<T
>& x
) { return x
.data
; }
51 inline T
* elements(JArray
<T
>* x
) { return x
->data
; }
53 }; // end extern "Java"
55 /* These typesdefs match those in JNI. */
56 typedef __JArray
*jarray
;
57 typedef JArray
<jobject
> *jobjectArray
;
58 typedef JArray
<jboolean
> *jbooleanArray
;
59 typedef JArray
<jbyte
> *jbyteArray
;
60 typedef JArray
<jchar
> *jcharArray
;
61 typedef JArray
<jshort
> *jshortArray
;
62 typedef JArray
<jint
> *jintArray
;
63 typedef JArray
<jlong
> *jlongArray
;
64 typedef JArray
<jfloat
> *jfloatArray
;
65 typedef JArray
<jdouble
> *jdoubleArray
;
66 typedef JArray
<jstring
> *jstringArray
;
68 extern class _Jv_PrimClass _Jv_byteClass
, _Jv_shortClass
, _Jv_intClass
,
69 _Jv_longClass
, _Jv_booleanClass
, _Jv_charClass
, _Jv_floatClass
,
70 _Jv_doubleClass
, _Jv_voidClass
;
71 #define JvPrimClass(TYPE) ((jclass) & _Jv_##TYPE##Class)
73 extern "C" jobjectArray
_Jv_NewObjectArray(jsize length
, jclass
, jobject init
);
74 extern "C" jobject
_Jv_NewPrimArray (jclass eltype
, jint count
);
76 extern inline jobjectArray
77 JvNewObjectArray (jsize length
, jclass cls
, jobject init
)
79 return _Jv_NewObjectArray (length
, cls
, init
);
82 extern inline jcharArray
83 JvNewCharArray (jint length
)
85 return (jcharArray
) _Jv_NewPrimArray (JvPrimClass (char), length
);
88 extern inline jbooleanArray
89 JvNewBooleanArray (jint length
)
91 return (jbooleanArray
) _Jv_NewPrimArray (JvPrimClass (boolean
), length
);
94 extern inline jbyteArray
95 JvNewByteArray (jint length
)
97 return (jbyteArray
) _Jv_NewPrimArray (JvPrimClass (byte
), length
);
100 extern inline jshortArray
101 JvNewShortArray (jint length
)
103 return (jshortArray
) _Jv_NewPrimArray (JvPrimClass (short), length
);
106 extern inline jintArray
107 JvNewIntArray (jint length
)
109 return (jintArray
) _Jv_NewPrimArray (JvPrimClass (int), length
);
112 extern inline jlongArray
113 JvNewLongArray (jint length
)
115 return (jlongArray
) _Jv_NewPrimArray (JvPrimClass (long), length
);
118 extern inline jfloatArray
119 JvNewFloatArray (jint length
)
121 return (jfloatArray
) _Jv_NewPrimArray (JvPrimClass (float), length
);
124 extern inline jdoubleArray
125 JvNewDoubleArray (jint length
)
127 return (jdoubleArray
) _Jv_NewPrimArray (JvPrimClass (double), length
);
131 extern "C" jstringArray
JvConvertArgv(int argc
, const char **argv
);
133 inline jsize
JvGetArrayLength (jarray array
) { return array
->length
; }
135 #endif /* __GCJ_ARRAY_H__ */