mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
Add new verifiers for files and directories. Update codegen to be able to create these
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Submodule support/coding/codegen updated: 14ed29d516...1ca72c0202
Reference in New Issue
Block a user