Utility.h

Go to the documentation of this file.
00001 // @(#)root/pyroot:$Id: Utility.h 36042 2010-10-03 13:05:27Z wlav $
00002 // Author: Wim Lavrijsen, Apr 2004
00003 
00004 #ifndef PYROOT_UTILITY_H
00005 #define PYROOT_UTILITY_H
00006 
00007 // ROOT
00008 #include "DllImport.h"
00009 
00010 // CINT
00011 namespace Cint {
00012    class G__ClassInfo;
00013 }
00014 
00015 // Standard
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 // general place holder for function parameters
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 // additional converter functions
00039    ULong_t PyLongOrInt_AsULong( PyObject* pyobject );
00040    ULong64_t PyLongOrInt_AsULong64( PyObject* pyobject );
00041 
00042    namespace Utility {
00043 
00044    // convenience functions for adding methods to classes
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    // helpers for dynamically constructing binary operators
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    // helper for template classes and methods
00059       Bool_t BuildTemplateName( PyObject*& pyname, PyObject* args, int argoff );
00060 
00061    // initialize proxy type objects
00062       Bool_t InitProxy( PyObject* module, PyTypeObject* pytype, const char* name );
00063 
00064    // retrieve the memory buffer from pyobject, return buflength, tc (optional) is python
00065    // array.array type code, size is type size, buf will point to buffer, and if check is
00066    // true, some heuristics will be applied to check buffer compatibility with the type
00067       int GetBuffer( PyObject* pyobject, char tc, int size, void*& buf, Bool_t check = kTRUE );
00068 
00069    // memory handling
00070       enum EMemoryPolicy { kHeuristics = 1, kStrict = 2 };
00071       R__EXTERN EMemoryPolicy gMemoryPolicy;
00072       Bool_t SetMemoryPolicy( EMemoryPolicy e );
00073 
00074    // signal safety
00075       enum ESignalPolicy { kFast = 1, kSafe = 2 };
00076       R__EXTERN ESignalPolicy gSignalPolicy;
00077       Bool_t SetSignalPolicy( ESignalPolicy e );
00078 
00079    // data/return types
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    // data/operator mappings
00107       std::string MapOperatorName( const std::string& name, Bool_t bTakesParames );
00108 
00109    // meta information
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    // CINT integration
00115       void ErrMsgCallback( char* msg );
00116       void ErrMsgHandler( int level, Bool_t abort, const char* location, const char* msg );
00117 
00118    // install a python function with CINT; returns identifier
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    // for threading: save call to PyErr_Occurred()
00126       PyObject* PyErr_Occurred_WithGIL();
00127 
00128    } // namespace Utility
00129 
00130 } // namespace PyROOT
00131 
00132 #endif // !PYROOT_UTILITY_H

Generated on Tue Jul 5 14:10:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1