Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Executors.h
Go to the documentation of this file.
1 // @(#)root/pyroot:$Id$
2 // Author: Wim Lavrijsen, Jan 2005
3 #ifndef PYROOT_EXECUTORS_H
4 #define PYROOT_EXECUTORS_H
5 
6 // Bindings
7 #include "TCallContext.h"
8 
9 // Standard
10 #include <string>
11 #include <map>
12 
13 
14 namespace PyROOT {
15 
16  class TExecutor {
17  public:
18  virtual ~TExecutor() {}
19  virtual PyObject* Execute(
20  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* ) = 0;
21  };
22 
23 #define PYROOT_DECLARE_BASIC_EXECUTOR( name ) \
24  class T##name##Executor : public TExecutor { \
25  public: \
26  virtual PyObject* Execute( \
27  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* ); \
28  }
29 
30 // executors for built-ins
31  PYROOT_DECLARE_BASIC_EXECUTOR( Bool );
32  PYROOT_DECLARE_BASIC_EXECUTOR( BoolConstRef );
33  PYROOT_DECLARE_BASIC_EXECUTOR( Char );
34  PYROOT_DECLARE_BASIC_EXECUTOR( CharConstRef );
35  PYROOT_DECLARE_BASIC_EXECUTOR( UChar );
36  PYROOT_DECLARE_BASIC_EXECUTOR( UCharConstRef );
37  PYROOT_DECLARE_BASIC_EXECUTOR( Short );
38  PYROOT_DECLARE_BASIC_EXECUTOR( Int );
39  PYROOT_DECLARE_BASIC_EXECUTOR( Long );
40  PYROOT_DECLARE_BASIC_EXECUTOR( ULong );
41  PYROOT_DECLARE_BASIC_EXECUTOR( LongLong );
42  PYROOT_DECLARE_BASIC_EXECUTOR( ULongLong );
43  PYROOT_DECLARE_BASIC_EXECUTOR( Float );
44  PYROOT_DECLARE_BASIC_EXECUTOR( Double );
45  PYROOT_DECLARE_BASIC_EXECUTOR( LongDouble );
46  PYROOT_DECLARE_BASIC_EXECUTOR( Void );
47  PYROOT_DECLARE_BASIC_EXECUTOR( CString );
48 
49 // pointer/array executors
50  PYROOT_DECLARE_BASIC_EXECUTOR( VoidArray );
51  PYROOT_DECLARE_BASIC_EXECUTOR( BoolArray );
52  PYROOT_DECLARE_BASIC_EXECUTOR( ShortArray );
53  PYROOT_DECLARE_BASIC_EXECUTOR( UShortArray );
54  PYROOT_DECLARE_BASIC_EXECUTOR( CharArray );
55  PYROOT_DECLARE_BASIC_EXECUTOR( UCharArray );
56  PYROOT_DECLARE_BASIC_EXECUTOR( IntArray );
57  PYROOT_DECLARE_BASIC_EXECUTOR( UIntArray );
58  PYROOT_DECLARE_BASIC_EXECUTOR( LongArray );
59  PYROOT_DECLARE_BASIC_EXECUTOR( ULongArray );
60  PYROOT_DECLARE_BASIC_EXECUTOR( FloatArray );
61  PYROOT_DECLARE_BASIC_EXECUTOR( DoubleArray );
62 
63 // special cases
64  PYROOT_DECLARE_BASIC_EXECUTOR( STLString );
65  PYROOT_DECLARE_BASIC_EXECUTOR( TGlobal );
66 
67  class TCppObjectExecutor : public TExecutor {
68  public:
69  TCppObjectExecutor( Cppyy::TCppType_t klass ) : fClass( klass ) {}
70  virtual PyObject* Execute(
71  Cppyy::TCppMethod_t, Cppyy::TCppObject_t,TCallContext* );
72 
73  protected:
74  Cppyy::TCppType_t fClass;
75  };
76 
77  class TCppObjectByValueExecutor : public TCppObjectExecutor {
78  public:
79  using TCppObjectExecutor::TCppObjectExecutor;
80  virtual PyObject* Execute(
81  Cppyy::TCppMethod_t, Cppyy::TCppObject_t,TCallContext* );
82  };
83 
84  class TRefExecutor : public TExecutor {
85  public:
86  TRefExecutor() : fAssignable( 0 ) {}
87 
88  public:
89  virtual Bool_t SetAssignable( PyObject* );
90 
91  protected:
92  PyObject* fAssignable;
93  };
94 
95  PYROOT_DECLARE_BASIC_EXECUTOR( Constructor );
96  PYROOT_DECLARE_BASIC_EXECUTOR( PyObject );
97 
98 #define PYROOT_DECLARE_BASIC_REFEXECUTOR( name ) \
99  class T##name##RefExecutor : public TRefExecutor { \
100  public: \
101  virtual PyObject* Execute( \
102  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* ); \
103  }
104 
105  PYROOT_DECLARE_BASIC_REFEXECUTOR( Bool );
106  PYROOT_DECLARE_BASIC_REFEXECUTOR( Char );
107  PYROOT_DECLARE_BASIC_REFEXECUTOR( UChar );
108  PYROOT_DECLARE_BASIC_REFEXECUTOR( Short );
109  PYROOT_DECLARE_BASIC_REFEXECUTOR( UShort );
110  PYROOT_DECLARE_BASIC_REFEXECUTOR( Int );
111  PYROOT_DECLARE_BASIC_REFEXECUTOR( UInt );
112  PYROOT_DECLARE_BASIC_REFEXECUTOR( Long );
113  PYROOT_DECLARE_BASIC_REFEXECUTOR( ULong );
114  PYROOT_DECLARE_BASIC_REFEXECUTOR( LongLong );
115  PYROOT_DECLARE_BASIC_REFEXECUTOR( ULongLong );
116  PYROOT_DECLARE_BASIC_REFEXECUTOR( Float );
117  PYROOT_DECLARE_BASIC_REFEXECUTOR( Double );
118  PYROOT_DECLARE_BASIC_REFEXECUTOR( LongDouble );
119  PYROOT_DECLARE_BASIC_REFEXECUTOR( STLString );
120 
121 // special cases
122  class TCppObjectRefExecutor : public TRefExecutor {
123  public:
124  TCppObjectRefExecutor( Cppyy::TCppType_t klass ) : fClass( klass ) {}
125  virtual PyObject* Execute(
126  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* );
127 
128  protected:
129  Cppyy::TCppType_t fClass;
130  };
131 
132  class TCppObjectPtrPtrExecutor : public TCppObjectExecutor {
133  public:
134  using TCppObjectExecutor::TCppObjectExecutor;
135  virtual PyObject* Execute(
136  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* );
137  };
138 
139  class TCppObjectPtrRefExecutor : public TCppObjectExecutor {
140  public:
141  using TCppObjectExecutor::TCppObjectExecutor;
142  virtual PyObject* Execute(
143  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* );
144  };
145 
146  class TCppObjectArrayExecutor : public TCppObjectExecutor {
147  public:
148  TCppObjectArrayExecutor( Cppyy::TCppType_t klass, Py_ssize_t array_size )
149  : TCppObjectExecutor ( klass ), fArraySize( array_size ) {}
150  virtual PyObject* Execute(
151  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* );
152 
153  protected:
154  Py_ssize_t fArraySize;
155  };
156 
157 // smart pointer executors
158  class TCppObjectBySmartPtrExecutor : public TExecutor {
159  public:
160  TCppObjectBySmartPtrExecutor( Cppyy::TCppType_t klass, Cppyy::TCppType_t rawPtrType,
161  Cppyy::TCppMethod_t deref ) : fClass( klass ), fRawPtrType( rawPtrType ), fDereferencer( deref ) {}
162 
163  virtual PyObject* Execute(
164  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* );
165 
166  protected:
167  Cppyy::TCppType_t fClass;
168  Cppyy::TCppType_t fRawPtrType;
169  Cppyy::TCppMethod_t fDereferencer;
170  };
171 
172  class TCppObjectBySmartPtrPtrExecutor : public TCppObjectBySmartPtrExecutor {
173  public:
174  using TCppObjectBySmartPtrExecutor::TCppObjectBySmartPtrExecutor;
175 
176  virtual PyObject* Execute(
177  Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext* );
178  };
179 
180  class TCppObjectBySmartPtrRefExecutor : public TRefExecutor {
181  public:
182  TCppObjectBySmartPtrRefExecutor( Cppyy::TCppType_t klass, Cppyy::TCppType_t rawPtrType,
183  Cppyy::TCppMethod_t deref ) : fClass( klass ), fRawPtrType( rawPtrType ), fDereferencer( deref ) {}
184 
185  virtual PyObject* Execute(
186  Cppyy::TCppMethod_t, Cppyy::TCppObject_t,TCallContext* );
187 
188  protected:
189  Cppyy::TCppType_t fClass;
190  Cppyy::TCppType_t fRawPtrType;
191  Cppyy::TCppMethod_t fDereferencer;
192  };
193 
194 // create executor from fully qualified type
195  TExecutor* CreateExecutor( const std::string& fullType,
196  Bool_t manage_smart_ptr = kTRUE );
197 
198 } // namespace PyROOT
199 
200 #endif // !PYROOT_EXECUTORS_H