ATLAS Offline Software
Loading...
Searching...
No Matches
PyReverseProxy Struct Reference

A utility class to convert a C++ object to a PyObject. More...

#include <PyReverseProxy.h>

Collaboration diagram for PyReverseProxy:

Public Member Functions

 ~PyReverseProxy ()
 destructor
void setFunc (PyObject *func)
 setter
void getObj (void *&obj)
PyObjecttoPyObj (void *obj)

Static Public Member Functions

static PyReverseProxygetProxy (const std::string &key)
 factory method

Private Member Functions

 PyReverseProxy ()
 default constructor : never used
 PyReverseProxy (const std::string &key)
 constructor

Private Attributes

std::string m_key
 key
void * m_obj
 C++ obj.
PyObjectm_func
 python code fragment to convert C++ obj to PyObj

Static Private Attributes

static std::unordered_map< std::string, PyReverseProxy * > s_proxyMap ATLAS_THREAD_SAFE
 proxy map protected by the python GIL.

Detailed Description

A utility class to convert a C++ object to a PyObject.

Author
Tadashi Maeno

Definition at line 27 of file PyReverseProxy.h.

Constructor & Destructor Documentation

◆ ~PyReverseProxy()

PyReverseProxy::~PyReverseProxy ( )
inline

destructor

Definition at line 30 of file PyReverseProxy.h.

31 {
32 RootUtils::PyGILStateEnsure gil;
33 s_proxyMap.erase(m_key);
34 }
std::string m_key
key

◆ PyReverseProxy() [1/2]

PyReverseProxy::PyReverseProxy ( )
inlineprivate

default constructor : never used

Definition at line 71 of file PyReverseProxy.h.

72 {}

◆ PyReverseProxy() [2/2]

PyReverseProxy::PyReverseProxy ( const std::string & key)
inlineprivate

constructor

Definition at line 75 of file PyReverseProxy.h.

76 : m_key(key), m_obj(0), m_func(0)
77 {}
void * m_obj
C++ obj.
PyObject * m_func
python code fragment to convert C++ obj to PyObj

Member Function Documentation

◆ getObj()

void PyReverseProxy::getObj ( void *& obj)
inline

Definition at line 46 of file PyReverseProxy.h.

47 {
48 obj = m_obj;
49 }

◆ getProxy()

PyReverseProxy * PyReverseProxy::getProxy ( const std::string & key)
inlinestatic

factory method

Definition at line 59 of file PyReverseProxy.h.

60 {
61 RootUtils::PyGILStateEnsure gil;
62 PyReverseProxy* & prox = s_proxyMap[key];
63 if (!prox) {
64 prox = new PyReverseProxy(key);
65 }
66 return prox;
67 }
PyReverseProxy()
default constructor : never used

◆ setFunc()

void PyReverseProxy::setFunc ( PyObject * func)
inline

setter

Definition at line 37 of file PyReverseProxy.h.

38 {
39 RootUtils::PyGILStateEnsure gil;
40 Py_DECREF(m_func);
41 m_func = func;
42 Py_INCREF(m_func);
43 }

◆ toPyObj()

PyObject * PyReverseProxy::toPyObj ( void * obj)
inline

Definition at line 51 of file PyReverseProxy.h.

52 {
53 RootUtils::PyGILStateEnsure gil;
54 m_obj = obj;
55 return PyObject_CallObject(m_func,NULL);
56 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::unordered_map<std::string, PyReverseProxy *> s_proxyMap PyReverseProxy::ATLAS_THREAD_SAFE
staticprivate

proxy map protected by the python GIL.

Definition at line 90 of file PyReverseProxy.h.

◆ m_func

PyObject* PyReverseProxy::m_func
private

python code fragment to convert C++ obj to PyObj

Definition at line 86 of file PyReverseProxy.h.

◆ m_key

std::string PyReverseProxy::m_key
private

key

Definition at line 80 of file PyReverseProxy.h.

◆ m_obj

void* PyReverseProxy::m_obj
private

C++ obj.

Definition at line 83 of file PyReverseProxy.h.


The documentation for this struct was generated from the following file: