00001
00002
00003
00004 #ifndef PYROOT_METHODPROXY_H
00005 #define PYROOT_METHODPROXY_H
00006
00007
00008 #include "DllImport.h"
00009
00010
00011 #include "PyCallable.h"
00012
00013
00014 #include <map>
00015 #include <string>
00016 #include <vector>
00017
00018
00019 namespace PyROOT {
00020
00021
00022
00023
00024
00025
00026
00027 class MethodProxy {
00028 public:
00029 typedef std::map< Long_t, Int_t > DispatchMap_t;
00030 typedef std::vector< PyCallable* > Methods_t;
00031
00032 struct MethodInfo_t {
00033 MethodInfo_t() : fFlags( kNone ) { fRefCount = new int(1); }
00034 ~MethodInfo_t();
00035
00036 enum EMethodInfoFlags {
00037 kNone = 0,
00038 kIsSorted = 1,
00039 kIsCreator = 2,
00040 kIsConstructor = 4,
00041 kIsHeuristics = 8,
00042 kIsStrict = 16,
00043 kReleaseGIL = 32
00044 };
00045
00046 std::string fName;
00047 MethodProxy::DispatchMap_t fDispatchMap;
00048 MethodProxy::Methods_t fMethods;
00049 UInt_t fFlags;
00050
00051 int* fRefCount;
00052 };
00053
00054 public:
00055 void Set( const std::string& name, std::vector< PyCallable* >& methods );
00056
00057 const std::string& GetName() const { return fMethodInfo->fName; }
00058 void AddMethod( PyCallable* pc );
00059 void AddMethod( MethodProxy* meth );
00060
00061 public:
00062 PyObject_HEAD
00063 ObjectProxy* fSelf;
00064 MethodInfo_t* fMethodInfo;
00065
00066 private:
00067 MethodProxy() {}
00068 };
00069
00070
00071
00072 R__EXTERN PyTypeObject MethodProxy_Type;
00073
00074 template< typename T >
00075 inline Bool_t MethodProxy_Check( T* object )
00076 {
00077 return object && PyObject_TypeCheck( object, &MethodProxy_Type );
00078 }
00079
00080 template< typename T >
00081 inline Bool_t MethodProxy_CheckExact( T* object )
00082 {
00083 return object && Py_TYPE(object) == &MethodProxy_Type;
00084 }
00085
00086
00087 inline MethodProxy* MethodProxy_New(
00088 const std::string& name, std::vector< PyCallable* >& methods )
00089 {
00090 MethodProxy* pymeth = (MethodProxy*)MethodProxy_Type.tp_new( &MethodProxy_Type, 0, 0 );
00091 pymeth->Set( name, methods );
00092 return pymeth;
00093 }
00094
00095 inline MethodProxy* MethodProxy_New( const std::string& name, PyCallable* method )
00096 {
00097 std::vector< PyCallable* > p;
00098 p.push_back( method );
00099 return MethodProxy_New( name, p );
00100 }
00101
00102 }
00103
00104 #endif // !PYROOT_METHODPROXY_H