Blender V5.0
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");
59static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
60{
61 static const char *kwlist[] = {nullptr};
62
63 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
64 return -1;
65 }
66 self->bp0D = new BinaryPredicate0D();
67 self->bp0D->py_bp0D = (PyObject *)self;
68 return 0;
69}
70
72{
73 delete self->bp0D;
74
75 Py_TYPE(self)->tp_free((PyObject *)self);
76}
77
79{
80 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->bp0D);
81}
82
84 PyObject *args,
85 PyObject *kwds)
86{
87 static const char *kwlist[] = {"inter1", "inter2", nullptr};
88 BPy_Interface0D *obj1, *obj2;
89
90 if (!PyArg_ParseTupleAndKeywords(
91 args, kwds, "O!O!", (char **)kwlist, &Interface0D_Type, &obj1, &Interface0D_Type, &obj2))
92 {
93 return nullptr;
94 }
95 if (typeid(*(self->bp0D)) == typeid(BinaryPredicate0D)) {
96 PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
97 return nullptr;
98 }
99 if (self->bp0D->operator()(*(obj1->if0D), *(obj2->if0D)) < 0) {
100 if (!PyErr_Occurred()) {
101 string class_name(Py_TYPE(self)->tp_name);
102 PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
103 }
104 return nullptr;
105 }
106 return PyBool_from_bool(self->bp0D->result);
107}
108
109/*----------------------BinaryPredicate0D get/setters ----------------------------*/
110
112 /* Wrap. */
113 BinaryPredicate0D_name_doc,
114 "The name of the binary 0D predicate.\n"
115 "\n"
116 ":type: str\n");
117static PyObject *BinaryPredicate0D_name_get(BPy_BinaryPredicate0D *self, void * /*closure*/)
118{
119 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
120}
121
122static PyGetSetDef BPy_BinaryPredicate0D_getseters[] = {
123 {"name",
125 (setter) nullptr,
126 BinaryPredicate0D_name_doc,
127 nullptr},
128 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
129};
130
131/*-----------------------BPy_BinaryPredicate0D type definition ------------------------------*/
132
134 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
135 /*tp_name*/ "BinaryPredicate0D",
136 /*tp_basicsize*/ sizeof(BPy_BinaryPredicate0D),
137 /*tp_itemsize*/ 0,
138 /*tp_dealloc*/ (destructor)BinaryPredicate0D___dealloc__,
139 /*tp_vectorcall_offset*/ 0,
140 /*tp_getattr*/ nullptr,
141 /*tp_setattr*/ nullptr,
142 /*tp_as_async*/ nullptr,
143 /*tp_repr*/ (reprfunc)BinaryPredicate0D___repr__,
144 /*tp_as_number*/ nullptr,
145 /*tp_as_sequence*/ nullptr,
146 /*tp_as_mapping*/ nullptr,
147 /*tp_hash*/ nullptr,
148 /*tp_call*/ (ternaryfunc)BinaryPredicate0D___call__,
149 /*tp_str*/ nullptr,
150 /*tp_getattro*/ nullptr,
151 /*tp_setattro*/ nullptr,
152 /*tp_as_buffer*/ nullptr,
153 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
154 /*tp_doc*/ BinaryPredicate0D___doc__,
155 /*tp_traverse*/ nullptr,
156 /*tp_clear*/ nullptr,
157 /*tp_richcompare*/ nullptr,
158 /*tp_weaklistoffset*/ 0,
159 /*tp_iter*/ nullptr,
160 /*tp_iternext*/ nullptr,
161 /*tp_methods*/ nullptr,
162 /*tp_members*/ nullptr,
164 /*tp_base*/ nullptr,
165 /*tp_dict*/ nullptr,
166 /*tp_descr_get*/ nullptr,
167 /*tp_descr_set*/ nullptr,
168 /*tp_dictoffset*/ 0,
169 /*tp_init*/ (initproc)BinaryPredicate0D___init__,
170 /*tp_alloc*/ nullptr,
171 /*tp_new*/ PyType_GenericNew,
172};
173
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