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

Method GetArg

gcore/gdalalgorithm.cpp:3516–3584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3514/************************************************************************/
3515
3516GDALAlgorithmArg *GDALAlgorithm::GetArg(const std::string &osName,
3517 bool suggestionAllowed, bool isConst)
3518{
3519 const auto nPos = osName.find_first_not_of('-');
3520 if (nPos == std::string::npos)
3521 return nullptr;
3522 std::string osKey = osName.substr(nPos);
3523 {
3524 const auto oIter = m_mapLongNameToArg.find(osKey);
3525 if (oIter != m_mapLongNameToArg.end())
3526 return oIter->second;
3527 }
3528 {
3529 const auto oIter = m_mapShortNameToArg.find(osKey);
3530 if (oIter != m_mapShortNameToArg.end())
3531 return oIter->second;
3532 }
3533
3534 if (!isConst && m_arbitraryLongNameArgsAllowed)
3535 {
3536 const auto nDotPos = osKey.find('.');
3537 const std::string osKeyEnd =
3538 nDotPos == std::string::npos ? osKey : osKey.substr(nDotPos + 1);
3539 if (IsKnownOutputRelatedBooleanArgName(osKeyEnd))
3540 {
3541 m_arbitraryLongNameArgsValuesBool.emplace_back(
3542 std::make_unique<bool>());
3543 AddArg(osKey, 0, std::string("User-provided argument ") + osKey,
3544 m_arbitraryLongNameArgsValuesBool.back().get())
3545 .SetUserProvided();
3546 }
3547 else
3548 {
3549 const std::string osKeyInit = osKey;
3550 if (osKey == "oo")
3551 osKey = GDAL_ARG_NAME_OPEN_OPTION;
3552 else if (osKey == "co")
3553 osKey = GDAL_ARG_NAME_CREATION_OPTION;
3554 else if (osKey == "of")
3555 osKey = GDAL_ARG_NAME_OUTPUT_FORMAT;
3556 else if (osKey == "if")
3557 osKey = GDAL_ARG_NAME_INPUT_FORMAT;
3558 m_arbitraryLongNameArgsValuesStr.emplace_back(
3559 std::make_unique<std::string>());
3560 auto &arg =
3561 AddArg(osKey, 0, std::string("User-provided argument ") + osKey,
3562 m_arbitraryLongNameArgsValuesStr.back().get())
3563 .SetUserProvided();
3564 if (osKey != osKeyInit)
3565 arg.AddAlias(osKeyInit);
3566 }
3567 const auto oIter = m_mapLongNameToArg.find(osKey);
3568 CPLAssert(oIter != m_mapLongNameToArg.end());
3569 return oIter->second;
3570 }
3571
3572 if (suggestionAllowed)
3573 {

Callers 15

LLVMFuzzerTestOneInputFunction · 0.80
TEST_FFunction · 0.80
test_algorithmFunction · 0.80
RunImplMethod · 0.80
GetUsageForCLIMethod · 0.80
MAIN_STARTFunction · 0.80
RunStepMethod · 0.80

Calls 5

CPLErrorFunction · 0.85
endMethod · 0.45
getMethod · 0.45
emptyMethod · 0.45
c_strMethod · 0.45

Tested by 6

TEST_FFunction · 0.64
test_algorithmFunction · 0.64