ec2423b2966bb0471857d215eb44a5c8f80ccfc5
[profile/ivi/qtdeclarative.git] / src / declarative / qml / ftw / qfastmetabuilder_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QFASTMETABUILDER_P_H
43 #define QFASTMETABUILDER_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists for the convenience
50 // of moc.  This header file may change from version to version without notice,
51 // or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qmetatype.h>
58 #include <QtCore/qmetaobject.h>
59
60 #include <private/qhashedstring_p.h>
61
62 QT_BEGIN_NAMESPACE
63
64 struct QMetaObject;
65 class QFastMetaBuilder
66 {
67 public:
68     QFastMetaBuilder();
69     ~QFastMetaBuilder();
70
71     struct StringRef {
72     public:
73         inline StringRef();
74         inline StringRef(const StringRef &);
75         inline StringRef &operator=(const StringRef &);
76
77         inline void load(const QHashedStringRef &);
78         inline void load(const QByteArray &);
79         inline void load(const char *);
80
81         inline bool isEmpty() const;
82         inline QFastMetaBuilder *builder() const;
83         inline int offset() const;
84         inline char *data();
85         inline int length() const;
86     private:
87         friend class QFastMetaBuilder;
88
89         QFastMetaBuilder *_b;
90         int _o;
91         int _l;
92     };
93     StringRef newString(int length);
94
95     // Returns class name
96     StringRef init(int classNameLength,
97                    int propertyCount, int methodCount, 
98                    int signalCount, int classInfoCount);
99
100     void setClassInfo(int index, const StringRef &key, const StringRef &value);
101
102     enum PropertyFlag {
103         None = 0x00000000,
104         Writable = 0x00000002,
105         Resettable = 0x00000004,
106         Constant = 0x00000400,
107         Final = 0x00000800
108     };
109     // void setProperty(int index, const StringRef &name, QMetaType::Type type, int notifySignal = -1);
110     void setProperty(int index, const StringRef &name, const StringRef &type, 
111                      QMetaType::Type mtype, PropertyFlag flags, int notifySignal = -1);
112     void setProperty(int index, const StringRef &name, const StringRef &type, 
113                      PropertyFlag flags, int notifySignal = -1);
114     void setMethod(int index, const StringRef &signature,
115                    const StringRef &parameterNames = StringRef(), 
116                    const StringRef &type = StringRef());
117     void setSignal(int index, const StringRef &signature, 
118                    const StringRef &parameterNames = StringRef(), 
119                    const StringRef &type = StringRef());
120
121     int metaObjectIndexForSignal(int) const;
122     int metaObjectIndexForMethod(int) const;
123
124     QByteArray toData() const { return m_data; }
125     static void fromData(QMetaObject *, const QMetaObject *parent, const QByteArray &);
126 private:
127     friend struct StringRef;
128
129     QByteArray m_data;
130     int m_zeroPtr;
131
132     void allocateStringData();
133     char *m_stringData;
134     int m_stringDataLength;
135     int m_stringDataAllocated;
136 };
137
138 QFastMetaBuilder::StringRef::StringRef()
139 : _b(0), _o(0), _l(0)
140 {
141 }
142
143 QFastMetaBuilder::StringRef::StringRef(const StringRef &o)
144 : _b(o._b), _o(o._o), _l(o._l)
145 {
146 }
147
148 QFastMetaBuilder::StringRef &QFastMetaBuilder::StringRef::operator=(const StringRef &o)
149 {
150     _b = o._b;
151     _o = o._o;
152     _l = o._l;
153     return *this;
154 }
155
156 bool QFastMetaBuilder::StringRef::isEmpty() const
157 {
158     return _l == 0;
159 }
160
161 QFastMetaBuilder *QFastMetaBuilder::StringRef::builder() const
162 {
163     return _b;
164 }
165
166 int QFastMetaBuilder::StringRef::offset() const
167 {
168     return _o;
169 }
170
171 char *QFastMetaBuilder::StringRef::data()
172 {
173     Q_ASSERT(_b);
174     if (_b->m_stringDataLength != _b->m_stringDataAllocated)
175         _b->allocateStringData();
176     return _b->m_stringData + _o;
177 }
178
179 int QFastMetaBuilder::StringRef::length() const
180 {
181     return _l;
182 }
183
184 void QFastMetaBuilder::StringRef::load(const QHashedStringRef &str)
185 {
186     Q_ASSERT(str.utf8length() == _l);
187     str.writeUtf8(data());
188     *(data() + _l) = 0;
189 }
190
191 void QFastMetaBuilder::StringRef::load(const QByteArray &str)
192 {
193     Q_ASSERT(str.length() == _l);
194     strcpy(data(), str.constData());
195 }
196
197 void QFastMetaBuilder::StringRef::load(const char *str)
198 {
199     Q_ASSERT(strlen(str) == (uint)_l);
200     strcpy(data(), str);
201 }
202
203 QT_END_NAMESPACE
204
205 #endif // QFASTMETABUILDER_P_H
206