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:
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 PyObject* GetSignature(bool show_formalargs = true) override;
54 PyObject* GetPrototype(bool show_formalargs = true) override;
55 PyObject* GetTypeName() override;
58
59 int GetPriority() override;
60 bool IsGreedy() override;
61
62 int GetMaxArgs() override;
63 PyObject* GetCoVarNames() override;
64 PyObject* GetArgDefault(int iarg, bool silent=true) override;
65 bool IsConst() override;
66
67 PyObject* GetScopeProxy() override;
69
70 PyCallable* Clone() override { return new CPPMethod(*this); }
71
73
74public:
76 CPyCppyy_PyArgs_t args, size_t nargsf, PyObject* kwds, CallContext* ctxt = nullptr) override;
77
78protected:
79 virtual bool ProcessArgs(PyCallArgs& args);
80
81 bool Initialize(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()
PyObject * GetSignature(bool show_formalargs=true) override
bool Initialize(CallContext *ctxt=nullptr)
bool ProcessKwds(PyObject *self_in, PyCallArgs &args)
void SetPyError_(PyObject *msg)
Cppyy::TCppScope_t fScope
Definition CPPMethod.h:109
virtual bool ProcessArgs(PyCallArgs &args)
int GetPriority() override
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
int GetArgMatchScore(PyObject *args_tuple) override
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
std::vector< Converter * > fConverters
Definition CPPMethod.h:113
PyObject * GetTypeName() override
PyObject * ExecuteFast(void *, ptrdiff_t, CallContext *)
PyObject * Execute(void *self, ptrdiff_t offset, CallContext *ctxt=nullptr)
Cppyy::TCppFuncAddr_t GetFunctionAddress() override
void Copy_(const CPPMethod &)
Definition CPPMethod.cxx:88
Executor * fExecutor
Definition CPPMethod.h:110
PyObject * GetCoVarNames() override
bool IsConst() override
PyObject * GetPrototype(bool show_formalargs=true) override
Construct a Python string from the method's prototype.
Cppyy::TCppMethod_t fMethod
Definition CPPMethod.h:108
Cppyy::TCppScope_t GetScope()
Definition CPPMethod.h:87
PyCallable * Clone() override
Definition CPPMethod.h:70
PyObject * GetArgDefault(int iarg, bool silent=true) override
int GetMaxArgs() override
bool VerifyArgCount_(Py_ssize_t)
Definition CPPMethod.cxx:68
bool IsGreedy() override
CPPMethod & operator=(const CPPMethod &)
Cppyy::TCppMethod_t GetMethod()
Definition CPPMethod.h:86
CPPMethod(Cppyy::TCppScope_t scope, Cppyy::TCppMethod_t method)
Executor * GetExecutor()
Definition CPPMethod.h:88
PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t=Cppyy::Reflex::OPTIMAL) override
PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr) override
PyObject * GetScopeProxy() override
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