b719960ec5dc56bf3bc8f74605017dedfcf95418
[platform/upstream/dbus.git] / qt / qdbustype_p.h
1 /* -*- C++ -*-
2  *
3  * Copyright (C) 2005 Thiago Macieira <thiago@kde.org>
4  * Copyright (C) 2006 Trolltech AS. All rights reserved.
5  *    Author: Thiago Macieira <thiago.macieira@trolltech.com>
6  *
7  * Licensed under the Academic Free License version 2.1
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #ifndef QDBUSTYPE_H
26 #define QDBUSTYPE_H
27
28 #include <QtCore/qvariant.h>
29 #include <QtCore/qbytearray.h>
30 #include <QtCore/qshareddata.h>
31 #include <QtCore/qlist.h>
32 #include "qdbusmacros.h"
33 #include <dbus/dbus.h>
34
35 // forward declaration
36 class QDBusTypeList;
37
38 class QDBusTypePrivate;
39 class QDBUS_EXPORT QDBusType
40 {
41 public:
42     QDBusType();
43     explicit QDBusType(int type);
44     explicit QDBusType(QVariant::Type type);
45     explicit QDBusType(const char* signature);
46     explicit QDBusType(DBusSignatureIter*);
47     explicit QDBusType(const QString& str);
48     explicit QDBusType(const QByteArray& str);
49     QDBusType(const QDBusType& other);
50
51     ~QDBusType();
52
53     QDBusType& operator=(const QDBusType& other);
54
55     int qvariantType() const;
56
57     int dbusType() const;
58     QByteArray dbusSignature() const;
59     bool isValid() const;
60     bool isBasic() const;
61     bool isContainer() const;
62
63     QDBusTypeList subTypes() const;
64
65     bool isArray() const;
66     QDBusType arrayElement() const;
67
68     bool isMap() const;
69     QDBusType mapKey() const;
70     QDBusType mapValue() const;
71
72     bool operator==(const QDBusType& other) const;
73     inline bool operator!=(const QDBusType &other) const
74     { return !(*this == other); }
75
76     static int qvariantType(int type);
77     static int qvariantType(const char* signature);
78     static int dbusType(QVariant::Type);
79     static const char* dbusSignature(QVariant::Type);
80
81     enum VariantListMode {
82         ListIsArray,
83         ListIsStruct
84     };
85     static QDBusType guessFromVariant(const QVariant &variant, VariantListMode = ListIsArray);
86
87 private:
88     QSharedDataPointer<QDBusTypePrivate> d;
89 };
90
91 class QDBUS_EXPORT QDBusTypeList: public QList<QDBusType>
92 {
93 public:
94     inline QDBusTypeList() { }
95     inline QDBusTypeList(const QDBusTypeList& other)
96         : QList<QDBusType>(other)
97         { }
98     inline QDBusTypeList(const QList<QDBusType>& other)
99         : QList<QDBusType>(other)
100         { }
101     QDBusTypeList(const char* signature);
102     QDBusTypeList(DBusSignatureIter*);
103
104     bool canBeMap() const;
105
106     QByteArray dbusSignature() const;
107 };
108
109 #endif // QDBUSTYPE_H