Mantid
Loading...
Searching...
No Matches
TypedPropertyValueHandler.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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
10#include "MantidPythonInterface/core/IsNone.h" // includes object.hpp
12
15
16#include <boost/python/call_method.hpp>
17#include <boost/python/converter/arg_from_python.hpp>
18#include <boost/python/extract.hpp>
19#include <memory>
20
21#include <string>
22
28template <typename ValueType, typename Enable = void>
31 using HeldType = ValueType;
32
39 void set(Kernel::IPropertyManager *alg, const std::string &name, const boost::python::object &value) const override {
40 alg->setProperty<ValueType>(name, boost::python::extract<ValueType>(value));
41 }
53 std::unique_ptr<Kernel::Property> create(const std::string &name, const boost::python::object &defaultValue,
54 const boost::python::object &validator,
55 const unsigned int direction) const override {
56 using boost::python::extract;
59 const ValueType valueInC = extract<ValueType>(defaultValue)();
60 std::unique_ptr<Kernel::Property> valueProp;
61 if (isNone(validator)) {
62 valueProp = std::make_unique<PropertyWithValue<ValueType>>(name, valueInC, direction);
63 } else {
64 const IValidator *propValidator = extract<IValidator *>(validator);
65 valueProp = std::make_unique<PropertyWithValue<ValueType>>(name, valueInC, propValidator->clone(), direction);
66 }
67 return valueProp;
68 }
69};
70
71} // namespace Mantid::PythonInterface::Registry
double value
The value of the point.
Definition: FitMW.cpp:51
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Interface to PropertyManager.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
IValidator is the basic interface for all validators for properties.
Definition: IValidator.h:43
virtual IValidator_sptr clone() const =0
Make a copy of the present type of validator.
The concrete, templated class for properties.
bool isNone(PyObject *ptr)
Definition: IsNone.h:26
This class provides a base-class objects that are able to take a python object and set it on an algor...
This class provides a templated class object that is able to take a python object and perform operati...
ValueType HeldType
Type required by TypeRegistry framework.
void set(Kernel::IPropertyManager *alg, const std::string &name, const boost::python::object &value) const override
Set function to handle Python -> C++ calls and get the correct type.
std::unique_ptr< Kernel::Property > create(const std::string &name, const boost::python::object &defaultValue, const boost::python::object &validator, const unsigned int direction) const override
Create a PropertyWithValue from the given python object value.