Use std::optional instead of mbgl::optional (#911)

This commit is contained in:
Bart Louwers
2023-03-17 12:51:59 +01:00
committed by GitHub
parent 36846439c6
commit 15ad65dd3d
482 changed files with 2605 additions and 2652 deletions

View File

@@ -94,13 +94,13 @@ mbgl::filesystem::path getValidPath(const std::string& manifestPath, const std::
if (mbgl::filesystem::exists(result)) {
return result.lexically_normal();
}
mbgl::Log::Warning(mbgl::Event::General, "Invalid path is provided inside the manifest file: %s", path.c_str());
mbgl::Log::Warning(mbgl::Event::General, "Invalid path is provided inside the manifest file: " + path);
return mbgl::filesystem::path{};
}
} // namespace
mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manifestPath,
std::optional<Manifest> ManifestParser::parseManifest(const std::string& manifestPath,
std::string testFilter) {
Manifest manifest;
const auto filePath = mbgl::filesystem::path(manifestPath);
@@ -108,8 +108,8 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
auto contents = readJson(filePath);
if (!contents.is<mbgl::JSDocument>()) {
mbgl::Log::Error(mbgl::Event::General, "Provided manifest file: %s is not a valid json", filePath.c_str());
return mbgl::nullopt;
mbgl::Log::Error(mbgl::Event::General, "Provided manifest file: " + std::string(filePath) + " is not a valid json");
return std::nullopt;
}
auto document = std::move(contents.get<mbgl::JSDocument>());
@@ -117,24 +117,24 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& resultPathValue = document["result_path"];
if (!resultPathValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General, "Invalid result_path is provided inside the manifest file: %s", filePath.c_str());
return mbgl::nullopt;
mbgl::Event::General, "Invalid result_path is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
manifest.resultPath = (getValidPath(manifest.manifestPath, resultPathValue.GetString()) / "").string();
if (manifest.resultPath.empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
if (document.HasMember("cache_path")) {
const auto& cachePathValue = document["cache_path"];
if (!cachePathValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General, "Invalid cache_path is provided inside the manifest file: %s", filePath.c_str());
return mbgl::nullopt;
mbgl::Event::General, "Invalid cache_path is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
manifest.cachePath = (getValidPath(manifest.manifestPath, ".") / cachePathValue.GetString()).string();
if (manifest.cachePath.empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
//TODO:PP
@@ -142,13 +142,12 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& apiKeyValue = document["access_token"];
if (!apiKeyValue.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid access_token is provided inside the manifest file: %s",
filePath.c_str());
return mbgl::nullopt;
"Invalid access_token is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
manifest.apiKey = apiKeyValue.GetString();
if (manifest.apiKey.empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
mbgl::filesystem::path baseTestPath;
@@ -156,13 +155,12 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& testPathValue = document["base_test_path"];
if (!testPathValue.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid base_test_path is provided inside the manifest file: %s",
filePath.c_str());
return mbgl::nullopt;
"Invalid base_test_path is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
baseTestPath = getValidPath(manifest.manifestPath, testPathValue.GetString());
if (baseTestPath.empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
mbgl::filesystem::path expectedMetricPath;
@@ -170,12 +168,12 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& metricPathValue = document["metric_path"];
if (!metricPathValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General, "Invalid metric_path is provided inside the manifest file: %s", filePath.c_str());
return mbgl::nullopt;
mbgl::Event::General, "Invalid metric_path is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
expectedMetricPath = getValidPath(manifest.manifestPath, metricPathValue.GetString());
if (expectedMetricPath.empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
std::vector<mbgl::filesystem::path> expectationPaths{};
@@ -183,20 +181,18 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& expectationPathValue = document["expectation_paths"];
if (!expectationPathValue.IsArray()) {
mbgl::Log::Warning(mbgl::Event::General,
"Provided expectation_paths inside the manifest file: %s is not a valid array",
filePath.c_str());
return mbgl::nullopt;
"Provided expectation_paths inside the manifest file: %s is not a valid array" + std::string(filePath));
return std::nullopt;
}
for (const auto& value : expectationPathValue.GetArray()) {
if (!value.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid expectation path item is provided inside the manifest file: %s",
filePath.c_str());
return mbgl::nullopt;
"Invalid expectation path item is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
expectationPaths.emplace_back(getValidPath(manifest.manifestPath, value.GetString()));
if (expectationPaths.back().empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
}
@@ -205,20 +201,18 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& ignorePathValue = document["ignore_paths"];
if (!ignorePathValue.IsArray()) {
mbgl::Log::Warning(mbgl::Event::General,
"Provided ignore_paths inside the manifest file: %s is not a valid array",
filePath.c_str());
return mbgl::nullopt;
"Provided ignore_paths inside the manifest file: " + std::string(filePath) + " is not a valid array");
return std::nullopt;
}
for (const auto& value : ignorePathValue.GetArray()) {
if (!value.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid ignore path item is provided inside the manifest file: %s",
filePath.c_str());
return mbgl::nullopt;
"Invalid ignore path item is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
ignorePaths.emplace_back(getValidPath(manifest.manifestPath, value.GetString()));
if (ignorePaths.back().empty()) {
return mbgl::nullopt;
return std::nullopt;
}
}
manifest.ignores = parseIgnores(ignorePaths);
@@ -228,16 +222,15 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& probesValue = document["probes"];
if (!probesValue.IsArray()) {
mbgl::Log::Warning(mbgl::Event::General,
"Provided probes inside the manifest file: %s is not a valid array",
filePath.c_str());
return mbgl::nullopt;
"Provided probes inside the manifest file: " + std::string(filePath) + "is not a valid array");
return std::nullopt;
}
for (const auto& value : probesValue.GetArray()) {
if (!value.IsString()) {
mbgl::Log::Warning(mbgl::Event::General,
"Invalid probe type is provided inside the manifest file: %s",
filePath.c_str());
return mbgl::nullopt;
"Invalid probe type is provided inside the manifest file: " +
std::string(filePath));
return std::nullopt;
}
manifest.probes.emplace(value.GetString());
}
@@ -247,8 +240,8 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
const auto& filterValue = document["filter"];
if (!filterValue.IsString()) {
mbgl::Log::Warning(
mbgl::Event::General, "Invalid filter is provided inside the manifest file: %s", filePath.c_str());
return mbgl::nullopt;
mbgl::Event::General, "Invalid filter is provided inside the manifest file: " + std::string(filePath));
return std::nullopt;
}
testFilter = filterValue.GetString();
@@ -294,5 +287,5 @@ mbgl::optional<Manifest> ManifestParser::parseManifest(const std::string& manife
}
}
return mbgl::optional<Manifest>(manifest);
return std::optional<Manifest>(manifest);
}