2 This file is part of Cute Chess.
4 Cute Chess is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Cute Chess is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
18 #include "engineconfiguration.h"
20 #include "engineoption.h"
21 #include "engineoptionfactory.h"
23 EngineConfiguration::EngineConfiguration()
24 : m_variants(QStringList() << "standard"),
25 m_whiteEvalPov(false),
26 m_restartMode(RestartAuto
)
30 EngineConfiguration::EngineConfiguration(const QString
& name
,
31 const QString
& command
,
32 const QString
& protocol
)
36 m_variants(QStringList() << "standard"),
37 m_whiteEvalPov(false),
38 m_restartMode(RestartAuto
)
42 EngineConfiguration::EngineConfiguration(const QVariant
& variant
)
43 : m_variants(QStringList() << "standard"),
44 m_whiteEvalPov(false),
45 m_restartMode(RestartAuto
)
47 const QVariantMap map
= variant
.toMap();
49 setName(map
["name"].toString());
50 setCommand(map
["command"].toString());
51 setWorkingDirectory(map
["workingDirectory"].toString());
52 setProtocol(map
["protocol"].toString());
54 if (map
.contains("initStrings"))
55 setInitStrings(map
["initStrings"].toStringList());
56 if (map
.contains("whitepov"))
57 setWhiteEvalPov(map
["whitepov"].toBool());
59 if (map
.contains("restart"))
61 const QString
val(map
["restart"].toString());
63 setRestartMode(RestartAuto
);
65 setRestartMode(RestartOn
);
66 else if (val
== "off")
67 setRestartMode(RestartOff
);
70 if (map
.contains("variants"))
71 setSupportedVariants(map
["variants"].toStringList());
73 if (map
.contains("options"))
75 const QVariantList optionsList
= map
["options"].toList();
76 EngineOption
* option
= 0;
78 foreach (const QVariant
& optionVariant
, optionsList
)
80 if ((option
= EngineOptionFactory::create(optionVariant
.toMap())) != 0)
86 EngineConfiguration::EngineConfiguration(const EngineConfiguration
& other
)
87 : m_name(other
.m_name
),
88 m_command(other
.m_command
),
89 m_workingDirectory(other
.m_workingDirectory
),
90 m_protocol(other
.m_protocol
),
91 m_arguments(other
.m_arguments
),
92 m_initStrings(other
.m_initStrings
),
93 m_variants(other
.m_variants
),
94 m_whiteEvalPov(other
.m_whiteEvalPov
),
95 m_restartMode(other
.m_restartMode
)
97 foreach (const EngineOption
* option
, other
.options())
98 addOption(option
->copy());
101 EngineConfiguration::~EngineConfiguration()
103 qDeleteAll(m_options
);
106 QVariant
EngineConfiguration::toVariant() const
110 map
.insert("name", m_name
);
111 map
.insert("command", m_command
);
112 map
.insert("workingDirectory", m_workingDirectory
);
113 map
.insert("protocol", m_protocol
);
115 if (!m_initStrings
.isEmpty())
116 map
.insert("initStrings", m_initStrings
);
118 map
.insert("whitepov", true);
120 if (m_restartMode
== RestartOn
)
121 map
.insert("restart", "on");
122 else if (m_restartMode
== RestartOff
)
123 map
.insert("restart", "off");
125 if (m_variants
.count("standard") != m_variants
.count())
126 map
.insert("variants", m_variants
);
128 if (!m_options
.isEmpty())
130 QVariantList optionsList
;
131 foreach (const EngineOption
* option
, m_options
)
132 optionsList
.append(option
->toVariant());
134 map
.insert("options", optionsList
);
140 void EngineConfiguration::setName(const QString
& name
)
145 void EngineConfiguration::setCommand(const QString
& command
)
150 void EngineConfiguration::setProtocol(const QString
& protocol
)
152 m_protocol
= protocol
;
155 void EngineConfiguration::setWorkingDirectory(const QString
& workingDir
)
157 m_workingDirectory
= workingDir
;
160 QString
EngineConfiguration::name() const
165 QString
EngineConfiguration::command() const
170 QString
EngineConfiguration::workingDirectory() const
172 return m_workingDirectory
;
175 QString
EngineConfiguration::protocol() const
180 QStringList
EngineConfiguration::arguments() const
185 void EngineConfiguration::setArguments(const QStringList
& arguments
)
187 m_arguments
= arguments
;
190 void EngineConfiguration::addArgument(const QString
& argument
)
192 m_arguments
<< argument
;
195 QStringList
EngineConfiguration::initStrings() const
197 return m_initStrings
;
200 void EngineConfiguration::setInitStrings(const QStringList
& initStrings
)
202 m_initStrings
= initStrings
;
205 void EngineConfiguration::addInitString(const QString
& initString
)
207 m_initStrings
<< initString
.split('\n');
210 QStringList
EngineConfiguration::supportedVariants() const
215 void EngineConfiguration::setSupportedVariants(const QStringList
& variants
)
217 m_variants
= variants
;
220 QList
<EngineOption
*> EngineConfiguration::options() const
225 void EngineConfiguration::setOptions(const QList
<EngineOption
*>& options
)
227 qDeleteAll(m_options
);
231 void EngineConfiguration::addOption(EngineOption
* option
)
233 Q_ASSERT(option
!= 0);
238 bool EngineConfiguration::whiteEvalPov() const
240 return m_whiteEvalPov
;
243 void EngineConfiguration::setWhiteEvalPov(bool whiteEvalPov
)
245 m_whiteEvalPov
= whiteEvalPov
;
248 EngineConfiguration::RestartMode
EngineConfiguration::restartMode() const
250 return m_restartMode
;
253 void EngineConfiguration::setRestartMode(RestartMode mode
)
255 m_restartMode
= mode
;
258 EngineConfiguration
& EngineConfiguration::operator=(const EngineConfiguration
& other
)
262 setName(other
.name());
263 setCommand(other
.command());
264 setProtocol(other
.protocol());
265 setWorkingDirectory(other
.workingDirectory());
266 setArguments(other
.arguments());
267 setInitStrings(other
.initStrings());
268 setSupportedVariants(other
.supportedVariants());
269 setWhiteEvalPov(other
.whiteEvalPov());
270 setRestartMode(other
.restartMode());
272 qDeleteAll(m_options
);
275 foreach (const EngineOption
* option
, other
.options())
276 addOption(option
->copy());