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:
38 CPPOverload* fNonTemplated; // holder for non-template overloads
39 CPPOverload* fTemplated; // holder for templated overloads
40 CPPOverload* fLowPriority; // low priority overloads such as void*/void**
42
44
45 uint64_t fFlags; // collective for all methods
46};
47
48typedef std::shared_ptr<TemplateInfo> TP_TInfo_t;
49
51private:
53 const std::string& cppname, const std::string& pyname, PyObject* pyclass);
54 void Set(const std::string& cppname, const std::string& pyname, PyObject* pyclass);
55
56public: // public, as the python C-API works with C structs
57 PyObject_HEAD
58 PyObject* fSelf; // must be first (same layout as CPPOverload)
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 PyObject* tmplArgs, 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:217
_object PyObject
#define pyname
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, PyObject *tmplArgs, 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)
Set of helper functions that are invoked from the pythonizors, on the Python side.
std::pair< uint64_t, CPPOverload * > TP_DispatchEntry_t
Template proxy object to return functions and methods.
bool CPPScope_Check(T *object)
Definition CPPScope.h:76
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