55template <
typename T, PyCFunction dispatcher>
struct FunctionTypeDispatcher
57 static PyObject* fun(PyObject* self, PyObject* args) {
return dispatcher(self,args); }
58 typedef PyCFunction OverloadType;
62template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::UnarySlot ,DispatcherAddress>
64 static PyObject* fun(PyObject* iSelf)
67 return DispatcherAddress(iSelf, args.get());
72template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::BinarySlot ,DispatcherAddress>
74 static PyObject* fun(PyObject* iSelf, PyObject* iOther)
76 TPyObjPtr args(Py_BuildValue(
"(O)", iOther));
77 return DispatcherAddress(iSelf, args.get());
82template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::TernarySlot ,DispatcherAddress>
84 static PyObject* fun(PyObject* iSelf, PyObject* iOther, PyObject* iThird)
86 TPyObjPtr args(Py_BuildValue(
"(O,O)", iOther, iThird));
87 PyObject* result = DispatcherAddress(iSelf, args.get());
88 if (!result && PyErr_ExceptionMatches(PyExc_TypeError) && iThird == Py_None)
92 TPyObjPtr args2(Py_BuildValue(
"(O)", iOther));
93 return DispatcherAddress(iSelf, args2.get());
100template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::SsizeArgSlot ,DispatcherAddress>
102 static PyObject* fun(PyObject* iSelf, Py_ssize_t iSize)
104 TPyObjPtr args(Py_BuildValue(
"(n)", iSize));
105 return DispatcherAddress(iSelf,args.get());
110template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::SsizeSsizeArgSlot ,DispatcherAddress>
112 static PyObject* fun(PyObject* iSelf, Py_ssize_t iSize, Py_ssize_t iSize2)
114 TPyObjPtr args(Py_BuildValue(
"(n,n)", iSize, iSize2));
115 return DispatcherAddress(iSelf,args.get());
120template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::LenSlot ,DispatcherAddress>
122 static Py_ssize_t fun(PyObject* iSelf)
125 TPyObjPtr temp(DispatcherAddress(iSelf,args.get()));
129 if (pyGetSimpleObject(temp.get(), result) != 0)
136template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::SsizeObjArgSlot ,DispatcherAddress>
138 static int fun(PyObject * iSelf, Py_ssize_t iSize, PyObject * iOther)
140 TPyObjPtr args(Py_BuildValue(
"(n,O)",iSize,iOther));
141 TPyObjPtr temp(DispatcherAddress(iSelf,args.get()));
142 return temp ? 0 : -1;
147template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::SsizeSsizeObjArgSlot ,DispatcherAddress>
149 static int fun(PyObject * iSelf, Py_ssize_t iSize, Py_ssize_t iSize2, PyObject * iOther)
151 TPyObjPtr args(Py_BuildValue(
"(n,n,O)",iSize,iSize2,iOther));
152 TPyObjPtr temp(DispatcherAddress(iSelf,args.get()));
153 return temp ? 0 : -1;
158template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::ObjObjSlot ,DispatcherAddress>
160 static int fun(PyObject * iSelf, PyObject * iOther)
162 TPyObjPtr args(Py_BuildValue(
"(O)",iOther));
163 TPyObjPtr temp(DispatcherAddress(iSelf,args.get()));
167 if (pyGetSimpleObject(temp.get(), result) != 0)
175template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::ObjObjArgSlot, DispatcherAddress>
177 static int fun(PyObject* self, PyObject* key, PyObject* value)
185 ? Py_BuildValue(
"(O,O)", key, value)
186 : Py_BuildValue(
"(O)", key));
187 TPyObjPtr temp(DispatcherAddress(self, args.get()));
190 LASS_ASSERT(!PyErr_Occurred());
193 if (!PyErr_Occurred())
195 PyErr_SetString(PyExc_AssertionError,
"ObjObjArgSlot: expected return value or exception.");
202template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::IterSlot ,DispatcherAddress>
204 static PyObject* fun(PyObject* iSelf)
207 return DispatcherAddress(iSelf, args.get());
212template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::IterNextSlot ,DispatcherAddress>
214 static PyObject* fun(PyObject* iSelf)
217 return DispatcherAddress(iSelf, args.get());
222template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::ArgKwSlot ,DispatcherAddress>
224 static PyObject* fun(PyObject* iSelf, PyObject* iArgs, PyObject* iKw)
228 if (!PyDict_CheckExact(iKw))
230 PyErr_BadInternalCall();
233 if (PyDict_Size(iKw) != 0)
235 PyErr_SetString(PyExc_TypeError,
"function takes no keyword arguments");
239 return DispatcherAddress(iSelf, iArgs);
244template <PyCFunction DispatcherAddress>
struct FunctionTypeDispatcher<lass::python::impl::InquirySlot ,DispatcherAddress>
246 static int fun(PyObject* iSelf)
249 TPyObjPtr temp(DispatcherAddress(iSelf,args.get()));
253 if (pyGetSimpleObject(temp.get(), result) != 0)
PyObjectPtr< PyObject >::Type TPyObjPtr
PyObjectPtr to a PyObject.
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.