Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPFunction.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "CPPFunction.h"
4#include "CPPInstance.h"
5
6
7//- CPPFunction public members --------------------------------------------------
9 CPPInstance*& self, PyObject* args, PyObject* kwds)
10{
11// add self as part of the function arguments (means bound member)
12 if (kwds) return this->ProcessKeywords((PyObject*)self, args, kwds);
13
14 Py_ssize_t sz = PyTuple_GET_SIZE(args);
15 PyObject* newArgs = PyTuple_New(sz+1);
16 for (int i = 0; i < sz; ++i) {
17 PyObject* item = PyTuple_GET_ITEM(args, i);
18 Py_INCREF(item);
19 PyTuple_SET_ITEM(newArgs, i+1, item);
20 }
21
22 Py_INCREF(self);
23 PyTuple_SET_ITEM(newArgs, 0, (PyObject*)self);
24
25 return newArgs;
26}
27
28//---------------------------------------------------------------------------
30 CPPInstance*& self, PyObject* args, PyObject* kwds, CallContext* ctxt)
31{
32// setup as necessary
33 if (fArgsRequired == -1 && !this->Initialize(ctxt))
34 return nullptr;
35
36// if function was attached to a class, self will be non-zero and should be
37// the first function argument, so reorder
38 if (self || kwds) {
39 if (!(args = this-> PreProcessArgs(self, args, kwds)))
40 return nullptr;
41 }
42
43// translate the arguments as normal
44 bool bConvertOk = this->ConvertAndSetArgs(args, ctxt);
45
46 if (self || kwds) Py_DECREF(args);
47
48 if (bConvertOk == false)
49 return nullptr;
50
51// execute function
52 return this->Execute(nullptr, 0, ctxt);
53}
54
55
56//- CPPReverseBinary public members ---------------------------------------------
58 CPPInstance*& self, PyObject* args, PyObject* kwds)
59{
60 if (self || kwds) {
61 // add self as part of the function arguments (means bound member)
62 if (!(args = this->CPPFunction::PreProcessArgs(self, args, kwds)))
63 return nullptr;
64 }
65
66// swap the arguments
67 PyObject* tmp = PyTuple_GET_ITEM(args, 0);
68 PyTuple_SET_ITEM(args, 0, PyTuple_GET_ITEM(args, 1));
69 PyTuple_SET_ITEM(args, 1, tmp);
70
71 return args;
72}
73
74//---------------------------------------------------------------------------
76 CPPInstance*& self, PyObject* args, PyObject* kwds, CallContext* ctxt)
77{
78// This Call() function is very similar to the one of CPPFunction: only
79// difference is that PreProcessArgs() is always called.
80
81// setup as necessary
82 if (fArgsRequired == -1 && !this->Initialize(ctxt))
83 return nullptr;
84
85// if function was attached to a class, self will be non-zero and should be
86// the first function argument, further, the arguments needs swapping
87 if (!(args = this->PreProcessArgs(self, args, kwds)))
88 return nullptr;
89
90// translate the arguments as normal
91 bool bConvertOk = this->ConvertAndSetArgs(args, ctxt);
92
93 if (self || kwds) Py_DECREF(args);
94
95 if (bConvertOk == false)
96 return nullptr;
97
98// execute function
99 return this->Execute(nullptr, 0, ctxt);
100}
_object PyObject
virtual PyObject * Call(CPPInstance *&, PyObject *args, PyObject *kwds, CallContext *ctx=nullptr)
virtual PyObject * PreProcessArgs(CPPInstance *&self, PyObject *args, PyObject *kwds)
PyObject * ProcessKeywords(PyObject *self, PyObject *args, PyObject *kwds)
virtual PyObject * Call(CPPInstance *&, PyObject *args, PyObject *kwds, CallContext *ctx=nullptr)
virtual PyObject * PreProcessArgs(CPPInstance *&self, PyObject *args, PyObject *kwds)