Mantid
Loading...
Searching...
No Matches
Sip.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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
11#include <sip.h>
12#include <stdexcept>
13
14namespace MantidQt {
15namespace Widgets {
16namespace Common {
17namespace Python {
18
19namespace Detail {
20EXPORT_OPT_MANTIDQT_COMMON const sipAPIDef *sipAPI();
21} // namespace Detail
22
27template <typename T> T *extract(const Object &obj) {
28 const auto sipapi = Detail::sipAPI();
29 if (!PyObject_TypeCheck(obj.ptr(), sipapi->api_wrapper_type)) {
30 throw std::runtime_error("extract() - Object is not a sip-wrapped type.");
31 }
32 // transfer ownership from python to C++
33 sipapi->api_transfer_to(obj.ptr(), 0);
34 // reinterpret to sipWrapper
35 auto wrapper = reinterpret_cast<sipSimpleWrapper *>(obj.ptr());
36#if (SIP_API_MAJOR_NR == 8 && SIP_API_MINOR_NR >= 1) || SIP_API_MAJOR_NR > 8
37 return static_cast<T *>(sipapi->api_get_address(wrapper));
38#elif SIP_API_MAJOR_NR == 8
39 return static_cast<T *>(wrapper->data);
40#else
41 return static_cast<T *>(wrapper->u.cppPtr);
42#endif
43}
44
45} // namespace Python
46} // namespace Common
47} // namespace Widgets
48
49} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double obj
the value of the quadratic function
EXPORT_OPT_MANTIDQT_COMMON const sipAPIDef * sipAPI()
Definition: Sip.cpp:15
boost::python::object Object
Definition: Object.h:29
T * extract(const Object &obj)
Extract a C++ object of type T from the Python object.
Definition: Sip.h:27
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...