Mantid
Loading...
Searching...
No Matches
PropertyManagerOwner.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
11#include "MantidKernel/Logger.h"
14#include <algorithm>
15#include <json/json.h>
16
17namespace Mantid::Kernel {
18namespace {
19// Get a reference to the logger
20Logger g_log("PropertyManagerOwner");
21} // namespace
22
25
27PropertyManagerOwner::PropertyManagerOwner(const PropertyManagerOwner &po) : m_properties(po.m_properties) {}
28
32 return *this;
33}
34
41void PropertyManagerOwner::declareProperty(std::unique_ptr<Property> p, const std::string &doc) {
42 m_properties->declareProperty(std::move(p), doc);
43}
44
49void PropertyManagerOwner::declareOrReplaceProperty(std::unique_ptr<Property> p, const std::string &doc) {
50 m_properties->declareOrReplaceProperty(std::move(p), doc);
51}
52
56
68void PropertyManagerOwner::setProperties(const std::string &propertiesJson,
69 const std::unordered_set<std::string> &ignoreProperties, bool createMissing) {
70 m_properties->setProperties(propertiesJson, this, ignoreProperties, createMissing);
71}
72
79void PropertyManagerOwner::setProperties(const ::Json::Value &jsonValue,
80 const std::unordered_set<std::string> &ignoreProperties, bool createMissing) {
81 m_properties->setProperties(jsonValue, this, ignoreProperties, createMissing);
82}
83
90void PropertyManagerOwner::setPropertiesWithString(const std::string &propertiesString,
91 const std::unordered_set<std::string> &ignoreProperties) {
92 m_properties->setPropertiesWithString(propertiesString, ignoreProperties);
93}
94
103void PropertyManagerOwner::setPropertyValue(const std::string &name, const std::string &value) {
104 m_properties->setPropertyValue(name, value);
105 this->afterPropertySet(name);
106}
107
115void PropertyManagerOwner::setPropertyValueFromJson(const std::string &name, const Json::Value &value) {
116 m_properties->setPropertyValueFromJson(name, value);
117 this->afterPropertySet(name);
118}
119
126void PropertyManagerOwner::setPropertyOrdinal(const int &index, const std::string &value) {
127 m_properties->setPropertyOrdinal(index, value);
128 this->afterPropertySet(m_properties->getPointerToPropertyOrdinal(index)->name());
129}
130
136bool PropertyManagerOwner::existsProperty(const std::string &name) const { return m_properties->existsProperty(name); }
137
141bool PropertyManagerOwner::validateProperties() const { return m_properties->validateProperties(); }
142
147size_t PropertyManagerOwner::propertyCount() const { return m_properties->propertyCount(); }
148
154std::string PropertyManagerOwner::getPropertyValue(const std::string &name) const {
155 return m_properties->getPropertyValue(name);
156}
157
164 return m_properties->getPointerToProperty(name);
165}
166
173 return m_properties->getPointerToPropertyOrdinal(index);
174}
175
180const std::vector<Property *> &PropertyManagerOwner::getProperties() const { return m_properties->getProperties(); }
181
186std::vector<std::string> PropertyManagerOwner::getDeclaredPropertyNames() const noexcept {
187 std::vector<std::string> names;
188 const auto &props = getProperties();
189 names.reserve(props.size());
190 std::transform(props.cbegin(), props.cend(), std::back_inserter(names),
191 [](auto &propPtr) { return propPtr->name(); });
192 return names;
193}
194
212 return m_properties->getProperty(name);
213}
214
219bool PropertyManagerOwner::isDefault(const std::string &name) const {
220 return m_properties->getPointerToProperty(name)->isDefault();
221}
222
230std::string PropertyManagerOwner::asString(bool withDefaultValues) const {
231 return m_properties->asString(withDefaultValues);
232}
239::Json::Value PropertyManagerOwner::asJson(bool withDefaultValues) const {
240 return m_properties->asJson(withDefaultValues);
241}
242
248void PropertyManagerOwner::removeProperty(const std::string &name, const bool delproperty) {
249 m_properties->removeProperty(name, delproperty);
250}
251
257std::unique_ptr<Property> PropertyManagerOwner::takeProperty(const size_t index) {
258 return m_properties->takeProperty(index);
259}
260
265
272void PropertyManagerOwner::afterPropertySet(const std::string &name) { m_properties->afterPropertySet(name); }
273
274} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Kernel/PropertyManagerOwner.h.
Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
bool validateProperties() const override
Validates all the properties in the collection.
PropertyManagerOwner & operator=(const PropertyManagerOwner &)
Assignment operator.
void afterPropertySet(const std::string &) override
Override this method to perform a custom action right after a property was set.
void setProperties(const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
Set the ordered list of properties by one string of values, separated by semicolons.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
void declareOrReplaceProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add or replace property in the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
void clear() override
Clears all properties under management.
void setPropertyOrdinal(const int &index, const std::string &value) override
Set the value of a property by an index N.B.
void declareProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
::Json::Value asJson(bool withDefaultValues=false) const override
Return the property manager serialized as a json object.
void setPropertyValueFromJson(const std::string &name, const Json::Value &value) override
Set the value of a property by Json::Value object.
const std::vector< Property * > & getProperties() const override
Get the list of managed properties.
std::vector< std::string > getDeclaredPropertyNames() const noexcept override
Return the list of declared property names.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void setPropertiesWithString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >()) override
Sets all the declared properties from a string.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
Property * getPointerToPropertyOrdinal(const int &index) const override
Get a property by an index.
std::shared_ptr< PropertyManager > m_properties
Shared pointer to the 'real' property manager.
size_t propertyCount() const override
Count the number of properties under management.
bool isDefault(const std::string &name) const
void removeProperty(const std::string &name, const bool delproperty=true) override
Removes the property from management.
void resetProperties() override
Reset property values back to initial values (blank or default values)
std::unique_ptr< Property > takeProperty(const size_t index) override
Removes the property from management returning a pointer to it.
std::string asString(bool withDefaultValues=false) const override
Return the property manager serialized as a string.
Property manager helper class.
Base class for properties.
Definition: Property.h:94
Utility class that enables the getProperty() method to effectively be templated on the return type.