Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / src / cpython / storage / data_line.c
blob81356ce2d8589dfd8a13da2b8eb95930aa3b3b1a
1 /* Copyright (C) 2013-2020 Roland Lutz
3 AUTOMATICALLY GENERATED FROM data_line.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_line(const struct xornsch_line *data)
25 PyObject *no_args = PyTuple_New(0);
26 Line *self = (Line *)PyObject_CallObject(
27 (PyObject *)&LineType, 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 return (PyObject *)self;
38 void prepare_line(Line *self,
39 xorn_obtype_t *type_return, const void **data_return)
41 self->data.line = ((LineAttr *)self->line)->data;
42 *type_return = xornsch_obtype_line;
43 *data_return = &self->data;
46 static PyObject *Line_new(
47 PyTypeObject *type, PyObject *args, PyObject *kwds)
49 Line *self = (Line *)type->tp_alloc(type, 0);
50 if (self == NULL)
51 return NULL;
53 PyObject *no_args = PyTuple_New(0);
54 self->line = PyObject_CallObject((PyObject *)&LineAttrType, no_args);
55 Py_DECREF(no_args);
57 if (self->line == NULL) {
58 Py_DECREF(self);
59 return NULL;
61 return (PyObject *)self;
64 static int Line_init(Line *self, PyObject *args, PyObject *kwds)
66 double x_arg = 0., y_arg = 0.;
67 double width_arg = 0., height_arg = 0.;
68 int color_arg = 0;
69 PyObject *line_arg = NULL;
71 static char *kwlist[] = {
72 "x", "y",
73 "width", "height",
74 "color",
75 "line",
76 NULL
79 if (!PyArg_ParseTupleAndKeywords(
80 args, kwds, "|ddddiO:Line", kwlist,
81 &x_arg, &y_arg,
82 &width_arg, &height_arg,
83 &color_arg,
84 &line_arg))
85 return -1;
87 if (line_arg != NULL && !PyObject_TypeCheck(line_arg, &LineAttrType)) {
88 char buf[BUFSIZ];
89 snprintf(buf, BUFSIZ,
90 "line attribute must be %.50s, not %.50s",
91 LineAttrType.tp_name, line_arg->ob_type->tp_name);
92 PyErr_SetString(PyExc_TypeError, buf);
93 return -1;
96 self->data.pos.x = x_arg;
97 self->data.pos.y = y_arg;
98 self->data.size.x = width_arg;
99 self->data.size.y = height_arg;
100 self->data.color = color_arg;
101 if (line_arg != NULL) {
102 Py_INCREF(line_arg);
103 Py_DECREF(self->line);
104 self->line = line_arg;
107 return 0;
110 static int Line_traverse(Line *self, visitproc visit, void *arg)
112 Py_VISIT(self->line);
113 return 0;
116 static int Line_clear(Line *self)
118 Py_CLEAR(self->line);
119 return 0;
122 static void Line_dealloc(Line *self)
124 Line_clear(self);
125 self->ob_type->tp_free((PyObject *)self);
128 static PyMemberDef Line_members[] = {
129 { "x", T_DOUBLE, offsetof(Line, data.pos.x), 0,
130 PyDoc_STR("") },
131 { "y", T_DOUBLE, offsetof(Line, data.pos.y), 0,
132 PyDoc_STR("") },
133 { "width", T_DOUBLE, offsetof(Line, data.size.x), 0,
134 PyDoc_STR("") },
135 { "height", T_DOUBLE, offsetof(Line, data.size.y), 0,
136 PyDoc_STR("") },
137 { "color", T_INT, offsetof(Line, data.color), 0,
138 PyDoc_STR("") },
139 { NULL, 0, 0, 0, NULL } /* Sentinel */
142 static PyObject *Line_getline(Line *self, void *closure)
144 Py_INCREF(self->line);
145 return self->line;
148 static int Line_setline(Line *self, PyObject *value, void *closure)
150 if (value == NULL) {
151 PyErr_SetString(PyExc_TypeError,
152 "line attribute cannot be deleted");
153 return -1;
156 if (!PyObject_TypeCheck(value, &LineAttrType)) {
157 char buf[BUFSIZ];
158 snprintf(buf, BUFSIZ,
159 "line attribute must be %.50s, not %.50s",
160 LineAttrType.tp_name, value->ob_type->tp_name);
161 PyErr_SetString(PyExc_TypeError, buf);
162 return -1;
165 Py_INCREF(value);
166 Py_DECREF(self->line);
167 self->line = value;
168 return 0;
171 static PyGetSetDef Line_getset[] = {
172 { "line", (getter)Line_getline, (setter)Line_setline,
173 PyDoc_STR(""), NULL },
174 { NULL, NULL, NULL, NULL, NULL } /* Sentinel */
177 PyTypeObject LineType = {
178 PyObject_HEAD_INIT(NULL)
179 0, /*ob_size*/
181 /* For printing, in format "<module>.<name>" */
182 "xorn.storage.Line", /* const char *tp_name */
184 /* For allocation */
185 sizeof(Line), /* Py_ssize_t tp_basicsize */
186 0, /* Py_ssize_t tp_itemsize */
188 /* Methods to implement standard operations */
189 (destructor)Line_dealloc, /* destructor tp_dealloc */
190 NULL, /* printfunc tp_print */
191 NULL, /* getattrfunc tp_getattr */
192 NULL, /* setattrfunc tp_setattr */
193 NULL, /* cmpfunc tp_compare */
194 NULL, /* reprfunc tp_repr */
196 /* Method suites for standard classes */
197 NULL, /* PyNumberMethods *tp_as_number */
198 NULL, /* PySequenceMethods *tp_as_sequence */
199 NULL, /* PyMappingMethods *tp_as_mapping */
201 /* More standard operations (here for binary compatibility) */
202 NULL, /* hashfunc tp_hash */
203 NULL, /* ternaryfunc tp_call */
204 NULL, /* reprfunc tp_str */
205 NULL, /* getattrofunc tp_getattro */
206 NULL, /* setattrofunc tp_setattro */
208 /* Functions to access object as input/output buffer */
209 NULL, /* PyBufferProcs *tp_as_buffer */
211 /* Flags to define presence of optional/expanded features */
212 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
213 /* long tp_flags */
215 /* Documentation string */
216 PyDoc_STR("Schematic line."),
217 /* const char *tp_doc */
219 /* Assigned meaning in release 2.0 */
220 /* call function for all accessible objects */
221 (traverseproc)Line_traverse,/* traverseproc tp_traverse */
223 /* delete references to contained objects */
224 (inquiry)Line_clear, /* inquiry tp_clear */
226 /* Assigned meaning in release 2.1 */
227 /* rich comparisons */
228 NULL, /* richcmpfunc tp_richcompare */
230 /* weak reference enabler */
231 0, /* Py_ssize_t tp_weaklistoffset */
233 /* Added in release 2.2 */
234 /* Iterators */
235 NULL, /* getiterfunc tp_iter */
236 NULL, /* iternextfunc tp_iternext */
238 /* Attribute descriptor and subclassing stuff */
239 NULL, /* struct PyMethodDef *tp_methods */
240 Line_members, /* struct PyMemberDef *tp_members */
241 Line_getset, /* struct PyGetSetDef *tp_getset */
242 NULL, /* struct _typeobject *tp_base */
243 NULL, /* PyObject *tp_dict */
244 NULL, /* descrgetfunc tp_descr_get */
245 NULL, /* descrsetfunc tp_descr_set */
246 0, /* Py_ssize_t tp_dictoffset */
247 (initproc)Line_init, /* initproc tp_init */
248 NULL, /* allocfunc tp_alloc */
249 Line_new, /* newfunc tp_new */
250 NULL, /* freefunc tp_free--Low-level free-memory routine */
251 NULL, /* inquiry tp_is_gc--For PyObject_IS_GC */
252 NULL, /* PyObject *tp_bases */
253 NULL, /* PyObject *tp_mro--method resolution order */
254 NULL, /* PyObject *tp_cache */
255 NULL, /* PyObject *tp_subclasses */
256 NULL, /* PyObject *tp_weaklist */
257 NULL, /* destructor tp_del */
259 /* Type attribute cache version tag. Added in version 2.6 */
260 0, /* unsigned int tp_version_tag */