Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPOverload.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_CPPOVERLOAD_H
2#define CPYCPPYY_CPPOVERLOAD_H
3
4// Bindings
5#include "PyCallable.h"
6
7// Standard
8#include <cstdint>
9#include <map>
10#include <string>
11#include <utility>
12#include <vector>
13
14
15namespace CPyCppyy {
16
17// Signature hashing for memoization (implementation in CPPOverload.cxx)
18uint64_t HashSignature(CPyCppyy_PyArgs_t args, size_t nargsf);
19
21public:
22 typedef std::vector<std::pair<uint64_t, PyCallable*>> DispatchMap_t;
23 typedef std::vector<PyCallable*> Methods_t;
24
42
43public:
44 void Set(const std::string& name, std::vector<PyCallable*>& methods);
45 void AdoptMethod(PyCallable* pc);
47
48 const std::string& GetName() const { return fMethodInfo->fName; }
49 bool HasMethods() const { return !fMethodInfo->fMethods.empty(); }
50
51// find a method based on the provided signature
52 PyObject* FindOverload(const std::string& signature, int want_const = -1);
54
55public: // public, as the python C-API works with C structs
57 CPPInstance* fSelf; // must be first (same layout as TemplateProxy)
59 uint32_t fFlags;
60#if PY_VERSION_HEX >= 0x03080000
62#endif
63
64private:
65 CPPOverload() = delete;
66};
67
68
69//- method proxy type and type verification ----------------------------------
71
72template<typename T>
73inline bool CPPOverload_Check(T* object)
74{
75 return object && PyObject_TypeCheck(object, &CPPOverload_Type);
76}
77
78template<typename T>
79inline bool CPPOverload_CheckExact(T* object)
80{
81 return object && Py_TYPE(object) == &CPPOverload_Type;
82}
83
84//- creation -----------------------------------------------------------------
86 const std::string& name, std::vector<PyCallable*>& methods)
87{
88// Create and initialize a new method proxy from the overloads.
89 CPPOverload* pymeth = (CPPOverload*)CPPOverload_Type.tp_new(&CPPOverload_Type, nullptr, nullptr);
90 pymeth->Set(name, methods);
91 return pymeth;
92}
93
94inline CPPOverload* CPPOverload_New(const std::string& name, PyCallable* method)
95{
96// Create and initialize a new method proxy from the method.
97 std::vector<PyCallable*> p;
98 p.push_back(method);
99 return CPPOverload_New(name, p);
100}
101
102} // namespace CPyCppyy
103
104#endif // !CPYCPPYY_CPPOVERLOAD_H
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
PyObject * CPyCppyy_PyArgs_t
Definition CPyCppyy.h:330
_object PyObject
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:110
#define CPYCPPYY_IMPORT
Definition CommonDefs.h:32
void MergeOverload(CPPOverload *meth)
void AdoptMethod(PyCallable *pc)
MethodInfo_t * fMethodInfo
Definition CPPOverload.h:58
PyObject * FindOverload(const std::string &signature, int want_const=-1)
PyObject_HEAD CPPInstance * fSelf
Definition CPPOverload.h:57
const std::string & GetName() const
Definition CPPOverload.h:48
std::vector< PyCallable * > Methods_t
Definition CPPOverload.h:23
std::vector< std::pair< uint64_t, PyCallable * > > DispatchMap_t
Definition CPPOverload.h:22
bool HasMethods() const
Definition CPPOverload.h:49
void Set(const std::string &name, std::vector< PyCallable * > &methods)
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable * > &methods)
Definition CPPOverload.h:85
bool CPPOverload_Check(T *object)
Definition CPPOverload.h:73
uint64_t HashSignature(CPyCppyy_PyArgs_t args, size_t nargsf)
PyTypeObject CPPOverload_Type
bool CPPOverload_CheckExact(T *object)
Definition CPPOverload.h:79
CPPOverload::DispatchMap_t fDispatchMap
Definition CPPOverload.h:31
MethodInfo_t(const MethodInfo_t &)=delete
MethodInfo_t & operator=(const MethodInfo_t &)=delete
CPPOverload::Methods_t fMethods
Definition CPPOverload.h:32