GDAL
gdalalg_pipeline.h
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
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
26class GDALAlgorithmStepRegistry final : public GDALRasterAlgorithmStepRegistry,
27 public GDALVectorAlgorithmStepRegistry
28{
29 public:
30 GDALAlgorithmStepRegistry() = default;
31 ~GDALAlgorithmStepRegistry() override;
32
35 template <class MyAlgorithm>
36 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 AlgInfo info;
42 info.m_name = name.empty() ? MyAlgorithm::NAME : name;
43 info.m_aliases = MyAlgorithm::GetAliasesStatic();
44 info.m_creationFunc = []() -> std::unique_ptr<GDALAlgorithm>
45 { return std::make_unique<MyAlgorithm>(); };
47 }
48};
49
50/************************************************************************/
51/* GDALPipelineAlgorithm */
52/************************************************************************/
53
54class 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 static std::vector<std::string> GetAliasesStatic()
64 {
65 return {
66#ifdef GDAL_PIPELINE_PROJ_NOSTALGIA
68 "+pipeline",
69 "+gdal=pipeline",
70#endif
71 };
72 }
73
74 GDALPipelineAlgorithm();
75
76 int GetInputType() const override
77 {
79 }
80
81 int GetOutputType() const override
82 {
84 }
85
86 protected:
87 GDALAlgorithmStepRegistry m_stepRegistry{};
88
89 GDALAlgorithmRegistry &GetStepRegistry() override
90 {
91 return m_stepRegistry;
92 }
93
94 const GDALAlgorithmRegistry &GetStepRegistry() const override
95 {
96 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 CreateNestedPipeline() const override
105 {
106 auto pipeline = std::make_unique<GDALPipelineAlgorithm>();
107 pipeline->m_bInnerPipeline = true;
108 return pipeline;
109 }
110};
111
113
114#endif
static constexpr const char * HIDDEN_ALIAS_SEPARATOR
Special value to put in m_aliases to separate public alias from hidden aliases.
Definition gdalalgorithm_cpp.h:2136
bool Register()
Register the algorithm of type MyAlgorithm.
Definition gdalalgorithm_cpp.h:2159
#define GDAL_OF_RASTER
Allow raster drivers to be used.
Definition gdal.h:1086
#define GDAL_OF_VECTOR
Allow vector drivers to be used.
Definition gdal.h:1091