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#ifndef Q_MOC_RUN
9#include <memory>
10#endif
11
12namespace Mantid::Kernel {
17StartsWithValidator::StartsWithValidator(const std::vector<std::string> &values)
18 : Kernel::StringListValidator(values) {}
23StartsWithValidator::StartsWithValidator(const std::set<std::string> &values) : Kernel::StringListValidator(values) {}
24
26IValidator_sptr StartsWithValidator::clone() const { return std::make_shared<StartsWithValidator>(*this); }
27
33std::string StartsWithValidator::checkValidity(const std::string &value) const {
34 if (std::any_of(m_allowedValues.cbegin(), m_allowedValues.cend(),
35 [&value](const auto &val) { return value.substr(0, val.size()) == val; })) {
36 return "";
37 }
38 if (isEmpty(value))
39 return "Select a value";
40 std::ostringstream os;
41 os << "The value \"" << value << "\" does not start with any of the allowed values";
42 return os.str();
43}
44
45} // 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...
Definition: ListValidator.h:29
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