Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "tee" pipeline step 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "gdalalg_tee.h" 14 : 15 : //! @cond Doxygen_Suppress 16 : 17 : /************************************************************************/ 18 : /* GDALTeeStepAlgorithmAbstract::~GDALTeeStepAlgorithmAbstract() */ 19 : /************************************************************************/ 20 : 21 : GDALTeeStepAlgorithmAbstract::~GDALTeeStepAlgorithmAbstract() = default; 22 : 23 : /************************************************************************/ 24 : /* GDALTeeStepAlgorithmAbstract::CopyFilenameBindingsFrom() */ 25 : /************************************************************************/ 26 : 27 18 : void GDALTeeStepAlgorithmAbstract::CopyFilenameBindingsFrom( 28 : const GDALTeeStepAlgorithmAbstract *other) 29 : { 30 18 : m_oMapNameToAlg = other->m_oMapNameToAlg; 31 18 : } 32 : 33 : /************************************************************************/ 34 : /* GDALTeeStepAlgorithmAbstract::BindFilename() */ 35 : /************************************************************************/ 36 : 37 25 : bool GDALTeeStepAlgorithmAbstract::BindFilename( 38 : const std::string &filename, GDALAbstractPipelineAlgorithm *alg, 39 : const std::vector<std::string> &args) 40 : { 41 25 : if (cpl::contains(m_oMapNameToAlg, filename)) 42 1 : return false; 43 24 : m_oMapNameToAlg[filename] = std::make_pair(alg, args); 44 24 : return true; 45 : } 46 : 47 : /************************************************************************/ 48 : /* GDALTeeStepAlgorithmAbstract::HasOutputString() */ 49 : /************************************************************************/ 50 : 51 2 : bool GDALTeeStepAlgorithmAbstract::HasOutputString() const 52 : { 53 3 : for (const auto &oIter : m_oMapNameToAlg) 54 : { 55 2 : const auto &pipelineAlg = oIter.second.first; 56 2 : if (pipelineAlg->HasSteps()) 57 : { 58 0 : if (pipelineAlg->HasOutputString()) 59 1 : return true; 60 : } 61 : else 62 : { 63 : // Before the tee pipeline has been constructed by 64 : // GDALTeeStepAlgorithmBase::RunStep(), there is no clean way 65 : // of knowing if a (future) inner step will have an output string 66 : // argument, so try to instantiate a step alg from each pipeline 67 : // token and call HasOutputString() on it. 68 2 : const auto &pipelineArgs = oIter.second.second; 69 6 : for (const auto &arg : pipelineArgs) 70 : { 71 5 : auto alg = pipelineAlg->GetStepAlg(arg); 72 5 : if (!alg) 73 : { 74 10 : alg = pipelineAlg->GetStepAlg( 75 15 : arg + GDALAbstractPipelineAlgorithm::RASTER_SUFFIX); 76 5 : if (!alg) 77 6 : alg = pipelineAlg->GetStepAlg( 78 9 : arg + GDALAbstractPipelineAlgorithm::VECTOR_SUFFIX); 79 : } 80 5 : if (alg && alg->HasOutputString()) 81 1 : return true; 82 : } 83 : } 84 : } 85 1 : return false; 86 : } 87 : 88 : GDALTeeRasterAlgorithm::~GDALTeeRasterAlgorithm() = default; 89 : 90 : GDALTeeVectorAlgorithm::~GDALTeeVectorAlgorithm() = default; 91 : 92 : //! @endcond