Mantid
Loading...
Searching...
No Matches
PythonObjectTypeValidator.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2025 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
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13
15
16#include <Python.h>
17#include <boost/python/extract.hpp>
18#include <boost/python/object.hpp>
19
20// forward declare
21namespace Json {
22class Value;
23}
24
25namespace {
26using namespace boost::python;
27static inline object const &validate_python_class(object const &pyclass) {
28 if (PyType_Check(pyclass.ptr())) {
29 return pyclass;
30 } else {
31 throw std::invalid_argument("Attempt to construct validator with an object instead of a class type");
32 }
33}
34} // namespace
35
37
38using namespace boost::python;
40
42
43public:
44 PythonObjectTypeValidator() : pythonClass(object()) {};
45
46 PythonObjectTypeValidator(object const &pyclass) : pythonClass(validate_python_class(pyclass)) {}
47
48 ~PythonObjectTypeValidator() override = default;
49
50 IValidator_sptr clone() const override { return std::make_shared<PythonObjectTypeValidator>(*this); };
51
52private:
54
55 std::string check(boost::any const &value) const override;
56};
57
58} // namespace Mantid::PythonInterface
double value
The value of the point.
Definition FitMW.cpp:51
IValidator is the basic interface for all validators for properties.
Definition IValidator.h:43
IValidator_sptr clone() const override
Make a copy of the present type of validator.
#define MANTID_PYTHONINTERFACE_CORE_DLL
Definition DllConfig.h:17
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26