Mantid
Loading...
Searching...
No Matches
IndexTypeProperty.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8
9namespace Mantid::API {
10IndexTypeProperty::IndexTypeProperty(const std::string &name, const int indexType)
11 : PropertyWithValue<std::string>(name, "", Kernel::Direction::Input) {
12 if (indexType & static_cast<int>(IndexType::WorkspaceIndex))
13 m_allowedValues.emplace_back("WorkspaceIndex");
14 if (indexType & static_cast<int>(IndexType::SpectrumNum))
15 m_allowedValues.emplace_back("SpectrumNumber");
16
17 if (m_allowedValues.empty())
18 throw std::invalid_argument("Argument indexType incorrectly specified");
19
21}
22
24 auto val = this->value();
25 if (val == "SpectrumNumber")
27 else if (val == "WorkspaceIndex")
29 else if (val.empty())
30 throw std::runtime_error("This value cannot be used until initialised");
31 else
32 throw std::runtime_error(val + " is an invalid IndexType.");
33}
34
36 int types(0);
37 const auto beg = m_allowedValues.cbegin();
38 const auto end = m_allowedValues.cend();
39
40 if (std::find(beg, end, "SpectrumNumber") != end) {
41 types |= static_cast<int>(IndexType::SpectrumNum);
42 }
43
44 if (std::find(beg, end, "WorkspaceIndex") != end) {
45 types |= static_cast<int>(IndexType::WorkspaceIndex);
46 }
47
48 return types;
49}
50
51std::vector<std::string> IndexTypeProperty::allowedValues() const { return m_allowedValues; }
52
54
56 std::string val;
57
58 switch (type) {
60 val = "SpectrumNumber";
61 break;
63 val = "WorkspaceIndex";
64 break;
65 }
66
67 *this = val;
68 return *this;
69}
70
71std::string IndexTypeProperty::generatePropertyName(const std::string &name) { return name + "IndexType"; }
72
73} // namespace Mantid::API
IndexTypeProperty : Implementation of a property which stores the type of input indices users require...
bool isMultipleSelectionAllowed() override
Is Multiple Selection Allowed.
std::vector< std::string > allowedValues() const override
Returns the set of valid values for this property, if such a set exists.
IndexTypeProperty(const std::string &name="IndexType", int indexType=static_cast< int >(IndexType::WorkspaceIndex))
static std::string generatePropertyName(const std::string &name="")
IndexTypeProperty & operator=(API::IndexType type)
std::vector< std::string > m_allowedValues
The concrete, templated class for properties.
std::string m_value
The value of the property.
const std::string & name() const
Get the property's name.
Definition: Property.cpp:60
const std::string type() const
Returns the type of the property as a string.
Definition: Property.cpp:76
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50