PR c++/7584
[official-gcc.git] / libjava / gcj / array.h
blobdb58ddfbdf874f71c1ac852fc9050b7190cd85ba
1 // array.h - Header file for CNI arrays. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2001 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
9 details. */
11 #ifndef __GCJ_ARRAY_H__
12 #define __GCJ_ARRAY_H__
14 #include <java/lang/Object.h>
16 extern "Java" {
18 class __JArray : public java::lang::Object
20 protected:
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
23 // that.
24 __JArray () : length (0)
27 public:
28 const jsize length;
29 friend jsize JvGetArrayLength (__JArray*);
32 template<class T>
33 class JArray : public __JArray
35 T data[0];
36 public:
37 friend T* elements<>(JArray<T>& x);
38 friend T* elements<>(JArray<T>* x);
39 // T* getData() { return data; }
40 // T& operator[](jint i) { return data[i]; }
43 template<class T>
44 inline T* elements(JArray<T>& x) { return x.data; }
45 template<class T>
46 inline T* elements(JArray<T>* x) { return x->data; }
48 }; // end extern "Java"
50 /* These typesdefs match those in JNI. */
51 typedef __JArray *jarray;
52 typedef JArray<jobject> *jobjectArray;
53 typedef JArray<jboolean> *jbooleanArray;
54 typedef JArray<jbyte> *jbyteArray;
55 typedef JArray<jchar> *jcharArray;
56 typedef JArray<jshort> *jshortArray;
57 typedef JArray<jint> *jintArray;
58 typedef JArray<jlong> *jlongArray;
59 typedef JArray<jfloat> *jfloatArray;
60 typedef JArray<jdouble> *jdoubleArray;
61 typedef JArray<jstring> *jstringArray;
63 extern java::lang::Class _Jv_byteClass, _Jv_shortClass, _Jv_intClass,
64 _Jv_longClass, _Jv_booleanClass, _Jv_charClass, _Jv_floatClass,
65 _Jv_doubleClass, _Jv_voidClass;
66 #define JvPrimClass(TYPE) (& _Jv_##TYPE##Class)
68 extern "C" jobjectArray _Jv_NewObjectArray(jsize length, jclass, jobject init);
69 extern "C" jobject _Jv_NewPrimArray (jclass eltype, jint count);
71 extern inline jobjectArray
72 JvNewObjectArray (jsize length, jclass cls, jobject init)
74 return _Jv_NewObjectArray (length, cls, init);
77 extern inline jcharArray
78 JvNewCharArray (jint length)
80 return (jcharArray) _Jv_NewPrimArray (JvPrimClass (char), length);
83 extern inline jbooleanArray
84 JvNewBooleanArray (jint length)
86 return (jbooleanArray) _Jv_NewPrimArray (JvPrimClass (boolean), length);
89 extern inline jbyteArray
90 JvNewByteArray (jint length)
92 return (jbyteArray) _Jv_NewPrimArray (JvPrimClass (byte), length);
95 extern inline jshortArray
96 JvNewShortArray (jint length)
98 return (jshortArray) _Jv_NewPrimArray (JvPrimClass (short), length);
101 extern inline jintArray
102 JvNewIntArray (jint length)
104 return (jintArray) _Jv_NewPrimArray (JvPrimClass (int), length);
107 extern inline jlongArray
108 JvNewLongArray (jint length)
110 return (jlongArray) _Jv_NewPrimArray (JvPrimClass (long), length);
113 extern inline jfloatArray
114 JvNewFloatArray (jint length)
116 return (jfloatArray) _Jv_NewPrimArray (JvPrimClass (float), length);
119 extern inline jdoubleArray
120 JvNewDoubleArray (jint length)
122 return (jdoubleArray) _Jv_NewPrimArray (JvPrimClass (double), length);
126 extern "C" jstringArray JvConvertArgv(int argc, const char **argv);
128 inline jsize JvGetArrayLength (jarray array) { return array->length; }
130 #endif /* __GCJ_ARRAY_H__ */