Akonadi

typehelper.cpp
1 /*
2  Copyright (c) 2017 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "typehelper.h"
21 #include "nodetree.h"
22 
23 #include <QString>
24 #include <QMetaType>
25 
26 bool TypeHelper::isNumericType(const QString &name)
27 {
28  const int metaTypeId = QMetaType::type(qPrintable(name));
29  if (metaTypeId == -1) {
30  return false;
31  }
32 
33  switch (metaTypeId) {
34  case QMetaType::Int:
35  case QMetaType::UInt:
36  case QMetaType::Double:
37  case QMetaType::Long:
38  case QMetaType::LongLong:
39  case QMetaType::Short:
40  case QMetaType::ULong:
41  case QMetaType::ULongLong:
42  case QMetaType::UShort:
43  case QMetaType::Float:
44  return true;
45  default:
46  return false;
47  }
48 }
49 
50 bool TypeHelper::isBoolType(const QString &name)
51 {
52  const int metaTypeId = QMetaType::type(qPrintable(name));
53  if (metaTypeId == -1) {
54  return false;
55  }
56 
57  switch (metaTypeId) {
58  case QMetaType::Bool:
59  return true;
60  default:
61  return false;
62  }
63 }
64 
65 bool TypeHelper::isBuiltInType(const QString &type)
66 {
67  // TODO: should be smarter than this....
68  return !type.startsWith(QLatin1String("Akonadi::Protocol"))
69  || type == QLatin1String("Akonadi::Protocol::Attributes") // typedef to QMap
70  || (type.startsWith(QLatin1String("Akonadi::Protocol")) // enums
71  && type.count(QStringLiteral("::")) > 2);
72 }
73 
74 bool TypeHelper::isContainer(const QString &type)
75 {
76  const int tplB = type.indexOf(QLatin1Char('<'));
77  const int tplE = type.lastIndexOf(QLatin1Char('>'));
78  return tplB > -1 && tplE > -1 && tplB < tplE;
79 }
80 
81 QString TypeHelper::containerType(const QString &type)
82 {
83  const int tplB = type.indexOf(QLatin1Char('<'));
84  const int tplE = type.indexOf(QLatin1Char('>'));
85  return type.mid(tplB + 1, tplE - tplB - 1);
86 }
87 
88 QString TypeHelper::containerName(const QString &type)
89 {
90  const int tplB = type.indexOf(QLatin1Char('<'));
91  return type.left(tplB);
92 }
93 
94 bool TypeHelper::isPointerType(const QString &type)
95 {
96  return type.endsWith(QLatin1String("Ptr"));
97 }
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
int type(const char *typeName)
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString mid(int position, int n) const const
int count() const const
QString left(int n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.