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
10#include "MantidKernel/Logger.h"
13
14#include <vector>
15
16namespace NeXus {
17class File;
18}
19
20namespace Mantid {
21
22namespace Kernel {
37template <typename TYPE> class DLLExport PropertyWithValue : public Property {
38public:
39 PropertyWithValue(std::string name, TYPE defaultValue, IValidator_sptr validator = IValidator_sptr(new NullValidator),
40 const unsigned int direction = Direction::Input);
41 PropertyWithValue(std::string name, TYPE defaultValue, const unsigned int direction);
42 PropertyWithValue(const std::string &name, TYPE defaultValue, const std::string &defaultValueStr,
43 IValidator_sptr validator, const unsigned int direction);
45 PropertyWithValue<TYPE> *clone() const override;
46
47 void saveProperty(::NeXus::File *file) override;
48 std::string value() const override;
49 std::string valueAsPrettyStr(const size_t maxLength = 0, const bool collapseLists = true) const override;
50 Json::Value valueAsJson() const override;
53 int size() const override;
54 std::string getDefault() const override;
55 std::string setValue(const std::string &value) override;
56 std::string setValueFromJson(const Json::Value &value) override;
57 std::string setDataItem(const std::shared_ptr<DataItem> &data) override;
61 virtual const TYPE &operator()() const;
62 virtual operator const TYPE &() const;
63 std::string isValid() const override;
64 bool isDefault() const override;
65 std::vector<std::string> allowedValues() const override;
67 virtual void replaceValidator(IValidator_sptr newValidator);
69
70protected:
74 // const TYPE m_initialValue;
76
77private:
78 std::string setValueFromProperty(const Property &right) override;
79
80 template <typename U> std::string setTypedValue(const U &value, const std::true_type &);
81
82 template <typename U> std::string setTypedValue(const U &value, const std::false_type &);
83
84 const TYPE getValueForAlias(const TYPE &alias) const;
85
88
91
93 PropertyWithValue() = default;
94};
95
96template <> MANTID_KERNEL_DLL void PropertyWithValue<float>::saveProperty(::NeXus::File *file);
97template <> MANTID_KERNEL_DLL void PropertyWithValue<double>::saveProperty(::NeXus::File *file);
98template <> MANTID_KERNEL_DLL void PropertyWithValue<int32_t>::saveProperty(::NeXus::File *file);
99template <> MANTID_KERNEL_DLL void PropertyWithValue<uint32_t>::saveProperty(::NeXus::File *file);
100template <> MANTID_KERNEL_DLL void PropertyWithValue<int64_t>::saveProperty(::NeXus::File *file);
101template <> MANTID_KERNEL_DLL void PropertyWithValue<uint64_t>::saveProperty(::NeXus::File *file);
102template <> MANTID_KERNEL_DLL void PropertyWithValue<std::string>::saveProperty(::NeXus::File *file);
103template <> MANTID_KERNEL_DLL void PropertyWithValue<std::vector<double>>::saveProperty(::NeXus::File *file);
104template <> MANTID_KERNEL_DLL void PropertyWithValue<std::vector<int32_t>>::saveProperty(::NeXus::File *file);
105
106template <typename TYPE> Logger PropertyWithValue<TYPE>::g_logger("PropertyWithValue");
107
108} // namespace Kernel
109} // namespace Mantid
const std::vector< double > & rhs
double value
The value of the point.
Definition: FitMW.cpp:51
double right
Definition: LineProfile.cpp:81
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
NullValidator is a validator that doesn't.
Definition: NullValidator.h:20
The concrete, templated class for properties.
bool isDefault() const override
Overriden function that returns if property has the same value that it was initialised with,...
int size() const override
Return the size of this property.
static Logger g_logger
Static reference to the logger class.
std::string setTypedValue(const U &value, const std::true_type &)
std::string setValue(const std::string &value) override
Set the value of the property via a string.
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
Returns the value of the property as a pretty printed string.
Json::Value valueAsJson() const override
Returns the value of the property as a Json::Value.
bool operator==(const PropertyWithValue< TYPE > &rhs) const
IValidator_sptr m_validator
Visitor validator class.
bool isMultipleSelectionAllowed() override
Is Multiple Selection Allowed.
PropertyWithValue(std::string name, TYPE defaultValue, const unsigned int direction)
PropertyWithValue(const PropertyWithValue< TYPE > &right)
PropertyWithValue(std::string name, TYPE defaultValue, IValidator_sptr validator=IValidator_sptr(new NullValidator), const unsigned int direction=Direction::Input)
PropertyWithValue< TYPE > * clone() const override
'Virtual copy constructor'
virtual PropertyWithValue & operator=(const TYPE &value)
const TYPE getValueForAlias(const TYPE &alias) const
PropertyWithValue(const std::string &name, TYPE defaultValue, const std::string &defaultValueStr, IValidator_sptr validator, const unsigned int direction)
PropertyWithValue & operator=(const PropertyWithValue &right)
std::string setValueFromJson(const Json::Value &value) override
Set the value of the property via a Json object.
PropertyWithValue()=default
Private default constructor.
virtual const TYPE & operator()() const
IValidator_sptr getValidator() const
virtual void replaceValidator(IValidator_sptr newValidator)
std::string setTypedValue(const U &value, const std::false_type &)
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.
void saveProperty(::NeXus::File *file) override
std::string value() const override
Returns the value of the property as a string.
std::string isValid() const override
Overridden function that checks whether the property, if not overriden returns "".
PropertyWithValue & operator+=(Property const *right) override
Add to this.
bool operator!=(const PropertyWithValue< TYPE > &rhs) const
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 the value of the property via a DataItem pointer.
std::string getDefault() const override
Get the default value for the property which is the value the property was initialised with.
Base class for properties.
Definition: Property.h:94
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.