Cute Chess 0.1
matchparser.h
1/*
2 This file is part of Cute Chess.
3 Copyright (C) 2008-2018 Cute Chess authors
4
5 Cute Chess is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Cute Chess is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef MATCHPARSER_H
20#define MATCHPARSER_H
21
22#include <QMap>
23#include <QMultiMap>
24#include <QStringList>
25#include <QVariant>
26
27
34{
35 public:
37 struct Option
38 {
50 QMap<QString, QString> toMap(const QString& validArgs) const;
51
54 };
55
57 MatchParser(const QStringList& args);
58
72 void addOption(const QString& name,
73 QVariant::Type type,
74 int minArgs = 0,
75 int maxArgs = -1,
76 bool duplicates = false);
84 QVariant takeOption(const QString& name);
86 QList<Option> options() const;
91 bool parse();
92
93 private:
94 struct PrivateOption
95 {
96 QVariant::Type type;
97 int priority;
98 int minArgs;
99 int maxArgs;
100 bool duplicates;
101 };
102
103 bool contains(const QString& optionName) const;
104
105 QStringList m_args;
106 QMultiMap<int, Option> m_options;
107 QMap<QString, PrivateOption> m_validOptions;
108 int m_priority;
109};
110
111#endif // MATCHPARSER_H
QVariant takeOption(const QString &name)
Definition matchparser.cpp:45
bool parse()
Definition matchparser.cpp:83
MatchParser(const QStringList &args)
Definition matchparser.cpp:22
QList< Option > options() const
Definition matchparser.cpp:56
void addOption(const QString &name, QVariant::Type type, int minArgs=0, int maxArgs=-1, bool duplicates=false)
Definition matchparser.cpp:28
Definition matchparser.h:38
QString name
The name of the option.
Definition matchparser.h:52
QVariant value
The value of the option.
Definition matchparser.h:53
QMap< QString, QString > toMap(const QString &validArgs) const
Definition matchparser.cpp:162