Mantid
Loading...
Searching...
No Matches
CallMethod.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
12
13#include <boost/python/call_method.hpp>
14#include <boost/python/class.hpp>
15
16namespace Mantid {
17namespace PythonInterface {
18
21 virtual ~UndefinedAttributeError() = default;
22};
23
24namespace detail {
36template <typename ReturnType, typename... Args>
37ReturnType callMethodImpl(PyObject *obj, const char *methodName, const Args &...args) {
38 try {
39 return boost::python::call_method<ReturnType, Args...>(obj, methodName, args...);
40 } catch (boost::python::error_already_set &) {
41 throw PythonException();
42 }
43}
44} // namespace detail
45
55template <typename ReturnType, typename... Args>
56ReturnType callMethodNoCheck(PyObject *obj, const char *methodName, const Args &...args) {
58 return detail::callMethodImpl<ReturnType, Args...>(obj, methodName, args...);
59}
60
70template <typename ReturnType, typename... Args>
71ReturnType callMethodNoCheck(const boost::python::object &obj, const char *methodName, const Args &...args) {
73 return detail::callMethodImpl<ReturnType, Args...>(obj.ptr(), methodName, args...);
74}
75
86template <typename ReturnType, typename... Args>
87ReturnType callMethod(PyObject *obj, const char *methodName, const Args &...args) {
89 if (typeHasAttribute(obj, methodName)) {
90 return detail::callMethodImpl<ReturnType, Args...>(obj, methodName, args...);
91 } else {
93 }
94}
95} // namespace PythonInterface
96} // namespace Mantid
double obj
the value of the quadratic function
Defines a structure for acquiring/releasing the Python GIL using the RAII pattern.
Exception type that captures the current Python error state as a generic C++ exception for any genera...
Definition: ErrorHandling.h:24
ReturnType callMethodImpl(PyObject *obj, const char *methodName, const Args &...args)
Wrapper around boost::python::call_method.
Definition: CallMethod.h:37
ReturnType callMethod(PyObject *obj, const char *methodName, const Args &...args)
Wrapper around boost::python::call_method to acquire GIL for duration of call.
Definition: CallMethod.h:87
bool MANTID_PYTHONINTERFACE_CORE_DLL typeHasAttribute(PyObject *obj, const char *attr)
This namespace contains helper functions for classes that are overridden in Python.
ReturnType callMethodNoCheck(PyObject *obj, const char *methodName, const Args &...args)
Wrapper around boost::python::call_method to acquire GIL for duration of call.
Definition: CallMethod.h:56
Helper class which provides the Collimation Length for SANS instruments.
Defines an exception for an undefined attribute.
Definition: CallMethod.h:20