OpenTTD Source  20241108-master-g80f628063a
getoptdata.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef GETOPTDATA_H
11 #define GETOPTDATA_H
12 
14 enum OptionDataType : uint8_t {
18 };
19 
21 struct OptionData {
23  char id;
24  char shortname = '\0';
25  const char *longname = nullptr;
26 };
27 
29 struct GetOptData {
30  using OptionSpan = std::span<const OptionData>;
31  using ArgumentSpan = std::span<char * const>;
32 
33  ArgumentSpan arguments;
34  const OptionSpan options;
35  const char *opt = nullptr;
36  const char *cont = nullptr;
37 
43  GetOptData(ArgumentSpan arguments, OptionSpan options) : arguments(arguments), options(options) {}
44 
45  int GetOpt();
46  int GetOpt(const OptionData &option);
47 };
48 
49 #endif /* GETOPTDATA_H */
OptionDataType
Flags of an option.
Definition: getoptdata.h:14
@ ODF_OPTIONAL_VALUE
An option with an optional value.
Definition: getoptdata.h:17
@ ODF_NO_VALUE
A plain option (no value attached to it).
Definition: getoptdata.h:15
@ ODF_HAS_VALUE
An option with a value.
Definition: getoptdata.h:16
Data storage for parsing command line options.
Definition: getoptdata.h:29
GetOptData(ArgumentSpan arguments, OptionSpan options)
Constructor of the data store.
Definition: getoptdata.h:43
ArgumentSpan arguments
Remaining command line arguments.
Definition: getoptdata.h:33
int GetOpt()
Find the next option.
Definition: getoptdata.cpp:22
const char * cont
Next call to GetOpt should start here (in the middle of an argument).
Definition: getoptdata.h:36
const OptionSpan options
Command line option descriptions.
Definition: getoptdata.h:34
const char * opt
Option value, if available (else nullptr).
Definition: getoptdata.h:35
Data of an option.
Definition: getoptdata.h:21
OptionDataType type
The type of option.
Definition: getoptdata.h:22
char shortname
Short option letter if available, else use '\0'.
Definition: getoptdata.h:24
char id
Unique identification of this option data, often the same as shortname.
Definition: getoptdata.h:23
const char * longname
Long option name including '-'/'–' prefix, use nullptr if not available.
Definition: getoptdata.h:25