Logo ROOT   6.12/07
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 
13 namespace 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 
24  class TemplateProxy {
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 >
56  inline Bool_t TemplateProxy_CheckExact( T* object )
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.
65  TemplateProxy* pytmpl = (TemplateProxy*)TemplateProxy_Type.tp_new( &TemplateProxy_Type, 0, 0 );
66  pytmpl->Set( name, pyclass );
67  return pytmpl;
68  }
69 
70 } // namespace PyROOT
71 
72 #endif // !PYROOT_TEMPLATEPROXY_H
void AddOverload(MethodProxy *mp)
Store overloads of this templated method.
double T(double x)
Definition: ChebyshevPol.h:34
MethodProxy * fNonTemplated
Definition: TemplateProxy.h:33
bool Bool_t
Definition: RtypesCore.h:59
TemplateProxy * TemplateProxy_New(const std::string &name, PyObject *pyclass)
Definition: TemplateProxy.h:62
MethodProxy * fTemplated
Definition: TemplateProxy.h:34
PyObject_HEAD PyObject * fSelf
Definition: TemplateProxy.h:30
Bool_t TemplateProxy_CheckExact(T *object)
Definition: TemplateProxy.h:56
void AddTemplate(PyCallable *pc)
PyTypeObject TemplateProxy_Type
void Set(const std::string &name, PyObject *pyclass)
Initialize the proxy for the given &#39;pyclass.&#39;.
#define R__EXTERN
Definition: DllImport.h:27
#define Py_TYPE(ob)
Definition: PyROOT.h:151
static constexpr double pc
Template proxy object to return functions and methods.
Definition: TemplateProxy.h:24
char name[80]
Definition: TGX11.cxx:109
Bool_t TemplateProxy_Check(T *object)
Definition: TemplateProxy.h:50
_object PyObject
Definition: TPyArg.h:20