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

Method RunValidationActions

gcore/gdalalgorithm.cpp:999–1231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

997/************************************************************************/
998
999bool GDALAlgorithmArg::RunValidationActions()
1000{
1001 bool ret = true;
1002
1003 if (GetType() == GAAT_STRING && !GetChoices().empty())
1004 {
1005 auto &val = Get<std::string>();
1006 std::string validVal = ValidateChoice(val);
1007 if (validVal.empty())
1008 ret = false;
1009 else
1010 val = std::move(validVal);
1011 }
1012 else if (GetType() == GAAT_STRING_LIST && !GetChoices().empty())
1013 {
1014 auto &values = Get<std::vector<std::string>>();
1015 for (std::string &val : values)
1016 {
1017 std::string validVal = ValidateChoice(val);
1018 if (validVal.empty())
1019 ret = false;
1020 else
1021 val = std::move(validVal);
1022 }
1023 }
1024
1025 const auto CheckMinCharCount =
1026 [this, &ret](const std::string &val, int nMinCharCount)
1027 {
1028 if (val.size() < static_cast<size_t>(nMinCharCount))
1029 {
1030 CPLError(CE_Failure, CPLE_IllegalArg,
1031 "Value of argument '%s' is '%s', but should have at least "
1032 "%d character%s",
1033 GetName().c_str(), val.c_str(), nMinCharCount,
1034 nMinCharCount > 1 ? "s" : "");
1035 ret = false;
1036 }
1037 };
1038
1039 const auto CheckMaxCharCount =
1040 [this, &ret](const std::string &val, int nMaxCharCount)
1041 {
1042 if (val.size() > static_cast<size_t>(nMaxCharCount))
1043 {
1044 CPLError(
1045 CE_Failure, CPLE_IllegalArg,
1046 "Value of argument '%s' is '%s', but should have no more than "
1047 "%d character%s",
1048 GetName().c_str(), val.c_str(), nMaxCharCount,
1049 nMaxCharCount > 1 ? "s" : "");
1050 ret = false;
1051 }
1052 };
1053
1054 switch (GetType())
1055 {
1056 case GAAT_BOOLEAN:

Callers 1

ValidateArgumentsMethod · 0.80

Calls 15

moveFunction · 0.85
CPLErrorFunction · 0.85
GetMinCharCountFunction · 0.85
GetMaxCharCountFunction · 0.85
CheckDuplicateValuesFunction · 0.85
CPLSPrintfFunction · 0.85
GetMinCountFunction · 0.85
GetMaxCountFunction · 0.85
GetTypeFunction · 0.70
GetNameFunction · 0.50

Tested by

no test coverage detected