00001
00002
00003
00004 #ifndef PYROOT_UTILITY_H
00005 #define PYROOT_UTILITY_H
00006
00007
00008 #include "DllImport.h"
00009
00010
00011 namespace Cint {
00012 class G__ClassInfo;
00013 }
00014
00015
00016 #include <map>
00017 #include <string>
00018
00019
00020 namespace PyROOT {
00021
00022 class PyCallable;
00023
00024 typedef PyDictEntry* (*DictLookup_t) ( PyDictObject*, PyObject*, Long_t );
00025 R__EXTERN DictLookup_t gDictLookupOrg;
00026 R__EXTERN Bool_t gDictLookupActive;
00027
00028
00029 union TParameter {
00030 Long_t fl;
00031 ULong_t ful;
00032 Long64_t fll;
00033 ULong64_t full;
00034 Double_t fd;
00035 void* fv;
00036 };
00037
00038
00039 ULong_t PyLongOrInt_AsULong( PyObject* pyobject );
00040 ULong64_t PyLongOrInt_AsULong64( PyObject* pyobject );
00041
00042 namespace Utility {
00043
00044
00045 Bool_t AddToClass( PyObject* pyclass, const char* label, PyCFunction cfunc,
00046 int flags = METH_VARARGS );
00047 Bool_t AddToClass( PyObject* pyclass, const char* label, const char* func );
00048 Bool_t AddToClass( PyObject* pyclass, const char* label, PyCallable* pyfunc );
00049
00050 Bool_t AddUsingToClass( PyObject* pyclass, const char* method );
00051
00052
00053 Bool_t AddBinaryOperator( PyObject* left, PyObject* right, const char* op, const char* label = "" );
00054 Bool_t AddBinaryOperator( PyObject* pyclass, const char* op, const char* label = "" );
00055 Bool_t AddBinaryOperator( PyObject* pyclass, const std::string& lcname, const std::string& rcname,
00056 const char* op, const char* label = "" );
00057
00058
00059 Bool_t BuildTemplateName( PyObject*& pyname, PyObject* args, int argoff );
00060
00061
00062 Bool_t InitProxy( PyObject* module, PyTypeObject* pytype, const char* name );
00063
00064
00065
00066
00067 int GetBuffer( PyObject* pyobject, char tc, int size, void*& buf, Bool_t check = kTRUE );
00068
00069
00070 enum EMemoryPolicy { kHeuristics = 1, kStrict = 2 };
00071 R__EXTERN EMemoryPolicy gMemoryPolicy;
00072 Bool_t SetMemoryPolicy( EMemoryPolicy e );
00073
00074
00075 enum ESignalPolicy { kFast = 1, kSafe = 2 };
00076 R__EXTERN ESignalPolicy gSignalPolicy;
00077 Bool_t SetSignalPolicy( ESignalPolicy e );
00078
00079
00080 const int kPtrMask = 0x10000000;
00081
00082 enum EDataType {
00083 kBool = 0x00000001,
00084 kChar = 0x00000002,
00085 kShort = 0x00000004,
00086 kInt = 0x00000008,
00087 kUInt = 0x00000010,
00088 kLong = 0x00000020,
00089 kULong = 0x00000040,
00090 kFloat = 0x00000080,
00091 kDouble = 0x00000100,
00092 kVoid = 0x00000200,
00093 kOther = 0x00000400,
00094 kLongLong = 0x00000800,
00095 kEnum = 0x00001000,
00096 kSTLString = 0x00002000,
00097 kMacro = 0x00004000,
00098 kString = kPtrMask | kChar,
00099 kDoublePtr = kPtrMask | kDouble,
00100 kFloatPtr = kPtrMask | kFloat,
00101 kLongPtr = kPtrMask | kLong,
00102 kIntPtr = kPtrMask | kInt,
00103 kVoidPtr = kPtrMask | kVoid
00104 };
00105
00106
00107 std::string MapOperatorName( const std::string& name, Bool_t bTakesParames );
00108
00109
00110 EDataType EffectiveType( const std::string& name );
00111 const std::string Compound( const std::string& name );
00112 const std::string ClassName( PyObject* pyobj );
00113
00114
00115 void ErrMsgCallback( char* msg );
00116 void ErrMsgHandler( int level, Bool_t abort, const char* location, const char* msg );
00117
00118
00119 Long_t InstallMethod( Cint::G__ClassInfo* scope, PyObject* callback,
00120 const std::string& mtName, const char* rtype, const char* signature,
00121 void* func, Int_t npar = 0, Long_t extra = 0 );
00122
00123 PyObject* GetInstalledMethod( int tagnum, Long_t* extra = 0 );
00124
00125
00126 PyObject* PyErr_Occurred_WithGIL();
00127
00128 }
00129
00130 }
00131
00132 #endif // !PYROOT_UTILITY_H