Logo ROOT  
Reference Guide
TemplateProxy.h
Go to the documentation of this file.
1// Author: Wim Lavrijsen, Jan 2008
2
3#ifndef PYROOT_TEMPLATEPROXY_H
4#define PYROOT_TEMPLATEPROXY_H
5
6// ROOT
7#include "DllImport.h"
8
9// Standard
10#include <string>
11
12
13namespace PyROOT {
14
15 class PyCallable;
16 class MethodProxy;
17
18/** Template proxy object to return functions and methods
19 @author WLAV
20 @date 01/15/2008
21 @version 1.0
22 */
23
25 public:
26 void Set( const std::string& name, PyObject* pyclass );
27
28 public: // public, as the python C-API works with C structs
29 PyObject_HEAD
30 PyObject* fSelf; // must be first (same layout as MethodProxy)
33 MethodProxy* fNonTemplated; // holder for non-template overloads
34 MethodProxy* fTemplated; // holder for templated overloads
35
36 public:
37 void AddOverload( MethodProxy* mp );
38 void AddOverload( PyCallable* pc );
39 void AddTemplate( PyCallable* pc );
40
41 private: // private, as the python C-API will handle creation
43 };
44
45
46//- template proxy type and type verification --------------------------------
47 R__EXTERN PyTypeObject TemplateProxy_Type;
48
49 template< typename T >
50 inline Bool_t TemplateProxy_Check( T* object )
51 {
52 return object && PyObject_TypeCheck( object, &TemplateProxy_Type );
53 }
54
55 template< typename T >
57 {
58 return object && Py_TYPE(object) == &TemplateProxy_Type;
59 }
60
61//- creation -----------------------------------------------------------------
62 inline TemplateProxy* TemplateProxy_New( const std::string& name, PyObject* pyclass )
63 {
64 // Create and initialize a new template method proxy for the class.
66 pytmpl->Set( name, pyclass );
67 return pytmpl;
68 }
69
70} // namespace PyROOT
71
72#endif // !PYROOT_TEMPLATEPROXY_H
#define R__EXTERN
Definition: DllImport.h:27
#define Py_TYPE(ob)
Definition: PyROOT.h:166
bool Bool_t
Definition: RtypesCore.h:59
char name[80]
Definition: TGX11.cxx:109
_object PyObject
Definition: TPyArg.h:20
Template proxy object to return functions and methods.
Definition: TemplateProxy.h:24
MethodProxy * fNonTemplated
Definition: TemplateProxy.h:33
void AddOverload(MethodProxy *mp)
Store overloads of this templated method.
void Set(const std::string &name, PyObject *pyclass)
Initialize the proxy for the given 'pyclass.'.
PyObject_HEAD PyObject * fSelf
Definition: TemplateProxy.h:30
void AddTemplate(PyCallable *pc)
MethodProxy * fTemplated
Definition: TemplateProxy.h:34
Bool_t TemplateProxy_Check(T *object)
Definition: TemplateProxy.h:50
TemplateProxy * TemplateProxy_New(const std::string &name, PyObject *pyclass)
Definition: TemplateProxy.h:62
PyTypeObject TemplateProxy_Type
Bool_t TemplateProxy_CheckExact(T *object)
Definition: TemplateProxy.h:56
double T(double x)
Definition: ChebyshevPol.h:34
static constexpr double pc