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 props = this->getProperties();
57 for (std::vector<Property *>::const_iterator prop = props.begin(); prop != props.end(); ++prop) {
58 if (name == (*prop)->name())
59 return true;
60 }
61 return false;
62}
63
69void IPropertyManager::updatePropertyValues(const IPropertyManager &other) {
70 auto props = this->getProperties();
71 for (auto &prop : props) {
72 const std::string propName = (*prop).name();
73 if (other.existsProperty(propName)) {
74 (*prop).setValueFromProperty(*other.getPointerToProperty(propName));
75 }
76 }
77}
78
84void IPropertyManager::setPropertySettings(const std::string &name, std::unique_ptr<IPropertySettings> settings) {
85 Property *prop = getPointerToProperty(name);
86 if (prop)
87 prop->setSettings(std::move(settings));
88}
89
94std::vector<Property *> IPropertyManager::getPropertiesInGroup(const std::string &group) const {
95 auto props = getProperties();
96 for (auto prop = props.begin(); prop != props.end();) {
97 if ((**prop).getGroup() == group) {
98 ++prop;
99 } else {
100 prop = props.erase(prop);
101 }
102 }
103 return props;
104}
105
106// Definitions for TypedValue cast operators
107// Have to come after getValue definitions above to keep MSVS2010 happy
108IPropertyManager::TypedValue::operator int16_t() { return pm.getValue<int16_t>(prop); }
109IPropertyManager::TypedValue::operator uint16_t() { return pm.getValue<uint16_t>(prop); }
110IPropertyManager::TypedValue::operator int32_t() { return pm.getValue<int32_t>(prop); }
111IPropertyManager::TypedValue::operator uint32_t() { return pm.getValue<uint32_t>(prop); }
112IPropertyManager::TypedValue::operator int64_t() { return pm.getValue<int64_t>(prop); }
113IPropertyManager::TypedValue::operator uint64_t() { return pm.getValue<uint64_t>(prop); }
114IPropertyManager::TypedValue::operator bool() { return pm.getValue<bool>(prop); }
115IPropertyManager::TypedValue::operator double() { return pm.getValue<double>(prop); }
116IPropertyManager::TypedValue::operator std::string() { return pm.getPropertyValue(prop); }
117IPropertyManager::TypedValue::operator OptionalBool() { return pm.getValue<OptionalBool>(prop); }
118IPropertyManager::TypedValue::operator Property *() { return pm.getPointerToProperty(prop); }
119
120#ifdef __APPLE__
121// These must precede the operator() declaration, temporarily switch batch to global namespace
122}
124DEFINE_IPROPERTYMANAGER_GETVALUE(std::vector<unsigned long>);
125// Intel 64-bit size_t
126namespace Mantid::Kernel {
127IPropertyManager::TypedValue::operator unsigned long() { return pm.getValue<unsigned long>(prop); }
128#endif
129} // namespace Mantid::Kernel
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:53
Helper class which provides the Collimation Length for SANS instruments.