QDirIterator refactoring
[qt-netbsd.git] / src / script / qscriptobject_p.h
blobd50dc239289ba1261b54e8fa9e2ff5cabf7b6877
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** No Commercial Usage
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the either Technology Preview License Agreement or the
13 ** Beta Release License Agreement.
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.
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.
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.
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at http://www.qtsoftware.com/contact.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef QSCRIPTOBJECT_P_H
43 #define QSCRIPTOBJECT_P_H
45 #include "qscriptobjectfwd_p.h"
47 #ifndef QT_NO_SCRIPT
49 QT_BEGIN_NAMESPACE
52 // W A R N I N G
53 // -------------
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.
59 // We mean it.
62 inline bool QScriptObject::findMember(QScriptNameIdImpl *nameId,
63 QScript::Member *m) const
65 const QScript::Member *members = m_members.constData();
66 const int size = m_members.size();
68 const QScript::Member *first = &members[-1];
69 const QScript::Member *last = &members[size - 1];
71 for (const QScript::Member *it = last; it != first; --it) {
72 if (it->nameId() == nameId && it->isValid()) {
73 *m = *it;
74 return true;
78 return false;
81 // assumes that m already points to the setter
82 inline bool QScriptObject::findGetter(QScript::Member *m) const
84 const QScript::Member *members = m_members.constData();
85 const QScript::Member *first = &members[-1];
86 const QScript::Member *last = &members[m->id() - 1];
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;
95 return false;
98 // assumes that m already points to the getter
99 inline bool QScriptObject::findSetter(QScript::Member *m) const
101 const QScript::Member *members = m_members.constData();
102 const QScript::Member *first = &members[-1];
103 const QScript::Member *last = &members[m->id() - 1];
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;
112 return false;
115 inline int QScriptObject::memberCount() const
117 return m_members.size();
120 inline void QScriptObject::createMember(QScriptNameIdImpl *nameId,
121 QScript::Member *member, uint flags)
123 member->object(nameId, m_values.size(), flags);
124 m_members.append(*member);
125 m_values.append(QScriptValueImpl());
128 inline void QScriptObject::member(int index, QScript::Member *member)
130 *member = m_members[index];
133 inline void QScriptObject::put(const QScript::Member &m, const QScriptValueImpl &v)
135 m_values[m.id()] = v;
138 inline QScriptValueImpl &QScriptObject::reference(const QScript::Member &m)
140 return m_values[m.id()];
143 inline void QScriptObject::get(const QScript::Member &m, QScriptValueImpl *v)
145 Q_ASSERT(m.isObjectProperty());
146 *v = m_values[m.id()];
149 inline void QScriptObject::removeMember(const QScript::Member &member)
151 m_members[member.id()].invalidate();
152 m_values[member.id()].invalidate();
155 inline QScriptObject::~QScriptObject()
157 finalize();
160 inline void QScriptObject::finalize()
162 finalizeData();
165 inline void QScriptObject::finalizeData()
167 if (m_data) {
168 m_data->finalize(m_class->engine());
169 delete m_data;
170 m_data = 0;
174 inline void QScriptObject::reset()
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;
184 QT_END_NAMESPACE
186 #endif // QT_NO_SCRIPT
188 #endif