Blender V4.5
BPy_BinaryPredicate0D.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BPy_Convert.h"
12#include "BPy_Interface0D.h"
13
14using namespace Freestyle;
15
17
18//-------------------MODULE INITIALIZATION--------------------------------
20{
21 if (module == nullptr) {
22 return -1;
23 }
24
25 if (PyType_Ready(&BinaryPredicate0D_Type) < 0) {
26 return -1;
27 }
28 PyModule_AddObjectRef(module, "BinaryPredicate0D", (PyObject *)&BinaryPredicate0D_Type);
29
30 return 0;
31}
32
33//------------------------INSTANCE METHODS ----------------------------------
34
36 /* Wrap. */
37 BinaryPredicate0D___doc__,
38 "Base class for binary predicates working on :class:`Interface0D`\n"
39 "objects. A BinaryPredicate0D is typically an ordering relation\n"
40 "between two Interface0D objects. The predicate evaluates a relation\n"
41 "between the two Interface0D instances and returns a boolean value (true\n"
42 "or false). It is used by invoking the __call__() method.\n"
43 "\n"
44 ".. method:: __init__()\n"
45 "\n"
46 " Default constructor.\n"
47 "\n"
48 ".. method:: __call__(inter1, inter2)\n"
49 "\n"
50 " Must be overload by inherited classes. It evaluates a relation\n"
51 " between two Interface0D objects.\n"
52 "\n"
53 " :arg inter1: The first Interface0D object.\n"
54 " :type inter1: :class:`Interface0D`\n"
55 " :arg inter2: The second Interface0D object.\n"
56 " :type inter2: :class:`Interface0D`\n"
57 " :return: True or false.\n"
58 " :rtype: bool\n");
59
60static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
61{
62 static const char *kwlist[] = {nullptr};
63
64 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
65 return -1;
66 }
67 self->bp0D = new BinaryPredicate0D();
68 self->bp0D->py_bp0D = (PyObject *)self;
69 return 0;
70}
71
73{
74 delete self->bp0D;
75
76 Py_TYPE(self)->tp_free((PyObject *)self);
77}
78
80{
81 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp0D);
82}
83
85 PyObject *args,
86 PyObject *kwds)
87{
88 static const char *kwlist[] = {"inter1", "inter2", nullptr};
89 BPy_Interface0D *obj1, *obj2;
90
91 if (!PyArg_ParseTupleAndKeywords(
92 args, kwds, "O!O!", (char **)kwlist, &Interface0D_Type, &obj1, &Interface0D_Type, &obj2))
93 {
94 return nullptr;
95 }
96 if (typeid(*(self->bp0D)) == typeid(BinaryPredicate0D)) {
97 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
98 return nullptr;
99 }
100 if (self->bp0D->operator()(*(obj1->if0D), *(obj2->if0D)) < 0) {
101 if (!PyErr_Occurred()) {
102 string class_name(Py_TYPE(self)->tp_name);
103 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
104 }
105 return nullptr;
106 }
107 return PyBool_from_bool(self->bp0D->result);
108}
109
110/*----------------------BinaryPredicate0D get/setters ----------------------------*/
111
113 /* Wrap. */
114 BinaryPredicate0D_name_doc,
115 "The name of the binary 0D predicate.\n"
116 "\n"
117 ":type: str");
118
119static PyObject *BinaryPredicate0D_name_get(BPy_BinaryPredicate0D *self, void * /*closure*/)
120{
121 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
122}
123
124static PyGetSetDef BPy_BinaryPredicate0D_getseters[] = {
125 {"name",
127 (setter) nullptr,
128 BinaryPredicate0D_name_doc,
129 nullptr},
130 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
131};
132
133/*-----------------------BPy_BinaryPredicate0D type definition ------------------------------*/
134
136 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
137 /*tp_name*/ "BinaryPredicate0D",
138 /*tp_basicsize*/ sizeof(BPy_BinaryPredicate0D),
139 /*tp_itemsize*/ 0,
140 /*tp_dealloc*/ (destructor)BinaryPredicate0D___dealloc__,
141 /*tp_vectorcall_offset*/ 0,
142 /*tp_getattr*/ nullptr,
143 /*tp_setattr*/ nullptr,
144 /*tp_as_async*/ nullptr,
145 /*tp_repr*/ (reprfunc)BinaryPredicate0D___repr__,
146 /*tp_as_number*/ nullptr,
147 /*tp_as_sequence*/ nullptr,
148 /*tp_as_mapping*/ nullptr,
149 /*tp_hash*/ nullptr,
150 /*tp_call*/ (ternaryfunc)BinaryPredicate0D___call__,
151 /*tp_str*/ nullptr,
152 /*tp_getattro*/ nullptr,
153 /*tp_setattro*/ nullptr,
154 /*tp_as_buffer*/ nullptr,
155 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
156 /*tp_doc*/ BinaryPredicate0D___doc__,
157 /*tp_traverse*/ nullptr,
158 /*tp_clear*/ nullptr,
159 /*tp_richcompare*/ nullptr,
160 /*tp_weaklistoffset*/ 0,
161 /*tp_iter*/ nullptr,
162 /*tp_iternext*/ nullptr,
163 /*tp_methods*/ nullptr,
164 /*tp_members*/ nullptr,
166 /*tp_base*/ nullptr,
167 /*tp_dict*/ nullptr,
168 /*tp_descr_get*/ nullptr,
169 /*tp_descr_set*/ nullptr,
170 /*tp_dictoffset*/ 0,
171 /*tp_init*/ (initproc)BinaryPredicate0D___init__,
172 /*tp_alloc*/ nullptr,
173 /*tp_new*/ PyType_GenericNew,
174};
175
PyTypeObject BinaryPredicate0D_Type
static PyObject * BinaryPredicate0D___call__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
static void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D *self)
static PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D *self)
static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_BinaryPredicate0D_getseters[]
PyDoc_STRVAR(BinaryPredicate0D___doc__, "Base class for binary predicates working on :class:`Interface0D`\n" "objects. A BinaryPredicate0D is typically an ordering relation\n" "between two Interface0D objects. The predicate evaluates a relation\n" "between the two Interface0D instances and returns a boolean value (true\n" "or false). It is used by invoking the __call__() method.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Must be overload by inherited classes. It evaluates a relation\n" " between two Interface0D objects.\n" "\n" " :arg inter1: The first Interface0D object.\n" " :type inter1: :class:`Interface0D`\n" " :arg inter2: The second Interface0D object.\n" " :type inter2: :class:`Interface0D`\n" " :return: True or false.\n" " :rtype: bool\n")
static PyObject * BinaryPredicate0D_name_get(BPy_BinaryPredicate0D *self, void *)
int BinaryPredicate0D_Init(PyObject *module)
PyObject * PyBool_from_bool(bool b)
PyTypeObject Interface0D_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796
PyObject_HEAD Freestyle::Interface0D * if0D