File indexing completed on 2024-04-21 03:52:04
0001 /* 0002 * BluezQt - Asynchronous BlueZ wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "TypeAnnotation.h" 0010 0011 #include <vector> 0012 0013 QString annotateType(AnnotationType from, AnnotationType to, const QString &type) 0014 { 0015 // clang-format off 0016 static const std::vector<std::vector<std::string>> table = { 0017 {"boolean", "b", ""}, 0018 //{{"fd"}, "", ""}, 0019 {"object", "o", ""}, 0020 {"string", "s", ""}, 0021 //{{"uint16"}, "", ""}, 0022 //{{"uint32"}, "", ""}, 0023 {"dict", "a{sv}", "QVariantMap"}, 0024 {"array{byte}", "ay", ""}, 0025 {"array{dict}", "aa{sv}", "QVariantMapList"}, 0026 {"array{string}", "as", ""}, 0027 }; 0028 // clang-format on 0029 0030 for (const auto &entry : table) { 0031 if (entry.at(static_cast<size_t>(from)) == type.toStdString()) { 0032 return QString::fromStdString(entry.at(static_cast<size_t>(to))); 0033 } 0034 } 0035 0036 return QString(); 0037 } 0038 0039 QString bluezToQt(const QString &type) 0040 { 0041 // clang-format off 0042 static const std::vector<std::vector<std::string>> table = { 0043 {"boolean", "bool"}, 0044 //{{"fd"}, ""}, 0045 {"object", "QDBusObjectPath"}, 0046 {"string", "QString"}, 0047 {"dict", "QVariantMap"}, 0048 {"array{byte}", "QByteArray"}, 0049 {"array{dict}", "QVariantMapList"}, 0050 {"array{string}", "QStringList"}, 0051 }; 0052 // clang-format on 0053 0054 for (const auto &entry : table) { 0055 if (entry.front() == type.toStdString()) { 0056 return QString::fromStdString(entry.back()); 0057 } 0058 } 0059 0060 return type; 0061 }