Debian Codegraph @

src/script/api/qscriptstring.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "config.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/ // compile on Windows
41 #include "qscriptstring.h"cxx . . $ `<file>/src/script/api/qscriptstring.h`/
42 #include "qscriptstring_p.h"cxx . . $ `<file>/src/script/api/qscriptstring_p.h`/
43 #include "qscriptengine.h"cxx . . $ `<file>/src/script/api/qscriptengine.h`/
44 #include "qscriptengine_p.h"cxx . . $ `<file>/src/script/api/qscriptengine_p.h`/
45
46 QT_BEGIN_NAMESPACEcxx . . $ `<external>/15045578679651060896/qglobal.h:148:10`!
47
48 /*!
49 \since 4.4
50 \class QScriptString
51 \inmodule QtScript
52 \brief The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
53
54 \ingroup script
55
56
57 QScriptString can be used to achieve faster (repeated)
58 property getting/setting, and comparison of property names, of
59 script objects.
60
61 To get a QScriptString representation of a string, pass the string
62 to QScriptEngine::toStringHandle(). The typical usage pattern is to
63 register one or more pre-defined strings when setting up your script
64 environment, then subsequently use the relevant QScriptString as
65 argument to e.g. QScriptValue::property().
66
67 Call the toString() function to obtain the string that a
68 QScriptString represents.
69
70 Call the toArrayIndex() function to convert a QScriptString to an
71 array index. This is useful when using QScriptClass to implement
72 array-like objects.
73 */
74
75 /*!
76 Constructs an invalid QScriptString.
77 */
78 QScriptStringcxx . . $ QScriptString#::QScriptStringcxx . . $ QScriptString#QScriptString(49f6e7a06ebc5aa8).()
79 : d_ptr(0)
80 {
81 }
82
83 /*!
84 Constructs a new QScriptString that is a copy of \a other.
85 */
86 QScriptStringcxx . . $ QScriptString#::QScriptStringcxx . . $ QScriptString#QScriptString(ae9d1fa6573bd2b8).(const QScriptStringcxx . . $ QScriptString# &other)
87 : d_ptr(other.d_ptr)
88 {
89 if (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).() && (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->typecxx . . $ QScriptStringPrivate#type. == QScriptStringPrivatecxx . . $ QScriptStringPrivate#::StackAllocatedcxx . . $ QScriptStringPrivate#StackAllocated.)) {
90 Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(d_func()->ref.load() != 1);
91 d_ptr.detach();
92 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->ref.store(1);
93 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->typecxx . . $ QScriptStringPrivate#type. = QScriptStringPrivatecxx . . $ QScriptStringPrivate#::HeapAllocatedcxx . . $ QScriptStringPrivate#HeapAllocated.;
94 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->enginecxx . . $ QScriptStringPrivate#engine.->registerScriptStringcxx . . $ QScriptEnginePrivate#registerScriptString(b26e228316739067).(d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).());
95 }
96 }
97
98 /*!
99 Destroys this QScriptString.
100 */
101 QScriptStringcxx . . $ QScriptString#::~cxx . . $ QScriptString#`~QScriptString`(49f6e7a06ebc5aa8).QScriptStringcxx . . $ QScriptString#()
102 {
103 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(QScriptString);
104 if (d) {
105 switch (d->typecxx . . $ QScriptStringPrivate#type.) {
106 case QScriptStringPrivatecxx . . $ QScriptStringPrivate#::StackAllocatedcxx . . $ QScriptStringPrivate#StackAllocated.:
107 Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(d->ref.load() == 1);
108 d->ref.ref(); // avoid deletion
109 break;
110 case QScriptStringPrivatecxx . . $ QScriptStringPrivate#::HeapAllocatedcxx . . $ QScriptStringPrivate#HeapAllocated.:
111 if (d->enginecxx . . $ QScriptStringPrivate#engine. && (d->ref.load() ==cxx . . $ `operator==`(99d45ab6e563cfed). 1)) {
112 // Make sure the identifier is removed from the correct engine.
113 QScriptcxx . . $ QScript/::APIShimcxx . . $ QScript/APIShim# shimcxx . . $ QScript/APIShim#APIShim(db35ed4eaf341aaa).(d->enginecxx . . $ QScriptStringPrivate#engine.);
114 d->identifier = JSCcxx . . $ `<built-in>:463:9`!::Identifiercxx . . $ QTJSC/Identifier#();
115 d->enginecxx . . $ QScriptStringPrivate#engine.->unregisterScriptStringcxx . . $ QScriptEnginePrivate#unregisterScriptString(b26e228316739067).(d);
116 }
117 break;
118 }
119 }
120 }
121
122 /*!
123 Assigns the \a other value to this QScriptString.
124 */
125 QScriptStringcxx . . $ QScriptString# &QScriptStringcxx . . $ QScriptString#::operatorcxx . . $ QScriptString#`operator=`(a5bd910b733c9fb).=(const QScriptStringcxx . . $ QScriptString# &other)
126 {
127 if (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).() && d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->enginecxx . . $ QScriptStringPrivate#engine. && (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->ref.load() ==cxx . . $ `operator==`(99d45ab6e563cfed). 1) && (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->typecxx . . $ QScriptStringPrivate#type. == QScriptStringPrivatecxx . . $ QScriptStringPrivate#::HeapAllocatedcxx . . $ QScriptStringPrivate#HeapAllocated.)) {
128 // current d_ptr will be deleted at the assignment below, so unregister it first
129 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->enginecxx . . $ QScriptStringPrivate#engine.->unregisterScriptStringcxx . . $ QScriptEnginePrivate#unregisterScriptString(b26e228316739067).(d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).());
130 }
131 d_ptr = other.d_ptr;
132 if (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).() && (d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->typecxx . . $ QScriptStringPrivate#type. == QScriptStringPrivatecxx . . $ QScriptStringPrivate#::StackAllocatedcxx . . $ QScriptStringPrivate#StackAllocated.)) {
133 Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:859:13`!(d_func()->ref.load() != 1);
134 d_ptr.detach();
135 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->ref.store(1);
136 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->typecxx . . $ QScriptStringPrivate#type. = QScriptStringPrivatecxx . . $ QScriptStringPrivate#::HeapAllocatedcxx . . $ QScriptStringPrivate#HeapAllocated.;
137 d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).()->enginecxx . . $ QScriptStringPrivate#engine.->registerScriptStringcxx . . $ QScriptEnginePrivate#registerScriptString(b26e228316739067).(d_funccxx . . $ QScriptString#d_func(98d8a4d88be7e74b).());
138 }
139 return *this;
140 }
141
142 /*!
143 Returns true if this QScriptString is valid; otherwise
144 returns false.
145 */
146 bool QScriptStringcxx . . $ QScriptString#::isValidcxx . . $ QScriptString#isValid(50ce9a9e25b4a850).() const
147 {
148 return QScriptStringPrivatecxx . . $ QScriptStringPrivate#::isValidcxx . . $ QScriptStringPrivate#isValid(94c89bb62f70010d).(*this);
149 }
150
151 /*!
152 Returns true if this QScriptString is equal to \a other;
153 otherwise returns false.
154 */
155 bool QScriptStringcxx . . $ QScriptString#::operatorcxx . . $ QScriptString#`operator==`(496134752549386d).==(const QScriptStringcxx . . $ QScriptString# &other) const
156 {
157 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptString);
158 if (!d || !other.d_funccxx . . $ QScriptString#d_func(6571a19f01a7283f).())
159 return d == other.d_funccxx . . $ QScriptString#d_func(6571a19f01a7283f).();
160 return d->identifier ==cxx . . $ `operator==`(99d45ab6e563cfed). other.d_funccxx . . $ QScriptString#d_func(6571a19f01a7283f).()->identifier;
161 }
162
163 /*!
164 Returns true if this QScriptString is not equal to \a other;
165 otherwise returns false.
166 */
167 bool QScriptStringcxx . . $ QScriptString#::operatorcxx . . $ QScriptString#`operator!=`(496134752549386d).!=(const QScriptStringcxx . . $ QScriptString# &other) const
168 {
169 return !operator==(other);
170 }
171
172 /*!
173 \since 4.6
174
175 Attempts to convert this QScriptString to a Qt Script array index,
176 and returns the result.
177
178 If a conversion error occurs, *\a{ok} is set to false; otherwise
179 *\a{ok} is set to true.
180 */
181 quint32cxx . . $ quint32# QScriptStringcxx . . $ QScriptString#::toArrayIndexcxx . . $ QScriptString#toArrayIndex(870b63f89c7fb98).(bool *ok) const
182 {
183 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptString);
184 if (!d) {
185 if (ok)
186 *ok = false;
187 return -1;
188 }
189 bool tmp;
190 bool *okok = ok ? ok : &tmp;
191 quint32cxx . . $ quint32# result = d->identifier.toArrayIndex(okok);
192 if (!*okok)
193 result = -1;
194 return result;
195 }
196
197 /*!
198 Returns the string that this QScriptString represents, or a
199 null string if this QScriptString is not valid.
200
201 \sa isValid()
202 */
203 QStringcxx . . $ QString# QScriptStringcxx . . $ QScriptString#::toStringcxx . . $ QScriptString#toString(6ef7b6c27b00b43d).() const
204 {
205 Q_Dcxx . . $ `<external>/15045578679651060896/qglobal.h:1177:9`!(const QScriptString);
206 if (!d || !d->enginecxx . . $ QScriptStringPrivate#engine.)
207 return QStringcxx . . $ QString#QString(e1217c004a86c950).();
208 return d->identifier.ustring();
209 }
210
211 /*!
212 Returns the string that this QScriptString represents, or a
213 null string if this QScriptString is not valid.
214
215 \sa toString()
216 */
217 QScriptStringcxx . . $ QScriptString#::operatorcxx . . $ QScriptString#`operator QString`(6ef7b6c27b00b43d). QStringcxx . . $ QString#() const
218 {
219 return toStringcxx . . $ QString#QString(e1217c004a86c950).();
220 }
221
222 uintcxx . . $ uint# qHashcxx . . $ qHash(29564d07a9e853f8).(const QScriptStringcxx . . $ QScriptString# &key)
223 {
224 QScriptStringPrivatecxx . . $ QScriptStringPrivate# *d = QScriptStringPrivatecxx . . $ QScriptStringPrivate#::getcxx . . $ QScriptStringPrivate#get(cdaec7eddb0d5575).(key);
225 if (!d)
226 return 0;
227 return qHashcxx . . $ qHash(29564d07a9e853f8).(d->identifier.ustring().rep());
228 }
229
230 QT_END_NAMESPACEcxx . . $ `<external>/15045578679651060896/qglobal.h:149:10`!