Mantid
Loading...
Searching...
No Matches
MultiFileValidator.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 +
9#include <memory>
10
11namespace Mantid::Kernel {
12namespace {
13// static logger
14Logger g_log("MultiFileValidator");
15} // namespace
16
19 : TypedValidator<std::vector<std::vector<std::string>>>(), m_fileValidator(std::vector<std::string>(), true) {}
20
25 : TypedValidator<std::vector<std::vector<std::string>>>(), m_fileValidator(mfv.m_fileValidator) {}
26
28 using std::swap;
30}
31
33 swap(*this, tmp);
34 return *this;
35}
36
41MultiFileValidator::MultiFileValidator(const std::vector<std::string> &extensions, bool testFilesExist)
42 : TypedValidator<std::vector<std::vector<std::string>>>(), m_fileValidator(extensions, testFilesExist) {}
43
45std::vector<std::string> MultiFileValidator::allowedValues() const { return m_fileValidator.allowedValues(); }
46
51IValidator_sptr MultiFileValidator::clone() const { return std::make_shared<MultiFileValidator>(*this); }
52
59std::string MultiFileValidator::checkValidity(const std::vector<std::vector<std::string>> &values) const {
60 if (values.empty())
61 return m_fileValidator.isValid("");
62
63 std::string accumulatedErrors;
64
65 for (auto row : values) {
66 for (const auto &valueIt : row) {
67 // For each filename value, check its validity, and and accumulate any
68 // errors.
69 std::string error = m_fileValidator.isValid(valueIt);
70 if (!error.empty()) {
71 if (accumulatedErrors.empty())
72 accumulatedErrors = "Could not validate the following file(s): " + valueIt;
73 else
74 accumulatedErrors.append(", ").append(valueIt);
75 }
76 }
77 }
78
79 return accumulatedErrors;
80}
81
82} // namespace Mantid::Kernel
gsl_vector * tmp
double error
Definition: IndexPeaks.cpp:133
std::vector< std::string > allowedValues() const override
Returns the set of valid values.
The MultiFileValidator validates a MultiFileProperty, which contains a vector of vectors* of filename...
FileValidator m_fileValidator
FileValidator instance used for validating multiple files.
friend void swap(MultiFileValidator &obj1, MultiFileValidator &obj2)
std::string checkValidity(const std::vector< std::vector< std::string > > &values) const override
Returns an error if at least one of the files is not valid, else "".
MultiFileValidator & operator=(MultiFileValidator)
std::vector< std::string > allowedValues() const override
Returns the set of allowed extensions.
IValidator_sptr clone() const override
Clone the validator.
void swap(MultiFileValidator &obj1, MultiFileValidator &obj2)
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
STL namespace.