LCOV - code coverage report
Current view: top level - apps - gdalalg_vector_pipeline.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 21 23 91.3 %
Date: 2026-06-03 16:29:47 Functions: 83 85 97.6 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  gdal "vector pipeline" subcommand
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef GDALALG_VECTOR_PIPELINE_INCLUDED
      14             : #define GDALALG_VECTOR_PIPELINE_INCLUDED
      15             : 
      16             : #include "gdalalg_abstract_pipeline.h"
      17             : #include "gdalvectorpipelinestepalgorithm.h"
      18             : 
      19             : //! @cond Doxygen_Suppress
      20             : 
      21             : /************************************************************************/
      22             : /*                   GDALVectorAlgorithmStepRegistry                    */
      23             : /************************************************************************/
      24             : 
      25         496 : class GDALVectorAlgorithmStepRegistry : public virtual GDALAlgorithmRegistry
      26             : {
      27             :   public:
      28         496 :     GDALVectorAlgorithmStepRegistry() = default;
      29             :     ~GDALVectorAlgorithmStepRegistry() override;
      30             : 
      31             :     /** Register the algorithm of type MyAlgorithm.
      32             :      */
      33             :     template <class MyAlgorithm>
      34       18024 :     bool Register(const std::string &name = std::string())
      35             :     {
      36             :         static_assert(
      37             :             std::is_base_of_v<GDALVectorPipelineStepAlgorithm, MyAlgorithm>,
      38             :             "Algorithm is not a GDALVectorPipelineStepAlgorithm");
      39             : 
      40       36048 :         AlgInfo info;
      41       18024 :         info.m_name = name.empty() ? MyAlgorithm::NAME : name;
      42       18024 :         info.m_aliases = MyAlgorithm::GetAliasesStatic();
      43       19745 :         info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm>
      44        1721 :         { return std::make_unique<MyAlgorithm>(); };
      45       36048 :         return GDALAlgorithmRegistry::Register(info);
      46             :     }
      47             : };
      48             : 
      49             : /************************************************************************/
      50             : /*                     GDALVectorPipelineAlgorithm                      */
      51             : /************************************************************************/
      52             : 
      53             : class GDALVectorPipelineAlgorithm final : public GDALAbstractPipelineAlgorithm
      54             : {
      55             :   public:
      56             :     static constexpr const char *NAME = "pipeline";
      57             :     static constexpr const char *DESCRIPTION =
      58             :         "Process a vector dataset applying several steps.";
      59             :     static constexpr const char *HELP_URL =
      60             :         "/programs/gdal_vector_pipeline.html";
      61             : 
      62        1067 :     static std::vector<std::string> GetAliasesStatic()
      63             :     {
      64             :         return {
      65             : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA
      66             :             GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR,
      67             :             "+pipeline",
      68             :             "+gdal=pipeline",
      69             : #endif
      70        4268 :         };
      71             :     }
      72             : 
      73             :     GDALVectorPipelineAlgorithm();
      74             : 
      75             :     std::string GetUsageForCLI(bool shortUsage,
      76             :                                const UsageOptions &usageOptions) const override;
      77             : 
      78             :     static void RegisterAlgorithms(GDALVectorAlgorithmStepRegistry &registry,
      79             :                                    bool forMixedPipeline);
      80             : 
      81         247 :     int GetInputType() const override
      82             :     {
      83         247 :         return GDAL_OF_VECTOR;
      84             :     }
      85             : 
      86           0 :     int GetOutputType() const override
      87             :     {
      88           0 :         return GDAL_OF_VECTOR;
      89             :     }
      90             : 
      91             :   protected:
      92             :     GDALVectorAlgorithmStepRegistry m_stepRegistry{};
      93             : 
      94         252 :     GDALAlgorithmRegistry &GetStepRegistry() override
      95             :     {
      96         252 :         return m_stepRegistry;
      97             :     }
      98             : 
      99         871 :     const GDALAlgorithmRegistry &GetStepRegistry() const override
     100             :     {
     101         871 :         return m_stepRegistry;
     102             :     }
     103             : 
     104             :   private:
     105             :     std::unique_ptr<GDALAbstractPipelineAlgorithm>
     106           2 :     CreateNestedPipeline() const override
     107             :     {
     108           4 :         auto pipeline = std::make_unique<GDALVectorPipelineAlgorithm>();
     109           2 :         pipeline->m_bInnerPipeline = true;
     110           4 :         return pipeline;
     111             :     }
     112             : };
     113             : 
     114             : //! @endcond
     115             : 
     116             : #endif

Generated by: LCOV version 1.14