Mantid
Loading...
Searching...
No Matches
PropertyWithValue.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#include "MantidKernel/DllConfig.h"
11#include "MantidKernel/Logger.h"
14
15#include <string>
16#include <vector>
17
18namespace Mantid {
19
20namespace Kernel {
35template <typename TYPE> class PropertyWithValue : public Property {
36public:
37 PropertyWithValue(std::string name, TYPE defaultValue, IValidator_sptr validator = nullptr,
38 const unsigned int direction = Direction::Input);
39 PropertyWithValue(std::string name, TYPE defaultValue, const unsigned int direction);
40 PropertyWithValue(const std::string &name, const TYPE &defaultValue, const std::string &defaultValueStr,
41 IValidator_sptr validator, const unsigned int direction);
44 PropertyWithValue<TYPE> *clone() const override;
45
46 void saveProperty(Nexus::File *file) override;
47 std::string value() const override;
48 std::string valueAsPrettyStr(const size_t maxLength = 0, const bool collapseLists = true) const override;
49 Json::Value valueAsJson() const override;
50 bool operator==(const PropertyWithValue<TYPE> &rhs) const;
51 bool operator!=(const PropertyWithValue<TYPE> &rhs) const;
52 int size() const override;
53 std::string getDefault() const override;
54 std::string setValue(const std::string &value) override;
55 std::string setValueFromJson(const Json::Value &value) override;
56 std::string setDataItem(const std::shared_ptr<DataItem> &data) override;
59 virtual PropertyWithValue &operator=(const TYPE &value);
60 virtual const TYPE &operator()() const;
61 virtual operator const TYPE &() const;
62 std::string isValid() const override;
63 bool isDefault() const override;
64 std::vector<std::string> allowedValues() const override;
65 bool isMultipleSelectionAllowed() override;
66 virtual void replaceValidator(IValidator_sptr newValidator);
68
69protected:
73 // const TYPE m_initialValue;
75
76private:
77 std::string setValueFromProperty(const Property &right) override;
78
79 template <typename U> std::string setTypedValue(const U &value, const std::true_type &);
80
81 template <typename U> std::string setTypedValue(const U &value, const std::false_type &);
82
83 const TYPE getValueForAlias(const TYPE &alias) const;
84
87
90};
91
92// Instantiated and exported by PropertyWithValue.cpp. OptionalBool and Matrix
93// are declared in OptionalBool.h and MatrixProperty.h.
112MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<std::vector<int32_t>>>);
113MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<std::vector<std::string>>>);
114MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::shared_ptr<PropertyManager>>);
115// The integer type of the same width that is not int64_t
116#if defined(_WIN32) || defined(__clang__) && defined(__APPLE__)
120MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<unsigned long>>);
121MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<std::vector<long>>>);
122#endif
123#ifdef __linux__
126MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<long long>>);
127MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<unsigned long long>>);
128MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue<std::vector<std::vector<long long>>>);
129#endif
130
131template <typename TYPE> Logger PropertyWithValue<TYPE>::g_logger("PropertyWithValue");
132
133} // namespace Kernel
134} // namespace Mantid
const std::vector< double > & rhs
double right
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
The concrete, templated class for properties.
virtual void replaceValidator(IValidator_sptr newValidator)
Replace the current validator with the given one.
bool isDefault() const override
Indicates if the property's value is the same as it was when it was set N.B.
int size() const override
Get the size of the property.
static Logger g_logger
Static reference to the logger class.
PropertyWithValue & operator=(const PropertyWithValue &right)
Copy assignment operator assigns only the value and the validator not the name, default (initial) val...
std::string setTypedValue(const U &value, const std::true_type &)
Helper function for setValue(DataItem_sptr).
std::string setValue(const std::string &value) override
Set the value of the property from a string representation.
PropertyWithValue & operator+=(Property const *right) override
Add the value of another property.
TYPE m_initialValue
the property's default value which is also its initial value
std::string valueAsPrettyStr(const size_t maxLength=0, const bool collapseLists=true) const override
Get the value of the property as a string.
Json::Value valueAsJson() const override
Attempt to construct a Json::Value object from the plain value.
bool operator==(const PropertyWithValue< TYPE > &rhs) const
Deep comparison.
IValidator_sptr m_validator
Visitor validator class.
bool isMultipleSelectionAllowed() override
Returns the set of valid values for this property, if such a set exists.
void saveProperty(Nexus::File *file) override
PropertyWithValue< TYPE > * clone() const override
'Virtual copy constructor'
const TYPE getValueForAlias(const TYPE &alias) const
Return value for a given alias.
virtual const TYPE & operator()() const
Allows you to get the value of the property via an expression like myProperty()
std::string setValueFromJson(const Json::Value &value) override
Set the value of the property from a Json representation.
IValidator_sptr getValidator() const
Returns the validator as a constant variable so it cannot be changed.
std::vector< std::string > allowedValues() const override
Returns the set of valid values for this property, if such a set exists.
TYPE m_value
The value of the property.
std::string value() const override
Get the value of the property as a string.
std::string isValid() const override
Check the value chosen for the property is OK, unless overidden it just calls the validator's isValid...
bool operator!=(const PropertyWithValue< TYPE > &rhs) const
Deep comparison (not equal).
std::string setValueFromProperty(const Property &right) override
Set the value of the property via a reference to another property.
std::string setDataItem(const std::shared_ptr< DataItem > &data) override
Set a property value via a DataItem.
std::string getDefault() const override
Get the value the property was initialised with -its default value.
Base class for properties.
Definition Property.h:95
unsigned int direction() const
returns the direction of the property
Definition Property.h:177
const std::string & name() const
Get the property's name.
Definition Property.cpp:63
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
MANTID_KERNEL_EXTERN_TEMPLATE(PropertyWithValue< Matrix< float > >)
Helper class which provides the Collimation Length for SANS instruments.
@ Input
An input workspace.
Definition Property.h:54