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
16
17#include <boost/python/call_method.hpp>
18#include <boost/python/converter/arg_from_python.hpp>
19#include <boost/python/extract.hpp>
20#include <memory>
21
22#include <string>
23
25GNU_DIAG_OFF("maybe-uninitialized")
30template <typename ValueType, typename Enable = void>
33 using HeldType = ValueType;
34
41 void set(Kernel::IPropertyManager *alg, const std::string &name, const boost::python::object &value) const override {
42 alg->setProperty<ValueType>(name, boost::python::extract<ValueType>(value));
43 }
55 std::unique_ptr<Kernel::Property> create(const std::string &name, const boost::python::object &defaultValue,
56 const boost::python::object &validator,
57 const unsigned int direction) const override {
58 using boost::python::extract;
61 const ValueType valueInC = extract<ValueType>(defaultValue)();
62 std::unique_ptr<Kernel::Property> valueProp;
63 if (isNone(validator)) {
64 valueProp = std::make_unique<PropertyWithValue<ValueType>>(name, valueInC, direction);
65 } else {
66 const IValidator *propValidator = extract<IValidator *>(validator);
67 valueProp = std::make_unique<PropertyWithValue<ValueType>>(name, valueInC, propValidator->clone(), direction);
68 }
69 return valueProp;
70 }
71};
72GNU_DIAG_ON("maybe-uninitialized")
73} // namespace Mantid::PythonInterface::Registry
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition System.h:37
#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:43
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.