blob: 93778f25dea32a42610e1d45caf35a900ad96c34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "compiler.h"
#include "request.h"
#include <QUrlQuery>
namespace CompilerExplorer::Api {
QFuture<Compilers> compilers(const Config &config,
const QString &languageId,
const QSet<QString> &extraFields)
{
QUrl url = config.url(QStringList{"api/compilers"}
<< (languageId.isEmpty() ? QString() : languageId));
QString fieldParam;
if (!extraFields.isEmpty()) {
QSet<QString> fields = {"id", "name", "lang", "compilerType", "semver"};
fields.unite(extraFields);
for (const auto &field : fields) {
if (!fieldParam.isEmpty())
fieldParam += ",";
fieldParam += field;
}
}
if (!fieldParam.isEmpty())
url.setQuery(QUrlQuery{{"fields", fieldParam}});
auto fromJson = [extraFields](const QJsonDocument &doc) {
const QJsonArray compilers = doc.array();
Compilers result;
for (const auto &compiler : compilers) {
QJsonObject obj = compiler.toObject();
Compiler c;
c.id = obj["id"].toString();
c.name = obj["name"].toString();
c.languageId = obj["lang"].toString();
c.compilerType = obj["compilerType"].toString();
c.version = obj["semver"].toString();
c.instructionSet = obj["instructionSet"].toString();
for (const auto &field : extraFields) {
c.extraFields[field] = obj[field].toString();
}
result.append(c);
}
return result;
};
return jsonRequest<Compilers>(config.networkManager, url, fromJson);
}
} // namespace CompilerExplorer::Api
|