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 const> settings);
115
117 std::vector<std::unique_ptr<IPropertySettings const>> const &getSettings() const;
118
120 void clearSettings();
121
124 virtual bool isDefault() const = 0;
126 bool remember() const;
127 void setRemember(bool);
128
129 void setDocumentation(const std::string &documentation);
130
131 virtual void saveProperty(Nexus::File * /*file*/) {
132 throw std::invalid_argument("Property::saveProperty - Cannot save '" + this->name() +
133 "', property type not implemented.");
134 }
136 virtual std::string value() const = 0;
138 virtual std::string valueAsPrettyStr(const size_t maxLength = 0, const bool collapseLists = true) const;
140 virtual Json::Value valueAsJson() const = 0;
142 virtual bool isValueSerializable() const { return true; }
145 virtual std::string setValue(const std::string &) = 0;
151 virtual std::string setValueFromJson(const Json::Value &) = 0;
153 virtual std::string setValueFromProperty(const Property &right) = 0;
156 virtual std::string setDataItem(const std::shared_ptr<DataItem> &) = 0;
159 virtual std::string getDefault() const = 0;
160
164 virtual bool isMultipleSelectionAllowed() { return false; }
165
166 virtual std::vector<std::string> allowedValues() const;
167
168 virtual const PropertyHistory createHistory() const;
169
171 void createTemporaryValue();
173 bool hasTemporaryValue() const;
174
176 unsigned int direction() const { return m_direction; }
177
179 virtual Property &operator+=(Property const *rhs) = 0;
180
181 virtual int size() const;
182
183 virtual const std::string &units() const;
184
185 virtual void setUnits(const std::string &unit);
186
187 virtual size_t getMemorySize() const { return sizeof(Property); }
188
192 virtual Property &merge(Property *) { return *this; }
193
195 void setGroup(const std::string &group) { m_group = group; }
196
198 const std::string &getGroup() { return m_group; }
199
200 bool autoTrim() const;
201 void setAutoTrim(const bool &setting);
202
203 bool disableReplaceWSButton() const;
204 void setDisableReplaceWSButton(const bool &disable);
205
206 bool isDynamicDefault() const;
207 void setIsDynamicDefault(const bool &flag);
208
209protected:
211 Property(std::string name, const std::type_info &type, const unsigned int &direction = Direction::Input);
213 Property(const Property &right);
215 std::string m_name;
216
217private:
220
222 std::string m_documentation;
224 const std::type_info *m_typeinfo;
226 const unsigned int m_direction;
228 std::string m_units;
229
231 std::vector<std::unique_ptr<IPropertySettings const>> m_settings;
232
234 std::string m_group;
235
238
241
245
248
252};
253
255MANTID_KERNEL_DLL bool operator==(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs);
257MANTID_KERNEL_DLL bool operator!=(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs);
258
260MANTID_KERNEL_DLL std::string getUnmangledTypeName(const std::type_info &type);
261
262} // namespace Kernel
263} // 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: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:224
std::vector< std::unique_ptr< IPropertySettings const > > m_settings
Property settings (enabled/visible)
Definition Property.h:231
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:187
Property()
Private default constructor.
void setGroup(const std::string &group)
Set the group this property belongs to.
Definition Property.h:195
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:176
std::string m_name
The name of the property.
Definition Property.h:215
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:226
virtual Property & merge(Property *)
Just returns the property (*this) unless overridden.
Definition Property.h:192
virtual bool isMultipleSelectionAllowed()
Is Multiple Selection Allowed.
Definition Property.h:164
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:240
std::string m_group
Name of the "group" of this property, for grouping in the GUI. Default "".
Definition Property.h:234
const std::string & getGroup()
Definition Property.h:198
bool m_disableReplaceWSButton
Flag to disable the generation of the "Replace Workspace" button on the OutputWorkspace property.
Definition Property.h:247
virtual ~Property()
Virtual destructor.
virtual Property & operator+=(Property const *rhs)=0
Add to this.
virtual void saveProperty(Nexus::File *)
Definition Property.h:131
std::string m_documentation
Longer, optional description of property.
Definition Property.h:222
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:244
std::string m_units
Units of the property (optional)
Definition Property.h:228
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:251
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:142
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: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