Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPOperator.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "CPPOperator.h"
4#include "CPPInstance.h"
5#include "Utility.h"
6
7
8//- constructor --------------------------------------------------------------
12{
13// a bit silly but doing it this way allows decoupling the initialization order
14 if (name == "__mul__")
15 fStub = CPPInstance_Type.tp_as_number->nb_multiply;
16 else if (name == CPPYY__div__)
17#if PY_VERSION_HEX < 0x03000000
18 fStub = CPPInstance_Type.tp_as_number->nb_divide;
19#else
20 fStub = CPPInstance_Type.tp_as_number->nb_true_divide;
21#endif
22 else if (name == "__add__")
23 fStub = CPPInstance_Type.tp_as_number->nb_add;
24 else if (name == "__sub__")
25 fStub = CPPInstance_Type.tp_as_number->nb_subtract;
26 else
27 fStub = nullptr;
28}
29
30//-----------------------------------------------------------------------------
33{
34// some operators can be a mix of global and class overloads; this method will
35// first try class overloads (the existence of this method means that such were
36// defined) and if failed, fall back on the global stubs
37// TODO: the fact that this is a method and not an overload means that the global
38// ones are tried for each method that fails during the overload resolution
39 PyObject* result = this->CPPMethod::Call(self, args, nargsf, kwds, ctxt);
40 if (result || !fStub || !self)
41 return result;
42
44 if (CPyCppyy_PyArgs_GET_SIZE(args, nargsf) != 1) {
45#if PY_VERSION_HEX >= 0x03080000
46 if ((CPyCppyy_PyArgs_GET_SIZE(args, nargsf) == 2 && CPyCppyy_PyArgs_GET_ITEM(args, 0) == (PyObject*)self))
47 idx_other = 1;
48 else
49#endif
50 return result;
51 }
52
53// fetch the current error, resetting the error buffer
55
57
58// if there was still a problem, restore the Python error buffer
59 if (!result) {
61 }
62
63 return result;
64}
#define CPPYY__div__
Definition CPyCppyy.h:111
static Py_ssize_t CPyCppyy_PyArgs_GET_SIZE(CPyCppyy_PyArgs_t args, size_t)
Definition CPyCppyy.h:337
PyObject * CPyCppyy_PyArgs_t
Definition CPyCppyy.h:330
static PyObject * CPyCppyy_PyArgs_GET_ITEM(CPyCppyy_PyArgs_t args, Py_ssize_t i)
Definition CPyCppyy.h:331
_object PyObject
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition TGX11.cxx:110
virtual PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr)
virtual PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr)
CPPOperator(Cppyy::TCppScope_t scope, Cppyy::TCppMethod_t method, const std::string &name)
void RestorePyError(PyError_t &error)
Definition Utility.cxx:1102
PyError_t FetchPyError()
Definition Utility.cxx:1082
PyTypeObject CPPInstance_Type
intptr_t TCppMethod_t
Definition cpp_cppyy.h:22
size_t TCppScope_t
Definition cpp_cppyy.h:18