PyLucene 3.4.0-1 import
[pylucene.git] / jcc / _jcc / java / util / Enumeration.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/Enumeration.h"
21
22 namespace java {
23     namespace util {
24         enum {
25             mid_hasMoreElements,
26             mid_nextElement,
27             max_mid
28         };
29
30         Class *Enumeration::class$ = NULL;
31         jmethodID *Enumeration::mids$ = NULL;
32
33         jclass Enumeration::initializeClass()
34         {
35             if (!class$)
36             {
37                 jclass cls = env->findClass("java/util/Enumeration");
38
39                 mids$ = new jmethodID[max_mid];
40                 mids$[mid_hasMoreElements] = env->getMethodID(cls, "hasMoreElements", "()Z");
41                 mids$[mid_nextElement] = env->getMethodID(cls, "nextElement", "()Ljava/lang/Object;");
42
43                 class$ = (Class *) new JObject(cls);
44             }
45
46             return (jclass) class$->this$;
47         }
48
49         jboolean Enumeration::hasMoreElements() const
50         {
51             return env->callBooleanMethod(this$, mids$[mid_hasMoreElements]);
52         }
53
54         Object Enumeration::nextElement() const
55         {
56             return Object(env->callObjectMethod(this$, mids$[mid_nextElement]));
57         }
58     }
59 }
60
61
62 #include "structmember.h"
63 #include "functions.h"
64 #include "macros.h"
65
66 namespace java {
67     namespace util {
68
69         static PyObject *t_Enumeration_hasMoreElements(t_Enumeration *self);
70         static PyObject *t_Enumeration_nextElement(t_Enumeration *self);
71
72         static PyMethodDef t_Enumeration__methods_[] = {
73             DECLARE_METHOD(t_Enumeration, hasMoreElements, METH_NOARGS),
74             DECLARE_METHOD(t_Enumeration, nextElement, METH_NOARGS),
75             { NULL, NULL, 0, NULL }
76         };
77
78         DECLARE_TYPE(Enumeration, t_Enumeration, JObject,
79                      java::util::Enumeration, abstract_init, 0, 0, 0, 0, 0);
80
81 #ifdef _java_generics
82         PyObject *t_Enumeration::wrap_Object(const Enumeration& object,
83                                              PyTypeObject *T)
84         {
85             PyObject *obj = t_Enumeration::wrap_Object(object);
86             if (obj != Py_None)
87             {
88                 t_Enumeration *self = (t_Enumeration *) obj;
89                 self->parameters[0] = T;
90             }
91             return obj;
92         }
93 #endif
94         static PyObject *t_Enumeration_hasMoreElements(t_Enumeration *self)
95         {
96             jboolean b;
97
98             OBJ_CALL(b = self->object.hasMoreElements());
99             Py_RETURN_BOOL(b);
100         }
101
102         static PyObject *t_Enumeration_nextElement(t_Enumeration *self)
103         {
104             Object nextElement((jobject) NULL);
105
106             OBJ_CALL(nextElement = self->object.nextElement());
107             return t_Object::wrap_Object(nextElement);
108         }
109     }
110 }