| 3128 | /************************************************************************/ |
| 3129 | |
| 3130 | bool GDALAlgorithm::ValidateArguments() |
| 3131 | { |
| 3132 | if (m_selectedSubAlg) |
| 3133 | return m_selectedSubAlg->ValidateArguments(); |
| 3134 | |
| 3135 | if (m_specialActionRequested) |
| 3136 | return true; |
| 3137 | |
| 3138 | m_arbitraryLongNameArgsAllowed = false; |
| 3139 | |
| 3140 | // If only --output=format=MEM/stream is specified and not --output, |
| 3141 | // then set empty name for --output. |
| 3142 | auto outputArg = GetArg(GDAL_ARG_NAME_OUTPUT); |
| 3143 | auto outputFormatArg = GetArg(GDAL_ARG_NAME_OUTPUT_FORMAT); |
| 3144 | if (outputArg && outputFormatArg && outputFormatArg->IsExplicitlySet() && |
| 3145 | !outputArg->IsExplicitlySet() && |
| 3146 | outputFormatArg->GetType() == GAAT_STRING && |
| 3147 | (EQUAL(outputFormatArg->Get<std::string>().c_str(), "MEM") || |
| 3148 | EQUAL(outputFormatArg->Get<std::string>().c_str(), "stream")) && |
| 3149 | outputArg->GetType() == GAAT_DATASET && |
| 3150 | (outputArg->GetDatasetInputFlags() & GADV_NAME)) |
| 3151 | { |
| 3152 | outputArg->Get<GDALArgDatasetValue>().Set(""); |
| 3153 | } |
| 3154 | |
| 3155 | // The method may emit several errors if several constraints are not met. |
| 3156 | bool ret = true; |
| 3157 | std::map<std::string, std::string> mutualExclusionGroupUsed; |
| 3158 | std::map<std::string, std::vector<std::string>> mutualDependencyGroupUsed; |
| 3159 | for (auto &arg : m_args) |
| 3160 | { |
| 3161 | // Check mutually exclusive/dependent arguments |
| 3162 | if (arg->IsExplicitlySet()) |
| 3163 | { |
| 3164 | |
| 3165 | const auto &mutualExclusionGroup = arg->GetMutualExclusionGroup(); |
| 3166 | if (!mutualExclusionGroup.empty()) |
| 3167 | { |
| 3168 | auto oIter = |
| 3169 | mutualExclusionGroupUsed.find(mutualExclusionGroup); |
| 3170 | if (oIter != mutualExclusionGroupUsed.end()) |
| 3171 | { |
| 3172 | ret = false; |
| 3173 | ReportError( |
| 3174 | CE_Failure, CPLE_AppDefined, |
| 3175 | "Argument '%s' is mutually exclusive with '%s'.", |
| 3176 | arg->GetName().c_str(), oIter->second.c_str()); |
| 3177 | } |
| 3178 | else |
| 3179 | { |
| 3180 | mutualExclusionGroupUsed[mutualExclusionGroup] = |
| 3181 | arg->GetName(); |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | const auto &mutualDependencyGroup = arg->GetMutualDependencyGroup(); |
| 3186 | if (!mutualDependencyGroup.empty()) |
| 3187 | { |