Mantid
Loading...
Searching...
No Matches
StartsWithValidator.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#include <algorithm>
9#ifndef Q_MOC_RUN
10#include <memory>
11#endif
12
13namespace Mantid::Kernel {
18StartsWithValidator::StartsWithValidator(const std::vector<std::string> &values)
19 : Kernel::StringListValidator(values) {}
24StartsWithValidator::StartsWithValidator(const std::set<std::string> &values) : Kernel::StringListValidator(values) {}
25
27IValidator_sptr StartsWithValidator::clone() const { return std::make_shared<StartsWithValidator>(*this); }
28
34std::string StartsWithValidator::checkValidity(const std::string &value) const {
35 if (std::any_of(m_allowedValues.cbegin(), m_allowedValues.cend(),
36 [&value](const auto &val) { return value.substr(0, val.size()) == val; })) {
37 return "";
38 }
39 if (isEmpty(value))
40 return "Select a value";
41 std::ostringstream os;
42 os << "The value \"" << value << "\" does not start with any of the allowed values";
43 return os.str();
44}
45
46} // namespace Mantid::Kernel
double value
The value of the point.
Definition FitMW.cpp:51
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
bool isEmpty(const T &value) const
Is the value considered empty.
std::vector< TYPE > m_allowedValues
The set of valid values.
std::string checkValidity(const std::string &value) const override
Checks if the string passed starts with one from the list.
IValidator_sptr clone() const override
Clone the validator.
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26