Cleanup: remove unused struct members from RenderStats
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DId.cpp
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16
17 /** \file
18  * \ingroup freestyle
19  */
20
21 #include "BPy_UnaryFunction0DId.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_Id/BPy_ShapeIdF0D.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 ///////////////////////////////////////////////////////////////////////////////////////////
33
34 //-------------------MODULE INITIALIZATION--------------------------------
35
36 int UnaryFunction0DId_Init(PyObject *module)
37 {
38   if (module == NULL) {
39     return -1;
40   }
41
42   if (PyType_Ready(&UnaryFunction0DId_Type) < 0) {
43     return -1;
44   }
45   Py_INCREF(&UnaryFunction0DId_Type);
46   PyModule_AddObject(module, "UnaryFunction0DId", (PyObject *)&UnaryFunction0DId_Type);
47
48   if (PyType_Ready(&ShapeIdF0D_Type) < 0) {
49     return -1;
50   }
51   Py_INCREF(&ShapeIdF0D_Type);
52   PyModule_AddObject(module, "ShapeIdF0D", (PyObject *)&ShapeIdF0D_Type);
53
54   return 0;
55 }
56
57 //------------------------INSTANCE METHODS ----------------------------------
58
59 static char UnaryFunction0DId___doc__[] =
60     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DId`\n"
61     "\n"
62     "Base class for unary functions (functors) that work on\n"
63     ":class:`Interface0DIterator` and return an :class:`Id` object.\n"
64     "\n"
65     ".. method:: __init__()\n"
66     "\n"
67     "   Default constructor.\n";
68
69 static int UnaryFunction0DId___init__(BPy_UnaryFunction0DId *self, PyObject *args, PyObject *kwds)
70 {
71   static const char *kwlist[] = {NULL};
72
73   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
74     return -1;
75   }
76   self->uf0D_id = new UnaryFunction0D<Id>();
77   self->uf0D_id->py_uf0D = (PyObject *)self;
78   return 0;
79 }
80
81 static void UnaryFunction0DId___dealloc__(BPy_UnaryFunction0DId *self)
82 {
83   if (self->uf0D_id) {
84     delete self->uf0D_id;
85   }
86   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
87 }
88
89 static PyObject *UnaryFunction0DId___repr__(BPy_UnaryFunction0DId *self)
90 {
91   return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_id);
92 }
93
94 static PyObject *UnaryFunction0DId___call__(BPy_UnaryFunction0DId *self,
95                                             PyObject *args,
96                                             PyObject *kwds)
97 {
98   static const char *kwlist[] = {"it", NULL};
99   PyObject *obj;
100
101   if (!PyArg_ParseTupleAndKeywords(
102           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
103     return NULL;
104   }
105
106   if (typeid(*(self->uf0D_id)) == typeid(UnaryFunction0D<Id>)) {
107     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
108     return NULL;
109   }
110   if (self->uf0D_id->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
111     if (!PyErr_Occurred()) {
112       string class_name(Py_TYPE(self)->tp_name);
113       PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
114     }
115     return NULL;
116   }
117   return BPy_Id_from_Id(self->uf0D_id->result);
118 }
119
120 /*-----------------------BPy_UnaryFunction0DId type definition ------------------------------*/
121
122 PyTypeObject UnaryFunction0DId_Type = {
123     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DId", /* tp_name */
124     sizeof(BPy_UnaryFunction0DId),                      /* tp_basicsize */
125     0,                                                  /* tp_itemsize */
126     (destructor)UnaryFunction0DId___dealloc__,          /* tp_dealloc */
127     0,                                                  /* tp_print */
128     0,                                                  /* tp_getattr */
129     0,                                                  /* tp_setattr */
130     0,                                                  /* tp_reserved */
131     (reprfunc)UnaryFunction0DId___repr__,               /* tp_repr */
132     0,                                                  /* tp_as_number */
133     0,                                                  /* tp_as_sequence */
134     0,                                                  /* tp_as_mapping */
135     0,                                                  /* tp_hash  */
136     (ternaryfunc)UnaryFunction0DId___call__,            /* tp_call */
137     0,                                                  /* tp_str */
138     0,                                                  /* tp_getattro */
139     0,                                                  /* tp_setattro */
140     0,                                                  /* tp_as_buffer */
141     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,           /* tp_flags */
142     UnaryFunction0DId___doc__,                          /* tp_doc */
143     0,                                                  /* tp_traverse */
144     0,                                                  /* tp_clear */
145     0,                                                  /* tp_richcompare */
146     0,                                                  /* tp_weaklistoffset */
147     0,                                                  /* tp_iter */
148     0,                                                  /* tp_iternext */
149     0,                                                  /* tp_methods */
150     0,                                                  /* tp_members */
151     0,                                                  /* tp_getset */
152     &UnaryFunction0D_Type,                              /* tp_base */
153     0,                                                  /* tp_dict */
154     0,                                                  /* tp_descr_get */
155     0,                                                  /* tp_descr_set */
156     0,                                                  /* tp_dictoffset */
157     (initproc)UnaryFunction0DId___init__,               /* tp_init */
158     0,                                                  /* tp_alloc */
159     0,                                                  /* tp_new */
160 };
161
162 ///////////////////////////////////////////////////////////////////////////////////////////
163
164 #ifdef __cplusplus
165 }
166 #endif