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
12
13#include <vector>
14
15namespace Mantid {
16
17namespace Kernel {
32template <typename TYPE> class DLLExport PropertyWithValue : public Property {
33public:
34 PropertyWithValue(std::string name, TYPE defaultValue, IValidator_sptr validator = IValidator_sptr(new NullValidator),
35 const unsigned int direction = Direction::Input);
36 PropertyWithValue(std::string name, TYPE defaultValue, const unsigned int direction);
37 PropertyWithValue(const std::string &name, const TYPE &defaultValue, const std::string &defaultValueStr,
38 IValidator_sptr validator, const unsigned int direction);
41 PropertyWithValue<TYPE> *clone() const override;
42
43 void saveProperty(Nexus::File *file) override;
44 std::string value() const override;
45 std::string valueAsPrettyStr(const size_t maxLength = 0, const bool collapseLists = true) const override;
46 Json::Value valueAsJson() const override;
47 bool operator==(const PropertyWithValue<TYPE> &rhs) const;
48 bool operator!=(const PropertyWithValue<TYPE> &rhs) const;
49 int size() const override;
50 std::string getDefault() const override;
51 std::string setValue(const std::string &value) override;
52 std::string setValueFromJson(const Json::Value &value) override;
53 std::string setDataItem(const std::shared_ptr<DataItem> &data) override;
54 PropertyWithValue &operator=(const PropertyWithValue &right);
56 virtual PropertyWithValue &operator=(const TYPE &value);
57 virtual const TYPE &operator()() const;
58 virtual operator const TYPE &() const;
59 std::string isValid() const override;
60 bool isDefault() const override;
61 std::vector<std::string> allowedValues() const override;
62 bool isMultipleSelectionAllowed() override;
63 virtual void replaceValidator(IValidator_sptr newValidator);
64 IValidator_sptr getValidator() const;
65
66protected:
70 // const TYPE m_initialValue;
72
73private:
74 std::string setValueFromProperty(const Property &right) override;
75
76 template <typename U> std::string setTypedValue(const U &value, const std::true_type &);
77
78 template <typename U> std::string setTypedValue(const U &value, const std::false_type &);
79
80 const TYPE getValueForAlias(const TYPE &alias) const;
81
84
87};
88
89template <> MANTID_KERNEL_DLL void PropertyWithValue<float>::saveProperty(Nexus::File *file);
90template <> MANTID_KERNEL_DLL void PropertyWithValue<double>::saveProperty(Nexus::File *file);
91template <> MANTID_KERNEL_DLL void PropertyWithValue<int32_t>::saveProperty(Nexus::File *file);
92template <> MANTID_KERNEL_DLL void PropertyWithValue<uint32_t>::saveProperty(Nexus::File *file);
93template <> MANTID_KERNEL_DLL void PropertyWithValue<int64_t>::saveProperty(Nexus::File *file);
94template <> MANTID_KERNEL_DLL void PropertyWithValue<uint64_t>::saveProperty(Nexus::File *file);
95template <> MANTID_KERNEL_DLL void PropertyWithValue<std::string>::saveProperty(Nexus::File *file);
96template <> MANTID_KERNEL_DLL void PropertyWithValue<std::vector<double>>::saveProperty(Nexus::File *file);
97template <> MANTID_KERNEL_DLL void PropertyWithValue<std::vector<int32_t>>::saveProperty(Nexus::File *file);
98
99template <typename TYPE> Logger PropertyWithValue<TYPE>::g_logger("PropertyWithValue");
100
101} // namespace Kernel
102} // namespace Mantid
std::string name
Definition Run.cpp:60
const std::vector< double > & rhs
double value
The value of the point.
Definition FitMW.cpp:51
double right
MANTID_NEXUS_DLL bool operator!=(std::string const &s, Mantid::Nexus::NexusAddress const &p)
MANTID_NEXUS_DLL bool operator==(std::string const &s, Mantid::Nexus::NexusAddress const &p)
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition System.h:37
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
NullValidator is a validator that doesn't.
The concrete, templated class for properties.
static Logger g_logger
Static reference to the logger class.
TYPE m_initialValue
the property's default value which is also its initial value
IValidator_sptr m_validator
Visitor validator class.
void saveProperty(Nexus::File *file) override
TYPE m_value
The value of the property.
Base class for properties.
Definition Property.h:94
MatrixWorkspace_sptr MANTID_API_DLL operator+=(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Adds two workspaces.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26
Helper class which provides the Collimation Length for SANS instruments.