ATLAS Offline Software
Loading...
Searching...
No Matches
PyReverseProxy.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef PYKERNEL_PYREVERSEPROXY_H
6#define PYKERNEL_PYREVERSEPROXY_H
7
13
14#ifdef _POSIX_C_SOURCE
15# undef _POSIX_C_SOURCE
16#endif
17#ifdef _XOPEN_SOURCE
18# undef _XOPEN_SOURCE
19#endif
20#include "Python.h"
21#include <unordered_map>
22#include <string>
25
26
28{
31 {
33 s_proxyMap.erase(m_key);
34 }
35
37 void setFunc (PyObject * func)
38 {
40 Py_DECREF(m_func);
41 m_func = func;
42 Py_INCREF(m_func);
43 }
44
45 // getter
46 void getObj (void *& obj)
47 {
48 obj = m_obj;
49 }
50
51 PyObject * toPyObj (void * obj)
52 {
54 m_obj = obj;
55 return PyObject_CallObject(m_func,NULL);
56 }
57
59 static PyReverseProxy * getProxy(const std::string & key)
60 {
62 PyReverseProxy* & prox = s_proxyMap[key];
63 if (!prox) {
64 prox = new PyReverseProxy(key);
65 }
66 return prox;
67 }
68
69private:
73
75 PyReverseProxy(const std::string &key)
76 : m_key(key), m_obj(0), m_func(0)
77 {}
78
80 std::string m_key;
81
83 void * m_obj;
84
87
90 static std::unordered_map<std::string, PyReverseProxy *> s_proxyMap ATLAS_THREAD_SAFE;
91};
92
93#endif
94
95
_object PyObject
Define macros for attributes used to control the static checker.
static std::unordered_map< std::string, PyReverseProxy * > s_proxyMap ATLAS_THREAD_SAFE
proxy map protected by the python GIL.
PyReverseProxy()
default constructor : never used
static PyReverseProxy * getProxy(const std::string &key)
factory method
~PyReverseProxy()
destructor
void * m_obj
C++ obj.
PyReverseProxy(const std::string &key)
constructor
void setFunc(PyObject *func)
setter
void getObj(void *&obj)
std::string m_key
key
PyObject * m_func
python code fragment to convert C++ obj to PyObj
PyObject * toPyObj(void *obj)