Configured build for Ubuntu and added Stempel polish analyzer
[pylucene.git] / jcc / _jcc / java / lang / Object.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/lang/String.h"
21
22 namespace java {
23     namespace lang {
24         enum {
25             mid__init_,
26             mid_toString,
27             mid_getClass,
28             mid_hashCode,
29             mid_equals,
30             max_mid
31         };
32
33         Class *Object::class$ = NULL;
34         jmethodID *Object::mids$ = NULL;
35
36         jclass Object::initializeClass()
37         {
38             if (!class$)
39             {
40                 jclass cls = env->findClass("java/lang/Object");
41
42                 mids$ = new jmethodID[max_mid];
43                 mids$[mid__init_] = env->getMethodID(cls, "<init>",
44                                                      "()V");
45                 mids$[mid_toString] = env->getMethodID(cls, "toString",
46                                                        "()Ljava/lang/String;");
47                 mids$[mid_getClass] = env->getMethodID(cls, "getClass",
48                                                        "()Ljava/lang/Class;");
49                 mids$[mid_hashCode] = env->getMethodID(cls, "hashCode",
50                                                        "()I");
51                 mids$[mid_equals] = env->getMethodID(cls, "equals",
52                                                      "(Ljava/lang/Object;)Z");
53
54                 class$ = (Class *) new JObject(cls);
55             }
56
57             return (jclass) class$->this$;
58         }
59
60         Object::Object() : JObject(env->newObject(initializeClass, &mids$, mid__init_)) {
61         }
62
63         String Object::toString() const
64         {
65             return String(env->callObjectMethod(this$, mids$[mid_toString]));
66         }
67
68         Class Object::getClass() const
69         {
70             return Class(env->callObjectMethod(this$, mids$[mid_getClass]));
71         }
72
73         int Object::hashCode() const
74         {
75             return env->callIntMethod(this$, mids$[mid_hashCode]);
76         }
77
78         jboolean Object::equals(const Object& a0) const
79         {
80             return env->callBooleanMethod(this$, mids$[mid_equals], a0.this$);
81         }
82     }
83 }
84
85
86 #include "structmember.h"
87 #include "functions.h"
88 #include "macros.h"
89
90 namespace java {
91     namespace lang {
92
93         static int t_Object_init(t_Object *self,
94                                  PyObject *args, PyObject *kwds);
95         static PyObject *t_Object_getClass(t_Object *self);
96         static PyObject *t_Object_equals(t_Object *self, PyObject *arg);
97
98         static PyMethodDef t_Object__methods_[] = {
99             DECLARE_METHOD(t_Object, getClass, METH_NOARGS),
100             DECLARE_METHOD(t_Object, equals, METH_O),
101             { NULL, NULL, 0, NULL }
102         };
103
104         DECLARE_TYPE(Object, t_Object, JObject, java::lang::Object,
105                      t_Object_init, 0, 0, 0, 0, 0);
106
107         static int t_Object_init(t_Object *self,
108                                  PyObject *args, PyObject *kwds)
109         {
110             switch (PyTuple_Size(args)) {
111               case 0:
112                 INT_CALL(self->object = Object());
113                 break;
114               default:
115                 PyErr_SetString(PyExc_ValueError, "invalid args");
116                 return -1;
117             }
118         
119             return 0;
120         }
121
122         static PyObject *t_Object_getClass(t_Object *self)
123         {
124             Class cls((jobject) NULL);
125
126             OBJ_CALL(cls = self->object.getClass());
127             return t_Class::wrap_Object(cls);
128         }
129
130         static PyObject *t_Object_equals(t_Object *self, PyObject *arg)
131         {
132             Object a0((jobject) NULL);
133             jboolean result;
134
135             if (!parseArg(arg, "o", &a0))
136             {
137                 OBJ_CALL(result = self->object.equals(a0));
138                 Py_RETURN_BOOL(result);
139             }
140
141             PyErr_SetArgsError((PyObject *) self, "equals", arg);
142             return NULL;
143         }
144     }
145 }