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.
21 #include "structmember.h"
29 static void t_JObject_dealloc(t_JObject *self);
30 static PyObject *t_JObject_new(PyTypeObject *type,
31 PyObject *args, PyObject *kwds);
33 static PyObject *t_JObject_richcmp(t_JObject *, PyObject *o2, int op);
34 static PyObject *t_JObject_str(t_JObject *self);
35 static PyObject *t_JObject_repr(t_JObject *self);
36 static int t_JObject_hash(t_JObject *self);
37 static PyObject *t_JObject__getJObject(t_JObject *self, void *data);
39 static PyMemberDef t_JObject_members[] = {
40 { NULL, 0, 0, 0, NULL }
43 static PyMethodDef t_JObject_methods[] = {
44 { NULL, NULL, 0, NULL }
47 static PyGetSetDef t_JObject_properties[] = {
48 { "_jobject", (getter) t_JObject__getJObject, NULL, NULL, NULL },
49 { NULL, NULL, NULL, NULL, NULL }
52 PyTypeObject PY_TYPE(JObject) = {
53 PyObject_HEAD_INIT(NULL)
55 "jcc.JObject", /* tp_name */
56 sizeof(t_JObject), /* tp_basicsize */
58 (destructor)t_JObject_dealloc, /* tp_dealloc */
63 (reprfunc)t_JObject_repr, /* tp_repr */
65 0, /* tp_as_sequence */
66 0, /* tp_as_mapping */
67 (hashfunc)t_JObject_hash, /* tp_hash */
69 (reprfunc)t_JObject_str, /* tp_str */
74 Py_TPFLAGS_BASETYPE), /* tp_flags */
75 "t_JObject objects", /* tp_doc */
78 (richcmpfunc)t_JObject_richcmp, /* tp_richcompare */
79 0, /* tp_weaklistoffset */
82 t_JObject_methods, /* tp_methods */
83 t_JObject_members, /* tp_members */
84 t_JObject_properties, /* tp_getset */
89 0, /* tp_dictoffset */
92 (newfunc)t_JObject_new, /* tp_new */
96 static void t_JObject_dealloc(t_JObject *self)
98 self->object = JObject(NULL);
99 self->ob_type->tp_free((PyObject *) self);
102 static PyObject *t_JObject_new(PyTypeObject *type,
103 PyObject *args, PyObject *kwds)
105 t_JObject *self = (t_JObject *) type->tp_alloc(type, 0);
107 self->object = JObject(NULL);
109 return (PyObject *) self;
112 static PyObject *t_JObject_richcmp(t_JObject *self, PyObject *arg, int op)
119 if (PyObject_TypeCheck(arg, &PY_TYPE(JObject)))
120 b = self->object == ((t_JObject *) arg)->object;
125 PyErr_SetString(PyExc_NotImplementedError, "<");
128 PyErr_SetString(PyExc_NotImplementedError, "<=");
131 PyErr_SetString(PyExc_NotImplementedError, ">");
134 PyErr_SetString(PyExc_NotImplementedError, ">=");
141 static PyObject *t_JObject_str(t_JObject *self)
143 if (self->object.this$)
145 char *utf = env->toString(self->object.this$);
148 utf = env->getClassName(self->object.this$);
153 PyUnicode_DecodeUTF8(utf, strlen(utf), "strict");
160 return PyString_FromString("<null>");
163 static PyObject *t_JObject_repr(t_JObject *self)
165 PyObject *name = PyObject_GetAttrString((PyObject *) self->ob_type,
167 PyObject *str = self->ob_type->tp_str((PyObject *) self);
168 #if PY_VERSION_HEX < 0x02040000
169 PyObject *args = Py_BuildValue("(OO)", name, str);
171 PyObject *args = PyTuple_Pack(2, name, str);
173 PyObject *format = PyString_FromString("<%s: %s>");
174 PyObject *repr = PyString_Format(format, args);
184 static int t_JObject_hash(t_JObject *self)
186 return env->hash(self->object.this$);
189 static PyObject *t_JObject__getJObject(t_JObject *self, void *data)
191 return PyCObject_FromVoidPtr((void *) self->object.this$, NULL);