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 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 {
52 enum Type {
56 None
57 };
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
109 virtual std::string isValid() const;
110
112 void setSettings(std::unique_ptr<IPropertySettings> settings);
114 IPropertySettings *getSettings();
116 void clearSettings();
117
120 virtual bool isDefault() const = 0;
122 bool remember() const;
123 void setRemember(bool);
124
125 void setDocumentation(const std::string &documentation);
126
127 virtual void saveProperty(::NeXus::File * /*file*/) {
128 throw std::invalid_argument("Property::saveProperty - Cannot save '" + this->name() +
129 "', property type not implemented.");
130 }
132 virtual std::string value() const = 0;
134 virtual std::string valueAsPrettyStr(const size_t maxLength = 0, const bool collapseLists = true) const;
136 virtual Json::Value valueAsJson() const = 0;
138 virtual bool isValueSerializable() const { return true; }
141 virtual std::string setValue(const std::string &) = 0;
147 virtual std::string setValueFromJson(const Json::Value &) = 0;
149 virtual std::string setValueFromProperty(const Property &right) = 0;
152 virtual std::string setDataItem(const std::shared_ptr<DataItem> &) = 0;
155 virtual std::string getDefault() const = 0;
156
160 virtual bool isMultipleSelectionAllowed() { return false; }
161
162 virtual std::vector<std::string> allowedValues() const;
163
164 virtual const PropertyHistory createHistory() const;
165
167 void createTemporaryValue();
169 bool hasTemporaryValue() const;
170
172 unsigned int direction() const { return m_direction; }
173
175 virtual Property &operator+=(Property const *rhs) = 0;
176 virtual void filterByTime(const Types::Core::DateAndTime &start, const Types::Core::DateAndTime &stop);
177 virtual void splitByTime(std::vector<SplittingInterval> &splitter, std::vector<Property *> outputs,
178 bool isProtonCharge = true) const;
179
180 virtual int size() const;
181
182 virtual const std::string &units() const;
183
184 virtual void setUnits(const std::string &unit);
185
186 virtual size_t getMemorySize() const { return sizeof(Property); }
187
191 virtual Property &merge(Property *) { return *this; }
192
194 void setGroup(const std::string &group) { m_group = group; }
195
197 const std::string &getGroup() { return m_group; }
198
199 bool autoTrim() const;
200 void setAutoTrim(const bool &setting);
201
202protected:
204 Property(std::string name, const std::type_info &type, const unsigned int &direction = Direction::Input);
206 Property(const Property &right);
208 std::string m_name;
209
210private:
213
215 std::string m_documentation;
217 const std::type_info *m_typeinfo;
219 const unsigned int m_direction;
221 std::string m_units;
222
224 std::unique_ptr<IPropertySettings> m_settings;
225
227 std::string m_group;
228
231
234
238};
239
241MANTID_KERNEL_DLL bool operator==(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs);
243MANTID_KERNEL_DLL bool operator!=(const Mantid::Kernel::Property &lhs, const Mantid::Kernel::Property &rhs);
244
246MANTID_KERNEL_DLL std::string getUnmangledTypeName(const std::type_info &type);
247
248} // namespace Kernel
249} // namespace Mantid
const std::vector< double > & rhs
double right
Definition: LineProfile.cpp:81
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:217
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:186
Property()
Private default constructor.
void setGroup(const std::string &group)
Set the group this property belongs to.
Definition: Property.h:194
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:172
std::string m_name
The name of the property.
Definition: Property.h:208
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:219
virtual Property & merge(Property *)
Just returns the property (*this) unless overridden.
Definition: Property.h:191
virtual bool isMultipleSelectionAllowed()
Is Multiple Selection Allowed.
Definition: Property.h:160
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:233
std::string m_group
Name of the "group" of this property, for grouping in the GUI. Default "".
Definition: Property.h:227
std::unique_ptr< IPropertySettings > m_settings
Property settings (enabled/visible)
Definition: Property.h:224
const std::string & getGroup()
Definition: Property.h:197
virtual ~Property()
Virtual destructor.
virtual void saveProperty(::NeXus::File *)
Definition: Property.h:127
virtual Property & operator+=(Property const *rhs)=0
Add to this.
std::string m_documentation
Longer, optional description of property.
Definition: Property.h:215
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:237
std::string m_units
Units of the property (optional)
Definition: Property.h:221
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.
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:138
Definition: Algorithm.h:38
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:291
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:259
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:300
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