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

Method ParseArgument

gcore/gdalalgorithm.cpp:1916–2164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1914/************************************************************************/
1915
1916bool GDALAlgorithm::ParseArgument(
1917 GDALAlgorithmArg *arg, const std::string &name, const std::string &value,
1918 std::map<
1919 GDALAlgorithmArg *,
1920 std::variant<std::vector<std::string>, std::vector<int>,
1921 std::vector<double>, std::vector<GDALArgDatasetValue>>>
1922 &inConstructionValues)
1923{
1924 const bool isListArg =
1925 GDALAlgorithmArgTypeIsList(arg->GetType()) && arg->GetMaxCount() > 1;
1926 if (arg->IsExplicitlySet() && !isListArg)
1927 {
1928 // Hack for "gdal info" to be able to pass an opened raster dataset
1929 // by "gdal raster info" to the "gdal vector info" algorithm.
1930 if (arg->SkipIfAlreadySet())
1931 {
1932 arg->SetSkipIfAlreadySet(false);
1933 return true;
1934 }
1935
1936 ReportError(CE_Failure, CPLE_IllegalArg,
1937 "Argument '%s' has already been specified.", name.c_str());
1938 return false;
1939 }
1940
1941 if (!arg->GetRepeatedArgAllowed() &&
1942 cpl::contains(inConstructionValues, arg))
1943 {
1944 ReportError(CE_Failure, CPLE_IllegalArg,
1945 "Argument '%s' has already been specified.", name.c_str());
1946 return false;
1947 }
1948
1949 switch (arg->GetType())
1950 {
1951 case GAAT_BOOLEAN:
1952 {
1953 if (value.empty() || value == "true")
1954 return arg->Set(true);
1955 else if (value == "false")
1956 return arg->Set(false);
1957 else
1958 {
1959 ReportError(
1960 CE_Failure, CPLE_IllegalArg,
1961 "Invalid value '%s' for boolean argument '%s'. Should be "
1962 "'true' or 'false'.",
1963 value.c_str(), name.c_str());
1964 return false;
1965 }
1966 }
1967
1968 case GAAT_STRING:
1969 {
1970 return arg->Set(value);
1971 }
1972
1973 case GAAT_INTEGER:

Callers

nothing calls this directly

Calls 15

containsFunction · 0.85
CPLStrtodFunction · 0.85
CSLTokenizeString2Function · 0.85
CSLAddStringFunction · 0.85
moveFunction · 0.85
GDALArgDatasetValueFunction · 0.85
SetDatasetNameMethod · 0.80
eraseMethod · 0.80
ReportErrorFunction · 0.50
GetTypeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected