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
11#include "MantidPythonInterface/kernel/DllConfig.h"
13
18
19#include <boost/python/call_method.hpp>
20#include <boost/python/converter/arg_from_python.hpp>
21#include <boost/python/extract.hpp>
22#include <memory>
23
24#include <string>
25
27GNU_DIAG_OFF("maybe-uninitialized")
32template <typename ValueType, typename Enable = void> struct TypedPropertyValueHandler : public PropertyValueHandler {
34 using HeldType = ValueType;
35
42 void set(Kernel::IPropertyManager *alg, const std::string &name, const boost::python::object &value) const override {
43 alg->setProperty<ValueType>(name, boost::python::extract<ValueType>(value));
44 }
56 std::unique_ptr<Kernel::Property> create(const std::string &name, const boost::python::object &defaultValue,
57 const boost::python::object &validator,
58 const unsigned int direction) const override {
59 using boost::python::extract;
62 const ValueType valueInC = extract<ValueType>(defaultValue)();
63 std::unique_ptr<Kernel::Property> valueProp;
64 if (isNone(validator)) {
65 valueProp = std::make_unique<PropertyWithValue<ValueType>>(name, valueInC, direction);
66 } else {
67 const IValidator *propValidator = extract<IValidator *>(validator);
68 valueProp = std::make_unique<PropertyWithValue<ValueType>>(name, valueInC, propValidator->clone(), direction);
69 }
70 return valueProp;
71 }
72};
73GNU_DIAG_ON("maybe-uninitialized")
74} // namespace Mantid::PythonInterface::Registry
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
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:37
virtual IValidator_sptr clone() const =0
Make a copy of the present type of validator.
The concrete, templated class for properties.
bool isNone(const 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.