Mantid
Loading...
Searching...
No Matches
DirectoryValidator.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 <Poco/Exception.h>
10#include <Poco/File.h>
11#include <Poco/Path.h>
12#include <memory>
13
14namespace Mantid::Kernel {
15
21 this->m_testExist = testDirectoryExists;
22}
23
25std::vector<std::string> DirectoryValidator::allowedValues() const { return std::vector<std::string>(); }
26
31IValidator_sptr DirectoryValidator::clone() const { return std::make_shared<DirectoryValidator>(*this); }
32
38std::string DirectoryValidator::checkValidity(const std::string &value) const {
39 // Check if the path is syntactically valid
40 if (!Poco::Path().tryParse(value)) {
41 return "Error in path syntax: \"" + value + "\".";
42 }
43
44 // If the path is required to exist check it is there
45 if (m_testExist) {
46 try {
47 if (value.empty() || !Poco::File(value).exists())
48 return "Directory \"" + value + "\" not found";
49 if (!Poco::File(value).isDirectory())
50 return "Directory \"" + value + "\" specified is actually a file";
51 } catch (Poco::FileException &) {
52 return "Error accessing directory \"" + value + "\"";
53 }
54 }
55
56 // Otherwise we are okay, file extensions are just a suggestion so no
57 // validation on them is necessary
58 return "";
59}
60
61} // namespace Mantid::Kernel
double value
The value of the point.
Definition: FitMW.cpp:51
IValidator_sptr clone() const override
Clone the validator.
DirectoryValidator(bool testDirectoryExists=true)
Constructor.
std::vector< std::string > allowedValues() const override
Returns the set of valid values.
std::string checkValidity(const std::string &value) const override
If m_fullTest=true if checks that the files exists, otherwise just that path syntax looks valid.
FileValidator is a validator that checks that a filepath is valid.
Definition: FileValidator.h:25
bool m_testExist
Flag indicating whether to test for existence of filename.
Definition: FileValidator.h:36
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26