Mantid
Loading...
Searching...
No Matches
EnumeratedStringProperty.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
10#include <vector>
11
12namespace Mantid {
13
14namespace Kernel {
23template <class E, std::vector<std::string> const *const names> class EnumeratedStringProperty : public Property {
24
26
27public:
28 // CONSTRUCTORS
29 EnumeratedStringProperty(std::string const &name, ENUMSTRING const &defaultValue = static_cast<E>(0),
32 EnumeratedStringProperty *clone() const override;
34
35 // GETTERS
36 std::string value() const override;
37 std::string valueAsPrettyStr(size_t const maxLength = 0, bool const collapseLists = true) const override;
38 Json::Value valueAsJson() const override;
39
40 bool operator==(EnumeratedStringProperty const &rhs) const;
41 bool operator!=(EnumeratedStringProperty const &rhs) const;
42 int size() const override;
43 std::string getDefault() const override;
44
49 operator ENUMSTRING() const { return this->m_value; };
50 operator E() const { return static_cast<E>(m_value); };
51 operator std::string() const { return static_cast<std::string>(m_value); };
52
53 ENUMSTRING operator()() const;
54 std::string isValid() const override;
55 bool isDefault() const override;
56 std::vector<std::string> allowedValues() const override;
57
58 // SETTERS
59 std::string setValue(E const value);
60 std::string setValue(std::string const &value) override;
61 std::string setValue(ENUMSTRING const &value);
62 std::string setValueFromJson(const Json::Value &value) override;
63 std::string setDataItem(const std::shared_ptr<DataItem> &data) override;
65 EnumeratedStringProperty const &operator=(std::string const &value);
67
68 // MUTATORS AND SUNDRY
70 void saveProperty(Nexus::File *file) override;
71
72protected:
77
78private:
79 std::string setValueFromProperty(Property const &right) override;
80
81 template <typename U> std::string setTypedValue(U const &value, std::true_type const &);
82
83 template <typename U> std::string setTypedValue(U const &value, std::false_type const &);
84};
85
86// template <typename TYPE> Logger PropertyWithValue<TYPE>::g_logger("PropertyWithValue");
87
88} // namespace Kernel
89} // namespace Mantid
90
const std::vector< double > & rhs
double right
A concrete property based on user options of a finite list of strings.
std::string isValid() const override
If the value has been set, then it is valid.
std::string setDataItem(const std::shared_ptr< DataItem > &data) override
Set a property value via a DataItem.
int size() const override
Get the size of the property.
std::string setTypedValue(U const &value, std::true_type const &)
Helper function for setValue(DataItem_sptr).
std::string getDefault() const override
Get the value the property was initialised with -its default value.
std::string valueAsPrettyStr(size_t const maxLength=0, bool const collapseLists=true) const override
Get the value of the property as a more prettier string.
ENUMSTRING m_initialValue
the property's default value which is also its initial value
Json::Value valueAsJson() const override
Attempt to construct a Json::Value object from the plain value.
EnumeratedStringProperty * clone() const override
Virtual copy constructor.
ENUMSTRING operator()() const
Allows you to get the value of the property simply by typing its name.
bool operator==(EnumeratedStringProperty const &rhs) const
Deep comparison.
EnumeratedStringProperty & operator=(EnumeratedStringProperty const &right)
Assignment operator.
ENUMSTRING m_value
The value of the property.
std::vector< std::string > allowedValues() const override
Returns the set of valid values for this property, if such a set exists.
std::string value() const override
Get the value of the property as a string.
bool isDefault() const override
Indicates if the property's value is the same as it was when it was set N.B.
std::string setValueFromProperty(Property const &right) override
Set the value of the property via a reference to another property.
bool operator!=(EnumeratedStringProperty const &rhs) const
Deep comparison (not equal).
std::string setValue(E const value)
Set the value of the property from a string representation.
EnumeratedStringProperty & operator+=(Property const *right) override
Add the value of another property.
std::string setValueFromJson(const Json::Value &value) override
Set the value of the property from a Json representation.
Base class for properties.
Definition Property.h:94
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:61
Helper class which provides the Collimation Length for SANS instruments.
Type
Enum giving the possible directions.
Definition Property.h:52
@ Input
An input workspace.
Definition Property.h:53