/src/gdal/apps/gdalalg_external.h
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: GDAL |
4 | | * Purpose: gdal "external" subcommand (always in pipeline) |
5 | | * Author: Even Rouault <even dot rouault at spatialys.com> |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 2026, Even Rouault <even dot rouault at spatialys.com> |
9 | | * |
10 | | * SPDX-License-Identifier: MIT |
11 | | ****************************************************************************/ |
12 | | |
13 | | #ifndef GDALALG_EXTERNAL_INCLUDED |
14 | | #define GDALALG_EXTERNAL_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 | | #ifndef _ |
23 | 0 | #define _(x) (x) |
24 | | #endif |
25 | | |
26 | | /************************************************************************/ |
27 | | /* GDALExternalAlgorithmBase */ |
28 | | /************************************************************************/ |
29 | | |
30 | | class GDALExternalAlgorithmBase /* non final */ |
31 | | { |
32 | | protected: |
33 | 0 | GDALExternalAlgorithmBase() = default; |
34 | | virtual ~GDALExternalAlgorithmBase(); |
35 | | |
36 | | CPLString m_command{}; |
37 | | |
38 | | std::string m_osTempInputFilename{}; |
39 | | std::string m_osTempOutputFilename{}; |
40 | | |
41 | | bool Run(const std::vector<std::string> &inputFormats, |
42 | | std::vector<GDALArgDatasetValue> &inputDataset, |
43 | | const std::string &outputFormat, |
44 | | GDALArgDatasetValue &outputDataset); |
45 | | }; |
46 | | |
47 | | /************************************************************************/ |
48 | | /* GDALExternalAlgorithm */ |
49 | | /************************************************************************/ |
50 | | |
51 | | template <class BaseStepAlgorithm, int nDatasetType> |
52 | | class GDALExternalAlgorithm /* non final */ : public BaseStepAlgorithm, |
53 | | public GDALExternalAlgorithmBase |
54 | | { |
55 | | public: |
56 | | static constexpr const char *NAME = "external"; |
57 | | static constexpr const char *DESCRIPTION = |
58 | | "Execute an external program as a step of a pipeline"; |
59 | | static constexpr const char *HELP_URL = "/programs/gdal_external.html"; |
60 | | |
61 | | GDALExternalAlgorithm() |
62 | 0 | : BaseStepAlgorithm(NAME, DESCRIPTION, HELP_URL, |
63 | 0 | GDALPipelineStepAlgorithm::ConstructorOptions() |
64 | 0 | .SetAddDefaultArguments(false)) |
65 | 0 | { |
66 | 0 | this->AddArg("command", 0, |
67 | 0 | _("External command, optionally with <INPUT> and/or " |
68 | 0 | "<OUTPUT> or <INPUT-OUTPUT> placeholders"), |
69 | 0 | &m_command) |
70 | 0 | .SetRequired() |
71 | 0 | .SetPositional() |
72 | 0 | .SetMinCharCount(1); |
73 | |
|
74 | 0 | this->AddInputFormatsArg(&this->m_inputFormats) |
75 | 0 | .SetMaxCount(1) |
76 | 0 | .AddMetadataItem(GAAMDI_EXCLUDED_FORMATS, {"MEM"}); |
77 | 0 | this->AddOutputFormatArg(&this->m_format, /* bStreamAllowed = */ false, |
78 | 0 | /* bGDALGAllowed = */ false) |
79 | 0 | .AddMetadataItem(GAAMDI_EXCLUDED_FORMATS, {"MEM"}); |
80 | | |
81 | | // Hidden |
82 | 0 | this->AddInputDatasetArg(&this->m_inputDataset, nDatasetType, false) |
83 | 0 | .SetMinCount(0) |
84 | 0 | .SetMaxCount(1) |
85 | 0 | .SetDatasetInputFlags(GADV_OBJECT) |
86 | 0 | .SetHidden(); |
87 | 0 | this->AddOutputDatasetArg(&this->m_outputDataset, nDatasetType, false) |
88 | 0 | .SetDatasetInputFlags(GADV_OBJECT) |
89 | 0 | .SetHidden(); |
90 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::GDALExternalAlgorithm() Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::GDALExternalAlgorithm() Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::GDALExternalAlgorithm() |
91 | | |
92 | | int GetInputType() const override |
93 | 0 | { |
94 | 0 | return nDatasetType; |
95 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::GetInputType() const Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::GetInputType() const Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::GetInputType() const |
96 | | |
97 | | int GetOutputType() const override |
98 | 0 | { |
99 | 0 | return nDatasetType; |
100 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::GetOutputType() const Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::GetOutputType() const Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::GetOutputType() const |
101 | | |
102 | | bool CanBeFirstStep() const override |
103 | 0 | { |
104 | 0 | return true; |
105 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::CanBeFirstStep() const Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::CanBeFirstStep() const Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::CanBeFirstStep() const |
106 | | |
107 | | bool CanBeMiddleStep() const override |
108 | 0 | { |
109 | 0 | return true; |
110 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::CanBeMiddleStep() const Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::CanBeMiddleStep() const Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::CanBeMiddleStep() const |
111 | | |
112 | | bool CanBeLastStep() const override |
113 | 0 | { |
114 | 0 | return true; |
115 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::CanBeLastStep() const Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::CanBeLastStep() const Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::CanBeLastStep() const |
116 | | |
117 | | bool IsNativelyStreamingCompatible() const override |
118 | 0 | { |
119 | 0 | return false; |
120 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::IsNativelyStreamingCompatible() const Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::IsNativelyStreamingCompatible() const Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::IsNativelyStreamingCompatible() const |
121 | | |
122 | | private: |
123 | | bool RunStep(GDALPipelineStepRunContext &) override |
124 | 0 | { |
125 | 0 | return GDALExternalAlgorithmBase::Run( |
126 | 0 | this->m_inputFormats, this->m_inputDataset, this->m_format, |
127 | 0 | this->m_outputDataset); |
128 | 0 | } Unexecuted instantiation: GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0>::RunStep(GDALPipelineStepRunContext&) Unexecuted instantiation: GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, 2>::RunStep(GDALPipelineStepRunContext&) Unexecuted instantiation: GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, 4>::RunStep(GDALPipelineStepRunContext&) |
129 | | }; |
130 | | |
131 | | /************************************************************************/ |
132 | | /* GDALExternalRasterOrVectorAlgorithm */ |
133 | | /************************************************************************/ |
134 | | |
135 | | class GDALExternalRasterOrVectorAlgorithm final |
136 | | : public GDALExternalAlgorithm<GDALPipelineStepAlgorithm, 0> |
137 | | { |
138 | | public: |
139 | 0 | GDALExternalRasterOrVectorAlgorithm() = default; |
140 | | |
141 | | ~GDALExternalRasterOrVectorAlgorithm() override; |
142 | | }; |
143 | | |
144 | | /************************************************************************/ |
145 | | /* GDALExternalRasterAlgorithm */ |
146 | | /************************************************************************/ |
147 | | |
148 | | class GDALExternalRasterAlgorithm final |
149 | | : public GDALExternalAlgorithm<GDALRasterPipelineStepAlgorithm, |
150 | | GDAL_OF_RASTER> |
151 | | { |
152 | | public: |
153 | 0 | GDALExternalRasterAlgorithm() = default; |
154 | | |
155 | | ~GDALExternalRasterAlgorithm() override; |
156 | | }; |
157 | | |
158 | | /************************************************************************/ |
159 | | /* GDALExternalVectorAlgorithm */ |
160 | | /************************************************************************/ |
161 | | |
162 | | class GDALExternalVectorAlgorithm final |
163 | | : public GDALExternalAlgorithm<GDALVectorPipelineStepAlgorithm, |
164 | | GDAL_OF_VECTOR> |
165 | | { |
166 | | public: |
167 | 0 | GDALExternalVectorAlgorithm() = default; |
168 | | |
169 | | ~GDALExternalVectorAlgorithm() override; |
170 | | }; |
171 | | |
172 | | //! @endcond |
173 | | |
174 | | #endif |