本文整理汇总了C++中DataPtr::data方法的典型用法代码示例。如果您正苦于以下问题:C++ DataPtr::data方法的具体用法?C++ DataPtr::data怎么用?C++ DataPtr::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataPtr
的用法示例。
在下文中一共展示了DataPtr::data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testThreadSafety
void TestSharedPtr::testThreadSafety()
{
DataPtr ptr = Data::create();
WeakPtr<Data> weakPtr(ptr);
Data *savedData = ptr.data();
QVERIFY(savedData != NULL);
QVERIFY(!ptr.isNull());
QVERIFY(!weakPtr.isNull());
Thread *t[5];
for (int i = 0; i < 5; ++i) {
t[i] = new Thread(ptr, this);
t[i]->start();
}
for (int i = 0; i < 5; ++i) {
t[i]->wait();
delete t[i];
}
QCOMPARE(ptr.data(), savedData);
QVERIFY(!ptr.isNull());
QVERIFY(!weakPtr.isNull());
for (int i = 0; i < 5; ++i) {
t[i] = new Thread(ptr, this);
t[i]->start();
}
QVERIFY(!ptr.isNull());
QVERIFY(!weakPtr.isNull());
ptr.reset();
QVERIFY(ptr.isNull());
for (int i = 0; i < 5; ++i) {
t[i]->wait();
delete t[i];
}
QVERIFY(!ptr.data());
QVERIFY(ptr.isNull());
QVERIFY(weakPtr.isNull());
DataPtr promotedPtr(weakPtr);
QVERIFY(!promotedPtr.data());
QVERIFY(promotedPtr.isNull());
}
示例2: testSharedPtrDict
void TestSharedPtr::testSharedPtrDict()
{
QHash<DataPtr, int> dict;
DataPtr nullPtr = Data::createNull();
dict[nullPtr] = 1;
QCOMPARE(dict.size(), 1);
QCOMPARE(dict[nullPtr], 1);
DataPtr validPtr1 = Data::create();
QCOMPARE(qHash(validPtr1.data()), qHash(validPtr1));
dict[validPtr1] = 2;
QCOMPARE(dict.size(), 2);
QCOMPARE(dict[nullPtr], 1);
QCOMPARE(dict[validPtr1], 2);
DataPtr validPtr2 = validPtr1;
QCOMPARE(validPtr1.data(), validPtr2.data());
QCOMPARE(qHash(validPtr1), qHash(validPtr2));
dict[validPtr2] = 3;
QCOMPARE(dict.size(), 2);
QCOMPARE(dict[nullPtr], 1);
QCOMPARE(dict[validPtr1], 3);
QCOMPARE(dict[validPtr2], 3);
DataPtr validPtrAlternative = Data::create();
QVERIFY(validPtr1.data() != validPtrAlternative.data());
QVERIFY(validPtr1 != validPtrAlternative);
QVERIFY(qHash(validPtr1) != qHash(validPtrAlternative));
dict[validPtrAlternative] = 4;
QCOMPARE(dict.size(), 3);
QCOMPARE(dict[nullPtr], 1);
QCOMPARE(dict[validPtr1], 3);
QCOMPARE(dict[validPtr2], 3);
QCOMPARE(dict[validPtrAlternative], 4);
}
示例3: load
bool CWorldMobPrototype::load(const String& resourceName)
{
CLog::instance()->log(CLog::msgFlagResources,CLog::msgLvlInfo,"Loading mob prototype from '%s'.\n",resourceName.c_str());
DataPtr dPtr = CResourceManager::instance()->load(resourceName);
if( !dPtr )
{
CLog::instance()->log(CLog::msgLvlError,"Error loading mob prototype: resource not found.\n",resourceName.c_str());
return false;
}
TiXmlDocument doc;
std::stringstream buf;
buf.write(dPtr->data(),dPtr->size());
buf >> doc;
if (doc.Error())
{
CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError, _("Error loading mob prototype: XML parser returned an error: %s\n"), doc.ErrorDesc());
return false;
}
TiXmlNode* root = doc.FirstChild();
while( root && root->Type() == TiXmlNode::DECLARATION )
root = root->NextSibling();
if( !root || root->Type() != TiXmlNode::ELEMENT || strcmp(root->ToElement()->Value(),"MobPrototype") )
{
CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError, _("Error loading mob prototype: resource isn't mob prototype. %s\n"),root->Value());
return false;
};
TiXmlNode* option;
for( option = root->FirstChild(); option; option = option->NextSibling() )
if( !processOption(option) )
{
CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError, _("Error loading mob prototype: error in file near '%s'.\n"),option->Value());
return false;
};
return true;
};
示例4:
DataPtrStreamWrapper(DataPtr &vec)
{
setg(vec->data(), vec->data(), vec->data() + vec->size());
}