X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fcliparser.h;h=240392647d6c6d563231c737b5cd7375613308ef;hp=53eaed84cf26b0131d84e94548d620c37166367a;hb=3d464695bf5b57c969f30e6f3b8b429890f976bf;hpb=b4226543fdbc7a44288986365e6b598d35144062 diff --git a/src/common/cliparser.h b/src/common/cliparser.h index 53eaed84..24039264 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-2014 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,52 +15,38 @@ * 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 CliArgType type, const char _shortName = 0, const QString _help = QString(), const QString _def = QString()); + CliParser(); - CliArgType type; - char shortName; - QString help; - QString def; - QString value; - bool boolValue; -}; -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(); - QString value(const QString &longName); - bool isSet(const QString &longName); - void addSwitch(const QString longName, const char shortName = 0, const QString help = QString()); - void addOption(const QString longName, const char shortName = 0, const QString help = QString(), const QString def = QString()); - void usage(); private: - 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; }; + #endif