Mantid
Loading...
Searching...
No Matches
ADSValidator.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 +
11#include <memory>
12#include <sstream>
13
14namespace Mantid::API {
15
17ADSValidator::ADSValidator(const bool allowMultiSelection, const bool isOptional)
18 : TypedValidator<std::vector<std::string>>(), m_AllowMultiSelection(allowMultiSelection), m_isOptional(isOptional) {
19}
20
22Kernel::IValidator_sptr ADSValidator::clone() const { return std::make_shared<ADSValidator>(*this); }
23
25
26void ADSValidator::setMultipleSelectionAllowed(const bool isMultiSelectionAllowed) {
27 m_AllowMultiSelection = isMultiSelectionAllowed;
28}
29
30bool ADSValidator::isOptional() const { return m_isOptional; }
31
32void ADSValidator::setOptional(const bool setOptional) { m_isOptional = setOptional; }
33
39std::string ADSValidator::checkValidity(const std::vector<std::string> &value) const {
40 if (!m_isOptional && value.empty())
41 return "Select a value";
42 if (!m_AllowMultiSelection && (value.size() > 1)) {
43 return "Only one workspace was expected.";
44 }
46 std::ostringstream os;
47 for (const auto &wsName : value) {
48 if (!ads.doesExist(wsName)) {
49 os << "The workspace \"" << wsName << "\" is not in the workspace list.\n";
50 }
51 }
52 return os.str();
53}
54
60std::vector<std::string> ADSValidator::allowedValues() const {
61 // Get the list of workspaces currently in the ADS
63 if (isOptional()) // Insert an empty option
64 {
65 vals.emplace_back("");
66 }
67 return vals;
68}
69
70} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::string checkValidity(const std::vector< std::string > &value) const override
Checks if the string passed is in the ADS, or if all members are in the ADS.
void setOptional(const bool setOptional)
bool m_AllowMultiSelection
if the validator should allow multiple selection
Definition: ADSValidator.h:50
std::vector< std::string > allowedValues() const override
Returns the current contents of the AnalysisDataService for input workspaces.
Kernel::IValidator_sptr clone() const override
Clone the validator.
bool isMultipleSelectionAllowed() override
ADSValidator(const bool allowMultiSelection=true, const bool isOptional=false)
Default constructor. Sets up an empty list of valid values.
bool m_isOptional
if the validator should an empty selection
Definition: ADSValidator.h:52
void setMultipleSelectionAllowed(const bool isMultiSelectionAllowed)
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
STL namespace.