Mantid
Loading...
Searching...
No Matches
MappingTypeHandler.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
11
15
16#include <boost/python/dict.hpp>
17
18using boost::python::dict;
19using boost::python::object;
20
21namespace Mantid {
22using Kernel::PropertyManager;
24
25namespace PythonInterface::Registry {
26
34void MappingTypeHandler::set(Kernel::IPropertyManager *alg, const std::string &name, const object &mapping) const {
36 if (ptrExtract.check()) { // try converting directly to a PropertyManager
37 alg->setProperty(name, ptrExtract());
38 } else if (PyObject_TypeCheck(mapping.ptr(), &PyDict_Type)) { // treat the value as a dict
39 alg->setProperty(name, createPropertyManager(dict(mapping)));
40 } else {
41 throw std::invalid_argument("Property " + name + " expects a dictionary");
42 }
43}
44
54std::unique_ptr<Kernel::Property> MappingTypeHandler::create(const std::string &name, const object &defaultValue,
55 const boost::python::api::object & /*validator*/,
56 const unsigned int direction) const {
57 // Wrap the property manager in a PropertyManagerProperty instance.
58 std::unique_ptr<Kernel::Property> valueProp =
59 std::make_unique<Kernel::PropertyManagerProperty>(name, createPropertyManager(dict(defaultValue)), direction);
60 return valueProp;
61}
62} // namespace PythonInterface::Registry
63} // namespace Mantid
Interface to PropertyManager.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void set(Kernel::IPropertyManager *alg, const std::string &name, const boost::python::api::object &mapping) const override
Sets the named property in the PropertyManager by extracting a new PropertyManager from the Python ob...
std::unique_ptr< Kernel::Property > create(const std::string &name, const boost::python::api::object &defaultValue, const boost::python::api::object &validator, const unsigned int direction) const override
Always throws a runtime_error.
MANTID_KERNEL_DLL PropertyManager_sptr createPropertyManager(const Json::Value &keyValues)
Attempt to create a PropertyManager from the Json::Value.
std::shared_ptr< PropertyManager > PropertyManager_sptr
Typedef for a shared pointer to a PropertyManager.
Helper class which provides the Collimation Length for SANS instruments.