1
0
Fork 0
flightgear/src/GUI/LauncherArgumentTokenizer.hxx
James Turner 268f9c9c33 Launcher: ensure extra args override launcher ones
Categorise arguments to ensure user-specified ones take precedence
over values set by the launcher.

When any positional arg is set, exclude all positional ones from being
set at all, to prevent strange interactions.
2018-06-25 23:06:20 +01:00

70 lines
1.5 KiB
C++

#ifndef LAUNCHERARGUMENTTOKENIZER_HXX
#define LAUNCHERARGUMENTTOKENIZER_HXX
#include <set>
#include <QString>
#include <QList>
#include <QObject>
#include <QJSValue>
class ArgumentToken
{
public:
explicit ArgumentToken(QString k, QString v = QString()) : arg(k), value(v) {}
QString arg;
QString value;
};
class LauncherArgumentTokenizer : public QObject
{
Q_OBJECT
Q_PROPERTY(QString argString READ argString WRITE setArgString NOTIFY argStringChanged)
Q_PROPERTY(QVariantList tokens READ tokens NOTIFY argStringChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY argStringChanged)
Q_PROPERTY(bool havePositionalArgs READ havePositionalArgs NOTIFY argStringChanged)
Q_PROPERTY(bool haveUnsupportedArgs READ haveUnsupportedArgs NOTIFY argStringChanged)
public:
LauncherArgumentTokenizer();
QString argString() const
{
return m_argString;
}
QVariantList tokens() const;
bool isValid() const;
bool haveUnsupportedArgs() const;
bool havePositionalArgs() const;
public slots:
void setArgString(QString argString);
signals:
void argStringChanged(QString argString);
private:
bool haveArgsIn(const std::set<std::string> &args) const;
void tokenize(QString in);
enum State {
Start = 0,
Key,
Value,
Quoted,
Comment
};
std::vector<ArgumentToken> m_tokens;
QString m_argString;
bool m_valid = false;
};
#endif // LAUNCHERARGUMENTTOKENIZER_HXX