Add new verifiers for files and directories. Update codegen to be able to create these

This commit is contained in:
Alexander Bock
2021-02-13 10:44:21 +01:00
parent afd484044d
commit e7bcb774ee
3 changed files with 64 additions and 1 deletions

View File

@@ -158,6 +158,28 @@ struct StringVerifier : public TemplateVerifier<std::string> {
std::string type() const override;
};
/**
* A Verifier that checks whether a given key inside a ghoul::Dictionary is a string and
* refers to an existing file on disk.
*/
struct FileVerifier : public StringVerifier {
TestResult operator()(const ghoul::Dictionary& dict,
const std::string& key) const override;
std::string type() const override;
};
/**
* A Verifier that checks whether a given key inside a ghoul::Dictionary is a string and
* refers to an existing directory on disk.
*/
struct DirectoryVerifier : public StringVerifier {
TestResult operator()(const ghoul::Dictionary& dict,
const std::string& key) const override;
std::string type() const override;
};
/**
* A Verifier that checks whether a given key inside a ghoul::Dictionary is another
* ghoul::Dictionary. The constructor takes a list of DocumentationEntry%s, which are used

View File

@@ -27,6 +27,7 @@
#include <openspace/documentation/documentationengine.h>
#include <ghoul/misc/misc.h>
#include <algorithm>
#include <filesystem>
namespace openspace::documentation {
@@ -177,6 +178,46 @@ std::string StringVerifier::type() const {
return "String";
}
TestResult FileVerifier::operator()(const ghoul::Dictionary& dict,
const std::string& key) const
{
TestResult res = StringVerifier::operator()(dict, key);
if (!res.success) {
return res;
}
std::string file = dict.value<std::string>(key);
if (!std::filesystem::exists(file) || !std::filesystem::is_regular_file(file)) {
res.success = false;
res.offenses.push_back({ key, TestResult::Offense::Reason::Verification });
}
return res;
}
std::string FileVerifier::type() const {
return "File";
}
TestResult DirectoryVerifier::operator()(const ghoul::Dictionary& dict,
const std::string& key) const
{
TestResult res = StringVerifier::operator()(dict, key);
if (!res.success) {
return res;
}
std::string dir = dict.value<std::string>(key);
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) {
res.success = false;
res.offenses.push_back({ key, TestResult::Offense::Reason::Verification });
}
return res;
}
std::string DirectoryVerifier::type() const {
return "Directory";
}
TestResult Color3Verifier::operator()(const ghoul::Dictionary& dictionary,
const std::string& key) const
{