Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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)
31  PyObject* fPyClass;
32  PyObject* fPyName;
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
42  TemplateProxy() {}
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