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
21DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<int16_t>)
22DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<uint16_t>)
23DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<int32_t>)
24DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<uint32_t>)
25DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<int64_t>)
26DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<uint64_t>)
27DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<double>)
28DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<std::string>)
29DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<std::vector<std::string>>)
30
31namespace Mantid::Kernel {
32// This template implementation has been left in because although you can't
33// assign to an existing string
34// via the getProperty() method, you can construct a local variable by saying,
35// e.g.: std::string s = getProperty("myProperty")
36template <> DLLExport std::string IPropertyManager::getValue<std::string>(const std::string &name) const {
37 return getPropertyValue(name);
38}
39
40template <> DLLExport Property *IPropertyManager::getValue<Property *>(const std::string &name) const {
41 return getPointerToProperty(name);
42}
43
44// If a string is given in the argument, we can be more flexible
45template <>
46IPropertyManager *IPropertyManager::setProperty<std::string>(const std::string &name, const std::string &value) {
47 this->setPropertyValue(name, value);
48 return this;
49}
50
55bool IPropertyManager::existsProperty(const std::string &name) const {
56 auto const &props = this->getProperties();
57 return std::any_of(props.cbegin(), props.cend(), [&name](const auto prop) { return name == prop->name(); });
58}
59
65void IPropertyManager::updatePropertyValues(const IPropertyManager &other) {
66 auto props = this->getProperties();
67 for (auto &prop : props) {
68 const std::string propName = (*prop).name();
69 if (other.existsProperty(propName)) {
70 (*prop).setValueFromProperty(*other.getPointerToProperty(propName));
71 }
72 }
73}
74
80void IPropertyManager::setPropertySettings(const std::string &name, std::unique_ptr<IPropertySettings> settings) {
81 Property *prop = getPointerToProperty(name);
82 if (prop)
83 prop->setSettings(std::move(settings));
84}
85
90std::vector<Property *> IPropertyManager::getPropertiesInGroup(const std::string &group) const {
91 auto props = getProperties();
92 for (auto prop = props.begin(); prop != props.end();) {
93 if ((**prop).getGroup() == group) {
94 ++prop;
95 } else {
96 prop = props.erase(prop);
97 }
98 }
99 return props;
100}
101
102// Definitions for TypedValue cast operators
103// Have to come after getValue definitions above to keep MSVS2010 happy
104IPropertyManager::TypedValue::operator int16_t() { return pm.getValue<int16_t>(prop); }
105IPropertyManager::TypedValue::operator uint16_t() { return pm.getValue<uint16_t>(prop); }
106IPropertyManager::TypedValue::operator int32_t() { return pm.getValue<int32_t>(prop); }
107IPropertyManager::TypedValue::operator uint32_t() { return pm.getValue<uint32_t>(prop); }
108IPropertyManager::TypedValue::operator int64_t() { return pm.getValue<int64_t>(prop); }
109IPropertyManager::TypedValue::operator uint64_t() { return pm.getValue<uint64_t>(prop); }
110IPropertyManager::TypedValue::operator bool() { return pm.getValue<bool>(prop); }
111IPropertyManager::TypedValue::operator double() { return pm.getValue<double>(prop); }
112IPropertyManager::TypedValue::operator std::string() { return pm.getPropertyValue(prop); }
113IPropertyManager::TypedValue::operator OptionalBool() { return pm.getValue<OptionalBool>(prop); }
114IPropertyManager::TypedValue::operator Property *() { return pm.getPointerToProperty(prop); }
115
116#ifdef __APPLE__
117// These must precede the operator() declaration, temporarily switch batch to global namespace
118}
120DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<unsigned long>);
121// Intel 64-bit size_t
122namespace Mantid::Kernel {
123IPropertyManager::TypedValue::operator unsigned long() { return pm.getValue<unsigned long>(prop); }
124#endif
125} // 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.