Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TemplateProxy.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_TEMPLATEPROXY_H
2#define CPYCPPYY_TEMPLATEPROXY_H
3
4// Bindings
5#include "CPPScope.h"
6#include "Utility.h"
7
8// Standard
9#include <map>
10#include <memory>
11#include <string>
12#include <utility>
13#include <vector>
14
15
16namespace CPyCppyy {
17
18class PyCallable;
19class CPPOverload;
20
21/** Template proxy object to return functions and methods
22 */
23
24typedef std::pair<uint64_t, CPPOverload*> TP_DispatchEntry_t;
25typedef std::map<std::string, std::vector<TP_DispatchEntry_t>> TP_DispatchMap_t;
26
28public:
30 TemplateInfo(const TemplateInfo&) = delete;
33
34public:
35 std::string fCppName;
37 CPPOverload* fNonTemplated; // holder for non-template overloads
38 CPPOverload* fTemplated; // holder for templated overloads
39 CPPOverload* fLowPriority; // low priority overloads such as void*/void**
40
43};
44
45typedef std::shared_ptr<TemplateInfo> TP_TInfo_t;
46
48private:
50 const std::string& cppname, const std::string& pyname, PyObject* pyclass);
51 void Set(const std::string& cppname, const std::string& pyname, PyObject* pyclass);
52
53public: // public, as the python C-API works with C structs
54 PyObject_HEAD
55 PyObject* fSelf; // must be first (same layout as CPPOverload)
58#if PY_VERSION_HEX >= 0x03080000
59 vectorcallfunc fVectorCall;
60#endif
62
63public:
64 void MergeOverload(CPPOverload* mp);
65 void AdoptMethod(PyCallable* pc);
66 void AdoptTemplate(PyCallable* pc);
67 PyObject* Instantiate(const std::string& fname,
68 CPyCppyy_PyArgs_t tmplArgs, size_t nargsf, Utility::ArgPreference, int* pcnt = nullptr);
69
70private: // private, as the python C-API will handle creation
71 TemplateProxy() = delete;
72};
73
74
75//- template proxy type and type verification --------------------------------
76extern PyTypeObject TemplateProxy_Type;
77
78template<typename T>
79inline bool TemplateProxy_Check(T* object)
80{
81 return object && PyObject_TypeCheck(object, &TemplateProxy_Type);
82}
83
84template<typename T>
85inline bool TemplateProxy_CheckExact(T* object)
86{
87 return object && Py_TYPE(object) == &TemplateProxy_Type;
88}
89
90//- creation -----------------------------------------------------------------
92 const std::string& cppname, const std::string& pyname, PyObject* pyclass)
93{
94// Create and initialize a new template method proxy for the class.
95 if (!CPPScope_Check(pyclass)) return nullptr;
96
97 TemplateProxy* pytmpl =
98 (TemplateProxy*)TemplateProxy_Type.tp_new(&TemplateProxy_Type, nullptr, nullptr);
99 pytmpl->Set(cppname, pyname, pyclass);
100 return pytmpl;
101}
102
103} // namespace CPyCppyy
104
105#endif // !CPYCPPYY_TEMPLATEPROXY_H
#define Py_TYPE(ob)
Definition CPyCppyy.h:196
PyObject * CPyCppyy_PyArgs_t
Definition CPyCppyy.h:330
_object PyObject
CPPOverload * fTemplated
TemplateInfo & operator=(const TemplateInfo &)=delete
TemplateInfo(const TemplateInfo &)=delete
CPPOverload * fLowPriority
TP_DispatchMap_t fDispatchMap
CPPOverload * fNonTemplated
PyObject * Instantiate(const std::string &fname, CPyCppyy_PyArgs_t tmplArgs, size_t nargsf, Utility::ArgPreference, int *pcnt=nullptr)
void Set(const std::string &cppname, const std::string &pyname, PyObject *pyclass)
PyObject_HEAD PyObject * fSelf
void AdoptTemplate(PyCallable *pc)
friend TemplateProxy * TemplateProxy_New(const std::string &cppname, const std::string &pyname, PyObject *pyclass)
void AdoptMethod(PyCallable *pc)
void MergeOverload(CPPOverload *mp)
std::pair< uint64_t, CPPOverload * > TP_DispatchEntry_t
Template proxy object to return functions and methods.
bool CPPScope_Check(T *object)
Definition CPPScope.h:81
bool TemplateProxy_CheckExact(T *object)
PyTypeObject TemplateProxy_Type
std::map< std::string, std::vector< TP_DispatchEntry_t > > TP_DispatchMap_t
bool TemplateProxy_Check(T *object)
TemplateProxy * TemplateProxy_New(const std::string &cppname, const std::string &pyname, PyObject *pyclass)
std::shared_ptr< TemplateInfo > TP_TInfo_t