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"
13#ifndef Q_MOC_RUN
14#include <memory>
15#endif
16
17#include <set>
18#include <stdexcept>
19#include <string>
20#include <vector>
21
22namespace Mantid::Nexus {
23class File;
24}
25
26namespace Json {
27class Value;
28}
29namespace std {
30class typeinfo;
31}
32
33namespace Mantid {
34namespace Types {
35namespace Core {
36class DateAndTime;
37}
38} // namespace Types
39namespace Kernel {
40//-----------------------------------------------------------------------------
41// Forward declarations
42//-----------------------------------------------------------------------------
43class DataItem;
44class IPropertySettings;
45class PropertyHistory;
46class SplittingInterval;
47
50struct Direction {
58
60 static const std::string asText(const unsigned int &direction) {
61 switch (direction) {
62 case Input:
63 return "Input";
64 case Output:
65 return "Output";
66 case InOut:
67 return "InOut";
68 default:
69 return "N/A";
70 }
71 }
72
74 static int asEnum(const std::string &direction) {
75 if (direction == "Input")
76 return Direction::Input;
77 else if (direction == "Output")
78 return Direction::Output;
79 else if (direction == "InOut")
80 return Direction::InOut;
81 else
82 return Direction::None;
83 }
84};
85
94class MANTID_KERNEL_DLL Property {
95public:
97 virtual Property *clone() const = 0;
99 virtual ~Property();
100
101 // Getters
102 const std::string &name() const;
103 const std::string &documentation() const;
104 const std::type_info *type_info() const;
105 const std::string type() const;
106
107 void setName(const std::string &name);
108
111 virtual std::string isValid() const;
112
114 void setSettings(std::unique_ptr<IPropertySettings> settings);
115
117 const IPropertySettings *getSettings() const;
118 IPropertySettings *getSettings();
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::unique_ptr<IPropertySettings> 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
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
This class stores information about the parameters used by an algorithm.
Base class for properties.
Definition Property.h:94
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
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
std::unique_ptr< IPropertySettings > m_settings
Property settings (enabled/visible)
Definition Property.h:232
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:276
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:244
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:285
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:50
Type
Enum giving the possible directions.
Definition Property.h:52
@ InOut
Both an input & output workspace.
Definition Property.h:55
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54
static const std::string asText(const unsigned int &direction)
Returns a text representation of the input Direction enum.
Definition Property.h:60
static int asEnum(const std::string &direction)
Returns an enum representation of the input Direction string.
Definition Property.h:74