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