array.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // array.h - Header file for CNI arrays. -*- c++ -*-
  2. /* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
  3. This file is part of libgcj.
  4. This software is copyrighted work licensed under the terms of the
  5. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. details. */
  7. #ifndef __GCJ_ARRAY_H__
  8. #define __GCJ_ARRAY_H__
  9. #include <java/lang/Object.h>
  10. extern "Java" {
  11. class __JArray : public java::lang::Object
  12. {
  13. protected:
  14. // This is just a hack to work around a warning emitted by the C++
  15. // compiler. We initialize `length' evilly, but it doesn't know
  16. // that.
  17. __JArray () : length (0)
  18. {
  19. }
  20. public:
  21. const jsize length;
  22. friend jsize JvGetArrayLength (__JArray*);
  23. };
  24. template<class T>
  25. class JArray;
  26. template<class T>
  27. inline T* elements(JArray<T>& x);
  28. template<class T>
  29. inline T* elements(JArray<T>* x);
  30. template<class T>
  31. class JArray : public __JArray
  32. {
  33. T data[0];
  34. public:
  35. friend T* elements<>(JArray<T>& x);
  36. friend T* elements<>(JArray<T>* x);
  37. // T* getData() { return data; }
  38. // T& operator[](jint i) { return data[i]; }
  39. };
  40. template<class T>
  41. inline T* elements(JArray<T>& x) { return x.data; }
  42. template<class T>
  43. inline T* elements(JArray<T>* x) { return x->data; }
  44. } // 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;
  57. extern java::lang::Class _Jv_byteClass, _Jv_shortClass, _Jv_intClass,
  58. _Jv_longClass, _Jv_booleanClass, _Jv_charClass, _Jv_floatClass,
  59. _Jv_doubleClass, _Jv_voidClass;
  60. /* The definition of this macro cannot be enclosed in parentheses
  61. because "JvPrimClass(x)" is used as a template argument. */
  62. #define JvPrimClass(TYPE) & _Jv_##TYPE##Class
  63. extern "C" jobjectArray _Jv_NewObjectArray(jsize length, jclass, jobject init);
  64. extern "C" jobject _Jv_NewPrimArray (jclass eltype, jint count);
  65. extern inline jobjectArray
  66. JvNewObjectArray (jsize length, jclass cls, jobject init)
  67. {
  68. return _Jv_NewObjectArray (length, cls, init);
  69. }
  70. extern inline jcharArray
  71. JvNewCharArray (jint length)
  72. {
  73. return (jcharArray) _Jv_NewPrimArray (JvPrimClass (char), length);
  74. }
  75. extern inline jbooleanArray
  76. JvNewBooleanArray (jint length)
  77. {
  78. return (jbooleanArray) _Jv_NewPrimArray (JvPrimClass (boolean), length);
  79. }
  80. extern inline jbyteArray
  81. JvNewByteArray (jint length)
  82. {
  83. return (jbyteArray) _Jv_NewPrimArray (JvPrimClass (byte), length);
  84. }
  85. extern inline jshortArray
  86. JvNewShortArray (jint length)
  87. {
  88. return (jshortArray) _Jv_NewPrimArray (JvPrimClass (short), length);
  89. }
  90. extern inline jintArray
  91. JvNewIntArray (jint length)
  92. {
  93. return (jintArray) _Jv_NewPrimArray (JvPrimClass (int), length);
  94. }
  95. extern inline jlongArray
  96. JvNewLongArray (jint length)
  97. {
  98. return (jlongArray) _Jv_NewPrimArray (JvPrimClass (long), length);
  99. }
  100. extern inline jfloatArray
  101. JvNewFloatArray (jint length)
  102. {
  103. return (jfloatArray) _Jv_NewPrimArray (JvPrimClass (float), length);
  104. }
  105. extern inline jdoubleArray
  106. JvNewDoubleArray (jint length)
  107. {
  108. return (jdoubleArray) _Jv_NewPrimArray (JvPrimClass (double), length);
  109. }
  110. extern "C" jstringArray JvConvertArgv(int argc, const char **argv);
  111. inline jsize JvGetArrayLength (jarray array) { return array->length; }
  112. #endif /* __GCJ_ARRAY_H__ */