"Framework/git@code.ornl.gov:mantidproject/mantid.git" did not exist on "04c2983246d34e452dd73ff392d514492a232561"
Newer
Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/PropertyManagerOwner.h"
#include "MantidKernel/PropertyManager.h"
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
namespace Mantid {
namespace Kernel {
namespace {
// Get a reference to the logger
Logger g_log("PropertyManagerOwner");
}
/// Default constructor
PropertyManagerOwner::PropertyManagerOwner()
: m_properties(new PropertyManager) {}
/// Copy constructor
PropertyManagerOwner::PropertyManagerOwner(const PropertyManagerOwner &po) {
m_properties = po.m_properties;
}
/// Assignment operator
PropertyManagerOwner &PropertyManagerOwner::
operator=(const PropertyManagerOwner &po) {
m_properties = po.m_properties;
return *this;
}
/** Add a property to the list of managed properties
* @param p :: The property object to add
* @param doc :: A description of the property that may be displayed to users
* @throw Exception::ExistsError if a property with the given name already
* exists
* @throw std::invalid_argument if the property declared has an empty name.
*/
void PropertyManagerOwner::declareProperty(Property *p,
const std::string &doc) {
m_properties->declareProperty(p, doc);
}
/** Set the ordered list of properties by one string of values.
* @param propertiesArray :: The list of property values
* @throw invalid_argument if error in parameters
*/
// Care will certainly be required in the calling of this function or it could
// all go horribly wrong!
void PropertyManagerOwner::setProperties(const std::string &propertiesArray) {
m_properties->setProperties(propertiesArray);
}
/** Set the value of a property by string
* N.B. bool properties must be set using 1/0 rather than true/false
* @param name :: The name of the property (case insensitive)
* @param value :: The value to assign to the property
* @throw Exception::NotFoundError if the named property is unknown
* @throw std::invalid_argument If the value is not valid for the property given
*/
void PropertyManagerOwner::setPropertyValue(const std::string &name,
const std::string &value) {
m_properties->setPropertyValue(name, value);
this->afterPropertySet(name);
}
/** Set the value of a property by an index
* N.B. bool properties must be set using 1/0 rather than true/false
* @param index :: The index of the property to assign
* @param value :: The value to assign to the property
* @throw std::runtime_error if the property index is too high
*/
void PropertyManagerOwner::setPropertyOrdinal(const int &index,
const std::string &value) {
m_properties->setPropertyOrdinal(index, value);
this->afterPropertySet(
m_properties->getPointerToPropertyOrdinal(index)->name());
}
/** Checks whether the named property is already in the list of managed
* property.
* @param name :: The name of the property (case insensitive)
* @return True if the property is already stored
*/
bool PropertyManagerOwner::existsProperty(const std::string &name) const {
return m_properties->existsProperty(name);
}
/** Validates all the properties in the collection
* @return True if all properties have a valid value
*/
bool PropertyManagerOwner::validateProperties() const {
return m_properties->validateProperties();
}
/**
* Count the number of properties under management
* @returns The number of properties being managed
*/
size_t PropertyManagerOwner::propertyCount() const {
return m_properties->propertyCount();
}
/** Get the value of a property as a string
* @param name :: The name of the property (case insensitive)
* @return The value of the named property
* @throw Exception::NotFoundError if the named property is unknown
*/
std::string
PropertyManagerOwner::getPropertyValue(const std::string &name) const {
return m_properties->getPropertyValue(name);
}
/** Get a property by name
* @param name :: The name of the property (case insensitive)
* @return A pointer to the named property
* @throw Exception::NotFoundError if the named property is unknown
*/
Property *
PropertyManagerOwner::getPointerToProperty(const std::string &name) const {
return m_properties->getPointerToProperty(name);
}
/** Get a property by an index
* @param index :: The name of the property (case insensitive)
* @return A pointer to the named property
* @throw std::runtime_error if the property index is too high
*/
Property *
PropertyManagerOwner::getPointerToPropertyOrdinal(const int &index) const {
return m_properties->getPointerToPropertyOrdinal(index);
}
/** Get the list of managed properties.
* The properties will be stored in the order that they were declared.
* @return A vector holding pointers to the list of properties
*/
const std::vector<Property *> &PropertyManagerOwner::getProperties() const {
return m_properties->getProperties();
}
/** Get the value of a property. Allows you to assign directly to a variable of
*the property's type
* (if a supported type).
*
* *** This method does NOT work for assigning to an existing std::string.
* In this case you have to use getPropertyValue() instead.
* Note that you can, though, construct a local string variable by writing,
* e.g. std::string s = getProperty("myProperty"). ***
*
* @param name :: The name of the property
* @return The value of the property. Will be cast to the desired type (if a
*supported type).
* @throw std::runtime_error If an attempt is made to assign a property to a
*different type
* @throw Exception::NotFoundError If the property requested does not exist
*/
IPropertyManager::TypedValue
PropertyManagerOwner::getProperty(const std::string &name) const {
return m_properties->getProperty(name);
}
/**
* @param name
* @return True if the property is its default value.
*/
bool PropertyManagerOwner::isDefault(const std::string &name) const {
return m_properties->getPointerToProperty(name)->isDefault();
}
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* Return the property manager serialized as a string.
* The format is propName=value,propName=value,propName=value
* @param withDefaultValues :: If true then the value of default parameters will
* be included
* @param separator :: character for the separator
* @returns A stringized version of the manager
*/
std::string PropertyManagerOwner::asString(bool withDefaultValues,
char separator) const {
return m_properties->asString(withDefaultValues, separator);
}
/**
* Removes the property from properties map.
* @param name :: Name of the property to be removed.
* @param delproperty :: if true, delete the named property
*/
void PropertyManagerOwner::removeProperty(const std::string &name,
const bool delproperty) {
m_properties->removeProperty(name, delproperty);
}
/**
* Clears all properties under management
*/
void PropertyManagerOwner::clear() { m_properties->clear(); }
/**
* Override this method to perform a custom action right after a property was
* set.
* The argument is the property name. Default - do nothing.
* @param name :: A property name.
*/
void PropertyManagerOwner::afterPropertySet(const std::string &name) {
m_properties->afterPropertySet(name);
}
} // namespace Kernel
} // namespace Mantid