MCPcopy Create free account
hub / github.com/OSGeo/gdal / ValidateFormat

Method ValidateFormat

gcore/gdalalgorithm.cpp:4489–4667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4487/************************************************************************/
4488
4489bool 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;

Callers

nothing calls this directly

Calls 14

GetGDALDriverManagerFunction · 0.85
GetArgFunction · 0.85
frontMethod · 0.80
GetHiddenDriverByNameMethod · 0.80
EQUALFunction · 0.50
ReportErrorFunction · 0.50
emptyMethod · 0.45
GetMetadataItemMethod · 0.45
c_strMethod · 0.45
GetNameMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected