Mantid
Loading...
Searching...
No Matches
Property.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidKernel/DllConfig.h"
14#ifndef Q_MOC_RUN
15#include <memory>
16#endif
17
18#include <set>
19#include <stdexcept>
20#include <string>
21#include <vector>
22
23namespace Mantid::Nexus {
24class File;
25}
26
27namespace Json {
28class Value;
29}
30namespace std {
31class typeinfo;
32}
33
34namespace Mantid {
35namespace Types {
36namespace Core {
37class DateAndTime;
38}
39} // namespace Types
40namespace Kernel {
41//-----------------------------------------------------------------------------
42// Forward declarations
43//-----------------------------------------------------------------------------
44class DataItem;
45class IPropertySettings;
46class PropertyHistory;
47class SplittingInterval;
48
51struct Direction {
59
61 static const std::string asText(const unsigned int &direction) {
62 switch (direction) {
63 case Input:
64 return "Input";
65 case Output:
66 return "Output";
67 case InOut:
68 return "InOut";
69 default:
70 return "N/A";
71 }
72 }
73
75 static int asEnum(const std::string &direction) {
76 if (direction == "Input")
77 return Direction::Input;
78 else if (direction == "Output")
79 return Direction::Output;
80 else if (direction == "InOut")
81 return Direction::InOut;
82 else
83 return Direction::None;
84 }
85};
86
95class MANTID_KERNEL_DLL Property {
96public:
98 virtual Property *clone() const = 0;
100 virtual ~Property();
101
102 // Getters
103 const std::string &name() const;
104 const std::string &documentation() const;
105 const std::type_info *type_info() const;
106 const std::string type() const;
107
108 void setName(const std::string &name);
109
112 virtual std::string isValid() const;
113
115 void setSettings(std::unique_ptr<IPropertySettings const> settings);
116
118 std::vector<std::unique_ptr<IPropertySettings const>> const &getSettings() const;
119
121 void clearSettings();
122
125 virtual bool isDefault() const = 0;
127 bool remember() const;
128 void setRemember(bool);
129
130 void setDocumentation(const std::string &documentation);
131
132 virtual void saveProperty(Nexus::File * /*file*/) {
133 throw std::invalid_argument("Property::saveProperty - Cannot save '" + this->name() +
134 "', property type not implemented.");
135 }
137 virtual std::string value() const = 0;
139 virtual std::string valueAsPrettyStr(const size_t maxLength = 0, const bool collapseLists = true) const;
141 virtual Json::Value valueAsJson() const = 0;
143 virtual bool isValueSerializable() const { return true; }
146 virtual std::string setValue(const std::string &) = 0;
152 virtual std::string setValueFromJson(const Json::Value &) = 0;
154 virtual std::string setValueFromProperty(const Property &right) = 0;
157 virtual std::string setDataItem(const std::shared_ptr<DataItem> &) = 0;
160 virtual std::string getDefault() const = 0;
161
165 virtual bool isMultipleSelectionAllowed() { return false; }
166
167 virtual std::vector<std::string> allowedValues() const;
168
169 virtual const PropertyHistory createHistory() const;
170
172 void createTemporaryValue();
174 bool hasTemporaryValue() const;
175
177 unsigned int direction() const { return m_direction; }
178
180 virtual Property &operator+=(Property const *rhs) = 0;
181
182 virtual int size() const;
183
184 virtual const std::string &units() const;
185
186 virtual void setUnits(const std::string &unit);
187
188 virtual size_t getMemorySize() const { return sizeof(Property); }
189
193 virtual Property &merge(Property *) { return *this; }
194
196 void setGroup(const std::string &group) { m_group = group; }
197
199 const std::string &getGroup() { return m_group; }
200
201 bool autoTrim() const;
202 void setAutoTrim(const bool &setting);
203
204 bool disableReplaceWSButton() const;
205 void setDisableReplaceWSButton(const bool &disable);
206
207 bool isDynamicDefault() const;
208 void setIsDynamicDefault(const bool &flag);
209
210protected:
212 Property(std::string name, const std::type_info &type, const unsigned int &direction = Direction::Input);
214 Property(const Property &right);
216 std::string m_name;
217
218private:
221
223 std::string m_documentation;
225 const std::type_info *m_typeinfo;
227 const unsigned int m_direction;
229 std::string m_units;
230
232 std::vector<std::unique_ptr<IPropertySettings const>> m_settings;
233
235 std::string m_group;
236
239
242
246
249
253};
254
256MANTID_KERNEL_DLL bool operator==(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs);
258MANTID_KERNEL_DLL bool operator!=(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs);
259
261MANTID_KERNEL_DLL std::string getUnmangledTypeName(const std::type_info &type);
262
263} // namespace Kernel
264} // namespace Mantid
std::string name
Definition Run.cpp:60
const std::vector< double > & rhs
double right
This class stores information about the parameters used by an algorithm.
Base class for properties.
Definition Property.h:95
virtual std::string setValueFromJson(const Json::Value &)=0
Set the value of the property via a Json object.
const std::type_info * m_typeinfo
The type of the property.
Definition Property.h:225
std::vector< std::unique_ptr< IPropertySettings const > > m_settings
Property settings (enabled/visible)
Definition Property.h:232
virtual std::string setDataItem(const std::shared_ptr< DataItem > &)=0
Set the value of the property via a DataItem pointer.
virtual size_t getMemorySize() const
Definition Property.h:188
Property()
Private default constructor.
void setGroup(const std::string &group)
Set the group this property belongs to.
Definition Property.h:196
virtual std::string setValueFromProperty(const Property &right)=0
Set the value of the property via a reference to another property.
unsigned int direction() const
returns the direction of the property
Definition Property.h:177
std::string m_name
The name of the property.
Definition Property.h:216
virtual std::string setValue(const std::string &)=0
Set the value of the property via a string.
const unsigned int m_direction
Whether the property is used as input, output or both to an algorithm.
Definition Property.h:227
virtual Property & merge(Property *)
Just returns the property (*this) unless overridden.
Definition Property.h:193
virtual bool isMultipleSelectionAllowed()
Is Multiple Selection Allowed.
Definition Property.h:165
virtual Property * clone() const =0
'Virtual copy constructor'
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
bool m_remember
Flag whether to save input values.
Definition Property.h:241
std::string m_group
Name of the "group" of this property, for grouping in the GUI. Default "".
Definition Property.h:235
const std::string & getGroup()
Definition Property.h:199
bool m_disableReplaceWSButton
Flag to disable the generation of the "Replace Workspace" button on the OutputWorkspace property.
Definition Property.h:248
virtual ~Property()
Virtual destructor.
virtual Property & operator+=(Property const *rhs)=0
Add to this.
virtual void saveProperty(Nexus::File *)
Definition Property.h:132
std::string m_documentation
Longer, optional description of property.
Definition Property.h:223
virtual std::string getDefault() const =0
Get the default value for the property which is the value the property was initialised with.
bool m_autotrim
Flag to determine if string inputs to the property should be automatically trimmed of whitespace.
Definition Property.h:245
std::string m_units
Units of the property (optional)
Definition Property.h:229
Property & operator=(const Property &right)
Private, unimplemented copy assignment operator.
virtual Json::Value valueAsJson() const =0
Returns the value of the property as a Json::Value.
bool m_isDynamicDefault
Flag to indicate that the property's value has been set programmatically, for example,...
Definition Property.h:252
virtual std::string value() const =0
Returns the value of the property as a string.
virtual bool isValueSerializable() const
Whether the string returned by value() can be used for serialization.
Definition Property.h:143
MANTID_KERNEL_DLL bool operator!=(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs)
Compares this to another property for inequality.
Definition Property.cpp:278
MANTID_KERNEL_DLL bool operator==(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs)
Compares this to another property for equality.
Definition Property.cpp:246
MANTID_KERNEL_DLL std::string getUnmangledTypeName(const std::type_info &type)
Return the name corresponding to the mangled string given by typeid.
Definition Property.cpp:287
Header for a base Nexus::Exception.
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition Property.h:51
Type
Enum giving the possible directions.
Definition Property.h:53
@ InOut
Both an input & output workspace.
Definition Property.h:56
@ Input
An input workspace.
Definition Property.h:54
@ Output
An output workspace.
Definition Property.h:55
static const std::string asText(const unsigned int &direction)
Returns a text representation of the input Direction enum.
Definition Property.h:61
static int asEnum(const std::string &direction)
Returns an enum representation of the input Direction string.
Definition Property.h:75