static void TestWStream(skiatest::Reporter* reporter) { SkDynamicMemoryWStream ds; const char s[] = "abcdefghijklmnopqrstuvwxyz"; int i; for (i = 0; i < 100; i++) { REPORTER_ASSERT(reporter, ds.write(s, 26)); } REPORTER_ASSERT(reporter, ds.bytesWritten() == 100 * 26); char* dst = new char[100 * 26 + 1]; dst[100*26] = '*'; ds.copyTo(dst); REPORTER_ASSERT(reporter, dst[100*26] == '*'); for (i = 0; i < 100; i++) { REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0); } { std::unique_ptr<SkStreamAsset> stream(ds.detachAsStream()); REPORTER_ASSERT(reporter, 100 * 26 == stream->getLength()); REPORTER_ASSERT(reporter, ds.bytesWritten() == 0); test_loop_stream(reporter, stream.get(), s, 26, 100); std::unique_ptr<SkStreamAsset> stream2(stream->duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); std::unique_ptr<SkStreamAsset> stream3(stream->fork()); REPORTER_ASSERT(reporter, stream3->isAtEnd()); char tmp; size_t bytes = stream->read(&tmp, 1); REPORTER_ASSERT(reporter, 0 == bytes); stream3->rewind(); test_loop_stream(reporter, stream3.get(), s, 26, 100); } for (i = 0; i < 100; i++) { REPORTER_ASSERT(reporter, ds.write(s, 26)); } REPORTER_ASSERT(reporter, ds.bytesWritten() == 100 * 26); { // Test that this works after a snapshot. std::unique_ptr<SkStreamAsset> stream(ds.detachAsStream()); REPORTER_ASSERT(reporter, ds.bytesWritten() == 0); test_loop_stream(reporter, stream.get(), s, 26, 100); std::unique_ptr<SkStreamAsset> stream2(stream->duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); } delete[] dst; SkString tmpDir = skiatest::GetTmpDir(); if (!tmpDir.isEmpty()) { test_filestreams(reporter, tmpDir.c_str()); } }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); printf("Please Input Process Num :\n"); int Pnumber; QTextStream stream(stdin); stream >> Pnumber; printf("Please Input fileBase Num :\n"); int fileBaseNum; QTextStream stream1(stdin); stream1 >> fileBaseNum; printf("Please Input fileSize (kB) :\n"); int fileSize; QTextStream stream2(stdin); stream2 >> fileSize; readConfig read; QString program = read.map["writeFileEXE"] ; QTime timer; timer.start(); CreateProcess Cprocess(Pnumber, fileBaseNum, program, fileSize, timer); Cprocess.clear_pro(); return 0; }
void dtkMatrixTestCase::testDataStream(void) { dtkDenseMatrix<double> m(121, 89); flens::fillRandom(m); QByteArray data; { QDataStream stream(&data, QIODevice::WriteOnly); stream << m; } dtkDenseMatrix<double> r; { QDataStream stream2(data); stream2 >> r; } QCOMPARE(r.numRows(), m.numRows()); QCOMPARE(r.numCols(), m.numCols()); const double *m_it = m.data(); const double *m_end = m.data() + m.numRows() * m.numCols(); const double *r_it = r.data(); for(; m_it != m_end; ++m_it, ++r_it) { QCOMPARE(*r_it, *m_it); } }
void sat::appendTmplXml() { QFile tmplXml(tmplXmlFile); if (tmplXml.open(QIODevice::ReadOnly)) { QTextStream stream(&tmplXml); QString tmp = stream.readLine(); QString file = ""; while (!tmp.isNull()) { file += tmp + "\n"; tmp = stream.readLine(); if (tmp.indexOf("</templates>") != -1) file += getTemplateTag(); } tmplXml.close(); if ( tmplXml.open( QIODevice::WriteOnly ) ) { QTextStream stream2(&tmplXml); stream2.setCodec("UTF-8"); stream2 << file; tmplXml.close(); } } }
TEST (json, fetch_object) { std::string string1 ("{ \"thing\": \"junktest\" }"); std::stringstream stream1 (string1); json_upgrade_test object1; auto error1 (rai::fetch_object (object1, stream1)); ASSERT_FALSE (error1); ASSERT_EQ ("changed", object1.text); boost::property_tree::ptree tree1; stream1.seekg (0); boost::property_tree::read_json (stream1, tree1); ASSERT_EQ ("changed", tree1.get <std::string> ("thing")); std::string string2 ("{ \"thing\": \"junktest2\" }"); std::stringstream stream2 (string2); json_upgrade_test object2; auto error2 (rai::fetch_object (object2, stream2)); ASSERT_FALSE (error2); ASSERT_EQ ("junktest2", object2.text); ASSERT_EQ ("{ \"thing\": \"junktest2\" }", string2); std::string string3 ("{ \"thing\": \"error\" }"); std::stringstream stream3 (string3); json_upgrade_test object3; auto error3 (rai::fetch_object (object3, stream3)); ASSERT_TRUE (error3); std::fstream stream4; rai::open_or_create (stream4, rai::unique_path().string()); json_upgrade_test object4; auto error4 (rai::fetch_object (object4, stream4)); ASSERT_FALSE (error4); ASSERT_EQ ("created", object4.text); boost::property_tree::ptree tree2; stream4.seekg (0); boost::property_tree::read_json (stream4, tree2); ASSERT_EQ ("created", tree2.get <std::string> ("thing")); }
/** Compares two files, excluding the REV property, as it doesn't remain the same always @param aExpectedFile The expected vcf file @param aFile This is the vcf file produced, and will be compared against aExpectedFile */ TBool CTestCompareCntFiles::CompareWholeFileL(const TDesC& aExpectedFile, const TDesC& aFile) { User::LeaveIfError(iFsSession.Connect()); CleanupClosePushL(iFsSession); RFile fileExpected; RFile fileOutput; CleanupClosePushL(fileExpected); CleanupClosePushL(fileOutput); TInt err; err = fileExpected.Open(iFsSession, aExpectedFile, EFileRead); if (err != KErrNone) { User::Leave(err); } err = fileOutput.Open(iFsSession, aFile, EFileWrite); if (err != KErrNone) { User::Leave(err); } RFileReadStream stream1(fileExpected); RFileReadStream stream2(fileOutput); CleanupClosePushL(stream1); CleanupClosePushL(stream2); TBuf8<0x80> bufO,bufC; TBool flag = ETrue; TInt line = 1; do { TRAP(err, stream1.ReadL(bufO, KLinefeedChar)); if (err == KErrNone || err == KErrEof) TRAP(err, stream2.ReadL(bufC, KLinefeedChar)); if (err != KErrNone && err != KErrEof) User::Leave(err); if (CompareLine(bufO, bufC) == EFalse) { flag = EFalse; break; } ++line; } while (err != KErrEof); CleanupStack::PopAndDestroy(4, &fileExpected); CleanupStack::PopAndDestroy(&iFsSession); iFsSession.Close(); if(flag) { return ETrue; } else { return EFalse; } }
void tst_QContactRelationship::datastream() { QSKIP("Datastream is not currently supported when using the QContactIdMock class"); //After QContactId introduction, the QCOMPARE at then end this case will fail, since //relationshipOut will contain contacts with "null" QContactIds, whereas //relationshipIn will contain contacts with QContactIds referring to //manager "a", which is an invalid one. QByteArray buffer; QDataStream stream1(&buffer, QIODevice::WriteOnly); QContactRelationship relationshipIn; QContact contact1; contact1.setId(QContactIdMock::createId("a", 1)); relationshipIn.setFirst(contact1); QContact contact2; contact2.setId(QContactIdMock::createId("a", 2)); relationshipIn.setSecond(contact2); relationshipIn.setRelationshipType(QContactRelationship::HasMember()); stream1 << relationshipIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); QContactRelationship relationshipOut; stream2 >> relationshipOut; QCOMPARE(relationshipOut, relationshipIn); }
void Msg::clearmsgCmd(const QString& from, const QStringList& list) { if(list[0] == "") { // no arg QFile f(manager()->dataDir() + "/msg/" + from); f.remove(); QString txt("You clear your messages"); manager()->connectionPlugin()->serverSend(from,txt); } else { if (list[0].toInt() < 1) { manager()->connectionPlugin()->serverSend(from, "Parameter(s) must be greater than 0!"); return; } int start = list[0].toInt() - 1; int stop = (list[1] == "")?(start+1):(list[1].toInt()); QFile f(manager()->dataDir() + "/msg/" + from); if (!f.open(QIODevice::ReadOnly)) { octInfo("Could not read message file\n"); return; } QTextStream stream(&f); QString line; QStringList l; while((line = stream.readLine()) != QString::null) l << line; f.close(); if (start >= l.count()) { manager()->connectionPlugin()->serverSend(from, "Too large(s) parameter(s)!"); return; } if (stop > l.count()) stop = l.count(); l.erase(l.begin() + start, l.begin() + stop); if (l.count()) { if (!f.open(QIODevice::WriteOnly)) { octInfo("Could not write message file.\n"); return; } QTextStream stream2(&f); for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) stream2 << (*it + "\n"); f.close(); } else f.remove(); QString txt("You clear message"); if (start + 1 == stop) txt += " " + QString::number(stop); else txt += "s " + QString::number(start+1) + " to " + QString::number(stop); manager()->connectionPlugin()->serverSend(from,txt); } }
void QPolyTime::parse(QString& filePath) { if(filePath.isEmpty() == true) { return ; } QFile file(filePath); if(file.open(QIODevice::ReadOnly) == false) { return ; } QTextStream stream(&file); stream.setCodec("UTF-8"); QStringList list; while(stream.atEnd() == false) { QString line1 = stream.readLine().trimmed(); list.append(convert(line1)); //qDebug()<<convert(line); } file.close(); QString newfilePath = filePath; newfilePath.replace("timeTable.txt", "tracePoints.lua"); QFile file2(newfilePath); if(file2.open(QIODevice::WriteOnly) == false) { qDebug()<<"open failed"; return ; } QString str; str += QString("function tracePoints.elapse(cityID1, cityID2)\n"); str += QString(" local funName = \"elapse_\" .. tostring(cityID1) .. \"_\" .. tostring(cityID2)\n "); str += QString(" if cityID1 > cityID2 then\n"); str += QString(" funName = \"elapse_\" .. tostring(cityID2) .. \"_\" .. tostring(cityID1)\n "); str += QString(" end\n"); str += QString(" if tracePoints[funName] == nil then\n"); str += QString(" return nil\n"); str += QString(" end\n"); str += QString(" return tracePoints[funName]();\n"); str += QString("end\n\n"); QTextStream stream2(&file2); stream2.setCodec("UTF-8"); stream2<<QString("tracePoints = {}\n"); foreach(QString single, list) { stream2<<single<<"\n"; } stream2<<str; file2.close(); qDebug()<<"ok"; }
virtual void main() { //init StatisticsReads stats; FastqEntry entry; QStringList infiles; QStringList in1 = getInfileList("in1"); QStringList in2 = getInfileList("in2"); if (in2.count()!=0 && in1.count()!=in2.count()) { THROW(CommandLineParsingException, "Input file lists 'in1' and 'in2' differ in counts!"); } //process for (int i=0; i<in1.count(); ++i) { //forward FastqFileStream stream(in1[i]); while(!stream.atEnd()) { stream.readEntry(entry); stats.update(entry, StatisticsReads::FORWARD); } infiles << in1[i]; //reverse (optional) if (i<in2.count()) { FastqFileStream stream2(in2[i]); while(!stream2.atEnd()) { stream2.readEntry(entry); stats.update(entry, StatisticsReads::REVERSE); } //check read counts matches if (stream.index()!=stream2.index()) { THROW(ArgumentException, "Differing number of reads in file '" + in1[i] + "' and '" + in2[i] + "'!"); } infiles << in2[i]; } } //store output QCCollection metrics = stats.getResult(); if (getFlag("txt")) { QStringList output; metrics.appendToStringList(output); Helper::storeTextFile(Helper::openFileForWriting(getOutfile("out"), true), output); } else { metrics.storeToQCML(getOutfile("out"), infiles, ""); } }
bool QUtf8Convert::checkBOM(QString filePath) { if(filePath.isEmpty() == true) { return false; } QFile file(filePath); if(file.open(QIODevice::ReadOnly) == false) { return false; } QDataStream stream(&file); //EF BB BF unsigned char a1 = 0; unsigned char a2 = 0; unsigned char a3 = 0; unsigned char b1 = 239; unsigned char b2 = 187; unsigned char b3 = 191; stream>>a1; stream>>a2; stream>>a3; //qDebug()<<a1<<a2<<a3; bool result = false; if( a1 == b1 && a2 == b2 && a3 == b3 ) { result = true; QString filePath2 = filePath + QString(".lua"); QFile file2(filePath2); if(file2.open(QIODevice::WriteOnly) == false) { return false; } QDataStream stream2(&file2); while(stream.atEnd() == false) { unsigned char t; stream>>t; stream2<<t; } file2.close(); }
QModelIndex TestDynamicModel::serializeUnserialize( const QModelIndex& index ) { Dynamic::DynamicModel *model = Dynamic::DynamicModel::instance(); QByteArray bytes; QDataStream stream( &bytes, QIODevice::WriteOnly ); model->serializeIndex( &stream, index ); QDataStream stream2( &bytes, QIODevice::ReadOnly ); return model->unserializeIndex( &stream2 ); }
uint32 Shader::Compile(uint32 type, const string &path) { ifstream stream(path); string line = ""; string source = ""; deque<string> str; while(stream.good()) { getline(stream, line); // extra parsing code? if(line[0] == '#') { str = Split(line, "\t <>\""); if(str[0] == "#include") { boost::filesystem::path p {path}; p = {p.remove_filename().string()+"/"+str[1]}; ifstream stream2(p.string()); string line = ""; while(stream2.good()) { getline(stream2, line); source += "\n"+line; } stream2.close(); continue; } } source += "\n"+line; } stream.close(); uint32 shader = glCreateShader(type); const char* csource = (source+"\0").c_str(); glShaderSource(shader, 1, &csource, 0); glCompileShader(shader); int32 logLength = 0; int32 result = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &result); glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); char error[logLength]; glGetShaderInfoLog(shader, logLength, 0, &error[0]); if (logLength > 0) { std::cout << error << "\n"; } return shader; }
void ImageWidget::readImageInfo() { int nn = socket->bytesAvailable(); if(bytesReceived <= 0) { if(socket->bytesAvailable() > 0) { info = new ImageInfo(); bytesReceived = socket->bytesAvailable(); QByteArray tt = socket->readAll(); QByteArray bt = tt.left(8); QDataStream stream1(bt); qint64 infosize; stream1 >>infosize; tt.remove(0,8); QByteArray ct = tt.left(8); QDataStream stream2(ct); stream2 >>totalBytes; tt.remove(0,8); QByteArray infoData = tt.left((int)infosize); tt.remove(0,(int)infosize); QString readData = QString::fromUtf8(infoData); QStringList ColumnList = readData.split(":"); info->id = ColumnList.at(0); info->title = ColumnList.at(1); info->size = ColumnList.at(2); info->path = ColumnList.at(3); info->bm = tt; if(bytesReceived == totalBytes) { socket->disconnectFromHost(); imageInfoList.append(*info); insertTableRow(*info); currentNum++; if(currentNum < imageCount) { ui->progressBar->setValue(currentNum); GetImageInfo(currentNum); }else{ disconnect(socket,SIGNAL(readyRead()),this,SLOT(readImageInfo())); connect(playlist,SIGNAL(clicked(QModelIndex)),this,SLOT(ImageChange(QModelIndex))); connect(playlist, SIGNAL(cellChanged(int,int)), this, SLOT(CheckBoxChanged(int, int))); ui->progressBar->hide(); } } }
virtual void main() { //init StatisticsReads stats; FastqEntry entry; QStringList infiles; //process forward read file QString in1 = getInfile("in1"); FastqFileStream stream(in1); while(!stream.atEnd()) { stream.readEntry(entry); stats.update(entry, StatisticsReads::FORWARD); } infiles << in1; //process reverse read file QString in2 = getInfile("in2"); if (in2!="") { FastqFileStream stream2(in2); while(!stream2.atEnd()) { stream2.readEntry(entry); stats.update(entry, StatisticsReads::REVERSE); } //check read counts matches if (stream.index()!=stream2.index()) { THROW(ArgumentException, "Differing number of reads in file '" + in1 + "' and '" + in2 + "'!"); } infiles << in2; } //store output QCCollection metrics = stats.getResult(); if (getFlag("txt")) { QStringList output; metrics.appendToStringList(output); Helper::storeTextFile(Helper::openFileForWriting(getOutfile("out"), true), output); } else { metrics.storeToQCML(getOutfile("out"), infiles, ""); } }
static void test_filestreams(skiatest::Reporter* reporter, const char* tmpDir) { SkString path = SkOSPath::Join(tmpDir, "wstream_test"); const char s[] = "abcdefghijklmnopqrstuvwxyz"; { SkFILEWStream writer(path.c_str()); if (!writer.isValid()) { ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str()); return; } for (int i = 0; i < 100; ++i) { writer.write(s, 26); } } { SkFILEStream stream(path.c_str()); REPORTER_ASSERT(reporter, stream.isValid()); test_loop_stream(reporter, &stream, s, 26, 100); SkAutoTDelete<SkStreamAsset> stream2(stream.duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); } { FILE* file = ::fopen(path.c_str(), "rb"); SkFILEStream stream(file, SkFILEStream::kCallerPasses_Ownership); REPORTER_ASSERT(reporter, stream.isValid()); test_loop_stream(reporter, &stream, s, 26, 100); SkAutoTDelete<SkStreamAsset> stream2(stream.duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); } }
TEST(IntNode, saveLoadAndSkip) { DefinitionNode root1(NULL, "root"); IntNode testa1(&root1, "testa", 1); IntNode testb1(&root1, "testb", 4); PackStream stream1; root1.save(&stream1); DefinitionNode root2(NULL, "root"); IntNode testb2(&root2, "testb"); PackStream stream2(&stream1); root2.load(&stream2); EXPECT_DOUBLE_EQ(4, testb2.getValue()); }
void parse (StringParser& p, T& out) { size_t start = p.pos (); std::istringstream stream (p.value ().substr (start)); std::istream& stream2 (stream); stream2 >> out; if (stream.fail ()) { stream.clear (); std::streampos pos = stream.tellg (); ASSERT (pos >= 0); throw ParseException (typeid (T), p.value (), start, start + (size_t) pos, "operator>> failed"); } stream.clear (); // Needed (for clearing EOF bit?), otherwise stream.tellg() fails (returns -1) std::streampos pos = stream.tellg (); ASSERT (pos >= 0); p.skip ((size_t) pos); }
void tst_QContactDetail::datastream() { QByteArray buffer; QDataStream stream1(&buffer, QIODevice::WriteOnly); QContactDetail detailIn("definition"); detailIn.setValue("key1", "value1"); detailIn.setValue("key2", "value2"); stream1 << detailIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); QContactDetail detailOut; stream2 >> detailOut; QCOMPARE(detailOut, detailIn); }
TEST (message, confirm_ack_serialization) { rai::keypair key1; auto vote (std::make_shared<rai::vote> (key1.pub, key1.prv, 0, std::unique_ptr<rai::block> (new rai::send_block (0, 1, 2, key1.prv, 4, 5)))); rai::confirm_ack con1 (vote); std::vector<uint8_t> bytes; { rai::vectorstream stream1 (bytes); con1.serialize (stream1); } rai::bufferstream stream2 (bytes.data (), bytes.size ()); bool error; rai::message_header header (error, stream2); rai::confirm_ack con2 (error, stream2, header); ASSERT_FALSE (error); ASSERT_EQ (con1, con2); }
void CAgentTest::CompareFilesL(const TDesC& aOutputFile,const TDesC& aCompareFile) { RFs fsSession; User::LeaveIfError(fsSession.Connect()); RFile file1,file2; TInt err=file1.Open(fsSession, aOutputFile, EFileRead); if (err!=KErrNone) { User::Leave(err); } CleanupClosePushL(file1); err=file2.Open(fsSession, aCompareFile, EFileRead); if (err!=KErrNone) { User::Leave(err); } CleanupClosePushL(file2); RFileReadStream stream1(file1); RFileReadStream stream2(file2); CleanupClosePushL(stream1); CleanupClosePushL(stream2); TBuf8<0x80> bufO,bufC; TInt line=1; do { TRAP(err,stream1.ReadL(bufO,TChar(0xa))); if (err==KErrNone || err==KErrEof) { TRAP(err,stream2.ReadL(bufC,TChar(0xa))); } if (err!=KErrNone && err!=KErrEof) { User::Leave(err); } CompareLines(bufO, bufC); ++line; } while (err!=KErrEof); CleanupStack::PopAndDestroy(4,&file1); }
void LoadFoodRemote::loadFood() { ifstream remoteFoodDb("calories.csv"); string value; int id = totalSimpleFood.size() + 1; while(getline(remoteFoodDb,value)) { stringstream stream(value); string word; list<string> valueList; string searchKeys = ""; string name = ""; string calories; int count = 0; while (getline(stream, word, ',') && count <= 1) { if (count == 0) { name = word; stringstream stream2(word); string key = ""; int count2 = 0; while(getline(stream2,key,' ')) { if (count2 == 0) searchKeys = key; else searchKeys = searchKeys + "," + key; count2++; } } valueList.push_back(word); count++; } string dictKey = "s" + static_cast<ostringstream*>( &(ostringstream() << id) )->str(); valueList.push_back(searchKeys); totalSimpleFood[dictKey] = valueList; id++; } }
void tst_QRay3D::dataStream() { #ifndef QT_NO_DATASTREAM Qt3DRender::RayCasting::QRay3D ray(QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f)); QByteArray data; { QDataStream stream(&data, QIODevice::WriteOnly); stream << ray; } Qt3DRender::RayCasting::QRay3D ray2; { QDataStream stream2(data); stream2 >> ray2; } QVERIFY(ray == ray2); #endif }
void MainWindow::SaveRecentFiles() { QFile file("recent.txt"); file.open(QIODevice::WriteOnly); if (!file.isOpen()) return; QTextStream stream(&file); while(!_recentFiles.isEmpty()) stream << _recentFiles.takeFirst() << "\n"; QFile file2("recentFiles.txt"); file2.open(QIODevice::WriteOnly); if (!file2.isOpen()) return; QTextStream stream2(&file2); while(!_recentCodeFiles.isEmpty()) stream2 << _recentCodeFiles.takeFirst() << "\n"; }
void tst_QBitArray::datastream() { QFETCH(QString, bitField); QFETCH(int, numBits); QFETCH(int, onBits); QBuffer buffer; QVERIFY(buffer.open(QBuffer::ReadWrite)); QDataStream stream(&buffer); QBitArray bits(bitField.size()); for (int i = 0; i < bitField.size(); ++i) { if (bitField.at(i) == QLatin1Char('1')) bits.setBit(i); } QCOMPARE(bits.count(), numBits); QCOMPARE(bits.count(true), onBits); QCOMPARE(bits.count(false), numBits - onBits); stream << bits << bits << bits; buffer.close(); QCOMPARE(stream.status(), QDataStream::Ok); QVERIFY(buffer.open(QBuffer::ReadWrite)); QDataStream stream2(&buffer); QBitArray array1, array2, array3; stream2 >> array1 >> array2 >> array3; QCOMPARE(array1.count(), numBits); QCOMPARE(array1.count(true), onBits); QCOMPARE(array1.count(false), numBits - onBits); QCOMPARE(array1, bits); QCOMPARE(array2, bits); QCOMPARE(array3, bits); }
int main() { typedef std::vector< copy_ptr<process_data> >::iterator iterator; assert(spawn_status::last_value == GEPD::ExitStatus::min); int const timeout = -1; // milliseconds realloc_ptr<unsigned char> erlang_buffer(32768, 4194304); // 4MB realloc_ptr<unsigned char> stream1(1, 16384); realloc_ptr<unsigned char> stream2(1, 16384); int status; if ((status = GEPD::init())) return status; int count; while ((status = GEPD::wait(count, timeout, erlang_buffer, stream1, stream2)) == GEPD::ExitStatus::ready) { iterator itr = processes.begin(); while (itr != processes.end() && count > 0) { if ((status = (*itr)->check(count, erlang_buffer))) { if (status != GEPD::ExitStatus::error_HUP) return status; if ((status = (*itr)->flush(count, erlang_buffer))) return status; iterator const dead = itr; (*dead)->close(); for (++itr; itr != processes.end(); ++itr) (*itr)->shift(); itr = processes.erase(dead); } else { ++itr; } } } return status; }
void Msg::unsubscribeCmd(const QString& from, const QStringList& list) { QString listname = list[0]; QStringList l = getUsers(listname); l.removeAll(from); QFile f(manager()->dataDir() + "/msg/" + listname); if (l.count()) { if (!f.open(QIODevice::WriteOnly)) { octInfo("Could not write message file.\n"); return; } QTextStream stream2(&f); for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) stream2 << (*it + "\n"); f.close(); } else f.remove(); QString txt("You unsubscribed from list " + listname); manager()->connectionPlugin()->serverSend(from,txt); }
void tst_QContactRelationship::datastream() { QByteArray buffer; QDataStream stream1(&buffer, QIODevice::WriteOnly); QContactRelationship relationshipIn; QContactId id1; id1.setManagerUri("a"); id1.setLocalId(1); relationshipIn.setFirst(id1); QContactId id2; id2.setManagerUri("b"); id2.setLocalId(2); relationshipIn.setSecond(id2); relationshipIn.setRelationshipType(QContactRelationship::HasMember); stream1 << relationshipIn; QVERIFY(buffer.size() > 0); QDataStream stream2(buffer); QContactRelationship relationshipOut; stream2 >> relationshipOut; QCOMPARE(relationshipOut, relationshipIn); }
bool COfficeFileFormatChecker::isXlsFormatFile (POLE::Storage * storage) { if (storage == NULL) return false; unsigned char buffer[10]; POLE::Stream stream(storage, L"Workbook"); if (stream.read(buffer,10) < 1) { POLE::Stream stream2(storage, L"Book"); if (stream2.read(buffer,10) < 1) { POLE::Stream stream3(storage, L"WORKBOOK"); if (stream3.read(buffer,10) < 1) { POLE::Stream stream4(storage, L"BOOK"); if (stream4.read(buffer,10) < 1) { POLE::Stream stream5(storage, L"book"); if (stream5.read(buffer,10) < 1) return false; } } } } if (storage->isDirectory(L"_VBA_PROJECT_CUR")) { bMacroEnabled = true; } return true; }
Trampoline AmbTest(Search &s) { CapturedVar<int> n, m; CapturedCont c1, c2, c3; UncountedCont c1_u = c1, c2_u = c2, c3_u = c3; combine_refs(c1, c2, c3); //note it can't safely use Search inside of functions that return a value *c1 = [=](Search &s) { return stream1(s, n, trampoline(c2_u, s)); }; *c2 = [=](Search &s) { return stream2(s, m, trampoline(c3_u, s)); }; *c3 = [=](Search &s) { if (*n != *m) return s.fail(); else { s.results.insert_or_assign("n", *n); s.results.insert_or_assign("m", *m); return end_search; } }; cout << c1.get()->use_count() << endl; cout << c2.get()->use_count() << endl; cout << c3.get()->use_count() << endl; return trampoline(c1, s); }