1/*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "TypeAnnotation.h"
10
11#include <vector>
12
13QString annotateType(AnnotationType from, AnnotationType to, const QString &type)
14{
15 // clang-format off
16 static const std::vector<std::vector<std::string>> table = {
17 {"boolean", "b", ""},
18 //{{"fd"}, "", ""},
19 {"object", "o", ""},
20 {"string", "s", ""},
21 //{{"uint16"}, "", ""},
22 //{{"uint32"}, "", ""},
23 {"dict", "a{sv}", "QVariantMap"},
24 {"array{byte}", "ay", ""},
25 {"array{dict}", "aa{sv}", "QVariantMapList"},
26 {"array{string}", "as", ""},
27 };
28 // clang-format on
29
30 for (const auto &entry : table) {
31 if (entry.at(n: static_cast<size_t>(from)) == type.toStdString()) {
32 return QString::fromStdString(s: entry.at(n: static_cast<size_t>(to)));
33 }
34 }
35
36 return QString();
37}
38
39QString bluezToQt(const QString &type)
40{
41 // clang-format off
42 static const std::vector<std::vector<std::string>> table = {
43 {"boolean", "bool"},
44 //{{"fd"}, ""},
45 {"object", "QDBusObjectPath"},
46 {"string", "QString"},
47 {"dict", "QVariantMap"},
48 {"array{byte}", "QByteArray"},
49 {"array{dict}", "QVariantMapList"},
50 {"array{string}", "QStringList"},
51 };
52 // clang-format on
53
54 for (const auto &entry : table) {
55 if (entry.front() == type.toStdString()) {
56 return QString::fromStdString(s: entry.back());
57 }
58 }
59
60 return type;
61}
62

source code of bluez-qt/tools/bluezapi2qt/TypeAnnotation.cpp