Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPGetSetItem.cxx
Go to the documentation of this file.
1// Bindings
2#include "CPyCppyy.h"
3#include "CPPGetSetItem.h"
4#include "Executors.h"
5
6
7//- protected members ---------------------------------------------------------
9{
10// basic call will do
11 if (!CPPMethod::InitExecutor_(executor))
12 return false;
13
14// check to make sure we're dealing with a RefExecutor
15 if (!dynamic_cast<RefExecutor*>(executor)) {
16 PyErr_Format(PyExc_NotImplementedError,
17 "no __setitem__ handler for return type (%s)",
18 this->GetReturnTypeName().c_str());
19 return false;
20 }
21
22 return true;
23}
24
25//-----------------------------------------------------------------------------
27 CPPInstance*& self, PyObject* args, PyObject* kwds)
28{
29// Prepare executor with a buffer for the return value.
30 Py_ssize_t nArgs = PyTuple_GET_SIZE(args);
31 if (nArgs <= 1) {
32 PyErr_SetString(PyExc_TypeError, "insufficient arguments to __setitem__");
33 return nullptr;
34 }
35
36// strip the last element of args to be used on return
37 ((RefExecutor*)this->GetExecutor())->SetAssignable(PyTuple_GET_ITEM(args, nArgs-1));
38 PyObject* subset = PyTuple_GetSlice(args, 0, nArgs-1);
39
40// see whether any of the arguments is a tuple itself
41 Py_ssize_t realsize = 0;
42 for (Py_ssize_t i = 0; i < nArgs - 1; ++i) {
43 PyObject* item = PyTuple_GET_ITEM(subset, i);
44 realsize += PyTuple_Check(item) ? PyTuple_GET_SIZE(item) : 1;
45 }
46
47// unroll any tuples, if present in the arguments
48 PyObject* unrolled = 0;
49 if (realsize != nArgs-1) {
50 unrolled = PyTuple_New(realsize);
51
52 int current = 0;
53 for (int i = 0; i < nArgs - 1; ++i, ++current) {
54 PyObject* item = PyTuple_GET_ITEM(subset, i);
55 if (PyTuple_Check(item)) {
56 for (int j = 0; j < PyTuple_GET_SIZE(item); ++j, ++current) {
57 PyObject* subitem = PyTuple_GET_ITEM(item, j);
58 Py_INCREF(subitem);
59 PyTuple_SET_ITEM(unrolled, current, subitem);
60 }
61 } else {
62 Py_INCREF(item);
63 PyTuple_SET_ITEM(unrolled, current, item);
64 }
65 }
66 }
67
68// continue normal method processing
69 PyObject* result = CPPMethod::PreProcessArgs(self, unrolled ? unrolled : subset, kwds);
70
71 Py_XDECREF(unrolled);
72 Py_DECREF(subset);
73 return result;
74}
75
76
77//-----------------------------------------------------------------------------
79 CPPInstance*& self, PyObject* args, PyObject* kwds)
80{
81// Unroll tuples for call, otherwise just like CPPMethod (this is very similar
82// to the code in CPPSetItem above, but subtly different in the details, hence
83// not factored out).
84 Py_ssize_t nArgs = PyTuple_GET_SIZE(args);
85
86// see whether any of the arguments is a tuple itself
87 Py_ssize_t realsize = 0;
88 for (Py_ssize_t i = 0; i < nArgs; ++i) {
89 PyObject* item = PyTuple_GET_ITEM(args, i);
90 realsize += PyTuple_Check(item) ? PyTuple_GET_SIZE(item) : 1;
91 }
92
93// unroll any tuples, if present in the arguments
94 PyObject* unrolled = 0;
95 if (realsize != nArgs-1) {
96 unrolled = PyTuple_New(realsize);
97
98 int current = 0;
99 for (int i = 0; i < nArgs; ++i, ++current) {
100 PyObject* item = PyTuple_GET_ITEM(args, i);
101 if (PyTuple_Check(item)) {
102 for (int j = 0; j < PyTuple_GET_SIZE(item); ++j, ++current) {
103 PyObject* subitem = PyTuple_GET_ITEM(item, j);
104 Py_INCREF(subitem);
105 PyTuple_SET_ITEM(unrolled, current, subitem);
106 }
107 } else {
108 Py_INCREF(item);
109 PyTuple_SET_ITEM(unrolled, current, item);
110 }
111 }
112 }
113
114// continue normal method processing
115 PyObject* result = CPPMethod::PreProcessArgs(self, unrolled ? unrolled : args, kwds);
116
117 Py_XDECREF(unrolled);
118 return result;
119}
_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
virtual PyObject * PreProcessArgs(CPPInstance *&self, PyObject *args, PyObject *kwds)
std::string GetReturnTypeName()
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
virtual PyObject * PreProcessArgs(CPPInstance *&self, PyObject *args, PyObject *kwds)
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
virtual PyObject * PreProcessArgs(CPPInstance *&self, PyObject *args, PyObject *kwds)