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