forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.h
More file actions
87 lines (63 loc) · 3.16 KB
/
Utility.h
File metadata and controls
87 lines (63 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// @(#)root/pyroot:$Id$
// Author: Wim Lavrijsen, Apr 2004
#ifndef PYROOT_UTILITY_H
#define PYROOT_UTILITY_H
// Standard
#include <map>
#include <string>
#include <vector>
namespace PyROOT {
class PyCallable;
R__EXTERN dict_lookup_func gDictLookupOrg;
R__EXTERN Bool_t gDictLookupActive;
// additional converter functions
ULong_t PyLongOrInt_AsULong( PyObject* pyobject );
ULong64_t PyLongOrInt_AsULong64( PyObject* pyobject );
namespace Utility {
// convenience functions for adding methods to classes
Bool_t AddToClass( PyObject* pyclass, const char* label, PyCFunction cfunc,
int flags = METH_VARARGS );
Bool_t AddToClass( PyObject* pyclass, const char* label, const char* func );
Bool_t AddToClass( PyObject* pyclass, const char* label, PyCallable* pyfunc );
Bool_t AddUsingToClass( PyObject* pyclass, const char* method );
// helpers for dynamically constructing binary operators
Bool_t AddBinaryOperator( PyObject* left, PyObject* right,
const char* op, const char* label, const char* alt_label = NULL );
Bool_t AddBinaryOperator( PyObject* pyclass,
const char* op, const char* label, const char* alt_label = NULL );
Bool_t AddBinaryOperator( PyObject* pyclass, const std::string& lcname, const std::string& rcname,
const char* op, const char* label, const char* alt_label = NULL );
// helper for template classes and methods
PyObject* BuildTemplateName( PyObject* pyname, PyObject* args, int argoff );
// initialize proxy type objects
Bool_t InitProxy( PyObject* module, PyTypeObject* pytype, const char* name );
// retrieve the memory buffer from pyobject, return buflength, tc (optional) is python
// array.array type code, size is type size, buf will point to buffer, and if check is
// true, some heuristics will be applied to check buffer compatibility with the type
int GetBuffer( PyObject* pyobject, char tc, int size, void*& buf, Bool_t check = kTRUE );
// data/operator mappings
std::string MapOperatorName( const std::string& name, Bool_t bTakesParames );
// meta information
const std::string Compound( const std::string& name );
Py_ssize_t ArraySize( const std::string& name );
const std::string ClassName( PyObject* pyobj );
// CINT integration
void ErrMsgCallback( char* msg );
void ErrMsgHandler( int level, Bool_t abort, const char* location, const char* msg );
// create a wrapper for the python function with Cling; returns function pointer
void* CreateWrapperMethod( PyObject* pyfunc, Long_t user,
const char* retType, const std::vector<std::string>& signature, const char* callback );
// for threading: save call to PyErr_Occurred()
PyObject* PyErr_Occurred_WithGIL();
// for GUI driving; install/remove event callback
PyObject* InstallGUIEventInputHook();
PyObject* RemoveGUIEventInputHook();
} // namespace Utility
class PyGILRAII {
PyGILState_STATE m_GILState;
public:
PyGILRAII():m_GILState(PyGILState_Ensure()){}
~PyGILRAII(){PyGILState_Release(m_GILState);}
};
} // namespace PyROOT
#endif // !PYROOT_UTILITY_H