Mantid
Loading...
Searching...
No Matches
IPropertyManager.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 +
8#include "MantidKernel/DllConfig.h"
11
12#include <algorithm>
13
24DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<int16_t>)
25DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<uint16_t>)
26DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<int32_t>)
27DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<uint32_t>)
28DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<int64_t>)
29DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<uint64_t>)
30DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<double>)
31DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<std::string>)
32DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<std::vector<std::string>>)
33
34namespace Mantid::Kernel {
35// This template implementation has been left in because although you can't
36// assign to an existing string
37// via the getProperty() method, you can construct a local variable by saying,
38// e.g.: std::string s = getProperty("myProperty")
39template <> MANTID_KERNEL_DLL std::string IPropertyManager::getValue<std::string>(const std::string &name) const {
40 return getPropertyValue(name);
41}
42
43template <> MANTID_KERNEL_DLL Property *IPropertyManager::getValue<Property *>(const std::string &name) const {
44 return getPointerToProperty(name);
45}
46
47// If a string is given in the argument, we can be more flexible
48template <>
49IPropertyManager *IPropertyManager::setProperty<std::string>(const std::string &name, const std::string &value) {
50 this->setPropertyValue(name, value);
51 return this;
52}
53
58bool IPropertyManager::existsProperty(const std::string &name) const {
59 auto const &props = this->getProperties();
60 return std::any_of(props.cbegin(), props.cend(), [&name](const auto prop) { return name == prop->name(); });
61}
62
68void IPropertyManager::updatePropertyValues(const IPropertyManager &other) {
69 auto props = this->getProperties();
70 for (auto &prop : props) {
71 const std::string propName = (*prop).name();
72 if (other.existsProperty(propName)) {
73 (*prop).setValueFromProperty(*other.getPointerToProperty(propName));
74 }
75 }
76}
77
83void IPropertyManager::setPropertySettings(const std::string &name, std::unique_ptr<IPropertySettings const> settings) {
84 Property *prop = getPointerToProperty(name);
85 if (prop)
86 prop->setSettings(std::move(settings));
87}
88
93bool IPropertyManager::isPropertyEnabled(const std::string &name) const {
94 Property *prop = getPointerToProperty(name);
95 // Allow any setting in the chain of settings to disable the property.
96 return std::all_of(prop->getSettings().begin(), prop->getSettings().end(),
97 [this](auto const &ptr) { return ptr->isEnabled(this); });
98}
99
107bool IPropertyManager::isPropertyVisible(const std::string &name) const {
108 Property *prop = getPointerToProperty(name);
109 // Allow any setting in the chain of settings to hide the property.
110 return std::all_of(prop->getSettings().begin(), prop->getSettings().end(),
111 [this](auto const &ptr) { return ptr->isVisible(this); });
112}
113
118std::vector<Property *> IPropertyManager::getPropertiesInGroup(const std::string &group) const {
119 auto props = getProperties();
120 for (auto prop = props.begin(); prop != props.end();) {
121 if ((**prop).getGroup() == group) {
122 ++prop;
123 } else {
124 prop = props.erase(prop);
125 }
126 }
127 return props;
128}
129
130// Definitions for TypedValue cast operators
131// Have to come after getValue definitions above to keep MSVS2010 happy
132IPropertyManager::TypedValue::operator int16_t() { return pm.getValue<int16_t>(prop); }
133IPropertyManager::TypedValue::operator uint16_t() { return pm.getValue<uint16_t>(prop); }
134IPropertyManager::TypedValue::operator int32_t() { return pm.getValue<int32_t>(prop); }
135IPropertyManager::TypedValue::operator uint32_t() { return pm.getValue<uint32_t>(prop); }
136IPropertyManager::TypedValue::operator int64_t() { return pm.getValue<int64_t>(prop); }
137IPropertyManager::TypedValue::operator uint64_t() { return pm.getValue<uint64_t>(prop); }
138IPropertyManager::TypedValue::operator bool() { return pm.getValue<bool>(prop); }
139IPropertyManager::TypedValue::operator double() { return pm.getValue<double>(prop); }
140IPropertyManager::TypedValue::operator std::string() { return pm.getPropertyValue(prop); }
141IPropertyManager::TypedValue::operator OptionalBool() { return pm.getValue<OptionalBool>(prop); }
142IPropertyManager::TypedValue::operator Property *() { return pm.getPointerToProperty(prop); }
143
144#ifdef __APPLE__
145// These must precede the operator() declaration, temporarily switch batch to global namespace
146}
148DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<unsigned long>);
149// Intel 64-bit size_t
150namespace Mantid::Kernel {
151IPropertyManager::TypedValue::operator unsigned long() { return pm.getValue<unsigned long>(prop); }
152#endif
153} // namespace Mantid::Kernel
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
#define DEFINE_IPROPERTYMANAGER_GETVALUE(type)
A macro for defining getValue functions for new types.
Helper class which provides the Collimation Length for SANS instruments.