Fixed argument checking in __init__ methods of Interface1D, Predicates,
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DVectorViewShape.cpp
1 #include "BPy_UnaryFunction0DVectorViewShape.h"
2
3 #include "../BPy_Convert.h"
4 #include "../Iterator/BPy_Interface0DIterator.h"
5
6 #include "UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.h"
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 ///////////////////////////////////////////////////////////////////////////////////////////
13
14 /*---------------  Python API function prototypes for UnaryFunction0DVectorViewShape instance  -----------*/
15 static int UnaryFunction0DVectorViewShape___init__(BPy_UnaryFunction0DVectorViewShape* self, PyObject *args, PyObject *kwds);
16 static void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVectorViewShape* self);
17 static PyObject * UnaryFunction0DVectorViewShape___repr__(BPy_UnaryFunction0DVectorViewShape* self);
18
19 static PyObject * UnaryFunction0DVectorViewShape_getName( BPy_UnaryFunction0DVectorViewShape *self);
20 static PyObject * UnaryFunction0DVectorViewShape___call__( BPy_UnaryFunction0DVectorViewShape *self, PyObject *args, PyObject *kwds);
21
22 /*----------------------UnaryFunction0DVectorViewShape instance definitions ----------------------------*/
23 static PyMethodDef BPy_UnaryFunction0DVectorViewShape_methods[] = {
24         {"getName", ( PyCFunction ) UnaryFunction0DVectorViewShape_getName, METH_NOARGS, "( )Returns the string of the name of the unary 0D function."},
25         {NULL, NULL, 0, NULL}
26 };
27
28 /*-----------------------BPy_UnaryFunction0DVectorViewShape type definition ------------------------------*/
29
30 PyTypeObject UnaryFunction0DVectorViewShape_Type = {
31         PyObject_HEAD_INIT( NULL ) 
32         0,                                                      /* ob_size */
33         "UnaryFunction0DVectorViewShape",                               /* tp_name */
34         sizeof( BPy_UnaryFunction0DVectorViewShape ),   /* tp_basicsize */
35         0,                                                      /* tp_itemsize */
36         
37         /* methods */
38         (destructor)UnaryFunction0DVectorViewShape___dealloc__, /* tp_dealloc */
39         NULL,                                                   /* printfunc tp_print; */
40         NULL,                                                   /* getattrfunc tp_getattr; */
41         NULL,                                                   /* setattrfunc tp_setattr; */
42         NULL,                                                                           /* tp_compare */
43         (reprfunc)UnaryFunction0DVectorViewShape___repr__,                                      /* tp_repr */
44
45         /* Method suites for standard classes */
46
47         NULL,                       /* PyNumberMethods *tp_as_number; */
48         NULL,                       /* PySequenceMethods *tp_as_sequence; */
49         NULL,                       /* PyMappingMethods *tp_as_mapping; */
50
51         /* More standard operations (here for binary compatibility) */
52
53         NULL,                                           /* hashfunc tp_hash; */
54         (ternaryfunc)UnaryFunction0DVectorViewShape___call__,                       /* ternaryfunc tp_call; */
55         NULL,                       /* reprfunc tp_str; */
56         NULL,                       /* getattrofunc tp_getattro; */
57         NULL,                       /* setattrofunc tp_setattro; */
58
59         /* Functions to access object as input/output buffer */
60         NULL,                       /* PyBufferProcs *tp_as_buffer; */
61
62   /*** Flags to define presence of optional/expanded features ***/
63         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,               /* long tp_flags; */
64
65         NULL,                       /*  char *tp_doc;  Documentation string */
66   /*** Assigned meaning in release 2.0 ***/
67         /* call function for all accessible objects */
68         NULL,                       /* traverseproc tp_traverse; */
69
70         /* delete references to contained objects */
71         NULL,                       /* inquiry tp_clear; */
72
73   /***  Assigned meaning in release 2.1 ***/
74   /*** rich comparisons ***/
75         NULL,                       /* richcmpfunc tp_richcompare; */
76
77   /***  weak reference enabler ***/
78         0,                          /* long tp_weaklistoffset; */
79
80   /*** Added in release 2.2 ***/
81         /*   Iterators */
82         NULL,                       /* getiterfunc tp_iter; */
83         NULL,                       /* iternextfunc tp_iternext; */
84
85   /*** Attribute descriptor and subclassing stuff ***/
86         BPy_UnaryFunction0DVectorViewShape_methods,     /* struct PyMethodDef *tp_methods; */
87         NULL,                           /* struct PyMemberDef *tp_members; */
88         NULL,                                           /* struct PyGetSetDef *tp_getset; */
89         &UnaryFunction0D_Type,                                                  /* struct _typeobject *tp_base; */
90         NULL,                                                   /* PyObject *tp_dict; */
91         NULL,                                                   /* descrgetfunc tp_descr_get; */
92         NULL,                                                   /* descrsetfunc tp_descr_set; */
93         0,                              /* long tp_dictoffset; */
94         (initproc)UnaryFunction0DVectorViewShape___init__, /* initproc tp_init; */
95         NULL,                                                   /* allocfunc tp_alloc; */
96         NULL,           /* newfunc tp_new; */
97         
98         /*  Low-level free-memory routine */
99         NULL,                       /* freefunc tp_free;  */
100         
101         /* For PyObject_IS_GC */
102         NULL,                       /* inquiry tp_is_gc;  */
103         NULL,                       /* PyObject *tp_bases; */
104         
105         /* method resolution order */
106         NULL,                       /* PyObject *tp_mro;  */
107         NULL,                       /* PyObject *tp_cache; */
108         NULL,                       /* PyObject *tp_subclasses; */
109         NULL,                       /* PyObject *tp_weaklist; */
110         NULL
111 };
112
113 //-------------------MODULE INITIALIZATION--------------------------------
114
115 PyMODINIT_FUNC UnaryFunction0DVectorViewShape_Init( PyObject *module ) {
116
117         if( module == NULL )
118                 return;
119
120         if( PyType_Ready( &UnaryFunction0DVectorViewShape_Type ) < 0 )
121                 return;
122         Py_INCREF( &UnaryFunction0DVectorViewShape_Type );
123         PyModule_AddObject(module, "UnaryFunction0DVectorViewShape", (PyObject *)&UnaryFunction0DVectorViewShape_Type);
124         
125         if( PyType_Ready( &GetOccludersF0D_Type ) < 0 )
126                 return;
127         Py_INCREF( &GetOccludersF0D_Type );
128         PyModule_AddObject(module, "GetOccludersF0D", (PyObject *)&GetOccludersF0D_Type);
129         
130 }
131
132 //------------------------INSTANCE METHODS ----------------------------------
133
134 int UnaryFunction0DVectorViewShape___init__(BPy_UnaryFunction0DVectorViewShape* self, PyObject *args, PyObject *kwds)
135 {
136     if ( !PyArg_ParseTuple(args, "") )
137         return -1;
138         self->uf0D_vectorviewshape = new UnaryFunction0D< std::vector<ViewShape*> >();
139         self->uf0D_vectorviewshape->py_uf0D = (PyObject *)self;
140         return 0;
141 }
142
143 void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVectorViewShape* self)
144 {
145         if (self->uf0D_vectorviewshape)
146                 delete self->uf0D_vectorviewshape;
147         UnaryFunction0D_Type.tp_dealloc((PyObject*)self);
148 }
149
150
151 PyObject * UnaryFunction0DVectorViewShape___repr__(BPy_UnaryFunction0DVectorViewShape* self)
152 {
153         return PyString_FromFormat("type: %s - address: %p", self->uf0D_vectorviewshape->getName().c_str(), self->uf0D_vectorviewshape );
154 }
155
156 PyObject * UnaryFunction0DVectorViewShape_getName( BPy_UnaryFunction0DVectorViewShape *self )
157 {
158         return PyString_FromString( self->uf0D_vectorviewshape->getName().c_str() );
159 }
160
161 PyObject * UnaryFunction0DVectorViewShape___call__( BPy_UnaryFunction0DVectorViewShape *self, PyObject *args, PyObject *kwds)
162 {
163         PyObject *obj;
164
165         if( kwds != NULL ) {
166                 PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
167                 return NULL;
168         }
169         if(!PyArg_ParseTuple(args, "O!", &Interface0DIterator_Type, &obj))
170                 return NULL;
171
172         if( typeid(*(self->uf0D_vectorviewshape)) == typeid(UnaryFunction0D< std::vector<ViewShape*> >) ) {
173                 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
174                 return NULL;
175         }
176         if (self->uf0D_vectorviewshape->operator()(*( ((BPy_Interface0DIterator *) obj)->if0D_it )) < 0) {
177                 if (!PyErr_Occurred()) {
178                         string msg(self->uf0D_vectorviewshape->getName() + " __call__ method failed");
179                         PyErr_SetString(PyExc_RuntimeError, msg.c_str());
180                 }
181                 return NULL;
182         }
183         PyObject *list = PyList_New(NULL);
184         
185         for( unsigned int i = 0; i < self->uf0D_vectorviewshape->result.size(); i++)
186                 PyList_Append(list, BPy_ViewShape_from_ViewShape(*( self->uf0D_vectorviewshape->result[i] )) );
187         
188         return list;
189 }
190
191 ///////////////////////////////////////////////////////////////////////////////////////////
192
193 #ifdef __cplusplus
194 }
195 #endif