summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/cmdutils.cpp27
-rw-r--r--util/cmdutils.h22
2 files changed, 26 insertions, 23 deletions
diff --git a/util/cmdutils.cpp b/util/cmdutils.cpp
index 890f07f8..bd52cf8f 100644
--- a/util/cmdutils.cpp
+++ b/util/cmdutils.cpp
@@ -50,7 +50,7 @@ FlagStyle Parser::flagStyle()
}
// setup methods
-void Parser::addSwitch(QString name, bool def) throw (const char *)
+void Parser::addSwitch(QString name, bool def)
{
if (m_params.contains(name))
throw "Name not unique";
@@ -66,7 +66,7 @@ void Parser::addSwitch(QString name, bool def) throw (const char *)
m_optionList.append(param);
}
-void Parser::addOption(QString name, QVariant def) throw (const char *)
+void Parser::addOption(QString name, QVariant def)
{
if (m_params.contains(name))
throw "Name not unique";
@@ -82,7 +82,7 @@ void Parser::addOption(QString name, QVariant def) throw (const char *)
m_optionList.append(param);
}
-void Parser::addArgument(QString name, bool required, QVariant def) throw (const char *)
+void Parser::addArgument(QString name, bool required, QVariant def)
{
if (m_params.contains(name))
throw "Name not unique";
@@ -91,12 +91,13 @@ void Parser::addArgument(QString name, bool required, QVariant def) throw (const
param->name = name;
param->def = def;
param->required = required;
+ param->metavar = name;
m_positionals.append(param);
m_params[name] = (CommonDef *)param;
}
-void Parser::addDocumentation(QString name, QString doc, QString metavar) throw (const char *)
+void Parser::addDocumentation(QString name, QString doc, QString metavar)
{
if (!m_params.contains(name))
throw "Name does not exist";
@@ -107,7 +108,7 @@ void Parser::addDocumentation(QString name, QString doc, QString metavar) throw
param->metavar = metavar;
}
-void Parser::addShortOpt(QString name, QChar flag) throw (const char *)
+void Parser::addShortOpt(QString name, QChar flag)
{
if (!m_params.contains(name))
throw "Name does not exist";
@@ -135,7 +136,7 @@ QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags)
{
PositionalDef *param = it2.next();
help << " " << param->metavar;
- help << " " << QString(helpIndent - param->name.length() - 1, ' ');
+ help << " " << QString(helpIndent - param->metavar.length() - 1, ' ');
help << param->doc << "\r\n";
}
}
@@ -203,7 +204,7 @@ QString Parser::compileUsage(QString progName, bool useFlags)
{
PositionalDef *param = it2.next();
usage << " " << (param->required ? "<" : "[");
- usage << param->name;
+ usage << param->metavar;
usage << (param->required ? ">" : "]");
}
@@ -211,7 +212,7 @@ QString Parser::compileUsage(QString progName, bool useFlags)
}
// parsing
-QHash<QString, QVariant> Parser::parse(QStringList argv) throw (ParsingError)
+QHash<QString, QVariant> Parser::parse(QStringList argv)
{
QHash<QString, QVariant> map;
@@ -411,20 +412,20 @@ void Parser::getPrefix(QString &opt, QString &flag)
}
// ParsingError
-ParsingError::ParsingError(const QString &what) throw()
+ParsingError::ParsingError(const QString &what)
{
m_what = what;
}
-ParsingError::ParsingError(const ParsingError &e) throw()
+ParsingError::ParsingError(const ParsingError &e)
{
m_what = e.m_what;
}
-char *ParsingError::what() const throw()
+const char *ParsingError::what() const throw()
{
- return m_what.toLocal8Bit().data();
+ return m_what.toLocal8Bit().constData();
}
-QString ParsingError::qwhat() const throw()
+QString ParsingError::qwhat() const
{
return m_what;
}
diff --git a/util/cmdutils.h b/util/cmdutils.h
index 10f8a9db..690c96fd 100644
--- a/util/cmdutils.h
+++ b/util/cmdutils.h
@@ -68,11 +68,11 @@ enum class ArgumentStyle {
class ParsingError : public std::exception
{
public:
- ParsingError(const QString &what) throw();
- ParsingError(const ParsingError &e) throw();
+ ParsingError(const QString &what);
+ ParsingError(const ParsingError &e);
~ParsingError() throw() {}
- char *what() const throw();
- QString qwhat() const throw();
+ const char *what() const throw();
+ QString qwhat() const;
private:
QString m_what;
};
@@ -119,14 +119,14 @@ public:
* @param name the parameter name
* @param def the default value
*/
- void addSwitch(QString name, bool def=false) throw (const char *);
+ void addSwitch(QString name, bool def=false);
/**
* @brief define an option that takes an additional argument
* @param name the parameter name
* @param def the default value
*/
- void addOption(QString name, QVariant def=QVariant()) throw (const char *);
+ void addOption(QString name, QVariant def=QVariant());
/**
* @brief define a positional argument
@@ -134,7 +134,7 @@ public:
* @param required wether this argument is required
* @param def the default value
*/
- void addArgument(QString name, bool required=true, QVariant def=QVariant()) throw (const char *);
+ void addArgument(QString name, bool required=true, QVariant def=QVariant());
/**
* @brief adds a flag to an existing parameter
@@ -143,15 +143,17 @@ public:
* @see addSwitch addArgument addOption
* Note: any one parameter can only have one flag
*/
- void addShortOpt(QString name, QChar flag) throw (const char *);
+ void addShortOpt(QString name, QChar flag);
/**
* @brief adds documentation to a Parameter
* @param name the parameter name
* @param metavar a string to be displayed as placeholder for the value
* @param doc a QString containing the documentation
+ * Note: on positional arguments, metavar replaces the name as displayed.
+ * on options , metavar replaces the value placeholder
*/
- void addDocumentation(QString name, QString doc, QString metavar=QString()) throw (const char *);
+ void addDocumentation(QString name, QString doc, QString metavar=QString());
/**
* @brief generate a help message
@@ -175,7 +177,7 @@ public:
* @param argv a QStringList containing the program ARGV
* @return a QHash mapping argument names to their values
*/
- QHash<QString, QVariant> parse(QStringList argv) throw (ParsingError);
+ QHash<QString, QVariant> parse(QStringList argv);
/**
* @brief clear all definitions