Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPMethod.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_CPPMETHOD_H
2#define CPYCPPYY_CPPMETHOD_H
3
4// Bindings
5#include "PyCallable.h"
6
7// Standard
8#include <map>
9#include <string>
10#include <vector>
11
12
13namespace CPyCppyy {
14
15class Executor;
16class Converter;
17
19public:
20 PyCallArgs(CPPInstance*& self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds)
21 : fSelf(self), fArgs(args), fNArgsf(nargsf), fKwds(kwds), fFlags(kNone) {}
23
25 kNone = 0x0000,
26 kIsOffset = 0x0001, // args were offset by 1 to drop self
27 kSelfSwap = 0x0002, // args[-1] and self need swapping
28 kArgsSwap = 0x0004, // args[0] and args[1] need swapping
29#if PY_VERSION_HEX >= 0x03080000
30 kDoFree = 0x0008, // args need to be free'd (vector call only)
31 kDoItemDecref = 0x0010 // items in args need a decref (vector call only)
32#else
33 kDoDecref = 0x0020 // args need a decref
34#endif
35 };
36
37public:
40 size_t fNArgsf;
42 int fFlags;
43};
44
45class CPPMethod : public PyCallable {
46public:
48 CPPMethod(const CPPMethod&);
50 virtual ~CPPMethod();
51
52public:
53 virtual PyObject* GetSignature(bool show_formalargs = true);
54 virtual PyObject* GetPrototype(bool show_formalargs = true);
55 virtual PyObject* GetTypeName();
58
59 virtual int GetPriority();
60 virtual bool IsGreedy();
61
62 virtual int GetMaxArgs();
63 virtual PyObject* GetCoVarNames();
64 virtual PyObject* GetArgDefault(int iarg, bool silent=true);
65 virtual bool IsConst();
66
67 virtual PyObject* GetScopeProxy();
69
70 virtual PyCallable* Clone() { return new CPPMethod(*this); }
71
72 virtual int GetArgMatchScore(PyObject* args_tuple);
73
74public:
75 virtual PyObject* Call(CPPInstance*& self,
76 CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds, CallContext* ctxt = nullptr);
77
78protected:
79 virtual bool ProcessArgs(PyCallArgs& args);
80
81 bool Initialize(CallContext* ctxt = nullptr);
82 bool ProcessKwds(PyObject* self_in, PyCallArgs& args);
83 bool ConvertAndSetArgs(CPyCppyy_PyArgs_t, size_t nargsf, CallContext* ctxt = nullptr);
84 PyObject* Execute(void* self, ptrdiff_t offset, CallContext* ctxt = nullptr);
85
89 std::string GetSignatureString(bool show_formalargs = true);
90 std::string GetReturnTypeName();
91
92 virtual bool InitExecutor_(Executor*&, CallContext* ctxt = nullptr);
93
94private:
95 void Copy_(const CPPMethod&);
96 void Destroy_();
98
99 PyObject* ExecuteFast(void*, ptrdiff_t, CallContext*);
100 PyObject* ExecuteProtected(void*, ptrdiff_t, CallContext*);
101
102 bool InitConverters_();
103
104 void SetPyError_(PyObject* msg);
105
106private:
107// representation
111
112// call dispatch buffers
113 std::vector<Converter*> fConverters;
114 std::map<std::string, int>* fArgIndices;
115
116protected:
117// cached value that doubles as initialized flag (uninitialized if -1)
119};
120
121} // namespace CPyCppyy
122
123#endif // !CPYCPPYY_CPPMETHOD_H
int Py_ssize_t
Definition CPyCppyy.h:215
PyObject * CPyCppyy_PyArgs_t
Definition CPyCppyy.h:330
_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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
std::string GetReturnTypeName()
bool Initialize(CallContext *ctxt=nullptr)
bool ProcessKwds(PyObject *self_in, PyCallArgs &args)
void SetPyError_(PyObject *msg)
virtual PyObject * GetSignature(bool show_formalargs=true)
Cppyy::TCppScope_t fScope
Definition CPPMethod.h:109
virtual bool ProcessArgs(PyCallArgs &args)
virtual PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t=Cppyy::Reflex::OPTIMAL)
virtual int GetArgMatchScore(PyObject *args_tuple)
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
virtual bool IsConst()
virtual PyObject * GetPrototype(bool show_formalargs=true)
Construct a Python string from the method's prototype.
std::string GetSignatureString(bool show_formalargs=true)
PyObject * ExecuteProtected(void *, ptrdiff_t, CallContext *)
bool ConvertAndSetArgs(CPyCppyy_PyArgs_t, size_t nargsf, CallContext *ctxt=nullptr)
std::map< std::string, int > * fArgIndices
Definition CPPMethod.h:114
virtual PyObject * GetCoVarNames()
std::vector< Converter * > fConverters
Definition CPPMethod.h:113
virtual PyObject * GetScopeProxy()
PyObject * ExecuteFast(void *, ptrdiff_t, CallContext *)
PyObject * Execute(void *self, ptrdiff_t offset, CallContext *ctxt=nullptr)
void Copy_(const CPPMethod &)
Definition CPPMethod.cxx:88
virtual int GetPriority()
Executor * fExecutor
Definition CPPMethod.h:110
Cppyy::TCppMethod_t fMethod
Definition CPPMethod.h:108
Cppyy::TCppScope_t GetScope()
Definition CPPMethod.h:87
virtual PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr)
virtual PyCallable * Clone()
Definition CPPMethod.h:70
virtual PyObject * GetArgDefault(int iarg, bool silent=true)
virtual bool IsGreedy()
bool VerifyArgCount_(Py_ssize_t)
Definition CPPMethod.cxx:68
CPPMethod & operator=(const CPPMethod &)
virtual int GetMaxArgs()
Cppyy::TCppMethod_t GetMethod()
Definition CPPMethod.h:86
Executor * GetExecutor()
Definition CPPMethod.h:88
virtual PyObject * GetTypeName()
virtual Cppyy::TCppFuncAddr_t GetFunctionAddress()
CPyCppyy_PyArgs_t fArgs
Definition CPPMethod.h:39
CPPInstance *& fSelf
Definition CPPMethod.h:38
PyCallArgs(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds)
Definition CPPMethod.h:20
const FormatId_t OPTIMAL
Definition Reflex.h:22
intptr_t TCppMethod_t
Definition cpp_cppyy.h:22
size_t TCppScope_t
Definition cpp_cppyy.h:18
void * TCppFuncAddr_t
Definition cpp_cppyy.h:25