ObjFW
OFOptionsParser.h
1 /*
2  * Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFString.h"
18 
19 @class OFMapTable;
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
28 typedef struct {
30  OFUnichar shortOption;
31 
35  OFString *__unsafe_unretained _Nullable longOption;
36 
47  signed char hasArgument;
48 
53  bool *_Nullable isSpecifiedPtr;
54 
59  OFString *__autoreleasing _Nullable *_Nullable argumentPtr;
61 
67 OF_SUBCLASSING_RESTRICTED
69 {
70  OFOptionsParserOption *_options;
71  OFMapTable *_longOptions;
72  OFArray OF_GENERIC(OFString *) *_arguments;
73  size_t _index, _subIndex;
74  OFUnichar _lastOption;
75  OFString *_Nullable _lastLongOption, *_Nullable _argument;
76  bool _done;
77 }
78 
87 @property (readonly, nonatomic) OFUnichar lastOption;
88 
104 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *lastLongOption;
105 
110 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *argument;
111 
115 @property (readonly, nonatomic)
117 
127 + (instancetype)parserWithOptions: (const OFOptionsParserOption *)options;
128 
129 - (instancetype)init OF_UNAVAILABLE;
130 
141 - (instancetype)initWithOptions: (const OFOptionsParserOption *)options
142  OF_DESIGNATED_INITIALIZER;
143 
162 - (OFUnichar)nextOption;
163 @end
164 
165 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:105
A class similar to OFDictionary, but providing more options how keys and objects should be retained,...
Definition: OFMapTable.h:74
The root class for all other classes inside ObjFW.
Definition: OFObject.h:688
A class for parsing the program options specified on the command line.
Definition: OFOptionsParser.h:69
OFString * lastLongOption
The long option for the last parsed option, or nil if the last parsed option was not passed as a long...
Definition: OFOptionsParser.h:104
OFString * argument
The argument for the last parsed option, or nil if the last parsed option takes no argument.
Definition: OFOptionsParser.h:110
OFArray * remainingArguments
The arguments following the last option.
Definition: OFOptionsParser.h:116
A class for handling strings.
Definition: OFString.h:135
An option which can be parsed by an OFOptionsParser.
Definition: OFOptionsParser.h:28
OFString *__autoreleasing * argumentPtr
Definition: OFOptionsParser.h:59
bool * isSpecifiedPtr
Definition: OFOptionsParser.h:53
signed char hasArgument
Definition: OFOptionsParser.h:47
OFUnichar shortOption
Definition: OFOptionsParser.h:30