| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qcommandlineoption.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | class QCommandLineOptionPrivate : public QSharedData | - | ||||||
| 6 | { | - | ||||||
| 7 | public: | - | ||||||
| 8 | __attribute__((noinline)) | - | ||||||
| 9 | explicit QCommandLineOptionPrivate(const QString &name) | - | ||||||
| 10 | : names(removeInvalidNames(QStringList(name))), | - | ||||||
| 11 | hidden(false) | - | ||||||
| 12 | { } | - | ||||||
| 13 | - | |||||||
| 14 | __attribute__((noinline)) | - | ||||||
| 15 | explicit QCommandLineOptionPrivate(const QStringList &names) | - | ||||||
| 16 | : names(removeInvalidNames(names)), | - | ||||||
| 17 | hidden(false) | - | ||||||
| 18 | { } | - | ||||||
| 19 | - | |||||||
| 20 | static QStringList removeInvalidNames(QStringList nameList); | - | ||||||
| 21 | - | |||||||
| 22 | - | |||||||
| 23 | QStringList names; | - | ||||||
| 24 | - | |||||||
| 25 | - | |||||||
| 26 | - | |||||||
| 27 | QString valueName; | - | ||||||
| 28 | - | |||||||
| 29 | - | |||||||
| 30 | QString description; | - | ||||||
| 31 | - | |||||||
| 32 | - | |||||||
| 33 | QStringList defaultValues; | - | ||||||
| 34 | - | |||||||
| 35 | - | |||||||
| 36 | bool hidden; | - | ||||||
| 37 | }; | - | ||||||
| 38 | QCommandLineOption::QCommandLineOption(const QString &name) | - | ||||||
| 39 | : d(new QCommandLineOptionPrivate(name)) | - | ||||||
| 40 | { | - | ||||||
| 41 | } | - | ||||||
| 42 | QCommandLineOption::QCommandLineOption(const QStringList &names) | - | ||||||
| 43 | : d(new QCommandLineOptionPrivate(names)) | - | ||||||
| 44 | { | - | ||||||
| 45 | } | - | ||||||
| 46 | QCommandLineOption::QCommandLineOption(const QString &name, const QString &description, | - | ||||||
| 47 | const QString &valueName, | - | ||||||
| 48 | const QString &defaultValue) | - | ||||||
| 49 | : d(new QCommandLineOptionPrivate(name)) | - | ||||||
| 50 | { | - | ||||||
| 51 | setValueName(valueName); | - | ||||||
| 52 | setDescription(description); | - | ||||||
| 53 | setDefaultValue(defaultValue); | - | ||||||
| 54 | } | - | ||||||
| 55 | QCommandLineOption::QCommandLineOption(const QStringList &names, const QString &description, | - | ||||||
| 56 | const QString &valueName, | - | ||||||
| 57 | const QString &defaultValue) | - | ||||||
| 58 | : d(new QCommandLineOptionPrivate(names)) | - | ||||||
| 59 | { | - | ||||||
| 60 | setValueName(valueName); | - | ||||||
| 61 | setDescription(description); | - | ||||||
| 62 | setDefaultValue(defaultValue); | - | ||||||
| 63 | } | - | ||||||
| 64 | - | |||||||
| 65 | - | |||||||
| 66 | - | |||||||
| 67 | - | |||||||
| 68 | - | |||||||
| 69 | - | |||||||
| 70 | - | |||||||
| 71 | QCommandLineOption::QCommandLineOption(const QCommandLineOption &other) | - | ||||||
| 72 | : d(other.d) | - | ||||||
| 73 | { | - | ||||||
| 74 | } | - | ||||||
| 75 | - | |||||||
| 76 | - | |||||||
| 77 | - | |||||||
| 78 | - | |||||||
| 79 | QCommandLineOption::~QCommandLineOption() | - | ||||||
| 80 | { | - | ||||||
| 81 | } | - | ||||||
| 82 | - | |||||||
| 83 | - | |||||||
| 84 | - | |||||||
| 85 | - | |||||||
| 86 | - | |||||||
| 87 | QCommandLineOption &QCommandLineOption::operator=(const QCommandLineOption &other) | - | ||||||
| 88 | { | - | ||||||
| 89 | d = other.d; | - | ||||||
| 90 | return *this; | - | ||||||
| 91 | } | - | ||||||
| 92 | QStringList QCommandLineOption::names() const | - | ||||||
| 93 | { | - | ||||||
| 94 | return d->names; | - | ||||||
| 95 | } | - | ||||||
| 96 | - | |||||||
| 97 | namespace { | - | ||||||
| 98 | struct IsInvalidName | - | ||||||
| 99 | { | - | ||||||
| 100 | typedef bool result_type; | - | ||||||
| 101 | typedef QString argument_type; | - | ||||||
| 102 | - | |||||||
| 103 | __attribute__((noinline)) | - | ||||||
| 104 | result_type operator()(const QString &name) const noexcept | - | ||||||
| 105 | { | - | ||||||
| 106 | if (__builtin_expect(!!(name.isEmpty()), false)
| 0-2387 | ||||||
| 107 | return never executed: warn("be empty");return warn("be empty");never executed: return warn("be empty"); | 0 | ||||||
| 108 | - | |||||||
| 109 | const QChar c = name.at(0); | - | ||||||
| 110 | if (__builtin_expect(!!(c == QLatin1Char('-')), false)
| 1-2386 | ||||||
| 111 | return executed 1 time by 1 test: warn("start with a '-'");return warn("start with a '-'");Executed by:
executed 1 time by 1 test: return warn("start with a '-'");Executed by:
| 1 | ||||||
| 112 | if (__builtin_expect(!!(c == QLatin1Char('/')), false)
| 0-2386 | ||||||
| 113 | return never executed: warn("start with a '/'");return warn("start with a '/'");never executed: return warn("start with a '/'"); | 0 | ||||||
| 114 | if (__builtin_expect(!!(name.contains(QLatin1Char('='))), false)
| 0-2386 | ||||||
| 115 | return never executed: warn("contain a '='");return warn("contain a '='");never executed: return warn("contain a '='"); | 0 | ||||||
| 116 | - | |||||||
| 117 | return executed 2386 times by 2 tests: false;return false;Executed by:
executed 2386 times by 2 tests: return false;Executed by:
| 2386 | ||||||
| 118 | } | - | ||||||
| 119 | - | |||||||
| 120 | __attribute__((noinline)) | - | ||||||
| 121 | static bool warn(const char *what) noexcept | - | ||||||
| 122 | { | - | ||||||
| 123 | QMessageLogger(__FILE__, 273279, __PRETTY_FUNCTION__).warning("QCommandLineOption: Option names cannot %s", what); | - | ||||||
| 124 | return executed 1 time by 1 test: true;return true;Executed by:
executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||
| 125 | } | - | ||||||
| 126 | }; | - | ||||||
| 127 | } | - | ||||||
| 128 | - | |||||||
| 129 | - | |||||||
| 130 | QStringList QCommandLineOptionPrivate::removeInvalidNames(QStringList nameList) | - | ||||||
| 131 | { | - | ||||||
| 132 | if (__builtin_expect(!!(nameList.isEmpty()), false)) | - | ||||||
| 133 | QMessageLogger(__FILE__, 283289, __PRETTY_FUNCTION__).warning("QCommandLineOption: Options must have at least one name"); | - | ||||||
| 134 | else | - | ||||||
| 135 | nameList.erase(std::remove_if(nameList.begin(), nameList.end(), IsInvalidName()), | - | ||||||
| 136 | nameList.end()); | - | ||||||
| 137 | return nameList; | - | ||||||
| 138 | } | - | ||||||
| 139 | void QCommandLineOption::setValueName(const QString &valueName) | - | ||||||
| 140 | { | - | ||||||
| 141 | d->valueName = valueName; | - | ||||||
| 142 | } | - | ||||||
| 143 | QString QCommandLineOption::valueName() const | - | ||||||
| 144 | { | - | ||||||
| 145 | return d->valueName; | - | ||||||
| 146 | } | - | ||||||
| 147 | void QCommandLineOption::setDescription(const QString &description) | - | ||||||
| 148 | { | - | ||||||
| 149 | d->description = description; | - | ||||||
| 150 | } | - | ||||||
| 151 | - | |||||||
| 152 | - | |||||||
| 153 | - | |||||||
| 154 | - | |||||||
| 155 | - | |||||||
| 156 | - | |||||||
| 157 | QString QCommandLineOption::description() const | - | ||||||
| 158 | { | - | ||||||
| 159 | return d->description; | - | ||||||
| 160 | } | - | ||||||
| 161 | void QCommandLineOption::setDefaultValue(const QString &defaultValue) | - | ||||||
| 162 | { | - | ||||||
| 163 | QStringList newDefaultValues; | - | ||||||
| 164 | if (!defaultValue.isEmpty()) { | - | ||||||
| 165 | newDefaultValues.reserve(1); | - | ||||||
| 166 | newDefaultValues << defaultValue; | - | ||||||
| 167 | } | - | ||||||
| 168 | - | |||||||
| 169 | d->defaultValues.swap(newDefaultValues); | - | ||||||
| 170 | } | - | ||||||
| 171 | void QCommandLineOption::setDefaultValues(const QStringList &defaultValues) | - | ||||||
| 172 | { | - | ||||||
| 173 | d->defaultValues = defaultValues; | - | ||||||
| 174 | } | - | ||||||
| 175 | - | |||||||
| 176 | - | |||||||
| 177 | - | |||||||
| 178 | - | |||||||
| 179 | - | |||||||
| 180 | - | |||||||
| 181 | QStringList QCommandLineOption::defaultValues() const | - | ||||||
| 182 | { | - | ||||||
| 183 | return d->defaultValues; | - | ||||||
| 184 | } | - | ||||||
| 185 | void QCommandLineOption::setHidden(bool hide) | - | ||||||
| 186 | { | - | ||||||
| 187 | d->hidden = hide; | - | ||||||
| 188 | } | - | ||||||
| 189 | bool QCommandLineOption::isHidden() const | - | ||||||
| 190 | { | - | ||||||
| 191 | return d->hidden; | - | ||||||
| 192 | } | - | ||||||
| 193 | - | |||||||
| 194 | - | |||||||
| Switch to Source code | Preprocessed file |