13#ifndef GDAL_ALGORITHM_CPP_INCLUDED
14#define GDAL_ALGORITHM_CPP_INCLUDED
16#include "gdalalgorithm_c.h"
26#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
27 (defined(DOXYGEN_SKIP) || __cplusplus >= 201703L || _MSC_VER >= 1920)
46constexpr const char *GAAC_COMMON =
"Common";
49constexpr const char *GAAC_BASE =
"Base";
52constexpr const char *GAAC_ADVANCED =
"Advanced";
55constexpr const char *GAAC_ESOTERIC =
"Esoteric";
59constexpr const char *GAAMDI_REQUIRED_CAPABILITIES =
"required_capabilities";
62constexpr const char *GAAMDI_VRT_COMPATIBLE =
"vrt_compatible";
65constexpr const char *GAAMDI_ALLOWED_FORMATS =
"allowed_formats";
68constexpr const char *GAAMDI_EXCLUDED_FORMATS =
"excluded_formats";
71constexpr const char *GDAL_ARG_NAME_INPUT =
"input";
74constexpr const char *GDAL_ARG_NAME_INPUT_FORMAT =
"input-format";
77constexpr const char *GDAL_ARG_NAME_INPUT_LAYER =
"input-layer";
80constexpr const char *GDAL_ARG_NAME_OPEN_OPTION =
"open-option";
83constexpr const char *GDAL_ARG_NAME_OUTPUT =
"output";
86constexpr const char *GDAL_ARG_NAME_OUTPUT_STRING =
"output-string";
89constexpr const char *GDAL_ARG_NAME_STDOUT =
"stdout";
92constexpr const char *GDAL_ARG_NAME_OUTPUT_FORMAT =
"output-format";
95constexpr const char *GDAL_ARG_NAME_OUTPUT_LAYER =
"output-layer";
98constexpr const char *GDAL_ARG_NAME_CREATION_OPTION =
"creation-option";
101constexpr const char *GDAL_ARG_NAME_LAYER_CREATION_OPTION =
102 "layer-creation-option";
105constexpr const char *GDAL_ARG_NAME_UPDATE =
"update";
108constexpr const char *GDAL_ARG_NAME_OVERWRITE =
"overwrite";
111constexpr const char *GDAL_ARG_NAME_OVERWRITE_LAYER =
"overwrite-layer";
114constexpr const char *GDAL_ARG_NAME_APPEND =
"append";
117constexpr const char *GDAL_ARG_NAME_READ_ONLY =
"read-only";
120constexpr const char *GDAL_ARG_NAME_NUM_THREADS =
"num-threads";
123constexpr const char *GDAL_ARG_NAME_NUM_THREADS_INT_HIDDEN =
124 "num-threads-int-hidden";
127constexpr const char *GDAL_ARG_NAME_QUIET =
"quiet";
132constexpr const char *GDAL_ALG_DCAP_RASTER_OR_MULTIDIM_RASTER =
133 "raster-or-multidim-raster";
140std::string CPL_DLL GDALAlgorithmArgDatasetTypeName(GDALArgDatasetType);
156 : m_name(name), m_nameSet(true)
218 m_name = other.m_name;
234 void Set(
const std::string &name);
238 void Set(std::unique_ptr<GDALDataset> poDS);
251 m_openedByAlgorithm =
true;
257 return m_openedByAlgorithm;
278 std::string m_name{};
281 bool m_nameSet =
false;
284 bool m_openedByAlgorithm =
false;
303 static constexpr int UNBOUNDED = std::numeric_limits<int>::max();
314 const std::string &description,
315 GDALAlgorithmArgType type);
320 m_aliases.push_back(alias);
327 m_shortNameAliases.push_back(shortNameAlias);
335 m_hiddenAliases.push_back(alias);
370 m_category = category;
378 m_hasDefaultValue =
true;
385 if constexpr (std::is_same_v<T, bool>)
387 m_defaultValue = value;
395 if constexpr (std::is_same_v<T, std::string>)
397 m_defaultValue = value;
405 if constexpr (std::is_same_v<T, int>)
407 m_defaultValue = value;
415 if constexpr (std::is_assignable_v<double &, T>)
417 m_defaultValue =
static_cast<double>(value);
423 case GAAT_STRING_LIST:
425 if constexpr (std::is_same_v<T, std::string>)
427 m_defaultValue = std::vector<std::string>{value};
430 else if constexpr (std::is_same_v<T,
431 std::vector<std::string>>)
433 m_defaultValue = value;
439 case GAAT_INTEGER_LIST:
441 if constexpr (std::is_same_v<T, int>)
443 m_defaultValue = std::vector<int>{value};
446 else if constexpr (std::is_same_v<T, std::vector<int>>)
448 m_defaultValue = value;
456 if constexpr (std::is_assignable_v<double &, T>)
459 std::vector<double>{
static_cast<double>(value)};
462 else if constexpr (std::is_same_v<T, std::vector<double>>)
464 m_defaultValue = value;
471 case GAAT_DATASET_LIST:
475 catch (
const std::bad_variant_access &)
481 "Argument %s: SetDefault(): unexpected type for value",
490 return SetDefault(std::string(value));
512 m_displayHintAboutRepetition = displayHint;
522 m_packedValuesAllowed = allowed;
532 m_repeatedArgAllowed = allowed;
548 typename T,
typename... U,
549 typename std::enable_if<!std::is_same_v<T, std::vector<std::string> &>,
553 m_choices.push_back(std::forward<T>(first));
554 SetChoices(std::forward<U>(rest)...);
575 m_minValIsIncluded =
true;
587 m_minValIsIncluded =
false;
595 m_maxValIsIncluded =
true;
603 m_maxValIsIncluded =
false;
612 m_minCharCount = count;
627 template <
typename T,
typename... U>
630 m_hiddenChoices.push_back(std::forward<T>(first));
631 SetHiddenChoices(std::forward<U>(rest)...);
641 m_hiddenForCLI = hiddenForCLI;
650 m_hiddenForAPI = hiddenForAPI;
659 m_hiddenForCLI =
true;
660 m_hiddenForAPI =
true;
684 m_isOutput = isOutput;
693 m_mutualExclusionGroup = group;
701 const std::vector<std::string> &values)
703 m_metadata[name] = values;
713 m_readFromFileAtSyntaxAllowed =
true;
721 m_removeSQLComments =
true;
730 m_autoOpenDataset = autoOpen;
739 m_userProvided =
true;
764 return m_shortNameAliases;
770 return m_description;
809 return m_hiddenChoices;
815 return {m_minVal, m_minValIsIncluded};
821 return {m_maxVal, m_maxValIsIncluded};
829 return m_minCharCount;
861 return m_displayHintAboutRepetition;
870 return m_packedValuesAllowed;
879 return m_repeatedArgAllowed;
891 return m_hasDefaultValue;
898 return m_hiddenForCLI && m_hiddenForAPI;
907 return m_hiddenForCLI;
915 CPL_WARN_DEPRECATED("Use IsHiddenForAPI() instead")
917 return m_hiddenForAPI;
924 return m_hiddenForAPI;
955 return m_mutualExclusionGroup;
964 return m_readFromFileAtSyntaxAllowed;
971 return m_removeSQLComments;
979 return m_autoOpenDataset;
986 return m_userProvided;
990 inline const std::map<std::string, std::vector<std::string>>
997 inline const std::vector<std::string> *
1000 const auto iter = m_metadata.find(name);
1001 return iter == m_metadata.end() ? nullptr : &(iter->second);
1020 return std::get<T>(m_defaultValue);
1030 return m_datasetType;
1040 m_datasetType = type;
1056 return m_datasetInputFlags;
1071 return m_datasetOutputFlags;
1080 m_datasetInputFlags = flags;
1089 m_datasetOutputFlags = flags;
1093 const std::string m_longName;
1094 const std::string m_shortName;
1095 const std::string m_description;
1096 const GDALAlgorithmArgType m_type;
1097 std::string m_category = GAAC_BASE;
1098 std::string m_metaVar{};
1099 std::string m_mutualExclusionGroup{};
1102 bool m_required =
false;
1103 bool m_positional =
false;
1104 bool m_hasDefaultValue =
false;
1105 bool m_hiddenForCLI =
false;
1106 bool m_hiddenForAPI =
false;
1107 bool m_isInput =
true;
1108 bool m_isOutput =
false;
1109 bool m_packedValuesAllowed =
true;
1110 bool m_repeatedArgAllowed =
true;
1111 bool m_displayHintAboutRepetition =
true;
1112 bool m_readFromFileAtSyntaxAllowed =
false;
1113 bool m_removeSQLComments =
false;
1114 bool m_autoOpenDataset =
true;
1115 bool m_userProvided =
false;
1116 std::map<std::string, std::vector<std::string>> m_metadata{};
1117 std::vector<std::string> m_aliases{};
1118 std::vector<std::string> m_hiddenAliases{};
1119 std::vector<char> m_shortNameAliases{};
1120 std::vector<std::string> m_choices{};
1121 std::vector<std::string> m_hiddenChoices{};
1122 std::variant<bool, std::string, int, double, std::vector<std::string>,
1123 std::vector<int>, std::vector<double>>
1125 double m_minVal = std::numeric_limits<double>::quiet_NaN();
1126 double m_maxVal = std::numeric_limits<double>::quiet_NaN();
1127 bool m_minValIsIncluded =
false;
1128 bool m_maxValIsIncluded =
false;
1129 int m_minCharCount = 0;
1130 GDALArgDatasetType m_datasetType =
1136 int m_datasetInputFlags = GADV_NAME | GADV_OBJECT;
1141 int m_datasetOutputFlags = GADV_OBJECT;
1158 : m_decl(decl), m_value(pValue)
1160 if constexpr (!std::is_same_v<T, GDALArgDatasetValue> &&
1161 !std::is_same_v<T, std::vector<GDALArgDatasetValue>>)
1167 *std::get<T *>(m_value) = decl.
GetDefault<T>();
1169 catch (
const std::bad_variant_access &e)
1174 "*std::get<T *>(m_value) = decl.GetDefault<T>() "
1194 return m_decl.GetName();
1200 return m_decl.GetShortName();
1206 return m_decl.GetAliases();
1212 return m_decl.GetShortNameAliases();
1218 return m_decl.GetDescription();
1224 return m_decl.GetMetaVar();
1230 return m_decl.GetType();
1236 return m_decl.GetCategory();
1242 return m_decl.IsRequired();
1248 return m_decl.GetMinCount();
1254 return m_decl.GetMaxCount();
1260 return m_decl.GetDisplayHintAboutRepetition();
1266 return m_decl.GetPackedValuesAllowed();
1272 return m_decl.GetRepeatedArgAllowed();
1278 return m_decl.IsPositional();
1284 return m_decl.GetChoices();
1290 return m_decl.GetHiddenChoices();
1296 inline std::vector<std::string>
1299 if (m_autoCompleteFunction)
1300 return m_autoCompleteFunction(currentValue);
1307 return m_decl.GetMinValue();
1313 return m_decl.GetMaxValue();
1319 return m_decl.GetMinCharCount();
1325 return m_explicitlySet;
1331 return m_decl.HasDefaultValue();
1337 return m_decl.IsHidden();
1343 return m_decl.IsHiddenForCLI();
1348 CPL_WARN_DEPRECATED("Use IsHiddenForAPI() instead")
1350 return m_decl.IsHiddenForAPI();
1356 return m_decl.IsHiddenForAPI();
1362 return m_decl.IsInput();
1368 return m_decl.IsOutput();
1374 return m_decl.IsReadFromFileAtSyntaxAllowed();
1380 return m_decl.IsRemoveSQLCommentsEnabled();
1386 return m_decl.GetMutualExclusionGroup();
1390 inline const std::map<std::string, std::vector<std::string>>
1393 return m_decl.GetMetadata();
1397 inline const std::vector<std::string> *
1400 return m_decl.GetMetadataItem(name);
1406 return m_decl.GetDefault<T>();
1412 return m_decl.AutoOpenDataset();
1418 return m_decl.IsUserProvided();
1424 return m_decl.GetDatasetType();
1430 return m_decl.GetDatasetInputFlags();
1436 return m_decl.GetDatasetOutputFlags();
1455 template <
class T>
inline T &
Get()
1457 return *(std::get<T *>(m_value));
1476 template <
class T>
inline const T &
Get()
const
1478 return *(std::get<T *>(m_value));
1486 bool Set(
bool value);
1493 bool Set(
const std::string &value);
1502 return Set(std::string(value ? value :
""));
1528 bool Set(
int value);
1531 bool Set(
double value);
1546 bool Set(std::unique_ptr<GDALDataset> ds);
1553 bool SetDatasetName(
const std::string &name);
1568 bool Set(
const std::vector<std::string> &value);
1575 bool Set(
const std::vector<int> &value);
1582 bool Set(
const std::vector<double> &value);
1589 bool Set(std::vector<GDALArgDatasetValue> &&value);
1683 m_skipIfAlreadySet = skip;
1690 return m_skipIfAlreadySet;
1697 bool Serialize(std::string &serializedArg,
bool absolutePath =
false)
const;
1700 static std::string GetEscapedString(
const std::string &s);
1703 void NotifyValueSet()
1705 m_explicitlySet =
true;
1716 std::vector<std::string> *, std::vector<int> *,
1717 std::vector<double> *, std::vector<GDALArgDatasetValue> *>
1720 std::vector<std::function<void()>> m_actions{};
1722 std::vector<std::function<bool()>> m_validationActions{};
1724 std::function<std::vector<std::string>(
const std::string &)>
1725 m_autoCompleteFunction{};
1730 bool m_skipIfAlreadySet =
false;
1731 bool m_explicitlySet =
false;
1733 template <
class T>
bool SetInternal(
const T &value)
1735 m_explicitlySet =
true;
1736 *std::get<T *>(m_value) = value;
1737 return RunAllActions();
1740 bool ProcessString(std::string &value)
const;
1742 bool RunAllActions();
1744 bool RunValidationActions();
1745 std::string ValidateChoice(
const std::string &value)
const;
1746 bool ValidateIntRange(
int val)
const;
1747 bool ValidateRealRange(
double val)
const;
1760namespace test_gdal_algorithm
1762struct test_gdal_algorithm;
1772 friend struct test_gdal_algorithm::test_gdal_algorithm;
1826 if constexpr (!std::is_same_v<T, GDALArgDatasetValue> &&
1827 !std::is_same_v<T, std::vector<GDALArgDatasetValue>>)
1834 *std::get<bool *>(m_value) = m_decl.
GetDefault<
bool>();
1837 *std::get<std::string *>(m_value) =
1841 *std::get<int *>(m_value) = m_decl.
GetDefault<
int>();
1844 *std::get<double *>(m_value) =
1847 case GAAT_STRING_LIST:
1848 *std::get<std::vector<std::string> *>(m_value) =
1849 m_decl.
GetDefault<std::vector<std::string>>();
1851 case GAAT_INTEGER_LIST:
1852 *std::get<std::vector<int> *>(m_value) =
1855 case GAAT_REAL_LIST:
1856 *std::get<std::vector<double> *>(m_value) =
1860 case GAAT_DATASET_LIST:
1864 catch (
const std::bad_variant_access &)
1868 "Argument %s: SetDefault(): unexpected type for value",
1878 return SetDefault(std::string(value));
1919 typename T,
typename... U,
1920 typename std::enable_if<!std::is_same_v<T, std::vector<std::string> &>,
1924 m_decl.
SetChoices(std::forward<T>(first), std::forward<U>(rest)...);
1937 template <
typename T,
typename... U>
1941 std::forward<U>(rest)...);
2047 const std::vector<std::string> &values)
2080 m_actions.push_back(f);
2092 m_validationActions.push_back(f);
2100 std::function<std::vector<std::string>(
const std::string &)> f)
2102 m_autoCompleteFunction = std::move(f);
2113 SetIsCRSArg(
bool noneAllowed =
false,
2114 const std::vector<std::string> &specialValues =
2115 std::vector<std::string>());
2136 static constexpr const char *HIDDEN_ALIAS_SEPARATOR =
"==hide==";
2145 std::string m_name{};
2147 std::vector<std::string> m_aliases{};
2150 std::function m_creationFunc{};
2153 std::function<std::unique_ptr<GDALAlgorithm>(
void)> m_creationFunc{};
2162 info.
m_name = MyAlgorithm::NAME;
2163 info.
m_aliases = MyAlgorithm::GetAliasesStatic();
2165 {
return std::make_unique<MyAlgorithm>(); };
2166 return Register(info);
2171 bool Register(
const AlgInfo &info);
2178 std::vector<std::string> GetNames()
const;
2183 std::unique_ptr<GDALAlgorithm> Instantiate(
const std::string &name)
const;
2189 std::unique_ptr<GDALAlgorithm>
2190 Instantiate(
const std::vector<std::string> &path)
const;
2196 template <
typename... V>
2197 inline std::unique_ptr<GDALAlgorithm>
Instantiate(
const std::string &first,
2200 std::vector<std::string> path;
2201 return InstantiateInternal(path, first, std::forward<V>(rest)...);
2207 auto iter = m_mapNameToInfo.find(name);
2208 return iter != m_mapNameToInfo.end() ? &(iter->second) :
nullptr;
2214 return m_mapNameToInfo.empty();
2219 virtual std::unique_ptr<GDALAlgorithm>
2220 InstantiateTopLevel(
const std::string &name)
const;
2223 std::map<std::string, AlgInfo> m_mapNameToInfo{};
2224 std::map<std::string, AlgInfo> m_mapAliasToInfo{};
2225 std::map<std::string, AlgInfo> m_mapHiddenAliasToInfo{};
2227 std::unique_ptr<GDALAlgorithm>
2228 InstantiateInternal(std::vector<std::string> &path);
2230 template <
typename... V>
2231 std::unique_ptr<GDALAlgorithm>
2232 InstantiateInternal(std::vector<std::string> &path,
2233 const std::string &first, V &&...rest)
2235 path.push_back(first);
2236 return InstantiateInternal(path, std::forward<V>(rest)...);
2262 friend struct test_gdal_algorithm::test_gdal_algorithm;
2276 return m_description;
2282 return m_longDescription;
2296 return m_helpFullURL;
2306 bool HasSubAlgorithms()
const;
2313 std::vector<std::string> GetSubAlgorithmNames()
const;
2316 std::unique_ptr<GDALAlgorithm>
2317 InstantiateSubAlgorithm(
const std::string &name,
2318 bool suggestionAllowed =
true)
const;
2321 const std::vector<std::unique_ptr<GDALAlgorithmArg>> &
GetArgs()
const
2327 std::vector<std::unique_ptr<GDALAlgorithmArg>> &
GetArgs()
2333 std::string GetSuggestionForArgumentName(
const std::string &osName)
const;
2337 bool suggestionAllowed =
false)
2339 return GetArg(osName, suggestionAllowed,
false);
2345 auto alg = GetArg(osName,
false);
2349 "Argument '%s' does not exist", osName.c_str());
2357 bool suggestionAllowed =
false)
const
2360 osName, suggestionAllowed,
true);
2366 const auto alg = GetArg(osName,
false);
2370 "Argument '%s' does not exist", osName.c_str());
2392 m_parseForAutoCompletion =
true;
2401 m_referencePath = referencePath;
2407 return m_referencePath;
2413 return m_supportsStreamedOutput;
2425 m_executionForStreamOutput =
true;
2432 ParseCommandLineArguments(
const std::vector<std::string> &args);
2443 virtual bool ValidateArguments();
2448 bool Run(GDALProgressFunc pfnProgress =
nullptr,
2449 void *pProgressData =
nullptr);
2454 virtual bool Finalize();
2467 : isPipelineStep(false), maxOptLen(0), isPipelineMain(false)
2476 GetUsageForCLI(
bool shortUsage,
2477 const UsageOptions &usageOptions = UsageOptions())
const;
2483 virtual std::string GetUsageAsJSON()
const;
2492 if (m_selectedSubAlg)
2500 return m_helpRequested;
2506 return m_JSONUsageRequested;
2512 if (m_selectedSubAlg)
2513 return m_selectedSubAlg->IsProgressBarRequested();
2514 return m_progressBarRequested;
2527 static std::vector<std::string> GetAliasesStatic()
2540 target->m_calledFromCommandLine = m_calledFromCommandLine;
2543 if (m_specialActionRequested)
2545 target->m_specialActionRequested = m_specialActionRequested;
2546 target->m_helpRequested = m_helpRequested;
2547 target->m_helpDocRequested = m_helpDocRequested;
2548 target->m_JSONUsageRequested = m_JSONUsageRequested;
2555 virtual std::vector<std::string>
2556 GetAutoComplete(std::vector<std::string> &args,
bool lastWordIsComplete,
2557 bool showAllOptions);
2562 m_calledFromCommandLine =
true;
2568 return m_calledFromCommandLine;
2572 virtual bool HasOutputString()
const;
2577 static bool SaveGDALG(
const std::string &filename, std::string &outString,
2578 const std::string &commandLine);
2587 friend class GDALRasterReprojectUtils;
2596 std::vector<std::
string> m_callPath{};
2599 std::string m_longDescription{};
2602 bool m_progressBarRequested =
true;
2605 bool m_quiet =
false;
2608 bool m_skipValidationInParseCommandLine =
false;
2612 std::vector<std::string> m_aliases{};
2615 bool m_supportsStreamedOutput =
false;
2618 bool m_executionForStreamOutput =
false;
2621 bool m_hidden =
false;
2624 std::map<std::string, GDALDataset *> m_oMapDatasetNameToDataset{};
2627 GDALAlgorithm(
const std::string &name,
const std::string &description,
2628 const std::string &helpURL);
2637 return m_subAlgRegistry.Register<MyAlgorithm>();
2644 return m_subAlgRegistry.Register(info);
2650 m_arbitraryLongNameArgsAllowed =
true;
2656 const std::string &helpMessage,
2662 const std::string &helpMessage,
2663 std::string *pValue);
2668 const std::string &helpMessage,
2674 const std::string &helpMessage,
2680 GDALArgDatasetType type);
2684 AddArg(
const std::string &longName,
char chShortName,
2692 const std::string &helpMessage,
2693 std::vector<std::string> *pValue);
2698 const std::string &helpMessage,
2699 std::vector<int> *pValue);
2704 const std::string &helpMessage,
2705 std::vector<double> *pValue);
2709 AddArg(
const std::string &longName,
char chShortName,
2710 const std::string &helpMessage,
2711 std::vector<GDALArgDatasetValue> *pValue,
2720 bool positionalAndRequired =
true,
const char *helpMessage =
nullptr);
2724 std::vector<GDALArgDatasetValue> *pValue,
2727 bool positionalAndRequired =
true,
const char *helpMessage =
nullptr);
2731 AddOpenOptionsArg(std::vector<std::string> *pValue,
2732 const char *helpMessage =
nullptr);
2736 AddOutputOpenOptionsArg(std::vector<std::string> *pValue,
2737 const char *helpMessage =
nullptr);
2741 AddInputFormatsArg(std::vector<std::string> *pValue,
2742 const char *helpMessage =
nullptr);
2749 bool positionalAndRequired =
true,
const char *helpMessage =
nullptr);
2753 AddOverwriteArg(
bool *pValue,
const char *helpMessage =
nullptr);
2757 AddOverwriteLayerArg(
bool *pValue,
const char *helpMessage =
nullptr);
2761 AddUpdateArg(
bool *pValue,
const char *helpMessage =
nullptr);
2765 AddAppendLayerArg(
bool *pValue,
const char *helpMessage =
nullptr);
2769 AddOutputStringArg(std::string *pValue,
const char *helpMessage =
nullptr);
2773 AddStdoutArg(
bool *pValue,
const char *helpMessage =
nullptr);
2777 AddOutputFormatArg(std::string *pValue,
bool bStreamAllowed =
false,
2778 bool bGDALGAllowed =
false,
2779 const char *helpMessage =
nullptr);
2783 AddOutputDataTypeArg(std::string *pValue,
2784 const char *helpMessage =
nullptr);
2788 AddNodataArg(std::string *pValue,
bool noneAllowed,
2789 const std::string &optionName =
"nodata",
2790 const char *helpMessage =
nullptr);
2794 AddCreationOptionsArg(std::vector<std::string> *pValue,
2795 const char *helpMessage =
nullptr);
2799 AddLayerCreationOptionsArg(std::vector<std::string> *pValue,
2800 const char *helpMessage =
nullptr);
2804 AddLayerNameArg(std::string *pValue,
const char *helpMessage =
nullptr);
2808 AddOutputLayerNameArg(std::string *pValue,
2809 const char *helpMessage =
nullptr);
2813 AddLayerNameArg(std::vector<std::string> *pValue,
2814 const char *helpMessage =
nullptr);
2818 AddArrayNameArg(std::string *pValue,
const char *helpMessage =
nullptr);
2822 AddArrayNameArg(std::vector<std::string> *pValue,
2823 const char *helpMessage =
nullptr);
2830 AddMemorySizeArg(
size_t *pValue, std::string *pStrValue,
2831 const std::string &optionName,
const char *helpMessage);
2835 AddGeometryTypeArg(std::string *pValue,
const char *helpMessage =
nullptr);
2838 static void SetAutoCompleteFunctionForLayerName(
2843 static void SetAutoCompleteFunctionForFieldName(
2846 std::vector<GDALArgDatasetValue> &datasetArg);
2850 AddFieldNameArg(std::string *pValue,
const char *helpMessage =
nullptr);
2855 std::string *pStrValue,
const std::string &argName = std::string(),
2856 const char *helpMessage =
nullptr);
2860 AddBandArg(
int *pValue,
const char *helpMessage =
nullptr);
2864 AddBandArg(std::vector<int> *pValue,
const char *helpMessage =
nullptr);
2868 AddBBOXArg(std::vector<double> *pValue,
const char *helpMessage =
nullptr);
2872 AddActiveLayerArg(std::string *pValue,
const char *helpMessage =
nullptr);
2879 AddNumThreadsArg(
int *pValue, std::string *pStrValue,
2880 const char *helpMessage =
nullptr);
2884 AddAbsolutePathArg(
bool *pValue,
const char *helpMessage =
nullptr);
2888 AddPixelFunctionNameArg(std::string *pValue,
2889 const char *helpMessage =
nullptr);
2893 AddPixelFunctionArgsArg(std::vector<std::string> *pValue,
2894 const char *helpMessage =
nullptr);
2897 void AddProgressArg();
2907 m_validationActions.push_back(f);
2911 static bool AddOptionsSuggestions(
const char *pszXML,
int datasetType,
2912 const std::string ¤tValue,
2913 std::vector<std::string> &oRet);
2919 bool RunPreStepPipelineValidations()
const;
2922 bool IsGDALGOutput()
const;
2936 virtual ProcessGDALGOutputRet ProcessGDALGOutput();
2941 virtual bool CheckSafeForStreamOutput();
2945 bool bGDALGAllowed)
const;
2948 static std::vector<std::string>
2949 FormatAutoCompleteFunction(
const GDALAlgorithmArg &arg,
bool bStreamAllowed,
2950 bool bGDALGAllowed);
2954 const std::string &alias);
2957 char shortNameAlias);
2961 std::vector<std::string>
2962 OpenOptionCompleteFunction(
const std::string ¤tValue)
const;
2967 static bool IsKnownOutputRelatedBooleanArgName(std::string_view osName);
2972 m_displayInJSONUsage = b;
2983 std::pair<std::vector<std::pair<GDALAlgorithmArg *, std::string>>,
size_t>
2984 GetArgNamesForCLI()
const;
2987 std::string GetUsageForCLIEnd()
const;
2991 const std::string m_name{};
2992 const std::string m_description{};
2993 const std::string m_helpURL{};
2994 const std::string m_helpFullURL{};
2995 bool m_parsedSubStringAlreadyCalled =
false;
2996 bool m_displayInJSONUsage =
true;
2997 bool m_specialActionRequested =
false;
2998 bool m_helpRequested =
false;
2999 bool m_calledFromCommandLine =
false;
3002 bool m_helpDocRequested =
false;
3004 bool m_JSONUsageRequested =
false;
3005 bool m_parseForAutoCompletion =
false;
3006 std::string m_referencePath{};
3007 std::vector<std::string> m_dummyConfigOptions{};
3008 std::vector<std::unique_ptr<GDALAlgorithmArg>> m_args{};
3009 std::map<std::string, GDALAlgorithmArg *> m_mapLongNameToArg{};
3010 std::map<std::string, GDALAlgorithmArg *> m_mapShortNameToArg{};
3011 std::vector<GDALAlgorithmArg *> m_positionalArgs{};
3013 std::unique_ptr<GDALAlgorithm> m_selectedSubAlgHolder{};
3014 std::function<std::vector<std::string>(
const std::vector<std::string> &)>
3015 m_autoCompleteFunction{};
3016 std::vector<std::function<bool()>> m_validationActions{};
3018 std::string m_dummyVal{};
3025 bool m_arbitraryLongNameArgsAllowed =
false;
3027 std::vector<std::unique_ptr<std::string>>
3028 m_arbitraryLongNameArgsValuesStr{};
3029 std::vector<std::unique_ptr<bool>> m_arbitraryLongNameArgsValuesBool{};
3031 friend GDALAlgorithmArgH GDALAlgorithmGetArg(GDALAlgorithmH hAlg,
3032 const char *pszArgName);
3033 friend GDALAlgorithmArgH
3034 GDALAlgorithmGetArgNonConst(GDALAlgorithmH hAlg,
const char *pszArgName);
3035 GDALAlgorithmArg *GetArg(
const std::string &osName,
bool suggestionAllowed,
3039 AddArg(std::unique_ptr<GDALInConstructionAlgorithmArg> arg);
3042 const std::string &value,
3045 std::variant<std::vector<std::string>, std::vector<int>,
3046 std::vector<double>, std::vector<GDALArgDatasetValue>>>
3047 &inConstructionValues);
3049 bool ValidateBandArg()
const;
3051 virtual bool RunImpl(GDALProgressFunc pfnProgress,
void *pProgressData) = 0;
3056 void ExtractLastOptionAndValue(std::vector<std::string> &args,
3057 std::string &option,
3058 std::string &value)
const;
3060 std::vector<std::string> AutoCompleteArrayName()
const;
3067struct GDALAlgorithmHS
3070 std::unique_ptr<GDALAlgorithm> uniquePtr{};
3072 GDALAlgorithmHS(
const GDALAlgorithmHS &) =
delete;
3073 GDALAlgorithmHS &operator=(
const GDALAlgorithmHS &) =
delete;
3078 GDALAlgorithmHS() =
default;
3080 explicit GDALAlgorithmHS(std::unique_ptr<GDALAlgorithm> alg)
3081 : uniquePtr(std::move(alg)), ptr(uniquePtr.get())
3085 static std::unique_ptr<GDALAlgorithmHS> FromRef(
GDALAlgorithm &alg)
3087 auto ret = std::make_unique<GDALAlgorithmHS>();
3100 explicit GDALContainerAlgorithm(
3101 const std::string &name,
const std::string &description = std::string(),
3102 const std::string &helpURL = std::string())
3108 bool RunImpl(GDALProgressFunc,
void *)
override;
3123 static constexpr const char *ROOT_ALG_NAME =
"gdal";
3137 void DeclareAlgorithm(
const std::vector<std::string> &path,
3142 std::vector<std::string>
3143 GetDeclaredSubAlgorithmNames(
const std::vector<std::string> &path)
const;
3146 bool HasDeclaredSubAlgorithm(
const std::vector<std::string> &path)
const;
3149 std::unique_ptr<GDALAlgorithm>
3150 InstantiateDeclaredSubAlgorithm(
const std::vector<std::string> &path)
const;
3153 std::unique_ptr<GDALAlgorithm>
3154 InstantiateTopLevel(
const std::string &name)
const override;
3160 std::map<std::string, Node> children{};
3168 const Node *GetNodeFromPath(
const std::vector<std::string> &path)
const;
Argument declaration.
Definition gdalalgorithm_cpp.h:299
const std::string & GetCategory() const
Return the argument category: GAAC_COMMON, GAAC_BASE, GAAC_ADVANCED, GAAC_ESOTERIC or a custom catego...
Definition gdalalgorithm_cpp.h:785
std::pair< double, bool > GetMaxValue() const
Return the maximum value and whether it is included.
Definition gdalalgorithm_cpp.h:819
GDALAlgorithmArgDecl & AddShortNameAlias(char shortNameAlias)
Declare a shortname alias.
Definition gdalalgorithm_cpp.h:325
bool GetPackedValuesAllowed() const
Return whether, for list type of arguments, several values, space separated, may be specified.
Definition gdalalgorithm_cpp.h:868
GDALAlgorithmArgDecl & SetReadFromFileAtSyntaxAllowed()
Set that this (string) argument accepts the @filename syntax to mean that the content of the specifie...
Definition gdalalgorithm_cpp.h:711
int GetDatasetOutputFlags() const
Indicates which components among name and dataset are modified, when this argument serves as an outpu...
Definition gdalalgorithm_cpp.h:1069
int GetMaxCount() const
Return the maximum number of values for the argument.
Definition gdalalgorithm_cpp.h:851
bool IsOutput() const
Return whether (at least part of) the value of the argument is set during the execution of the algori...
Definition gdalalgorithm_cpp.h:944
GDALAlgorithmArgDecl & SetMinCount(int count)
Declare the minimum number of values for the argument.
Definition gdalalgorithm.cpp:192
GDALAlgorithmArgDecl & SetPackedValuesAllowed(bool allowed)
Declares whether, for list type of arguments, several values, comma separated, may be specified.
Definition gdalalgorithm_cpp.h:520
bool IsOnlyForCLI() const
Return whether the argument is only for CLI usage.
Definition gdalalgorithm_cpp.h:914
GDALAlgorithmArgDecl & SetMaxCount(int count)
Declare the maximum number of values for the argument.
Definition gdalalgorithm.cpp:211
bool HasDefaultValue() const
Return if the argument has a declared default value.
Definition gdalalgorithm_cpp.h:889
const std::string & GetShortName() const
Return the short name, or empty string if there is none.
Definition gdalalgorithm_cpp.h:750
void SetDatasetOutputFlags(int flags)
Set which components among name and dataset are modified when this argument serves as an output.
Definition gdalalgorithm_cpp.h:1087
GDALAlgorithmArgDecl & SetHiddenChoices(T &&first, U &&...rest)
Declares the, hidden, allowed values (as strings) for the argument.
Definition gdalalgorithm_cpp.h:628
GDALAlgorithmArgDecl & SetDefault(const char *value)
Declare a default value for the argument.
Definition gdalalgorithm_cpp.h:488
GDALAlgorithmArgType GetType() const
Return the type.
Definition gdalalgorithm_cpp.h:791
const std::vector< std::string > & GetHiddenChoices() const
Return the allowed hidden values (as strings) for the argument.
Definition gdalalgorithm_cpp.h:807
bool IsHidden() const
Return whether the argument is hidden.
Definition gdalalgorithm_cpp.h:896
bool IsInput() const
Indicate whether the value of the argument is read-only during the execution of the algorithm.
Definition gdalalgorithm_cpp.h:930
GDALAlgorithmArgDecl & SetMaxValueIncluded(double max)
Set the maximum (included) value allowed.
Definition gdalalgorithm_cpp.h:592
bool IsHiddenForAPI() const
Return whether the argument is hidden for API usage For example "--help".
Definition gdalalgorithm_cpp.h:922
GDALAlgorithmArgDecl & SetHiddenForAPI(bool hiddenForAPI=true)
Declare that the argument is hidden in the context of an API use.
Definition gdalalgorithm_cpp.h:648
const std::string & GetMetaVar() const
Return the "meta-var" hint.
Definition gdalalgorithm_cpp.h:777
bool GetDisplayHintAboutRepetition() const
Returns whether in --help message one should display hints about the minimum/maximum number of values...
Definition gdalalgorithm_cpp.h:859
const std::vector< std::string > & GetAliases() const
Return the aliases (potentially none)
Definition gdalalgorithm_cpp.h:756
bool IsPositional() const
Return if the argument is a positional one.
Definition gdalalgorithm_cpp.h:883
GDALAlgorithmArgDecl & SetMaxValueExcluded(double max)
Set the maximum (excluded) value allowed.
Definition gdalalgorithm_cpp.h:600
void SetDatasetType(GDALArgDatasetType type)
Set which type of dataset is allowed / generated.
Definition gdalalgorithm_cpp.h:1038
bool IsRequired() const
Return whether the argument is required.
Definition gdalalgorithm_cpp.h:834
bool IsRemoveSQLCommentsEnabled() const
Returns whether SQL comments must be removed from a (string) argument.
Definition gdalalgorithm_cpp.h:969
GDALAlgorithmArgDecl & SetMutualExclusionGroup(const std::string &group)
Set the name of the mutual exclusion group to which this argument belongs to.
Definition gdalalgorithm_cpp.h:691
int GetMinCount() const
Return the minimum number of values for the argument.
Definition gdalalgorithm_cpp.h:842
GDALAlgorithmArgDecl & SetCategory(const std::string &category)
Declare the argument category: GAAC_COMMON, GAAC_BASE, GAAC_ADVANCED, GAAC_ESOTERIC or a custom categ...
Definition gdalalgorithm_cpp.h:368
GDALAlgorithmArgDecl & SetChoices(T &&first, U &&...rest)
Declares the allowed values (as strings) for the argument.
Definition gdalalgorithm_cpp.h:551
const std::vector< std::string > * GetMetadataItem(const std::string &name) const
Get user-defined metadata by item name.
Definition gdalalgorithm_cpp.h:998
bool GetRepeatedArgAllowed() const
Return whether, for list type of arguments, the argument may be repeated.
Definition gdalalgorithm_cpp.h:877
GDALAlgorithmArgDecl & SetIsInput(bool isInput=true)
Indicate whether the value of the argument is read-only during the execution of the algorithm.
Definition gdalalgorithm_cpp.h:667
void SetDatasetInputFlags(int flags)
Set which components among name and dataset are accepted as input, when this argument serves as an in...
Definition gdalalgorithm_cpp.h:1078
GDALAlgorithmArgDecl & SetRepeatedArgAllowed(bool allowed)
Declares whether, for list type of arguments, the argument may be repeated.
Definition gdalalgorithm_cpp.h:530
int GetMinCharCount() const
Return the minimum number of characters (for arguments of type GAAT_STRING and GAAT_STRING_LIST)
Definition gdalalgorithm_cpp.h:827
const std::vector< char > & GetShortNameAliases() const
Return the shortname aliases (potentially none)
Definition gdalalgorithm_cpp.h:762
const std::string & GetMutualExclusionGroup() const
Return the name of the mutual exclusion group to which this argument belongs to, or empty string if i...
Definition gdalalgorithm_cpp.h:953
GDALAlgorithmArgDecl & SetMinCharCount(int count)
Sets the minimum number of characters (for arguments of type GAAT_STRING and GAAT_STRING_LIST)
Definition gdalalgorithm_cpp.h:610
bool IsReadFromFileAtSyntaxAllowed() const
Return if this (string) argument accepts the @filename syntax to mean that the content of the specifi...
Definition gdalalgorithm_cpp.h:962
GDALAlgorithmArgDecl & AddAlias(const std::string &alias)
Declare an alias.
Definition gdalalgorithm_cpp.h:318
bool IsHiddenForCLI() const
Return whether the argument must not be mentioned in CLI usage.
Definition gdalalgorithm_cpp.h:905
GDALAlgorithmArgDecl & SetPositional()
Declare that the argument is positional.
Definition gdalalgorithm_cpp.h:341
GDALArgDatasetType GetDatasetType() const
Get which type of dataset is allowed / generated.
Definition gdalalgorithm_cpp.h:1028
GDALAlgorithmArgDecl & SetRequired()
Declare that the argument is required.
Definition gdalalgorithm_cpp.h:349
GDALAlgorithmArgDecl & SetUserProvided()
Declares that this argument has been created on-the-fly from user-provided argument.
Definition gdalalgorithm_cpp.h:737
const std::vector< std::string > & GetChoices() const
Return the allowed values (as strings) for the argument.
Definition gdalalgorithm_cpp.h:799
bool AutoOpenDataset() const
Returns whether the dataset should be opened automatically by GDALAlgorithm.
Definition gdalalgorithm_cpp.h:977
GDALAlgorithmArgDecl & SetMetaVar(const std::string &metaVar)
Declare the "meta-var" hint.
Definition gdalalgorithm_cpp.h:359
bool IsUserProvided() const
Returns whether the argument has been user-provided.
Definition gdalalgorithm_cpp.h:984
std::pair< double, bool > GetMinValue() const
Return the minimum value and whether it is included.
Definition gdalalgorithm_cpp.h:813
GDALAlgorithmArgDecl & AddMetadataItem(const std::string &name, const std::vector< std::string > &values)
Set user-defined metadata item.
Definition gdalalgorithm_cpp.h:700
int GetDatasetInputFlags() const
Indicates which components among name and dataset are accepted as input, when this argument serves as...
Definition gdalalgorithm_cpp.h:1054
const T & GetDefault() const
Return the default value of the argument.
Definition gdalalgorithm_cpp.h:1018
const std::string & GetDescription() const
Return the description.
Definition gdalalgorithm_cpp.h:768
GDALAlgorithmArgDecl & AddHiddenAlias(const std::string &alias)
Declare an hidden alias (i.e.
Definition gdalalgorithm_cpp.h:333
GDALAlgorithmArgDecl & SetMinValueIncluded(double min)
Set the minimum (included) value allowed.
Definition gdalalgorithm_cpp.h:572
GDALAlgorithmArgDecl & SetDefault(const T &value)
Declare a default value for the argument.
Definition gdalalgorithm_cpp.h:376
GDALAlgorithmArgDecl & SetChoices(const std::vector< std::string > &choices)
Declares the allowed values (as strings) for the argument.
Definition gdalalgorithm_cpp.h:561
GDALAlgorithmArgDecl & SetHiddenForCLI(bool hiddenForCLI=true)
Declare that the argument must not be mentioned in CLI usage.
Definition gdalalgorithm_cpp.h:639
GDALAlgorithmArgDecl & SetIsOutput(bool isOutput=true)
Indicate whether (at least part of) the value of the argument is set during the execution of the algo...
Definition gdalalgorithm_cpp.h:682
GDALAlgorithmArgDecl & SetAutoOpenDataset(bool autoOpen)
Sets whether the dataset should be opened automatically by GDALAlgorithm.
Definition gdalalgorithm_cpp.h:728
GDALAlgorithmArgDecl & SetDisplayHintAboutRepetition(bool displayHint)
Declare whether in --help message one should display hints about the minimum/maximum number of values...
Definition gdalalgorithm_cpp.h:510
GDALAlgorithmArgDecl & SetHidden()
Declare that the argument is hidden.
Definition gdalalgorithm_cpp.h:657
const std::string & GetName() const
Return the (long) name.
Definition gdalalgorithm_cpp.h:744
const std::map< std::string, std::vector< std::string > > GetMetadata() const
Get user-defined metadata.
Definition gdalalgorithm_cpp.h:991
GDALAlgorithmArgDecl & SetMinValueExcluded(double min)
Set the minimum (excluded) value allowed.
Definition gdalalgorithm_cpp.h:584
GDALAlgorithmArgDecl & SetRemoveSQLCommentsEnabled()
Sets that SQL comments must be removed from a (string) argument.
Definition gdalalgorithm_cpp.h:719
Argument of an algorithm.
Definition gdalalgorithm_cpp.h:1153
bool IsRemoveSQLCommentsEnabled() const
Alias for GDALAlgorithmArgDecl::IsRemoveSQLCommentsEnabled()
Definition gdalalgorithm_cpp.h:1378
T & Get()
Return the value of the argument, which is by decreasing order of priority:
Definition gdalalgorithm_cpp.h:1455
const std::vector< std::string > & GetAliases() const
Alias for GDALAlgorithmArgDecl::GetAliases()
Definition gdalalgorithm_cpp.h:1204
bool IsExplicitlySet() const
Return whether the argument value has been explicitly set with Set()
Definition gdalalgorithm_cpp.h:1323
int GetMinCount() const
Alias for GDALAlgorithmArgDecl::GetMinCount()
Definition gdalalgorithm_cpp.h:1246
GDALAlgorithmArg & operator=(const std::string &value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1613
const std::string & GetCategory() const
Alias for GDALAlgorithmArgDecl::GetCategory()
Definition gdalalgorithm_cpp.h:1234
bool IsInput() const
Alias for GDALAlgorithmArgDecl::IsInput()
Definition gdalalgorithm_cpp.h:1360
int GetMinCharCount() const
Alias for GDALAlgorithmArgDecl::GetMinCharCount()
Definition gdalalgorithm_cpp.h:1317
const T & Get() const
Return the value of the argument, which is by decreasing order of priority:
Definition gdalalgorithm_cpp.h:1476
bool IsRequired() const
Alias for GDALAlgorithmArgDecl::IsRequired()
Definition gdalalgorithm_cpp.h:1240
GDALAlgorithmArg & operator=(int value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1599
const std::string & GetName() const
Alias for GDALAlgorithmArgDecl::GetName()
Definition gdalalgorithm_cpp.h:1192
int GetDatasetInputFlags() const
Alias for GDALAlgorithmArgDecl::GetDatasetInputFlags()
Definition gdalalgorithm_cpp.h:1428
int GetMaxCount() const
Alias for GDALAlgorithmArgDecl::GetMaxCount()
Definition gdalalgorithm_cpp.h:1252
bool IsReadFromFileAtSyntaxAllowed() const
Alias for GDALAlgorithmArgDecl::IsReadFromFileAtSyntaxAllowed()
Definition gdalalgorithm_cpp.h:1372
const std::string & GetMetaVar() const
Alias for GDALAlgorithmArgDecl::GetMetaVar()
Definition gdalalgorithm_cpp.h:1222
int GetDatasetOutputFlags() const
Alias for GDALAlgorithmArgDecl::GetDatasetOutputFlags()
Definition gdalalgorithm_cpp.h:1434
GDALAlgorithmArg & operator=(const std::vector< int > &value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1641
const std::map< std::string, std::vector< std::string > > GetMetadata() const
Alias for GDALAlgorithmArgDecl::GetMetadata()
Definition gdalalgorithm_cpp.h:1391
const std::vector< std::string > & GetHiddenChoices() const
Alias for GDALAlgorithmArgDecl::GetHiddenChoices()
Definition gdalalgorithm_cpp.h:1288
const std::string & GetShortName() const
Alias for GDALAlgorithmArgDecl::GetShortName()
Definition gdalalgorithm_cpp.h:1198
GDALAlgorithmArg & operator=(const OGRSpatialReference &value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1634
const std::string & GetDescription() const
Alias for GDALAlgorithmArgDecl::GetDescription()
Definition gdalalgorithm_cpp.h:1216
GDALAlgorithmArg & operator=(const char *value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1620
const std::vector< std::string > * GetMetadataItem(const std::string &name) const
Alias for GDALAlgorithmArgDecl::GetMetadataItem()
Definition gdalalgorithm_cpp.h:1398
const std::vector< char > & GetShortNameAliases() const
Alias for GDALAlgorithmArgDecl::GetShortNameAliases()
Definition gdalalgorithm_cpp.h:1210
std::pair< double, bool > GetMaxValue() const
Alias for GDALAlgorithmArgDecl::GetMaxValue()
Definition gdalalgorithm_cpp.h:1311
bool Set(GDALDataType dt)
Set the value for a GAAT_STRING argument from a GDALDataType It cannot be called several times for a ...
Definition gdalalgorithm_cpp.h:1510
const std::vector< std::string > & GetChoices() const
Alias for GDALAlgorithmArgDecl::GetChoices()
Definition gdalalgorithm_cpp.h:1282
void SetSkipIfAlreadySet(bool skip=true)
Advanced method used to make "gdal info" and "gdal raster|vector info" to avoid re-opening an already...
Definition gdalalgorithm_cpp.h:1681
bool GetPackedValuesAllowed() const
Alias for GDALAlgorithmArgDecl::GetPackedValuesAllowed()
Definition gdalalgorithm_cpp.h:1264
bool IsOnlyForCLI() const
Alias for GDALAlgorithmArgDecl::IsOnlyForCLI()
Definition gdalalgorithm_cpp.h:1347
bool IsOutput() const
Alias for GDALAlgorithmArgDecl::IsOutput()
Definition gdalalgorithm_cpp.h:1366
virtual ~GDALAlgorithmArg()
Destructor.
bool HasDefaultValue() const
Alias for GDALAlgorithmArgDecl::HasDefaultValue()
Definition gdalalgorithm_cpp.h:1329
std::vector< std::string > GetAutoCompleteChoices(const std::string ¤tValue) const
Return auto completion choices, if a auto completion function has been registered.
Definition gdalalgorithm_cpp.h:1297
bool IsHidden() const
Alias for GDALAlgorithmArgDecl::IsHidden()
Definition gdalalgorithm_cpp.h:1335
bool Set(const char *value)
Set the value for a GAAT_STRING argument.
Definition gdalalgorithm_cpp.h:1500
bool GetDisplayHintAboutRepetition() const
Alias for GDALAlgorithmArgDecl::GetDisplayHintAboutRepetition()
Definition gdalalgorithm_cpp.h:1258
GDALAlgorithmArgDecl m_decl
Argument declaration.
Definition gdalalgorithm_cpp.h:1713
GDALAlgorithmArg(const GDALAlgorithmArgDecl &decl, T *pValue)
Constructor.
Definition gdalalgorithm_cpp.h:1157
bool IsPositional() const
Alias for GDALAlgorithmArgDecl::IsPositional()
Definition gdalalgorithm_cpp.h:1276
GDALAlgorithmArg & operator=(const std::vector< double > &value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1648
bool AutoOpenDataset() const
Alias for GDALAlgorithmArgDecl::AutoOpenDataset()
Definition gdalalgorithm_cpp.h:1410
bool SkipIfAlreadySet() const
Advanced method used to make "gdal info" and "gdal raster|vector info" to avoid re-opening an already...
Definition gdalalgorithm_cpp.h:1688
const GDALAlgorithmArgDecl & GetDeclaration() const
Return the argument declaration.
Definition gdalalgorithm_cpp.h:1186
GDALAlgorithmArg & operator=(const std::vector< std::string > &value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1655
bool GetRepeatedArgAllowed() const
Alias for GDALAlgorithmArgDecl::GetRepeatedArgAllowed()
Definition gdalalgorithm_cpp.h:1270
GDALAlgorithmArg & operator=(double value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1606
std::pair< double, bool > GetMinValue() const
Alias for GDALAlgorithmArgDecl::GetMinValue()
Definition gdalalgorithm_cpp.h:1305
GDALAlgorithmArgType GetType() const
Alias for GDALAlgorithmArgDecl::GetType()
Definition gdalalgorithm_cpp.h:1228
GDALAlgorithmArg & operator=(GDALDataset *value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1662
const std::string & GetMutualExclusionGroup() const
Alias for GDALAlgorithmArgDecl::GetMutualExclusionGroup()
Definition gdalalgorithm_cpp.h:1384
bool IsHiddenForAPI() const
Alias for GDALAlgorithmArgDecl::IsHiddenForAPI()
Definition gdalalgorithm_cpp.h:1354
bool IsUserProvided() const
Alias for GDALAlgorithmArgDecl::IsUserProvided()
Definition gdalalgorithm_cpp.h:1416
GDALArgDatasetType GetDatasetType() const
Alias for GDALAlgorithmArgDecl::GetDatasetType()
Definition gdalalgorithm_cpp.h:1422
GDALAlgorithmArg & operator=(bool value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1592
bool IsHiddenForCLI() const
Alias for GDALAlgorithmArgDecl::IsHiddenForCLI()
Definition gdalalgorithm_cpp.h:1341
GDALAlgorithmArg & operator=(GDALDataType value)
Set the value of the argument.
Definition gdalalgorithm_cpp.h:1627
const T & GetDefault() const
Alias for GDALAlgorithmArgDecl::GetDefault()
Definition gdalalgorithm_cpp.h:1404
Algorithm information.
Definition gdalalgorithm_cpp.h:2142
std::function m_creationFunc
Creation function.
Definition gdalalgorithm_cpp.h:2150
std::string m_name
Algorithm (short) name.
Definition gdalalgorithm_cpp.h:2145
std::vector< std::string > m_aliases
Aliases.
Definition gdalalgorithm_cpp.h:2147
Registry of GDAL algorithms.
Definition gdalalgorithm_cpp.h:2132
bool empty() const
Returns true if there are no algorithms registered.
Definition gdalalgorithm_cpp.h:2212
std::unique_ptr< GDALAlgorithm > Instantiate(const std::string &first, V &&...rest)
Instantiate an algorithm by its path.
Definition gdalalgorithm_cpp.h:2197
const AlgInfo * GetInfo(const std::string &name) const
Get an algorithm by its name.
Definition gdalalgorithm_cpp.h:2205
bool Register()
Register the algorithm of type MyAlgorithm.
Definition gdalalgorithm_cpp.h:2159
GDAL algorithm.
Definition gdalalgorithm_cpp.h:2261
virtual void WarnIfDeprecated()
Method that an algorithm can implement to issue a warning message about its deprecation.
Definition gdalalgorithm_cpp.h:2978
bool SupportsStreamedOutput() const
Returns whether this algorithm supports a streamed output dataset.
Definition gdalalgorithm_cpp.h:2411
void AddValidationAction(std::function< bool()> f)
Register an action that is executed by the ValidateArguments() method.
Definition gdalalgorithm_cpp.h:2905
const std::string & GetHelpFullURL() const
Get the algorithm full URL, resolving relative URLs.
Definition gdalalgorithm_cpp.h:2294
void SetCallPath(const std::vector< std::string > &path)
Set the calling path to this algorithm.
Definition gdalalgorithm_cpp.h:2381
bool IsJSONUsageRequested() const
Whether the --json-usage flag has been specified.
Definition gdalalgorithm_cpp.h:2504
void SetReferencePathForRelativePaths(const std::string &referencePath)
Set the reference file paths used to interpret relative paths.
Definition gdalalgorithm_cpp.h:2399
bool m_progressBarRequested
Whether a progress bar is requested (value of --progress argument)
Definition gdalalgorithm_cpp.h:2602
bool IsHidden() const
Returns whether this algorithm is hidden.
Definition gdalalgorithm_cpp.h:2300
const std::string & GetLongDescription() const
Get the long algorithm description.
Definition gdalalgorithm_cpp.h:2280
std::vector< std::unique_ptr< GDALAlgorithmArg > > & GetArgs()
Return the potential arguments of the algorithm.
Definition gdalalgorithm_cpp.h:2327
void SetCalledFromCommandLine()
Set whether the algorithm is called from the command line.
Definition gdalalgorithm_cpp.h:2560
bool RegisterSubAlgorithm()
Register the sub-algorithm of type MyAlgorithm.
Definition gdalalgorithm_cpp.h:2635
const std::string & GetDescription() const
Get the algorithm description (a few sentences at most)
Definition gdalalgorithm_cpp.h:2274
ProcessGDALGOutputRet
Return value for ProcessGDALGOutput.
Definition gdalalgorithm_cpp.h:2926
bool IsCalledFromCommandLine() const
Return whether the algorithm is called from the command line.
Definition gdalalgorithm_cpp.h:2566
GDALAlgorithm & GetActualAlgorithm()
Return the actual algorithm that is going to be invoked, when the current algorithm has sub-algorithm...
Definition gdalalgorithm_cpp.h:2490
const GDALAlgorithmArg * GetArg(const std::string &osName, bool suggestionAllowed=false) const
Return an argument from its long name, short name or an alias.
Definition gdalalgorithm_cpp.h:2356
void AllowArbitraryLongNameArgs()
Allow arbitrary user arguments using long name syntax (–something)
Definition gdalalgorithm_cpp.h:2648
GDALAlgorithmArg & operator[](const std::string &osName)
Return an argument from its long name, short name or an alias.
Definition gdalalgorithm_cpp.h:2343
GDALAlgorithmArg * GetArg(const std::string &osName, bool suggestionAllowed=false)
Return an argument from its long name, short name or an alias.
Definition gdalalgorithm_cpp.h:2336
bool m_quiet
Whether a progress bar is disabled (value of --quiet argument)
Definition gdalalgorithm_cpp.h:2605
const std::string & GetHelpURL() const
Get the algorithm help URL.
Definition gdalalgorithm_cpp.h:2288
const std::vector< std::unique_ptr< GDALAlgorithmArg > > & GetArgs() const
Return the potential arguments of the algorithm.
Definition gdalalgorithm_cpp.h:2321
const std::string & GetName() const
Get the algorithm name.
Definition gdalalgorithm_cpp.h:2268
bool RegisterSubAlgorithm(const GDALAlgorithmRegistry::AlgInfo &info)
Register a sub-algoritm by its AlgInfo structure.
Definition gdalalgorithm_cpp.h:2642
void SetParseForAutoCompletion()
Set hint before calling ParseCommandLineArguments() that it must try to be be graceful when possible,...
Definition gdalalgorithm_cpp.h:2390
void SetExecutionForStreamedOutput()
Indicates that the algorithm must be run to generate a streamed output dataset.
Definition gdalalgorithm_cpp.h:2423
const GDALAlgorithmArg & operator[](const std::string &osName) const
Return an argument from its long name, short name or an alias.
Definition gdalalgorithm_cpp.h:2364
bool IsProgressBarRequested() const
Whether the --progress flag has been specified.
Definition gdalalgorithm_cpp.h:2510
const std::string & GetReferencePathForRelativePaths() const
Return the reference file paths used to interpret relative paths.
Definition gdalalgorithm_cpp.h:2405
const std::vector< std::string > & GetAliases() const
Return alias names (generally short) for the current algorithm.
Definition gdalalgorithm_cpp.h:2518
void SetDisplayInJSONUsage(bool b)
Set whether this algorithm should be reported in JSON usage.
Definition gdalalgorithm_cpp.h:2970
bool PropagateSpecialActionTo(GDALAlgorithm *target)
Used by the "gdal info" special algorithm when it first tries to run "gdal raster info",...
Definition gdalalgorithm_cpp.h:2538
bool IsHelpRequested() const
Whether the --help flag has been specified.
Definition gdalalgorithm_cpp.h:2498
Value for an argument that points to a GDALDataset.
Definition gdalalgorithm_cpp.h:149
GDALArgDatasetValue()=default
Default (empty) constructor.
const std::string & GetName() const
Get dataset name.
Definition gdalalgorithm_cpp.h:222
GDALDataset * BorrowDataset()
Borrow the GDALDataset* instance (may be null), leaving its reference counter unchanged.
Definition gdalalgorithm_cpp.h:204
GDALArgDatasetValue(const std::string &name)
Constructor by dataset name.
Definition gdalalgorithm_cpp.h:155
const GDALDataset * GetDatasetRef() const
Get a GDALDataset* instance (may be null).
Definition gdalalgorithm_cpp.h:196
GDALDataset * GetDatasetRef()
Get a GDALDataset* instance (may be null).
Definition gdalalgorithm_cpp.h:187
bool HasDatasetBeenOpenedByAlgorithm() const
Whether the dataset has been opened by the algorithm.
Definition gdalalgorithm_cpp.h:255
void SetOwnerArgument(GDALAlgorithmArg *arg)
Set the argument that owns us.
Definition gdalalgorithm_cpp.h:264
void SetDatasetOpenedByAlgorithm()
Set that the dataset has been opened by the algorithm.
Definition gdalalgorithm_cpp.h:249
bool IsNameSet() const
Return whether a dataset name has been set.
Definition gdalalgorithm_cpp.h:228
void BorrowDatasetFrom(GDALArgDatasetValue &other)
Borrow the GDALDataset* instance from another GDALArgDatasetValue, leaving its reference counter unch...
Definition gdalalgorithm_cpp.h:214
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:76
Global registry of GDAL algorithms.
Definition gdalalgorithm_cpp.h:3120
std::function< std::unique_ptr< GDALAlgorithm >()> InstantiateFunc
Instantiation function.
Definition gdalalgorithm_cpp.h:3129
Technical class used by GDALAlgorithm when constructing argument declarations.
Definition gdalalgorithm_cpp.h:1771
GDALInConstructionAlgorithmArg & SetDatasetInputFlags(int flags)
Alias for GDALAlgorithmArgDecl::SetDatasetInputFlags()
Definition gdalalgorithm_cpp.h:2062
GDALInConstructionAlgorithmArg & SetDefault(const T &value)
Alias for GDALAlgorithmArgDecl::SetDefault()
Definition gdalalgorithm_cpp.h:1822
GDALInConstructionAlgorithmArg & AddAction(std::function< void()> f)
Register an action that is executed, once and exactly once, if the argument is explicitly set,...
Definition gdalalgorithm_cpp.h:2078
GDALInConstructionAlgorithmArg & SetHiddenChoices(T &&first, U &&...rest)
Alias for GDALAlgorithmArgDecl::SetHiddenChoices()
Definition gdalalgorithm_cpp.h:1938
GDALInConstructionAlgorithmArg & SetMaxValueIncluded(double max)
Alias for GDALAlgorithmArgDecl::SetMaxValueIncluded()
Definition gdalalgorithm_cpp.h:1960
GDALInConstructionAlgorithmArg & SetHidden()
Alias for GDALAlgorithmArgDecl::SetHidden()
Definition gdalalgorithm_cpp.h:1981
GDALInConstructionAlgorithmArg & SetDatasetOutputFlags(int flags)
Alias for GDALAlgorithmArgDecl::SetDatasetOutputFlags()
Definition gdalalgorithm_cpp.h:2069
GDALInConstructionAlgorithmArg & SetReadFromFileAtSyntaxAllowed()
Alias for GDALAlgorithmArgDecl::SetReadFromFileAtSyntaxAllowed()
Definition gdalalgorithm_cpp.h:2016
~GDALInConstructionAlgorithmArg() override
Destructor.
GDALInConstructionAlgorithmArg & SetMinCount(int count)
Alias for GDALAlgorithmArgDecl::SetMinCount()
Definition gdalalgorithm_cpp.h:1882
GDALInConstructionAlgorithmArg & SetIsOutput(bool isOutput=true)
Alias for GDALAlgorithmArgDecl::SetIsOutput()
Definition gdalalgorithm_cpp.h:2009
GDALInConstructionAlgorithmArg & SetRemoveSQLCommentsEnabled()
Alias for GDALAlgorithmArgDecl::SetRemoveSQLCommentsEnabled()
Definition gdalalgorithm_cpp.h:2023
GDALInConstructionAlgorithmArg & SetDefault(const char *value)
Alias for GDALAlgorithmArgDecl::SetDefault()
Definition gdalalgorithm_cpp.h:1876
GDALInConstructionAlgorithmArg & SetMaxCount(int count)
Alias for GDALAlgorithmArgDecl::SetMaxCount()
Definition gdalalgorithm_cpp.h:1889
GDALInConstructionAlgorithmArg & SetMaxValueExcluded(double max)
Alias for GDALAlgorithmArgDecl::SetMaxValueExcluded()
Definition gdalalgorithm_cpp.h:1967
GDALInConstructionAlgorithmArg & SetHiddenForAPI(bool hiddenForAPI=true)
Alias for GDALAlgorithmArgDecl::SetHiddenForAPI()
Definition gdalalgorithm_cpp.h:1995
GDALInConstructionAlgorithmArg & SetDisplayHintAboutRepetition(bool displayHint)
Alias for GDALAlgorithmArgDecl::SetDisplayHintAboutRepetition()
Definition gdalalgorithm_cpp.h:1897
GDALInConstructionAlgorithmArg & SetAutoOpenDataset(bool autoOpen)
Alias for GDALAlgorithmArgDecl::SetAutoOpenDataset()
Definition gdalalgorithm_cpp.h:2030
GDALInConstructionAlgorithmArg & SetDatasetType(GDALArgDatasetType datasetType)
Alias for GDALAlgorithmArgDecl::SetDatasetType()
Definition gdalalgorithm_cpp.h:2055
GDALInConstructionAlgorithmArg & SetAutoCompleteFunction(std::function< std::vector< std::string >(const std::string &)> f)
Register a function that will return a list of valid choices for the value of the argument.
Definition gdalalgorithm_cpp.h:2099
GDALInConstructionAlgorithmArg & SetPackedValuesAllowed(bool allowed)
Alias for GDALAlgorithmArgDecl::SetPackedValuesAllowed()
Definition gdalalgorithm_cpp.h:1904
GDALInConstructionAlgorithmArg & SetUserProvided()
Alias for GDALAlgorithmArgDecl::SetUserProvided()
Definition gdalalgorithm_cpp.h:2118
GDALInConstructionAlgorithmArg & SetChoices(const std::vector< std::string > &choices)
Alias for GDALAlgorithmArgDecl::SetChoices()
Definition gdalalgorithm_cpp.h:1930
GDALInConstructionAlgorithmArg & SetMinCharCount(int count)
Alias for GDALAlgorithmArgDecl::SetMinCharCount()
Definition gdalalgorithm_cpp.h:1974
GDALInConstructionAlgorithmArg & SetHiddenForCLI(bool hiddenForCLI=true)
Alias for GDALAlgorithmArgDecl::SetHiddenForCLI()
Definition gdalalgorithm_cpp.h:1988
GDALInConstructionAlgorithmArg & AddMetadataItem(const std::string &name, const std::vector< std::string > &values)
Alias for GDALAlgorithmArgDecl::AddMetadataItem()
Definition gdalalgorithm_cpp.h:2046
GDALInConstructionAlgorithmArg & SetMutualExclusionGroup(const std::string &group)
Alias for GDALAlgorithmArgDecl::SetMutualExclusionGroup()
Definition gdalalgorithm_cpp.h:2038
GDALInConstructionAlgorithmArg & SetMinValueIncluded(double min)
Alias for GDALAlgorithmArgDecl::SetMinValueIncluded()
Definition gdalalgorithm_cpp.h:1946
GDALInConstructionAlgorithmArg & SetChoices(T &&first, U &&...rest)
Alias for GDALAlgorithmArgDecl::SetChoices()
Definition gdalalgorithm_cpp.h:1922
GDALInConstructionAlgorithmArg & SetIsInput(bool isInput=true)
Alias for GDALAlgorithmArgDecl::SetIsInput()
Definition gdalalgorithm_cpp.h:2002
GDALInConstructionAlgorithmArg & SetRequired()
Alias for GDALAlgorithmArgDecl::SetRequired()
Definition gdalalgorithm_cpp.h:1800
GDALInConstructionAlgorithmArg & SetMetaVar(const std::string &metaVar)
Alias for GDALAlgorithmArgDecl::SetMetaVar()
Definition gdalalgorithm_cpp.h:1807
GDALInConstructionAlgorithmArg(GDALAlgorithm *owner, const GDALAlgorithmArgDecl &decl, T *pValue)
Constructor.
Definition gdalalgorithm_cpp.h:1777
GDALInConstructionAlgorithmArg & SetRepeatedArgAllowed(bool allowed)
Alias for GDALAlgorithmArgDecl::SetRepeatedArgAllowed()
Definition gdalalgorithm_cpp.h:1911
GDALInConstructionAlgorithmArg & SetMinValueExcluded(double min)
Alias for GDALAlgorithmArgDecl::SetMinValueExcluded()
Definition gdalalgorithm_cpp.h:1953
GDALInConstructionAlgorithmArg & SetCategory(const std::string &category)
Alias for GDALAlgorithmArgDecl::SetCategory()
Definition gdalalgorithm_cpp.h:1814
GDALInConstructionAlgorithmArg & AddValidationAction(std::function< bool()> f)
Register an action that is executed, once and exactly once, if the argument is explicitly set,...
Definition gdalalgorithm_cpp.h:2090
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
CPL error handling services.
#define CPLAssert(expr)
Assert on an expression.
Definition cpl_error.h:330
CPLErr
Error category.
Definition cpl_error.h:37
#define CPLE_AppDefined
Application defined error.
Definition cpl_error.h:85
int CPLErrorNum
Error number.
Definition cpl_error.h:80
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:844
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
GDALDataType
Definition gdal.h:48
#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
const char * GDALGetDataTypeName(GDALDataType)
Get name of data type.
Definition gdal_misc.cpp:715
#define GDAL_OF_MULTIDIM_RASTER
Allow multidimensional raster drivers to be used.
Definition gdal.h:1102
OGRFieldSubType
List of field subtypes.
Definition ogr_core.h:799
OGRFieldType
List of feature field types.
Definition ogr_core.h:772
Usage options.
Definition gdalalgorithm_cpp.h:2458
bool isPipelineStep
Whether this is a pipeline step.
Definition gdalalgorithm_cpp.h:2460
size_t maxOptLen
Maximum width of the names of the options.
Definition gdalalgorithm_cpp.h:2462
bool isPipelineMain
Whether this is a pipeline main.
Definition gdalalgorithm_cpp.h:2464