X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fcliparser.h;h=761eb0d4d3b9ad63e1ffb72c9a939d3ed31c0915;hp=3927df7e2db75f8d2e37d6f8c0bbcdd6c9829392;hb=abd7bd3611e560e0ede1b05d617c775614b6c808;hpb=6eb132ee838e98925303db804fd9f36a0c2f1c1b diff --git a/src/common/cliparser.h b/src/common/cliparser.h index 3927df7e..761eb0d4 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-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,48 +21,30 @@ #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(const CliArgType type, const char _shortName = 0, const QString _help = QString(), const QString _def = QString()); - CliParserArg &operator=(const CliParserArg &other); + CliParser(); - CliArgType type; - char shortName; - QString help; - QString def; - QString value; - bool boolValue; -}; -Q_DECLARE_METATYPE(CliParserArg); + bool init(const QStringList &arguments = QStringList()); -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: + 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; - QHash argsHash; - QHash::iterator> shortHash; + QMap argsMap; }; #endif