Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qcommandlineoption.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
3// Copyright (C) 2013 David Faure <faure@kde.org>
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
7
8#include "qset.h"
9
11
13{
14public:
18 { }
19
23 { }
24
26
29
33
36
39
40 QCommandLineOption::Flags flags;
41};
42
82{
83}
84
100{
101}
102
127 const QString &valueName,
128 const QString &defaultValue)
130{
133 setDefaultValue(defaultValue);
134}
135
163 const QString &valueName,
164 const QString &defaultValue)
166{
169 setDefaultValue(defaultValue);
170}
171
179 : d(other.d)
180{
181}
182
187{
188}
189
195{
196 d = other.d;
197 return *this;
198}
199
211{
212 return d->names;
213}
214
215namespace {
216 struct IsInvalidName
217 {
218 typedef bool result_type;
219 typedef QString argument_type;
220
222 result_type operator()(const QString &name) const noexcept
223 {
224 if (Q_UNLIKELY(name.isEmpty()))
225 return warn("be empty");
226
227 const QChar c = name.at(0);
228 if (Q_UNLIKELY(c == u'-'))
229 return warn("start with a '-'");
230 if (Q_UNLIKELY(c == u'/'))
231 return warn("start with a '/'");
232 if (Q_UNLIKELY(name.contains(u'=')))
233 return warn("contain a '='");
234
235 return false;
236 }
237
239 static bool warn(const char *what) noexcept
240 {
241 qWarning("QCommandLineOption: Option names cannot %s", what);
242 return true;
243 }
244 };
245} // unnamed namespace
246
247// static
249{
250 if (Q_UNLIKELY(nameList.isEmpty()))
251 qWarning("QCommandLineOption: Options must have at least one name");
252 else
253 nameList.removeIf(IsInvalidName());
254 return nameList;
255}
256
274{
275 d->valueName = valueName;
276}
277
286{
287 return d->valueName;
288}
289
300{
302}
303
310{
311 return d->description;
312}
313
325{
326 QStringList newDefaultValues;
327 if (!defaultValue.isEmpty()) {
328 newDefaultValues.reserve(1);
329 newDefaultValues << defaultValue;
330 }
331 // commit:
332 d->defaultValues.swap(newDefaultValues);
333}
334
344{
346}
347
354{
355 return d->defaultValues;
356}
357
364QCommandLineOption::Flags QCommandLineOption::flags() const
365{
366 return d->flags;
367}
368
376{
377 d->flags = flags;
378}
379
\inmodule QtCore
Definition qchar.h:48
QCommandLineOption::Flags flags
static QStringList removeInvalidNames(QStringList nameList)
Q_NEVER_INLINE QCommandLineOptionPrivate(const QString &name)
Q_NEVER_INLINE QCommandLineOptionPrivate(const QStringList &names)
QStringList names
The list of names used for this option.
QStringList defaultValues
The list of default values used for this option.
QString description
The description used for this option.
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
void setDescription(const QString &description)
Sets the description used for this option to description.
Flags flags() const
Returns a set of flags that affect this command-line option.
void setDefaultValue(const QString &defaultValue)
Sets the default value used for this option to defaultValue.
~QCommandLineOption()
Destroys the command line option object.
QString valueName() const
Returns the name of the expected value.
QString description() const
Returns the description set for this option.
void setFlags(Flags aflags)
Set the set of flags that affect this command-line option to flags.
void setDefaultValues(const QStringList &defaultValues)
Sets the list of default values used for this option to defaultValues.
void setValueName(const QString &name)
Sets the name of the expected value, for the documentation, to valueName.
QStringList defaultValues() const
Returns the default values set for this option.
QCommandLineOption & operator=(const QCommandLineOption &other)
Move-assigns other to this QCommandLineOption instance.
QStringList names() const
Returns the names set for this option.
QCommandLineOption(const QString &name)
Constructs a command line option object with the name name.
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
#define Q_NEVER_INLINE
Flags
#define qWarning
Definition qlogging.h:162
GLbitfield flags
GLuint name
const GLubyte * c
GLuint GLuint * names
QSharedPointer< T > other(t)
[5]