Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "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_PIPELINE_INCLUDED 14 : #define GDALALG_PIPELINE_INCLUDED 15 : 16 : //! @cond Doxygen_Suppress 17 : 18 : #include "gdalalg_abstract_pipeline.h" 19 : #include "gdalalg_raster_pipeline.h" 20 : #include "gdalalg_vector_pipeline.h" 21 : 22 : /************************************************************************/ 23 : /* GDALAlgorithmStepRegistry */ 24 : /************************************************************************/ 25 : 26 209 : class GDALAlgorithmStepRegistry final : public GDALRasterAlgorithmStepRegistry, 27 : public GDALVectorAlgorithmStepRegistry 28 : { 29 : public: 30 209 : GDALAlgorithmStepRegistry() = default; 31 : ~GDALAlgorithmStepRegistry() override; 32 : 33 : /** Register the algorithm of type MyAlgorithm. 34 : */ 35 : template <class MyAlgorithm> 36 1463 : bool Register(const std::string &name = std::string()) 37 : { 38 : static_assert(std::is_base_of_v<GDALPipelineStepAlgorithm, MyAlgorithm>, 39 : "Algorithm is not a GDALPipelineStepAlgorithm"); 40 : 41 2926 : AlgInfo info; 42 1463 : info.m_name = name.empty() ? MyAlgorithm::NAME : name; 43 1463 : info.m_aliases = MyAlgorithm::GetAliasesStatic(); 44 1570 : info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm> 45 107 : { return std::make_unique<MyAlgorithm>(); }; 46 2926 : return GDALAlgorithmRegistry::Register(info); 47 : } 48 : }; 49 : 50 : /************************************************************************/ 51 : /* GDALPipelineAlgorithm */ 52 : /************************************************************************/ 53 : 54 : class GDALPipelineAlgorithm final : public GDALAbstractPipelineAlgorithm 55 : 56 : { 57 : public: 58 : static constexpr const char *NAME = "pipeline"; 59 : static constexpr const char *DESCRIPTION = 60 : "Process a dataset applying several steps."; 61 : static constexpr const char *HELP_URL = "/programs/gdal_pipeline.html"; 62 : 63 1585 : static std::vector<std::string> GetAliasesStatic() 64 : { 65 : return { 66 : #ifdef GDAL_PIPELINE_PROJ_NOSTALGIA 67 : GDALAlgorithmRegistry::HIDDEN_ALIAS_SEPARATOR, 68 : "+pipeline", 69 : "+gdal=pipeline", 70 : #endif 71 6340 : }; 72 : } 73 : 74 : GDALPipelineAlgorithm(); 75 : 76 160 : int GetInputType() const override 77 : { 78 160 : return GDAL_OF_RASTER | GDAL_OF_VECTOR; 79 : } 80 : 81 0 : int GetOutputType() const override 82 : { 83 0 : return GDAL_OF_RASTER | GDAL_OF_VECTOR; 84 : } 85 : 86 : protected: 87 : GDALAlgorithmStepRegistry m_stepRegistry{}; 88 : 89 491 : GDALAlgorithmRegistry &GetStepRegistry() override 90 : { 91 491 : return m_stepRegistry; 92 : } 93 : 94 1059 : const GDALAlgorithmRegistry &GetStepRegistry() const override 95 : { 96 1059 : return m_stepRegistry; 97 : } 98 : 99 : std::string GetUsageForCLI(bool shortUsage, 100 : const UsageOptions &usageOptions) const override; 101 : 102 : private: 103 : std::unique_ptr<GDALAbstractPipelineAlgorithm> 104 33 : CreateNestedPipeline() const override 105 : { 106 66 : auto pipeline = std::make_unique<GDALPipelineAlgorithm>(); 107 33 : pipeline->m_bInnerPipeline = true; 108 66 : return pipeline; 109 : } 110 : }; 111 : 112 : //! @endcond 113 : 114 : #endif