Akonadi

typehelper.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Daniel Vrátil <dvratil@kde.og>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "typehelper.h"
8#include "nodetree.h"
9
10#include <QMetaType>
11#include <QString>
12
13bool TypeHelper::isNumericType(const QString &name)
14{
15 const int metaTypeId = QMetaType::fromName(qPrintable(name)).id();
16 if (metaTypeId == -1) {
17 return false;
18 }
19
20 switch (metaTypeId) {
21 case QMetaType::Int:
22 case QMetaType::UInt:
24 case QMetaType::Long:
31 return true;
32 default:
33 return false;
34 }
35}
36
37bool TypeHelper::isBoolType(const QString &name)
38{
39 const int metaTypeId = QMetaType::fromName(qPrintable(name)).id();
40 if (metaTypeId == -1) {
41 return false;
42 }
43
44 switch (metaTypeId) {
45 case QMetaType::Bool:
46 return true;
47 default:
48 return false;
49 }
50}
51
52bool TypeHelper::isBuiltInType(const QString &type)
53{
54 // TODO: should be smarter than this....
55 return !type.startsWith(QLatin1StringView("Akonadi::Protocol")) || type == QLatin1StringView("Akonadi::Protocol::Attributes") // typedef to QMap
56 || (type.startsWith(QLatin1StringView("Akonadi::Protocol")) // enums
57 && type.count(QStringLiteral("::")) > 2);
58}
59
60bool TypeHelper::isContainer(const QString &type)
61{
62 const int tplB = type.indexOf(QLatin1Char('<'));
63 const int tplE = type.lastIndexOf(QLatin1Char('>'));
64 return tplB > -1 && tplE > -1 && tplB < tplE;
65}
66
67QString TypeHelper::containerType(const QString &type)
68{
69 const int tplB = type.indexOf(QLatin1Char('<'));
70 const int tplE = type.indexOf(QLatin1Char('>'));
71 return type.mid(tplB + 1, tplE - tplB - 1);
72}
73
74QString TypeHelper::containerName(const QString &type)
75{
76 const int tplB = type.indexOf(QLatin1Char('<'));
77 return type.left(tplB);
78}
79
80bool TypeHelper::isPointerType(const QString &type)
81{
82 return type.endsWith(QLatin1StringView("Ptr"));
83}
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QMetaType fromName(QByteArrayView typeName)
int id() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.