X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fcliparser.h;h=aa46d1e70194fb3717c560feb2a24aeed5aae2c7;hp=00f22b982bad297e3d7e5bf40e32f5a6b14aa920;hb=16f22647e6890d3eb8c3e94f7a0700e12fa29e44;hpb=b3a2bd9e7d829afca26c6ab3ea09dfc6490319ce diff --git a/src/common/cliparser.h b/src/common/cliparser.h index 00f22b98..aa46d1e7 100644 --- a/src/common/cliparser.h +++ b/src/common/cliparser.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-2016 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,55 +15,37 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef CLIPARSER_H #define CLIPARSER_H -#include -#include -#include -#include +#include -class CliParserArg { +#include "abstractcliparser.h" + +//! Quassel's own parser for command line arguments +class CliParser : public AbstractCliParser +{ public: - enum CliArgType { - CliArgInvalid, - CliArgSwitch, - CliArgOption - }; - typedef CliArgType CliArgTypes; - - inline CliParserArg() {}; - CliParserArg(const CliParserArg &other); - CliParserArg(CliArgType type, QString longName, char shortName = 0, QVariant _def = QVariant()); - CliParserArg &operator=(const CliParserArg &other); + CliParser(); - CliArgType type; - QString lname; - char sname; - QString shortHelp; - QVariant def; - QVariant value; -}; -Q_DECLARE_METATYPE(CliParserArg); + bool init(const QStringList &arguments = QStringList()); + + QString value(const QString &longName); + bool isSet(const QString &longName); + void usage(); -class CliParser{ -public: - inline CliParser() {}; - CliParser(QStringList arguments); - bool parse(); - QVariant value(QString key); - void addSwitch(QString longName, char shortName = 0, QVariant def = false); - void addOption(QString longName, char shortName = 0, QVariant def = QVariant()); - void addHelp(QString key, QString txt); - void usage(); private: - void addArgument(CliParserArg::CliArgType type, QString longName, char shortName, QVariant def); - QStringList argsRaw; - QHash argsHash; - QHash::iterator> shortHash; + void addArgument(const QString &longName, const CliParserArg &arg); + bool addLongArg(const CliParserArg::CliArgType type, const QString &name, const QString &value = QString()); + bool addShortArg(const CliParserArg::CliArgType type, const char shortName, const QString &value = QString()); + QString escapedValue(const QString &value); + QString lnameOfShortArg(const char arg); + + QStringList argsRaw; + QMap argsMap; };