Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / src / cpython / storage / data_box.c
blob1ad12a7d8256ae7096af1a10274a6f34d2efdc82
1 /* Copyright (C) 2013-2020 Roland Lutz
3 AUTOMATICALLY GENERATED FROM data_box.m4 -- DO NOT EDIT
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #include "data.h"
20 #include <structmember.h>
23 PyObject *construct_box(const struct xornsch_box *data)
25 PyObject *no_args = PyTuple_New(0);
26 Box *self = (Box *)PyObject_CallObject(
27 (PyObject *)&BoxType, no_args);
28 Py_DECREF(no_args);
30 if (self == NULL)
31 return NULL;
33 self->data = *data;
34 ((LineAttr *)self->line)->data = data->line;
35 ((FillAttr *)self->fill)->data = data->fill;
36 return (PyObject *)self;
39 void prepare_box(Box *self,
40 xorn_obtype_t *type_return, const void **data_return)
42 self->data.line = ((LineAttr *)self->line)->data;
43 self->data.fill = ((FillAttr *)self->fill)->data;
44 *type_return = xornsch_obtype_box;
45 *data_return = &self->data;
48 static PyObject *Box_new(
49 PyTypeObject *type, PyObject *args, PyObject *kwds)
51 Box *self = (Box *)type->tp_alloc(type, 0);
52 if (self == NULL)
53 return NULL;
55 PyObject *no_args = PyTuple_New(0);
56 self->line = PyObject_CallObject((PyObject *)&LineAttrType, no_args);
57 self->fill = PyObject_CallObject((PyObject *)&FillAttrType, no_args);
58 Py_DECREF(no_args);
60 if (self->line == NULL) {
61 Py_DECREF(self);
62 return NULL;
64 if (self->fill == NULL) {
65 Py_DECREF(self);
66 return NULL;
68 return (PyObject *)self;
71 static int Box_init(Box *self, PyObject *args, PyObject *kwds)
73 double x_arg = 0., y_arg = 0.;
74 double width_arg = 0., height_arg = 0.;
75 int color_arg = 0;
76 PyObject *line_arg = NULL;
77 PyObject *fill_arg = NULL;
79 static char *kwlist[] = {
80 "x", "y",
81 "width", "height",
82 "color",
83 "line",
84 "fill",
85 NULL
88 if (!PyArg_ParseTupleAndKeywords(
89 args, kwds, "|ddddiOO:Box", kwlist,
90 &x_arg, &y_arg,
91 &width_arg, &height_arg,
92 &color_arg,
93 &line_arg,
94 &fill_arg))
95 return -1;
97 if (line_arg != NULL && !PyObject_TypeCheck(line_arg, &LineAttrType)) {
98 char buf[BUFSIZ];
99 snprintf(buf, BUFSIZ,
100 "line attribute must be %.50s, not %.50s",
101 LineAttrType.tp_name, line_arg->ob_type->tp_name);
102 PyErr_SetString(PyExc_TypeError, buf);
103 return -1;
105 if (fill_arg != NULL && !PyObject_TypeCheck(fill_arg, &FillAttrType)) {
106 char buf[BUFSIZ];
107 snprintf(buf, BUFSIZ,
108 "fill attribute must be %.50s, not %.50s",
109 FillAttrType.tp_name, fill_arg->ob_type->tp_name);
110 PyErr_SetString(PyExc_TypeError, buf);
111 return -1;
114 self->data.pos.x = x_arg;
115 self->data.pos.y = y_arg;
116 self->data.size.x = width_arg;
117 self->data.size.y = height_arg;
118 self->data.color = color_arg;
119 if (line_arg != NULL) {
120 Py_INCREF(line_arg);
121 Py_DECREF(self->line);
122 self->line = line_arg;
124 if (fill_arg != NULL) {
125 Py_INCREF(fill_arg);
126 Py_DECREF(self->fill);
127 self->fill = fill_arg;
130 return 0;
133 static int Box_traverse(Box *self, visitproc visit, void *arg)
135 Py_VISIT(self->line);
136 Py_VISIT(self->fill);
137 return 0;
140 static int Box_clear(Box *self)
142 Py_CLEAR(self->line);
143 Py_CLEAR(self->fill);
144 return 0;
147 static void Box_dealloc(Box *self)
149 Box_clear(self);
150 self->ob_type->tp_free((PyObject *)self);
153 static PyMemberDef Box_members[] = {
154 { "x", T_DOUBLE, offsetof(Box, data.pos.x), 0,
155 PyDoc_STR("") },
156 { "y", T_DOUBLE, offsetof(Box, data.pos.y), 0,
157 PyDoc_STR("") },
158 { "width", T_DOUBLE, offsetof(Box, data.size.x), 0,
159 PyDoc_STR("") },
160 { "height", T_DOUBLE, offsetof(Box, data.size.y), 0,
161 PyDoc_STR("") },
162 { "color", T_INT, offsetof(Box, data.color), 0,
163 PyDoc_STR("") },
164 { NULL, 0, 0, 0, NULL } /* Sentinel */
167 static PyObject *Box_getline(Box *self, void *closure)
169 Py_INCREF(self->line);
170 return self->line;
173 static int Box_setline(Box *self, PyObject *value, void *closure)
175 if (value == NULL) {
176 PyErr_SetString(PyExc_TypeError,
177 "line attribute cannot be deleted");
178 return -1;
181 if (!PyObject_TypeCheck(value, &LineAttrType)) {
182 char buf[BUFSIZ];
183 snprintf(buf, BUFSIZ,
184 "line attribute must be %.50s, not %.50s",
185 LineAttrType.tp_name, value->ob_type->tp_name);
186 PyErr_SetString(PyExc_TypeError, buf);
187 return -1;
190 Py_INCREF(value);
191 Py_DECREF(self->line);
192 self->line = value;
193 return 0;
196 static PyObject *Box_getfill(Box *self, void *closure)
198 Py_INCREF(self->fill);
199 return self->fill;
202 static int Box_setfill(Box *self, PyObject *value, void *closure)
204 if (value == NULL) {
205 PyErr_SetString(PyExc_TypeError,
206 "fill attribute cannot be deleted");
207 return -1;
210 if (!PyObject_TypeCheck(value, &FillAttrType)) {
211 char buf[BUFSIZ];
212 snprintf(buf, BUFSIZ,
213 "fill attribute must be %.50s, not %.50s",
214 FillAttrType.tp_name, value->ob_type->tp_name);
215 PyErr_SetString(PyExc_TypeError, buf);
216 return -1;
219 Py_INCREF(value);
220 Py_DECREF(self->fill);
221 self->fill = value;
222 return 0;
225 static PyGetSetDef Box_getset[] = {
226 { "line", (getter)Box_getline, (setter)Box_setline,
227 PyDoc_STR(""), NULL },
228 { "fill", (getter)Box_getfill, (setter)Box_setfill,
229 PyDoc_STR(""), NULL },
230 { NULL, NULL, NULL, NULL, NULL } /* Sentinel */
233 PyTypeObject BoxType = {
234 PyObject_HEAD_INIT(NULL)
235 0, /*ob_size*/
237 /* For printing, in format "<module>.<name>" */
238 "xorn.storage.Box", /* const char *tp_name */
240 /* For allocation */
241 sizeof(Box), /* Py_ssize_t tp_basicsize */
242 0, /* Py_ssize_t tp_itemsize */
244 /* Methods to implement standard operations */
245 (destructor)Box_dealloc, /* destructor tp_dealloc */
246 NULL, /* printfunc tp_print */
247 NULL, /* getattrfunc tp_getattr */
248 NULL, /* setattrfunc tp_setattr */
249 NULL, /* cmpfunc tp_compare */
250 NULL, /* reprfunc tp_repr */
252 /* Method suites for standard classes */
253 NULL, /* PyNumberMethods *tp_as_number */
254 NULL, /* PySequenceMethods *tp_as_sequence */
255 NULL, /* PyMappingMethods *tp_as_mapping */
257 /* More standard operations (here for binary compatibility) */
258 NULL, /* hashfunc tp_hash */
259 NULL, /* ternaryfunc tp_call */
260 NULL, /* reprfunc tp_str */
261 NULL, /* getattrofunc tp_getattro */
262 NULL, /* setattrofunc tp_setattro */
264 /* Functions to access object as input/output buffer */
265 NULL, /* PyBufferProcs *tp_as_buffer */
267 /* Flags to define presence of optional/expanded features */
268 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
269 /* long tp_flags */
271 /* Documentation string */
272 PyDoc_STR("Schematic box."),
273 /* const char *tp_doc */
275 /* Assigned meaning in release 2.0 */
276 /* call function for all accessible objects */
277 (traverseproc)Box_traverse,/* traverseproc tp_traverse */
279 /* delete references to contained objects */
280 (inquiry)Box_clear, /* inquiry tp_clear */
282 /* Assigned meaning in release 2.1 */
283 /* rich comparisons */
284 NULL, /* richcmpfunc tp_richcompare */
286 /* weak reference enabler */
287 0, /* Py_ssize_t tp_weaklistoffset */
289 /* Added in release 2.2 */
290 /* Iterators */
291 NULL, /* getiterfunc tp_iter */
292 NULL, /* iternextfunc tp_iternext */
294 /* Attribute descriptor and subclassing stuff */
295 NULL, /* struct PyMethodDef *tp_methods */
296 Box_members, /* struct PyMemberDef *tp_members */
297 Box_getset, /* struct PyGetSetDef *tp_getset */
298 NULL, /* struct _typeobject *tp_base */
299 NULL, /* PyObject *tp_dict */
300 NULL, /* descrgetfunc tp_descr_get */
301 NULL, /* descrsetfunc tp_descr_set */
302 0, /* Py_ssize_t tp_dictoffset */
303 (initproc)Box_init, /* initproc tp_init */
304 NULL, /* allocfunc tp_alloc */
305 Box_new, /* newfunc tp_new */
306 NULL, /* freefunc tp_free--Low-level free-memory routine */
307 NULL, /* inquiry tp_is_gc--For PyObject_IS_GC */
308 NULL, /* PyObject *tp_bases */
309 NULL, /* PyObject *tp_mro--method resolution order */
310 NULL, /* PyObject *tp_cache */
311 NULL, /* PyObject *tp_subclasses */
312 NULL, /* PyObject *tp_weaklist */
313 NULL, /* destructor tp_del */
315 /* Type attribute cache version tag. Added in version 2.6 */
316 0, /* unsigned int tp_version_tag */