OpenTTD Source: src/misc/getoptdata.h Source File

OpenTTD Source 15.0-beta1

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 {
15 ODF_NO_VALUE,
16 ODF_HAS_VALUE,
17 ODF_OPTIONAL_VALUE,
18};
19
21 struct OptionData {
22 OptionDataType type;
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
OptionDataType
Flags of an option.
Definition getoptdata.h:14
ODF_OPTIONAL_VALUE
@ ODF_OPTIONAL_VALUE
An option with an optional value.
Definition getoptdata.h:17
ODF_NO_VALUE
@ ODF_NO_VALUE
A plain option (no value attached to it).
Definition getoptdata.h:15
ODF_HAS_VALUE
@ ODF_HAS_VALUE
An option with a value.
Definition getoptdata.h:16
GetOptData
Data storage for parsing command line options.
Definition getoptdata.h:29
GetOptData::GetOptData
GetOptData(ArgumentSpan arguments, OptionSpan options)
Constructor of the data store.
Definition getoptdata.h:43
GetOptData::arguments
ArgumentSpan arguments
Remaining command line arguments.
Definition getoptdata.h:33
GetOptData::GetOpt
int GetOpt()
Find the next option.
Definition getoptdata.cpp:22
GetOptData::cont
const char * cont
Next call to GetOpt should start here (in the middle of an argument).
Definition getoptdata.h:36
GetOptData::options
const OptionSpan options
Command line option descriptions.
Definition getoptdata.h:34
GetOptData::opt
const char * opt
Option value, if available (else nullptr).
Definition getoptdata.h:35
OptionData
Data of an option.
Definition getoptdata.h:21
OptionData::type
OptionDataType type
The type of option.
Definition getoptdata.h:22
OptionData::shortname
char shortname
Short option letter if available, else use '\0'.
Definition getoptdata.h:24
OptionData::id
char id
Unique identification of this option data, often the same as shortname.
Definition getoptdata.h:23
OptionData::longname
const char * longname
Long option name including '-'/'–' prefix, use nullptr if not available.
Definition getoptdata.h:25