| 4487 | /************************************************************************/ |
| 4488 | |
| 4489 | bool GDALAlgorithm::ValidateFormat(const GDALAlgorithmArg &arg, |
| 4490 | bool bStreamAllowed, |
| 4491 | bool bGDALGAllowed) const |
| 4492 | { |
| 4493 | if (arg.GetChoices().empty()) |
| 4494 | { |
| 4495 | const auto Validate = |
| 4496 | [this, &arg, bStreamAllowed, bGDALGAllowed](const std::string &val) |
| 4497 | { |
| 4498 | if (const auto extraFormats = |
| 4499 | arg.GetMetadataItem(GAAMDI_EXTRA_FORMATS)) |
| 4500 | { |
| 4501 | for (const auto &extraFormat : *extraFormats) |
| 4502 | { |
| 4503 | if (EQUAL(val.c_str(), extraFormat.c_str())) |
| 4504 | return true; |
| 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | if (bStreamAllowed && EQUAL(val.c_str(), "stream")) |
| 4509 | return true; |
| 4510 | |
| 4511 | if (EQUAL(val.c_str(), "GDALG") && |
| 4512 | arg.GetName() == GDAL_ARG_NAME_OUTPUT_FORMAT) |
| 4513 | { |
| 4514 | if (bGDALGAllowed) |
| 4515 | { |
| 4516 | return true; |
| 4517 | } |
| 4518 | else |
| 4519 | { |
| 4520 | ReportError(CE_Failure, CPLE_NotSupported, |
| 4521 | "GDALG output is not supported."); |
| 4522 | return false; |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | const auto vrtCompatible = |
| 4527 | arg.GetMetadataItem(GAAMDI_VRT_COMPATIBLE); |
| 4528 | if (vrtCompatible && !vrtCompatible->empty() && |
| 4529 | vrtCompatible->front() == "false" && EQUAL(val.c_str(), "VRT")) |
| 4530 | { |
| 4531 | ReportError(CE_Failure, CPLE_NotSupported, |
| 4532 | "VRT output is not supported.%s", |
| 4533 | bGDALGAllowed |
| 4534 | ? " Consider using the GDALG driver instead " |
| 4535 | "(files with .gdalg.json extension)." |
| 4536 | : ""); |
| 4537 | return false; |
| 4538 | } |
| 4539 | |
| 4540 | const auto allowedFormats = |
| 4541 | arg.GetMetadataItem(GAAMDI_ALLOWED_FORMATS); |
| 4542 | if (allowedFormats && !allowedFormats->empty() && |
| 4543 | std::find(allowedFormats->begin(), allowedFormats->end(), |
| 4544 | val) != allowedFormats->end()) |
| 4545 | { |
| 4546 | return true; |
nothing calls this directly
no test coverage detected