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

Method CopyStepAlgorithmFromAnother

apps/gdalalg_abstract_pipeline.cpp:313–377  ·  view source on GitHub ↗

Copy arguments and other parameters from \a src to \a dst, typically * when turning a raster algorithm to the vector one of the same name, or * vice-versa. */

Source from the content-addressed store, hash-verified

311 * vice-versa.
312 */
313bool GDALAbstractPipelineAlgorithm::CopyStepAlgorithmFromAnother(
314 GDALPipelineStepAlgorithm *dst, const GDALPipelineStepAlgorithm *src,
315 bool maybeWriteStep) const
316{
317 if (src->GetName() == GDALTeeStepAlgorithmAbstract::NAME)
318 {
319 const auto poSrcTeeAlg =
320 dynamic_cast<const GDALTeeStepAlgorithmAbstract *>(src);
321 auto poDstTeeAlg = dynamic_cast<GDALTeeStepAlgorithmAbstract *>(dst);
322 CPLAssert(poSrcTeeAlg);
323 CPLAssert(poDstTeeAlg);
324 poDstTeeAlg->CopyFilenameBindingsFrom(poSrcTeeAlg);
325 }
326
327 if (maybeWriteStep)
328 {
329 // Propagate output parameters set at the pipeline level to the
330 // "write" step
331 for (auto &arg : dst->GetArgs())
332 {
333 if (!arg->IsHidden())
334 {
335 const auto pipelineArg = GetArg(arg->GetName());
336 if (pipelineArg && pipelineArg->IsExplicitlySet() &&
337 pipelineArg->GetType() == arg->GetType())
338 {
339 arg->SetSkipIfAlreadySet(true);
340 [[maybe_unused]] bool ret = arg->SetFrom(*pipelineArg);
341 CPLAssert(ret);
342 }
343 }
344 }
345 }
346
347 // Propagate parameters set on the old algorithm to the new one
348 for (const auto &srcArg : src->GetArgs())
349 {
350 if (srcArg->IsExplicitlySet())
351 {
352 auto dstArg = dst->GetArg(srcArg->GetName());
353 if (!dstArg)
354 {
355 dst->ReportError(CE_Failure, CPLE_IllegalArg,
356 "Option '--%s' is unknown",
357 srcArg->GetName().c_str());
358 return false;
359 }
360 else
361 {
362 dstArg->SetSkipIfAlreadySet(true);
363 if (!dstArg->SetFrom(*srcArg))
364 return false;
365 }
366 }
367 }
368
369 dst->m_oMapDatasetNameToDataset =
370 std::move(src->m_oMapDatasetNameToDataset);

Callers

nothing calls this directly

Calls 10

GetArgFunction · 0.85
moveFunction · 0.85
IsCalledFromCommandLineFunction · 0.85
GetArgMethod · 0.80
GetNameMethod · 0.45
GetTypeMethod · 0.45
SetFromMethod · 0.45
ReportErrorMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected