OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file source/blender/freestyle/intern/python/BPy_UnaryPredicate0D.cpp |
| 29 * \ingroup freestyle |
| 30 */ |
| 31 |
| 32 #include "BPy_UnaryPredicate0D.h" |
| 33 |
| 34 #include "BPy_Convert.h" |
| 35 #include "Iterator/BPy_Interface0DIterator.h" |
| 36 #include "UnaryPredicate0D/BPy_FalseUP0D.h" |
| 37 #include "UnaryPredicate0D/BPy_TrueUP0D.h" |
| 38 |
| 39 #ifdef __cplusplus |
| 40 extern "C" { |
| 41 #endif |
| 42 |
| 43 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 44 |
| 45 //-------------------MODULE INITIALIZATION-------------------------------- |
| 46 int UnaryPredicate0D_Init(PyObject *module) |
| 47 { |
| 48 if (module == NULL) |
| 49 return -1; |
| 50 |
| 51 if (PyType_Ready(&UnaryPredicate0D_Type) < 0) |
| 52 return -1; |
| 53 Py_INCREF(&UnaryPredicate0D_Type); |
| 54 PyModule_AddObject(module, "UnaryPredicate0D", (PyObject *)&UnaryPredica
te0D_Type); |
| 55 |
| 56 if (PyType_Ready(&FalseUP0D_Type) < 0) |
| 57 return -1; |
| 58 Py_INCREF(&FalseUP0D_Type); |
| 59 PyModule_AddObject(module, "FalseUP0D", (PyObject *)&FalseUP0D_Type); |
| 60 |
| 61 if (PyType_Ready(&TrueUP0D_Type) < 0) |
| 62 return -1; |
| 63 Py_INCREF(&TrueUP0D_Type); |
| 64 PyModule_AddObject(module, "TrueUP0D", (PyObject *)&TrueUP0D_Type); |
| 65 |
| 66 return 0; |
| 67 } |
| 68 |
| 69 //------------------------INSTANCE METHODS ---------------------------------- |
| 70 |
| 71 static char UnaryPredicate0D___doc__[] = |
| 72 "Base class for unary predicates that work on\n" |
| 73 ":class:`Interface0DIterator`. A UnaryPredicate0D is a functor that\n" |
| 74 "evaluates a condition on an Interface0DIterator and returns true or\n" |
| 75 "false depending on whether this condition is satisfied or not. The\n" |
| 76 "UnaryPredicate0D is used by invoking its __call__() method. Any\n" |
| 77 "inherited class must overload the __call__() method.\n" |
| 78 "\n" |
| 79 ".. method:: __init__()\n" |
| 80 "\n" |
| 81 " Default constructor.\n" |
| 82 "\n" |
| 83 ".. method:: __call__(it)\n" |
| 84 "\n" |
| 85 " Must be overload by inherited classes.\n" |
| 86 "\n" |
| 87 " :arg it: The Interface0DIterator pointing onto the Interface0D at\n" |
| 88 " which we wish to evaluate the predicate.\n" |
| 89 " :type it: :class:`Interface0DIterator`\n" |
| 90 " :return: True if the condition is satisfied, false otherwise.\n" |
| 91 " :rtype: bool\n"; |
| 92 |
| 93 static int UnaryPredicate0D___init__(BPy_UnaryPredicate0D *self, PyObject *args,
PyObject *kwds) |
| 94 { |
| 95 static const char *kwlist[] = {NULL}; |
| 96 |
| 97 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) |
| 98 return -1; |
| 99 self->up0D = new UnaryPredicate0D(); |
| 100 self->up0D->py_up0D = (PyObject *)self; |
| 101 return 0; |
| 102 } |
| 103 |
| 104 static void UnaryPredicate0D___dealloc__(BPy_UnaryPredicate0D* self) |
| 105 { |
| 106 if (self->up0D) |
| 107 delete self->up0D; |
| 108 Py_TYPE(self)->tp_free((PyObject*)self); |
| 109 } |
| 110 |
| 111 static PyObject * UnaryPredicate0D___repr__(BPy_UnaryPredicate0D* self) |
| 112 { |
| 113 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_
name, self->up0D); |
| 114 } |
| 115 |
| 116 static PyObject * UnaryPredicate0D___call__(BPy_UnaryPredicate0D *self, PyObject
*args, PyObject *kwds) |
| 117 { |
| 118 static const char *kwlist[] = {"it", NULL}; |
| 119 PyObject *py_if0D_it; |
| 120 |
| 121 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Int
erface0DIterator_Type, &py_if0D_it)) |
| 122 return NULL; |
| 123 |
| 124 Interface0DIterator *if0D_it = ((BPy_Interface0DIterator *)py_if0D_it)->
if0D_it; |
| 125 |
| 126 if (!if0D_it) { |
| 127 string class_name(Py_TYPE(self)->tp_name); |
| 128 PyErr_SetString(PyExc_RuntimeError, (class_name + " has no Inter
face0DIterator").c_str()); |
| 129 return NULL; |
| 130 } |
| 131 if (typeid(*(self->up0D)) == typeid(UnaryPredicate0D)) { |
| 132 PyErr_SetString(PyExc_TypeError, "__call__ method not properly o
verridden"); |
| 133 return NULL; |
| 134 } |
| 135 if (self->up0D->operator()(*if0D_it) < 0) { |
| 136 if (!PyErr_Occurred()) { |
| 137 string class_name(Py_TYPE(self)->tp_name); |
| 138 PyErr_SetString(PyExc_RuntimeError, (class_name + " __ca
ll__ method failed").c_str()); |
| 139 } |
| 140 return NULL; |
| 141 } |
| 142 return PyBool_from_bool(self->up0D->result); |
| 143 } |
| 144 |
| 145 /*----------------------UnaryPredicate0D get/setters ---------------------------
-*/ |
| 146 |
| 147 PyDoc_STRVAR(UnaryPredicate0D_name_doc, |
| 148 "The name of the unary 0D predicate.\n" |
| 149 "\n" |
| 150 ":type: str"); |
| 151 |
| 152 static PyObject *UnaryPredicate0D_name_get(BPy_UnaryPredicate0D *self, void *UNU
SED(closure)) |
| 153 { |
| 154 return PyUnicode_FromString(Py_TYPE(self)->tp_name); |
| 155 } |
| 156 |
| 157 static PyGetSetDef BPy_UnaryPredicate0D_getseters[] = { |
| 158 {(char *)"name", (getter)UnaryPredicate0D_name_get, (setter)NULL, (char
*)UnaryPredicate0D_name_doc, NULL}, |
| 159 {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ |
| 160 }; |
| 161 |
| 162 /*-----------------------BPy_UnaryPredicate0D type definition ------------------
------------*/ |
| 163 |
| 164 PyTypeObject UnaryPredicate0D_Type = { |
| 165 PyVarObject_HEAD_INIT(NULL, 0) |
| 166 "UnaryPredicate0D", /* tp_name */ |
| 167 sizeof(BPy_UnaryPredicate0D), /* tp_basicsize */ |
| 168 0, /* tp_itemsize */ |
| 169 (destructor)UnaryPredicate0D___dealloc__, /* tp_dealloc */ |
| 170 0, /* tp_print */ |
| 171 0, /* tp_getattr */ |
| 172 0, /* tp_setattr */ |
| 173 0, /* tp_reserved */ |
| 174 (reprfunc)UnaryPredicate0D___repr__, /* tp_repr */ |
| 175 0, /* tp_as_number */ |
| 176 0, /* tp_as_sequence */ |
| 177 0, /* tp_as_mapping */ |
| 178 0, /* tp_hash */ |
| 179 (ternaryfunc)UnaryPredicate0D___call__, /* tp_call */ |
| 180 0, /* tp_str */ |
| 181 0, /* tp_getattro */ |
| 182 0, /* tp_setattro */ |
| 183 0, /* tp_as_buffer */ |
| 184 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 185 UnaryPredicate0D___doc__, /* tp_doc */ |
| 186 0, /* tp_traverse */ |
| 187 0, /* tp_clear */ |
| 188 0, /* tp_richcompare */ |
| 189 0, /* tp_weaklistoffset */ |
| 190 0, /* tp_iter */ |
| 191 0, /* tp_iternext */ |
| 192 0, /* tp_methods */ |
| 193 0, /* tp_members */ |
| 194 BPy_UnaryPredicate0D_getseters, /* tp_getset */ |
| 195 0, /* tp_base */ |
| 196 0, /* tp_dict */ |
| 197 0, /* tp_descr_get */ |
| 198 0, /* tp_descr_set */ |
| 199 0, /* tp_dictoffset */ |
| 200 (initproc)UnaryPredicate0D___init__, /* tp_init */ |
| 201 0, /* tp_alloc */ |
| 202 PyType_GenericNew, /* tp_new */ |
| 203 }; |
| 204 |
| 205 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 206 |
| 207 #ifdef __cplusplus |
| 208 } |
| 209 #endif |
OLD | NEW |