1
/* ====================================================================
2
* Copyright (c) 2007-2008 Open Source Applications Foundation.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included
12
* in all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
* DEALINGS IN THE SOFTWARE.
21
* ====================================================================
2
* Licensed under the Apache License, Version 2.0 (the "License");
3
* you may not use this file except in compliance with the License.
4
* You may obtain a copy of the License at
6
* http://www.apache.org/licenses/LICENSE-2.0
8
* Unless required by applicable law or agreed to in writing, software
9
* distributed under the License is distributed on an "AS IS" BASIS,
10
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
* See the License for the specific language governing permissions and
12
* limitations under the License.
24
15
#ifndef _functions_h
90
96
PyObject *callSuper(PyTypeObject *type, PyObject *self,
91
97
const char *name, PyObject *args, int cardinality);
93
template<class T> PyObject *get_iterator(PyObject *self)
95
java::util::Iterator iterator((jobject) NULL);
97
OBJ_CALL(iterator = (((T *) self)->object.iterator()));
98
return java::util::t_Iterator::wrapObject(iterator);
101
template<class U, class V> PyObject *get_iterator_next(PyObject *self)
103
java::util::t_Iterator *iterator = (java::util::t_Iterator *) self;
106
OBJ_CALL(hasNext = iterator->object.hasNext());
109
PyErr_SetNone(PyExc_StopIteration);
113
V next((jobject) NULL);
114
OBJ_CALL(next = iterator->object.next());
116
jclass cls = java::lang::String::initializeClass();
117
if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
118
return env->fromJString((jstring) next.this$);
120
return U::wrapObject(next);
123
template<class U, class V> PyObject *get_enumeration_nextElement(PyObject *self)
125
java::util::t_Enumeration *enumeration = (java::util::t_Enumeration *) self;
126
jboolean hasMoreElements;
128
OBJ_CALL(hasMoreElements = enumeration->object.hasMoreElements());
129
if (!hasMoreElements)
131
PyErr_SetNone(PyExc_StopIteration);
135
V next((jobject) NULL);
136
OBJ_CALL(next = enumeration->object.nextElement());
138
jclass cls = java::lang::String::initializeClass();
139
if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
140
return env->fromJString((jstring) next.this$);
142
return U::wrapObject(next);
145
template<class T, class U, class V> PyObject *get_next(PyObject *self)
147
T *iterator = (T *) self;
148
V next((jobject) NULL);
150
OBJ_CALL(next = iterator->object.next());
153
PyErr_SetNone(PyExc_StopIteration);
157
jclass cls = java::lang::String::initializeClass();
158
if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
159
return env->fromJString((jstring) next.this$);
161
return U::wrapObject(next);
99
template<class T> PyObject *get_iterator(T *self)
101
java::util::Iterator iterator((jobject) NULL);
103
OBJ_CALL(iterator = self->object.iterator());
104
return java::util::t_Iterator::wrap_Object(iterator);
107
#ifdef _java_generics
108
template<class T> PyObject *get_generic_iterator(T *self)
110
java::util::Iterator iterator((jobject) NULL);
111
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
113
OBJ_CALL(iterator = self->object.iterator());
114
return java::util::t_Iterator::wrap_Object(iterator, param);
118
template<class T, class U> PyObject *get_iterator_next(T *self)
121
OBJ_CALL(hasNext = self->object.hasNext());
124
PyErr_SetNone(PyExc_StopIteration);
129
OBJ_CALL(next = env->iteratorNext(self->object.this$));
131
jclass cls = java::lang::String::initializeClass();
132
if (env->get_vm_env()->IsInstanceOf(next, cls))
133
return env->fromJString((jstring) next, 1);
135
return U::wrap_jobject(next);
138
#ifdef _java_generics
139
template<class T, class U> PyObject *get_generic_iterator_next(T *self)
142
OBJ_CALL(hasNext = self->object.hasNext());
145
PyErr_SetNone(PyExc_StopIteration);
150
OBJ_CALL(next = env->iteratorNext(self->object.this$));
152
jclass cls = java::lang::String::initializeClass();
153
if (env->get_vm_env()->IsInstanceOf(next, cls))
154
return env->fromJString((jstring) next, 1);
156
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
158
return wrapType(param, next);
160
return U::wrap_jobject(next);
164
template<class T, class U> PyObject *get_enumeration_next(T *self)
166
jboolean hasMoreElements;
167
OBJ_CALL(hasMoreElements = self->object.hasMoreElements());
168
if (!hasMoreElements)
170
PyErr_SetNone(PyExc_StopIteration);
175
OBJ_CALL(next = env->enumerationNext(self->object.this$));
177
jclass cls = java::lang::String::initializeClass();
178
if (env->get_vm_env()->IsInstanceOf(next, cls))
179
return env->fromJString((jstring) next, 1);
181
return U::wrap_jobject(next);
184
#ifdef _java_generics
185
template<class T, class U> PyObject *get_generic_enumeration_next(T *self)
187
jboolean hasMoreElements;
188
OBJ_CALL(hasMoreElements = self->object.hasMoreElements());
189
if (!hasMoreElements)
191
PyErr_SetNone(PyExc_StopIteration);
196
OBJ_CALL(next = env->enumerationNext(self->object.this$));
198
jclass cls = java::lang::String::initializeClass();
199
if (env->get_vm_env()->IsInstanceOf(next, cls))
200
return env->fromJString((jstring) next, 1);
202
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
204
return wrapType(param, next);
206
return U::wrap_jobject(next);
210
template<class T, class U, class V> PyObject *get_next(T *self)
212
V next((jobject) NULL);
213
OBJ_CALL(next = self->object.next());
216
PyErr_SetNone(PyExc_StopIteration);
220
jclass cls = java::lang::String::initializeClass();
221
if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
222
return env->fromJString((jstring) next.this$, 0);
224
return U::wrap_Object(next);
227
#ifdef _java_generics
228
template<class T, class U, class V> PyObject *get_generic_next(T *self)
230
V next((jobject) NULL);
231
OBJ_CALL(next = self->object.next());
234
PyErr_SetNone(PyExc_StopIteration);
238
jclass cls = java::lang::String::initializeClass();
239
if (env->get_vm_env()->IsInstanceOf(next.this$, cls))
240
return env->fromJString((jstring) next.this$, 0);
242
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL;
244
return wrapType(param, next.this$);
246
return U::wrap_Object(next);
164
250
PyObject *get_extension_iterator(PyObject *self);
165
251
PyObject *get_extension_next(PyObject *self);
166
252
PyObject *get_extension_nextElement(PyObject *self);
168
254
jobjectArray fromPySequence(jclass cls, PyObject *sequence);
169
PyObject *castCheck(PyObject *obj, jclass cls, int reportError);
171
extern PyTypeObject FinalizerClassType;
172
extern PyTypeObject FinalizerProxyType;
255
PyObject *castCheck(PyObject *obj, getclassfn initializeClass,
257
void installType(PyTypeObject *type, PyObject *module, char *name,
260
#ifdef _java_generics
261
PyObject *typeParameters(PyTypeObject *types[], size_t size);
264
extern PyTypeObject FinalizerClass$$Type;
265
extern PyTypeObject FinalizerProxy$$Type;