Mantid
Loading...
Searching...
No Matches
PythonObjectProperty.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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//----------------------------------------------------------------------
12#include "MantidPythonInterface/core/DllConfig.h"
13
17
18#include <boost/python/object.hpp>
19
20// forward declare
21namespace Json {
22class Value;
23}
24
25namespace Mantid::Kernel {
26using PythonObject = boost::python::object;
27
28// Instantiated and exported by PythonObjectProperty.cpp, where boost python is available
30} // namespace Mantid::Kernel
31
33
38
39class MANTID_PYTHONINTERFACE_CORE_DLL PythonObjectProperty : public Mantid::Kernel::PropertyWithValue<PythonObject> {
40public:
41 // Convenience typedefs
44
47
54 PythonObjectProperty(std::string const &name, PythonObject const &defaultValue,
55 IValidator_sptr const &validator = std::make_shared<NullValidator>(),
56 unsigned int const direction = Direction::Input)
57 : BaseClass(name, defaultValue, validator, direction) {}
58
64 PythonObjectProperty(std::string const &name, PythonObject const &defaultValue,
65 unsigned int const direction = Direction::Input)
66 : BaseClass(name, defaultValue, std::make_shared<NullValidator>(), direction) {}
67
74 PythonObjectProperty(std::string const &name, IValidator_sptr const &validator,
75 unsigned int const direction = Direction::Input)
76 : BaseClass(name, PythonObject(), validator, direction) {}
77
83 PythonObjectProperty(std::string const &name, unsigned int const direction = Direction::Input)
84 : BaseClass(name, PythonObject(), std::make_shared<NullValidator>(), direction) {}
85
93 PythonObjectProperty(std::string const &name, std::string const &strvalue,
94 IValidator_sptr const &validator = std::make_shared<NullValidator>(),
95 unsigned int const direction = Direction::Input)
96 : BaseClass(name, PythonObject(), strvalue, validator, direction) {}
97
100
102 PythonObjectProperty *clone() const override { return new PythonObjectProperty(*this); }
103
104 // Unhide the base class assignment operator
105 using BaseClass::operator=;
106
107 std::string getDefault() const override;
108 std::string setValue(PythonObject const &obj);
109 std::string setValue(std::string const &value) override;
110 std::string setValueFromJson(Json::Value const &value) override;
111 std::string setDataItem(std::shared_ptr<Kernel::DataItem> const &value) override;
112 bool isDefault() const override;
113};
114
115} // namespace Mantid::PythonInterface
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double obj
the value of the quadratic function
NullValidator is a validator that doesn't.
The concrete, templated class for properties.
PythonObjectProperty(std::string const &name, PythonObject const &defaultValue, unsigned int const direction=Direction::Input)
Constructor that's useful for output properties or inputs with non-None default and no validator.
PythonObjectProperty(std::string const &name, std::string const &strvalue, IValidator_sptr const &validator=std::make_shared< NullValidator >(), unsigned int const direction=Direction::Input)
Constructor from which you can set the property's values through a string:
PythonObjectProperty(std::string const &name, PythonObject const &defaultValue, IValidator_sptr const &validator=std::make_shared< NullValidator >(), unsigned int const direction=Direction::Input)
Constructor.
PythonObjectProperty()=delete
No default constructor.
PythonObjectProperty(PythonObjectProperty const &other)
Copy constructor.
PythonObjectProperty * clone() const override
This is required by Property interface.
PythonObjectProperty(std::string const &name, unsigned int const direction=Direction::Input)
Constructor that's useful for output properties or inputs with default value None and no validator.
PythonObjectProperty(std::string const &name, IValidator_sptr const &validator, unsigned int const direction=Direction::Input)
Constructor Will lead to the property having default value of None.
boost::python::object PythonObject
MANTID_PYTHONINTERFACE_CORE_EXTERN_TEMPLATE(PropertyWithValue< PythonObject >)
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition Property.h:51