/usr/include/tulip/PythonInterpreter.cxx is in libtulip-dev 4.6.0dfsg-2+b5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | /**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
TLP_PYTHON_SCOPE void decrefPyObject(PyObject *obj);
template<typename T>
bool PythonInterpreter::evalSingleStatementAndGetValue(const QString &pythonStatement, T &value) {
holdGIL();
PyObject *ret = evalPythonStatement(pythonStatement);
bool ok = false;
if (ret) {
PyObjectToCppObjectConvertor<T> convertor;
ok = convertor.convert(ret, value);
decrefPyObject(ret);
}
releaseGIL();
return ok;
}
template<typename PARAM_TYPE>
bool PythonInterpreter::callFunctionOneParam(const QString &module, const QString &function, const PARAM_TYPE ¶meter) {
tlp::DataSet parameters;
parameters.set("param1", parameter);
return callFunction(module, function, parameters);
}
template<typename PARAM1_TYPE, typename PARAM2_TYPE>
bool PythonInterpreter::callFunctionTwoParams(const QString &module, const QString &function, const PARAM1_TYPE ¶meter1, const PARAM2_TYPE ¶meter2) {
tlp::DataSet parameters;
parameters.set("param1", parameter1);
parameters.set("param2", parameter2);
return callFunction(module, function, parameters);
}
template<typename PARAM1_TYPE, typename PARAM2_TYPE, typename PARAM3_TYPE>
bool PythonInterpreter::callFunctionThreeParams(const QString &module, const QString &function, const PARAM1_TYPE ¶meter1, const PARAM2_TYPE ¶meter2,
const PARAM3_TYPE ¶meter3) {
tlp::DataSet parameters;
parameters.set("param1", parameter1);
parameters.set("param2", parameter2);
parameters.set("param3", parameter3);
return callFunction(module, function, parameters);
}
template<typename PARAM1_TYPE, typename PARAM2_TYPE, typename PARAM3_TYPE, typename PARAM4_TYPE>
bool PythonInterpreter::callFunctionFourParams(const QString &module, const QString &function, const PARAM1_TYPE ¶meter1, const PARAM2_TYPE ¶meter2,
const PARAM3_TYPE ¶meter3, const PARAM4_TYPE ¶meter4) {
tlp::DataSet parameters;
parameters.set("param1", parameter1);
parameters.set("param2", parameter2);
parameters.set("param3", parameter3);
parameters.set("param4", parameter4);
return callFunction(module, function, parameters);
}
template<typename PARAM_TYPE, typename RETURN_TYPE>
bool PythonInterpreter::callFunctionOneParamAndGetReturnValue(const QString &module, const QString &function, const PARAM_TYPE ¶meter, RETURN_TYPE &returnValue) {
tlp::DataSet parameters;
parameters.set("param1", parameter);
return callFunctionAndGetReturnValue(module, function, parameters, returnValue);
}
template<typename PARAM1_TYPE, typename PARAM2_TYPE, typename RETURN_TYPE>
bool PythonInterpreter::callFunctionTwoParamsAndGetReturnValue(const QString &module, const QString &function, const PARAM1_TYPE ¶meter1,
const PARAM2_TYPE ¶meter2, RETURN_TYPE &returnValue) {
tlp::DataSet parameters;
parameters.set("param1", parameter1);
parameters.set("param2", parameter2);
return callFunctionAndGetReturnValue(module, function, parameters, returnValue);
}
template<typename PARAM1_TYPE, typename PARAM2_TYPE, typename PARAM3_TYPE, typename RETURN_TYPE>
bool PythonInterpreter::callFunctionThreeParamsAndGetReturnValue(const QString &module, const QString &function, const PARAM1_TYPE ¶meter1,
const PARAM2_TYPE ¶meter2, const PARAM3_TYPE ¶meter3, RETURN_TYPE &returnValue) {
tlp::DataSet parameters;
parameters.set("param1", parameter1);
parameters.set("param2", parameter2);
parameters.set("param3", parameter3);
return callFunctionAndGetReturnValue(module, function, parameters, returnValue);
}
template<typename PARAM1_TYPE, typename PARAM2_TYPE, typename PARAM3_TYPE, typename PARAM4_TYPE, typename RETURN_TYPE>
bool PythonInterpreter::callFunctionFourParamsAndGetReturnValue(const QString &module, const QString &function, const PARAM1_TYPE ¶meter1,
const PARAM2_TYPE ¶meter2, const PARAM3_TYPE ¶meter3, const PARAM4_TYPE ¶meter4,
RETURN_TYPE &returnValue) {
tlp::DataSet parameters;
parameters.set("param1", parameter1);
parameters.set("param2", parameter2);
parameters.set("param3", parameter3);
parameters.set("param4", parameter4);
return callFunctionAndGetReturnValue(module, function, parameters, returnValue);
}
template<typename RETURN_TYPE>
bool PythonInterpreter::callFunctionAndGetReturnValue(const QString &module, const QString &function, const tlp::DataSet ¶meters, RETURN_TYPE &returnValue) {
holdGIL();
bool ok = false;
PyObject *ret = callPythonFunction(module, function, parameters);
PyObjectToCppObjectConvertor<RETURN_TYPE> retConvertor;
if (ret && retConvertor.convert(ret, returnValue)) {
ok = true;
}
decrefPyObject(ret);
releaseGIL();
return ok;
}
|