Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "raster 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_RASTER_PIPELINE_INCLUDED 14 : #define GDALALG_RASTER_PIPELINE_INCLUDED 15 : 16 : #include "gdalalgorithm.h" 17 : #include "gdalalg_abstract_pipeline.h" 18 : #include "gdalrasterpipelinestepalgorithm.h" 19 : 20 : //! @cond Doxygen_Suppress 21 : 22 : /************************************************************************/ 23 : /* GDALRasterAlgorithmStepRegistry */ 24 : /************************************************************************/ 25 : 26 526 : class GDALRasterAlgorithmStepRegistry : public virtual GDALAlgorithmRegistry 27 : { 28 : public: 29 526 : GDALRasterAlgorithmStepRegistry() = default; 30 : ~GDALRasterAlgorithmStepRegistry() override; 31 : 32 : /** Register the algorithm of type MyAlgorithm. 33 : */ 34 : template <class MyAlgorithm> 35 20706 : bool Register(const std::string &name = std::string()) 36 : { 37 : static_assert( 38 : std::is_base_of_v<GDALRasterPipelineStepAlgorithm, MyAlgorithm>, 39 : "Algorithm is not a GDALRasterPipelineStepAlgorithm"); 40 : 41 41412 : AlgInfo info; 42 20706 : info.m_name = name.empty() ? MyAlgorithm::NAME : name; 43 20706 : info.m_aliases = MyAlgorithm::GetAliasesStatic(); 44 22691 : info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm> 45 1985 : { return std::make_unique<MyAlgorithm>(); }; 46 41412 : return GDALAlgorithmRegistry::Register(info); 47 : } 48 : }; 49 : 50 : /************************************************************************/ 51 : /* GDALRasterPipelineAlgorithm */ 52 : /************************************************************************/ 53 : 54 : class GDALRasterPipelineAlgorithm final : public GDALAbstractPipelineAlgorithm 55 : { 56 : public: 57 : static constexpr const char *NAME = "pipeline"; 58 : static constexpr const char *DESCRIPTION = 59 : "Process a raster dataset applying several steps."; 60 : static constexpr const char *HELP_URL = 61 : "/programs/gdal_raster_pipeline.html"; 62 : 63 2101 : 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 8404 : }; 72 : } 73 : 74 : explicit GDALRasterPipelineAlgorithm(bool openForMixedRasterVector = false); 75 : 76 : std::string GetUsageForCLI(bool shortUsage, 77 : const UsageOptions &usageOptions) const override; 78 : 79 : static void RegisterAlgorithms(GDALRasterAlgorithmStepRegistry ®istry, 80 : bool forMixedPipeline); 81 : 82 288 : int GetInputType() const override 83 : { 84 288 : return GDAL_OF_RASTER; 85 : } 86 : 87 0 : int GetOutputType() const override 88 : { 89 0 : return GDAL_OF_RASTER; 90 : } 91 : 92 : protected: 93 : GDALRasterAlgorithmStepRegistry m_stepRegistry{}; 94 : 95 227 : GDALAlgorithmRegistry &GetStepRegistry() override 96 : { 97 227 : return m_stepRegistry; 98 : } 99 : 100 1011 : const GDALAlgorithmRegistry &GetStepRegistry() const override 101 : { 102 1011 : return m_stepRegistry; 103 : } 104 : 105 : private: 106 : std::unique_ptr<GDALAbstractPipelineAlgorithm> 107 2 : CreateNestedPipeline() const override 108 : { 109 4 : auto pipeline = std::make_unique<GDALRasterPipelineAlgorithm>(); 110 2 : pipeline->m_bInnerPipeline = true; 111 4 : return pipeline; 112 : } 113 : }; 114 : 115 : //! @endcond 116 : 117 : #endif