本文整理汇总了C++中QScriptString::toArrayIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptString::toArrayIndex方法的具体用法?C++ QScriptString::toArrayIndex怎么用?C++ QScriptString::toArrayIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptString
的用法示例。
在下文中一共展示了QScriptString::toArrayIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: queryProperty
QScriptClass::QueryFlags ScShiftPropertyContainer::queryProperty(const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
{
ScProfileFunction
SPropertyContainer *prop = (*unpackValue(object))->uncheckedCastTo<SPropertyContainer>();
if (!prop)
{
xAssertFail();
return 0;
}
*id = (uint)-1;
bool isArrayIndex = false;
qint32 pos = name.toArrayIndex(&isArrayIndex);
if(isArrayIndex)
{
*id = pos;
return flags;
}
else
{
SProperty *child = prop->findChild(name);
if(child)
{
return flags;
}
}
return 0;
}
示例2: propertyHelper
QScriptValue propertyHelper(const QByteArray* arrayBuffer, const QScriptString& name, uint id) {
bool ok = false;
name.toArrayIndex(&ok);
if (ok && arrayBuffer) {
QDataStream stream(*arrayBuffer);
stream.skipRawData(id);
T result;
stream >> result;
return result;
}
示例3: queryProperty
QScriptClass::QueryFlags ByteArrayClass::queryProperty(const QScriptValue &object,
const QScriptString &name,
QueryFlags flags, uint *id) {
QByteArray *ba = qscriptvalue_cast<QByteArray*>(object.data());
if (!ba)
return 0;
if (name == length) {
return flags;
} else {
bool isArrayIndex;
qint32 pos = name.toArrayIndex(&isArrayIndex);
if (!isArrayIndex)
return 0;
*id = pos;
if ((flags & HandlesReadAccess) && (pos >= ba->size()))
flags &= ~HandlesReadAccess;
return flags;
}
}
示例4: queryProperty
QScriptClass::QueryFlags TypedArray::queryProperty(const QScriptValue& object,
const QScriptString& name,
QueryFlags flags, uint* id) {
if (name == _bytesPerElementName || name == _lengthName) {
return flags &= HandlesReadAccess; // Only keep read access flags
}
quint32 byteOffset = object.data().property(_byteOffsetName).toInt32();
quint32 length = object.data().property(_lengthName).toInt32();
bool ok = false;
quint32 pos = name.toArrayIndex(&ok);
// Check that name is a valid index and arrayBuffer exists
if (ok && pos < length) {
*id = byteOffset + pos * _bytesPerElement; // save pos to avoid recomputation
return HandlesReadAccess | HandlesWriteAccess; // Read/Write access
}
return ArrayBufferViewClass::queryProperty(object, name, flags, id);
}
示例5: queryProperty
QScriptClass::QueryFlags AudioOutputCollection::queryProperty(
const QScriptValue &object, const QScriptString &name, QueryFlags flags, uint *id)
{
ActiveAudioTracks* tracks = this->_editor->getPoolOfActiveAudioTrack();
bool isArrayIndex;
quint32 pos = name.toArrayIndex(&isArrayIndex);
if (!isArrayIndex)
{
return 0;
}
*id = pos;
if (pos >= tracks->size())
{
return 0;
}
return flags;
}
示例6: test
void tst_QScriptString::test()
{
QScriptEngine eng;
{
QScriptString str;
QVERIFY(!str.isValid());
QVERIFY(str == str);
QVERIFY(!(str != str));
QVERIFY(str.toString().isNull());
QScriptString str1(str);
QVERIFY(!str1.isValid());
QScriptString str2 = str;
QVERIFY(!str2.isValid());
QCOMPARE(str.toArrayIndex(), quint32(0xffffffff));
}
for (int x = 0; x < 2; ++x) {
QString ciao = QString::fromLatin1("ciao");
QScriptString str = eng.toStringHandle(ciao);
QVERIFY(str.isValid());
QVERIFY(str == str);
QVERIFY(!(str != str));
QCOMPARE(str.toString(), ciao);
QScriptString str1(str);
QCOMPARE(str, str1);
QScriptString str2 = str;
QCOMPARE(str, str2);
QScriptString str3 = eng.toStringHandle(ciao);
QVERIFY(str3.isValid());
QCOMPARE(str, str3);
eng.collectGarbage();
QVERIFY(str.isValid());
QCOMPARE(str.toString(), ciao);
QVERIFY(str1.isValid());
QCOMPARE(str1.toString(), ciao);
QVERIFY(str2.isValid());
QCOMPARE(str2.toString(), ciao);
QVERIFY(str3.isValid());
QCOMPARE(str3.toString(), ciao);
}
{
QScriptEngine* eng2 = new QScriptEngine;
QString one = QString::fromLatin1("one");
QString two = QString::fromLatin1("two");
QScriptString oneInterned = eng2->toStringHandle(one);
QCOMPARE(oneInterned.toString(), one);
QScriptString twoInterned = eng2->toStringHandle(two);
QCOMPARE(twoInterned.toString(), two);
QVERIFY(oneInterned != twoInterned);
QVERIFY(!(oneInterned == twoInterned));
delete eng2;
}
}