PyLucene 3.4.0-1 import
[pylucene.git] / jcc / _jcc / java / util / Iterator.cpp
1 /*
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
5  *
6  *       http://www.apache.org/licenses/LICENSE-2.0
7  *
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.
13  */
14
15 #include <jni.h>
16 #include "JCCEnv.h"
17
18 #include "java/lang/Object.h"
19 #include "java/lang/Class.h"
20 #include "java/util/Iterator.h"
21
22 namespace java {
23     namespace util {
24         enum {
25             mid_hasNext,
26             mid_next,
27             max_mid
28         };
29
30         Class *Iterator::class$ = NULL;
31         jmethodID *Iterator::mids$ = NULL;
32
33         jclass Iterator::initializeClass()
34         {
35             if (!class$)
36             {
37                 jclass cls = env->findClass("java/util/Iterator");
38
39                 mids$ = new jmethodID[max_mid];
40                 mids$[mid_hasNext] = env->getMethodID(cls, "hasNext",
41                                                       "()Z");
42                 mids$[mid_next] = env->getMethodID(cls, "next",
43                                                    "()Ljava/lang/Object;");
44
45                 class$ = (Class *) new JObject(cls);
46             }
47
48             return (jclass) class$->this$;
49         }
50
51         jboolean Iterator::hasNext() const
52         {
53             return env->callBooleanMethod(this$, mids$[mid_hasNext]);
54         }
55
56         Object Iterator::next() const
57         {
58             return Object(env->callObjectMethod(this$, mids$[mid_next]));
59         }
60     }
61 }
62
63
64 #include "structmember.h"
65 #include "functions.h"
66 #include "macros.h"
67
68 namespace java {
69     namespace util {
70
71         static PyObject *t_Iterator_hasNext(t_Iterator *self);
72         static PyObject *t_Iterator_next(t_Iterator *self);
73
74         static PyMethodDef t_Iterator__methods_[] = {
75             DECLARE_METHOD(t_Iterator, hasNext, METH_NOARGS),
76             DECLARE_METHOD(t_Iterator, next, METH_NOARGS),
77             { NULL, NULL, 0, NULL }
78         };
79
80         DECLARE_TYPE(Iterator, t_Iterator, JObject, java::util::Iterator,
81                      abstract_init, 0, 0, 0, 0, 0);
82
83 #ifdef _java_generics
84         PyObject *t_Iterator::wrap_Object(const Iterator& object,
85                                           PyTypeObject *T)
86         {
87             PyObject *obj = t_Iterator::wrap_Object(object);
88             if (obj != Py_None)
89             {
90                 t_Iterator *self = (t_Iterator *) obj;
91                 self->parameters[0] = T;
92             }
93             return obj;
94         }
95
96         PyObject *t_Iterator::wrap_jobject(const jobject& object,
97                                            PyTypeObject *T)
98         {
99             PyObject *obj = t_Iterator::wrap_jobject(object);
100             if (obj != Py_None)
101             {
102                 t_Iterator *self = (t_Iterator *) obj;
103                 self->parameters[0] = T;
104             }
105             return obj;
106         }
107 #endif
108         static PyObject *t_Iterator_hasNext(t_Iterator *self)
109         {
110             jboolean b;
111
112             OBJ_CALL(b = self->object.hasNext());
113             Py_RETURN_BOOL(b);
114         }
115
116         static PyObject *t_Iterator_next(t_Iterator *self)
117         {
118             Object next((jobject) NULL);
119
120             OBJ_CALL(next = self->object.next());
121             return t_Object::wrap_Object(next);
122         }
123     }
124 }