From e7bcb774ee370f90ccf3b95518aaba1154156bf9 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 13 Feb 2021 10:44:21 +0100 Subject: [PATCH] Add new verifiers for files and directories. Update codegen to be able to create these --- include/openspace/documentation/verifier.h | 22 ++++++++++++ src/documentation/verifier.cpp | 41 ++++++++++++++++++++++ support/coding/codegen | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/openspace/documentation/verifier.h b/include/openspace/documentation/verifier.h index f4af4228a9..0126a804f7 100644 --- a/include/openspace/documentation/verifier.h +++ b/include/openspace/documentation/verifier.h @@ -158,6 +158,28 @@ struct StringVerifier : public TemplateVerifier { 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 diff --git a/src/documentation/verifier.cpp b/src/documentation/verifier.cpp index 780b5ea14f..5a766cee8f 100644 --- a/src/documentation/verifier.cpp +++ b/src/documentation/verifier.cpp @@ -27,6 +27,7 @@ #include #include #include +#include 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(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(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 { diff --git a/support/coding/codegen b/support/coding/codegen index 14ed29d516..1ca72c0202 160000 --- a/support/coding/codegen +++ b/support/coding/codegen @@ -1 +1 @@ -Subproject commit 14ed29d516c47151e5601a119ed68e7151c12ef5 +Subproject commit 1ca72c0202e3bd4b61510f84797db131591c8ca3