1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtScript module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QSCRIPTOBJECT_P_H
|
---|
43 | #define QSCRIPTOBJECT_P_H
|
---|
44 |
|
---|
45 | #include "qscriptobjectfwd_p.h"
|
---|
46 |
|
---|
47 | #ifndef QT_NO_SCRIPT
|
---|
48 |
|
---|
49 | QT_BEGIN_NAMESPACE
|
---|
50 |
|
---|
51 | //
|
---|
52 | // W A R N I N G
|
---|
53 | // -------------
|
---|
54 | //
|
---|
55 | // This file is not part of the Qt API. It exists purely as an
|
---|
56 | // implementation detail. This header file may change from version to
|
---|
57 | // version without notice, or even be removed.
|
---|
58 | //
|
---|
59 | // We mean it.
|
---|
60 | //
|
---|
61 |
|
---|
62 | inline bool QScriptObject::findMember(QScriptNameIdImpl *nameId,
|
---|
63 | QScript::Member *m) const
|
---|
64 | {
|
---|
65 | const QScript::Member *members = m_members.constData();
|
---|
66 | const int size = m_members.size();
|
---|
67 |
|
---|
68 | const QScript::Member *first = &members[-1];
|
---|
69 | const QScript::Member *last = &members[size - 1];
|
---|
70 |
|
---|
71 | for (const QScript::Member *it = last; it != first; --it) {
|
---|
72 | if (it->nameId() == nameId && it->isValid()) {
|
---|
73 | *m = *it;
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | return false;
|
---|
79 | }
|
---|
80 |
|
---|
81 | // assumes that m already points to the setter
|
---|
82 | inline bool QScriptObject::findGetter(QScript::Member *m) const
|
---|
83 | {
|
---|
84 | const QScript::Member *members = m_members.constData();
|
---|
85 | const QScript::Member *first = &members[-1];
|
---|
86 | const QScript::Member *last = &members[m->id() - 1];
|
---|
87 |
|
---|
88 | for (const QScript::Member *it = last; it != first; --it) {
|
---|
89 | if (it->nameId() == m->nameId() && it->isValid() && it->isGetter()) {
|
---|
90 | *m = *it;
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 |
|
---|
98 | // assumes that m already points to the getter
|
---|
99 | inline bool QScriptObject::findSetter(QScript::Member *m) const
|
---|
100 | {
|
---|
101 | const QScript::Member *members = m_members.constData();
|
---|
102 | const QScript::Member *first = &members[-1];
|
---|
103 | const QScript::Member *last = &members[m->id() - 1];
|
---|
104 |
|
---|
105 | for (const QScript::Member *it = last; it != first; --it) {
|
---|
106 | if (it->nameId() == m->nameId() && it->isValid() && it->isSetter()) {
|
---|
107 | *m = *it;
|
---|
108 | return true;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 | inline int QScriptObject::memberCount() const
|
---|
116 | {
|
---|
117 | return m_members.size();
|
---|
118 | }
|
---|
119 |
|
---|
120 | inline void QScriptObject::createMember(QScriptNameIdImpl *nameId,
|
---|
121 | QScript::Member *member, uint flags)
|
---|
122 | {
|
---|
123 | member->object(nameId, m_values.size(), flags);
|
---|
124 | m_members.append(*member);
|
---|
125 | m_values.append(QScriptValueImpl());
|
---|
126 | }
|
---|
127 |
|
---|
128 | inline void QScriptObject::member(int index, QScript::Member *member)
|
---|
129 | {
|
---|
130 | *member = m_members[index];
|
---|
131 | }
|
---|
132 |
|
---|
133 | inline void QScriptObject::put(const QScript::Member &m, const QScriptValueImpl &v)
|
---|
134 | {
|
---|
135 | m_values[m.id()] = v;
|
---|
136 | }
|
---|
137 |
|
---|
138 | inline QScriptValueImpl &QScriptObject::reference(const QScript::Member &m)
|
---|
139 | {
|
---|
140 | return m_values[m.id()];
|
---|
141 | }
|
---|
142 |
|
---|
143 | inline void QScriptObject::get(const QScript::Member &m, QScriptValueImpl *v)
|
---|
144 | {
|
---|
145 | Q_ASSERT(m.isObjectProperty());
|
---|
146 | *v = m_values[m.id()];
|
---|
147 | }
|
---|
148 |
|
---|
149 | inline void QScriptObject::removeMember(const QScript::Member &member)
|
---|
150 | {
|
---|
151 | m_members[member.id()].invalidate();
|
---|
152 | m_values[member.id()].invalidate();
|
---|
153 | }
|
---|
154 |
|
---|
155 | inline QScriptObject::~QScriptObject()
|
---|
156 | {
|
---|
157 | finalize();
|
---|
158 | }
|
---|
159 |
|
---|
160 | inline void QScriptObject::finalize()
|
---|
161 | {
|
---|
162 | finalizeData();
|
---|
163 | }
|
---|
164 |
|
---|
165 | inline void QScriptObject::finalizeData()
|
---|
166 | {
|
---|
167 | if (m_data) {
|
---|
168 | m_data->finalize(m_class->engine());
|
---|
169 | delete m_data;
|
---|
170 | m_data = 0;
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | inline void QScriptObject::reset()
|
---|
175 | {
|
---|
176 | m_prototype.invalidate();
|
---|
177 | m_scope.invalidate();
|
---|
178 | m_internalValue.invalidate();
|
---|
179 | m_members.resize(0);
|
---|
180 | m_values.resize(0);
|
---|
181 | m_data = 0;
|
---|
182 | }
|
---|
183 |
|
---|
184 | QT_END_NAMESPACE
|
---|
185 |
|
---|
186 | #endif // QT_NO_SCRIPT
|
---|
187 |
|
---|
188 | #endif
|
---|