void TestDocumentFileSynchronizerFactoryTest::writeToFile( const QString &filePath, const QByteArray &data, const QByteArray &header ) { QFile file; file.setFileName( filePath ); file.open( QIODevice::WriteOnly ); QDataStream outStream( &file ); outStream.writeRawData( header.data(), header.size() ); outStream.writeRawData( data.data(), data.size() ); file.close(); }
bool cc2DViewportLabel::toFile_MeOnly(QFile& out) const { if (!cc2DViewportObject::toFile_MeOnly(out)) return false; //ROI (dataVersion>=21) QDataStream outStream(&out); for (int i=0;i<4;++i) outStream << m_roi[i]; return true; }
bool ccPlane::toFile_MeOnly(QFile& out) const { if (!ccGenericPrimitive::toFile_MeOnly(out)) return false; //parameters (dataVersion>=21) QDataStream outStream(&out); outStream << m_xWidth; outStream << m_yWidth; return true; }
Song TagHelperIface::read(const QString &fileName) { DBUG << fileName; Song resp; QByteArray message; QDataStream outStream(&message, QIODevice::WriteOnly); outStream << QString(__FUNCTION__) << fileName; Reply reply=sendMessage(message); if (reply.status) { QDataStream inStream(reply.data); inStream >> resp; }
void NewstuffModelPrivate::saveRegistry() { QFile output( m_registryFile ); if ( !output.open( QFile::WriteOnly ) ) { mDebug() << "Cannot open " << m_registryFile << " for writing"; } else { QTextStream outStream( &output ); outStream << m_registryDocument.toString( 2 ); outStream.flush(); output.close(); } }
bool QgsRasterFileWriter::writeVRT( const QString& file ) { QFile outputFile( file ); if ( ! outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) { return false; } QTextStream outStream( &outputFile ); mVRTDocument.save( outStream, 2 ); return true; }
// test a wxFile and wxFileInput/OutputStreams of a known type // void FileKindTestCase::TestFd(wxFile& file, bool expected) { CPPUNIT_ASSERT(file.IsOpened()); CPPUNIT_ASSERT((wxGetFileKind(file.fd()) == wxFILE_KIND_DISK) == expected); CPPUNIT_ASSERT((file.GetKind() == wxFILE_KIND_DISK) == expected); wxFileInputStream inStream(file); CPPUNIT_ASSERT(inStream.IsSeekable() == expected); wxFileOutputStream outStream(file); CPPUNIT_ASSERT(outStream.IsSeekable() == expected); }
void CopyToVideoFile() { std::string targetFileName = "../../Samples/SmokeSim/SmokeVideo.raw"; ofstream outStream(targetFileName, std::ios::out|std::ios::binary|std::ios::ate); if (outStream.is_open()) { outStream.write (pixelBuffer, SCREEN_WIDTH * SCREEN_HEIGHT * 4); outStream.close(); } }
bool ccMaterialSet::toFile_MeOnly(QFile& out) const { if (!ccHObject::toFile_MeOnly(out)) return false; //Materials count (dataVersion>=20) uint32_t count = (uint32_t)size(); if (out.write((const char*)&count,4) < 0) return WriteError(); //texture filenames std::set<QString> texFilenames; QDataStream outStream(&out); //Write each material for (ccMaterialSet::const_iterator it = begin(); it!=end(); ++it) { //material name (dataVersion>=20) outStream << it->name; //texture (dataVersion>=20) outStream << it->textureFilename; texFilenames.insert(it->textureFilename); //material colors (dataVersion>=20) //we don't use QByteArray here as it has its own versions! if (out.write((const char*)it->diffuseFront,sizeof(float)*4) < 0) return WriteError(); if (out.write((const char*)it->diffuseBack,sizeof(float)*4) < 0) return WriteError(); if (out.write((const char*)it->ambient,sizeof(float)*4) < 0) return WriteError(); if (out.write((const char*)it->specular,sizeof(float)*4) < 0) return WriteError(); if (out.write((const char*)it->emission,sizeof(float)*4) < 0) return WriteError(); //material shininess (dataVersion>=20) outStream << it->shininessFront; outStream << it->shininessBack; } //now save the number of textures (dataVersion>=37) outStream << static_cast<uint32_t>(texFilenames.size()); //and save the textures (dataVersion>=37) { for (std::set<QString>::const_iterator it=texFilenames.begin(); it!=texFilenames.end(); ++it) { outStream << *it; //name outStream << ccMaterial::GetTexture(*it); //then image } } return true; }
void AssetManager::saveUserCfg(QStringList cfg) { QFile userCfg(LIBS_FILEPATH+TMP_USER_CFG_FILEPATH); userCfg.open(QIODevice::WriteOnly | QIODevice::Text); if (!userCfg.isOpen()) { qDebug() << "Failed to open user cfg."; } QTextStream outStream(&userCfg); for(int i = 0; i < cfg.length(); i++) outStream << cfg[i] << "\n"; userCfg.close(); }
std::string generatePtx(llvm::Module *module, int devMajor, int devMinor) { std::string mcpu; if ((devMajor == 3 && devMinor >= 5) || devMajor > 3) { mcpu = "sm_35"; } else if (devMajor >= 3 && devMinor >= 0) { mcpu = "sm_30"; } else { mcpu = "sm_20"; } // Select target given the module's triple llvm::Triple triple(module->getTargetTriple()); std::string errStr; const llvm::Target* target = nullptr; target = llvm::TargetRegistry::lookupTarget(triple.str(), errStr); iassert(target) << errStr; llvm::TargetOptions targetOptions; std::string features = "+ptx40"; std::unique_ptr<llvm::TargetMachine> targetMachine( target->createTargetMachine(triple.str(), mcpu, features, targetOptions, // llvm::Reloc::PIC_, llvm::Reloc::Default, llvm::CodeModel::Default, llvm::CodeGenOpt::Default)); // Make a passmanager and add emission to string llvm::legacy::PassManager pm; pm.add(new llvm::TargetLibraryInfoWrapperPass(triple)); // Set up constant NVVM reflect mapping llvm::StringMap<int> reflectMapping; reflectMapping["__CUDA_FTZ"] = 1; // Flush denormals to zero pm.add(llvm::createNVVMReflectPass(reflectMapping)); pm.add(llvm::createAlwaysInlinerPass()); targetMachine->Options.MCOptions.AsmVerbose = true; llvm::SmallString<8> ptxStr; llvm::raw_svector_ostream outStream(ptxStr); outStream.SetUnbuffered(); bool failed = targetMachine->addPassesToEmitFile( pm, outStream, targetMachine->CGFT_AssemblyFile, false); iassert(!failed); pm.run(*module); outStream.flush(); return ptxStr.str(); }
void Boonas::writeFile(QString filename) { float x, y, z, w; bool again = true; filename.append(".poly"); QFile* theDestination; theDestination = new QFile(filename); theDestination -> remove(); theDestination -> open(QIODevice::ReadWrite | QIODevice::Text); QTextStream outStream( theDestination ); do // do this loop while ther is more in orig { cursor = orig -> getCurrent(); // cursor is current cursor -> reset(); if(!(orig -> isNotLast())) { again = false; } outStream << "newObject" << endl; do { x = cursor -> getX(); // get point y = cursor -> getY(); z = cursor -> getZ(); w = cursor -> getW(); outStream << x << " " << y << " " << z << " " << w << endl; cursor -> advance(); } while(cursor -> hasNext()); // run through the points! x = cursor -> getX(); // get point y = cursor -> getY(); z = cursor -> getZ(); w = cursor -> getW(); outStream << x << " " << y << " " << z << " " << w << endl; cursor -> reset(); orig -> advance(); // advance what were working with } while(again); theDestination -> close(); delete theDestination; }
void TaskSetWriter::writeJSON() { QJsonArray taskArray; QJsonArray vmArray; map<QString, PeriodicTaskData *> tasksData = TASKS_DATA; map<QString, PeriodicTaskData *>::iterator taskIter; PeriodicTaskData *tempPTask; QJsonObject task; for (taskIter=tasksData.begin(); taskIter != tasksData.end(); taskIter++){ tempPTask = taskIter->second; task["task_name"] = tempPTask->name(); task["phase"] = (int)tempPTask->phase(); task["period"] = (int)tempPTask->ti(); task["deadline"] = (int)tempPTask->di(); task["computation_time"] = (int)tempPTask->ci(); task["kernel"] = tempPTask->kernel(); taskArray.append(task); } map<QString, VMData *> vmData = VMS_DATA; map<QString, VMData *>::iterator vmIter; VMData *tempVM; QJsonObject vm; for (vmIter=vmData.begin(); vmIter != vmData.end(); vmIter++){ tempVM = vmIter->second; vm["VM_name"] = tempVM->name(); vm["budget"] = (int)tempVM->budget(); vm["period"] = (int)tempVM->period(); vmArray.append(vm); } QJsonObject obj; obj["tasks"] = taskArray; obj["VMs"] = vmArray; QFile outputFile(_filename); outputFile.open(QIODevice::WriteOnly); /* Point a QTextStream object at the file */ QTextStream outStream(&outputFile); /* Write the line to the file */ outStream << QJsonDocument(obj).toJson(QJsonDocument::Compact); /* Close the file */ outputFile.close(); }
bool ccPolyline::toFile_MeOnly(QFile& out) const { if (!ccHObject::toFile_MeOnly(out)) return false; //we can't save the associated cloud here (as it may be shared by multiple polylines) //so instead we save it's unique ID (dataVersion>=28) //WARNING: the cloud must be saved in the same BIN file! (responsibility of the caller) ccPointCloud* vertices = dynamic_cast<ccPointCloud*>(m_theAssociatedCloud); if (!vertices) { ccLog::Warning("[ccPolyline::toFile_MeOnly] Polyline vertices is not a ccPointCloud structure?!"); return false; } uint32_t vertUniqueID = (m_theAssociatedCloud ? (uint32_t)vertices->getUniqueID() : 0); if (out.write((const char*)&vertUniqueID,4) < 0) return WriteError(); //number of points (references to) (dataVersion>=28) uint32_t pointCount = size(); if (out.write((const char*)&pointCount,4) < 0) return WriteError(); //points (references to) (dataVersion>=28) for (uint32_t i=0; i<pointCount; ++i) { uint32_t pointIndex = getPointGlobalIndex(i); if (out.write((const char*)&pointIndex,4) < 0) return WriteError(); } QDataStream outStream(&out); //Closing state (dataVersion>=28) outStream << m_isClosed; //RGB Color (dataVersion>=28) outStream << m_rgbColor[0]; outStream << m_rgbColor[1]; outStream << m_rgbColor[2]; //2D mode (dataVersion>=28) outStream << m_mode2D; //Foreground mode (dataVersion>=28) outStream << m_foreground; //The width of the line (dataVersion>=31) outStream << m_width; return true; }
void IncomingClientBase::send(Kiaro::Network::PacketBase *packet, const bool &reliable) { Kiaro::Common::U32 packet_flag = ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT; if (reliable) packet_flag = ENET_PACKET_FLAG_RELIABLE; // TODO: Packet Size Query Kiaro::Support::BitStream outStream(NULL, 0, 0); packet->packData(outStream); ENetPacket *enetPacket = enet_packet_create(outStream.raw(), outStream.length(), packet_flag); enet_peer_send(mInternalClient, 0, enetPacket); }
wxString Instance::ReadVersionFile() { if (!GetVersionFile().FileExists()) return _(""); // Open the file for reading wxFSFile *vFile = wxFileSystem().OpenFile(GetVersionFile().GetFullPath(), wxFS_READ); wxString retVal; wxStringOutputStream outStream(&retVal); outStream.Write(*vFile->GetStream()); wxDELETE(vFile); return retVal; }
void ClientGUI::sendToHost() { QByteArray block; QDataStream outStream(&block, QIODevice::WriteOnly); outStream.setVersion(QDataStream::Qt_4_0); outStream << (quint16)0; // reserve room for total data block size being sent outStream << (quint8)STRING; // set the command outStream << lineEditCommand->text(); // get the text from the command line outStream.device()->seek(0); outStream << (quint16)(block.size() - sizeof(quint16)); // calculate the size of the data textConsole->append(QString("%1 bytes out").arg(block.size() - sizeof(quint16))); m_tcpSocket->write(block); }
// Memory streams should be seekable // void FileKindTestCase::MemoryStream() { char buf[20]; wxMemoryInputStream inStream(buf, sizeof(buf)); CPPUNIT_ASSERT(inStream.IsSeekable()); wxMemoryOutputStream outStream(buf, sizeof(buf)); CPPUNIT_ASSERT(outStream.IsSeekable()); wxBufferedInputStream seekableBufferedInput(inStream); CPPUNIT_ASSERT(seekableBufferedInput.IsSeekable()); wxBufferedOutputStream seekableBufferedOutput(outStream); CPPUNIT_ASSERT(seekableBufferedOutput.IsSeekable()); }
void FileKindTestCase::SocketStream() { wxSocketClient client; wxSocketInputStream inStream(client); CPPUNIT_ASSERT(!inStream.IsSeekable()); wxSocketOutputStream outStream(client); CPPUNIT_ASSERT(!outStream.IsSeekable()); wxBufferedInputStream nonSeekableBufferedInput(inStream); CPPUNIT_ASSERT(!nonSeekableBufferedInput.IsSeekable()); wxBufferedOutputStream nonSeekableBufferedOutput(outStream); CPPUNIT_ASSERT(!nonSeekableBufferedOutput.IsSeekable()); }
bool ccBox::toFile_MeOnly(QFile& out) const { if (!ccGenericPrimitive::toFile_MeOnly(out)) return false; //parameters (dataVersion>=21) QDataStream outStream(&out); outStream << m_dims.x; outStream << m_dims.y; outStream << m_dims.z; return true; }
int main(int argc, char** argv) { // declare filestreams std::ifstream inStream1(inputFile1); std::ifstream inStream2(inputFile2); std::ofstream outStream(outFile); // call to merge() function per instrucitons merge(inStream1, inStream2, outStream); return 0; }
bool ccDish::toFile_MeOnly(QFile& out) const { if (!ccGenericPrimitive::toFile_MeOnly(out)) return false; //parameters (dataVersion>=21) QDataStream outStream(&out); outStream << m_baseRadius; outStream << m_secondRadius; outStream << m_height; return true; }
void Filter::write_filters() { QString name = qApp->applicationDirPath() + QDir::separator() + "filters.gsd"; QFile file(name); // создаем объект класса QFile if(file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) // открываем для записи и предварительно полностью обнуляем файл { QTextStream outStream(&file); for (int i = 0; i < filters.size(); i++) outStream << filters.at(i).GetEncodedTitle() << endl; file.close(); // записали и закрыли } }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void FilterMaker::updateTestLocations() { QString filterName = this->filterName->text(); QString pluginDir = this->pluginDir->text(); QString testPath = pluginDir + "/Test/TestFileLocations.h.in"; testPath = QDir::toNativeSeparators(testPath); QFile source(testPath); source.open(QFile::ReadOnly); QString contents = source.readAll(); source.close(); QString namespaceStr = createNamespaceString(); // Check to make sure we don't already have this filter in the namespace if (contents.contains(namespaceStr) == true) { return; } QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); QString searchString = "#endif"; while (sourceLines.hasNext()) { QString line = sourceLines.next(); if (line.contains(searchString)) { QString str("namespace UnitTest\n{"); QTextStream outStream(&str); outStream << namespaceStr << "\n"; outStream << "}\n"; outLines.push_back(str); outLines.push_back(line); } else { outLines.push_back(line); } } source.remove(); if (source.open(QIODevice::WriteOnly)) { source.write(outLines.join("\n").toLatin1().data()); source.close(); } }
void CFortEdit::InvokeEngine(QAbstractButton* button) { if (DInvocationUi.buttonBox->button(QDialogButtonBox::Ok) == button) { // Save the current map into a temp map file QString MapPath = QDir::current().absoluteFilePath("temp.map"); QFile outputFile(MapPath); try { DScene->SetAiPath(QDir::current().absoluteFilePath("temp.ai")); QString MapData = DScene->WriteToFile(); outputFile.open(QIODevice::WriteOnly); if (!outputFile.isOpen()){ QMessageBox* Msg = new QMessageBox; Msg->setText(QString("Error saving! %1,\nCan't open the file. Is it in use by another program?" ).arg(MapPath)); Msg->show(); } else { QTextStream outStream(&outputFile); outStream << MapData; outputFile.close(); } } catch (CMapException& E) { QMessageBox* Msg = new QMessageBox; Msg->setText(QString("Error saving! %1,\n%2" ).arg(MapPath).arg(E.Message())); Msg->show(); return; } QStringList Arg; Arg << "-dev "; Arg << "-mode " + DInvocationUi.modeCombo->itemText(DInvocationMode).toUpper(); Arg << "-map " + MapPath; Arg << "-ai " + DInvocationUi.aiCombo->itemText(DInvocationDifficulty).toUpper(); Arg << (DInvocationWind ? "-wind ON" : "-wind OFF"); if (DInvocationIndex > 0) { Arg << "-castle " << QString::number(DInvocationIndex); } qDebug() << Arg; QProcess* FortNitta = new QProcess(0); FortNitta->start(DEnginePath, Arg); } }
bool DepExportDialog::depExport(QFile *outputFile) { /* Try and open a file for output */ outputFile->open(QIODevice::WriteOnly); /* Check it opened OK */ if(!outputFile->isOpen()){ qDebug() << "- Error, unable to open" << outputFile->fileName() << "for output"; return false; } /* Point a QTextStream object at the file */ QTextStream outStream(outputFile); QSqlDatabase dbc = QSqlDatabase::database("CN"); QSqlQuery q(dbc); q.prepare(QString("SELECT text FROM dep WHERE id < 4")); q.exec(); while (q.next()) { /* Write the line to the file */ outStream << q.value(0).toString() + "\n"; } QString query = QString("SELECT version, cashregisterid, text FROM dep WHERE datetime BETWEEN '%1' AND '%2' AND id > 3").arg(fromDT->toString(Qt::ISODate)).arg(toDT->toString(Qt::ISODate)); // qDebug() << "DepExportDialog::onExportButton_clicked() query:" << query; q.prepare(query); q.exec(); int i = 0; int count = q.record().count(); progressbar->setMaximum(count); while (q.next()) { i++; progressbar->setValue(i); QString s = QString("%1\t%2\t%3\t%4\n").arg(i).arg(q.value(0).toString()).arg(q.value(1).toString()).arg(q.value(2).toString()); outStream << s; } /* Close the file */ outputFile->close(); return true; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void CheckFile(const std::string &filepath, const std::string &filename, const std::string &extension) { std::cout << "|-- CheckFile " << filepath << std::endl; bool exists; bool isDir; bool isFile; bool ok; { // Write a file so we can try and delete it std::cout << "|-- Create: '" << filepath << "'" << std::endl; std::ofstream outStream(filepath.c_str(), std::ios::out | std::ios::binary); DREAM3D_REQUIRE_EQUAL(false, outStream.fail() ); std::string data ( "MXADir_Test Contents"); outStream.write(data.c_str(), data.length()); DREAM3D_REQUIRE_EQUAL (outStream.bad(), false); outStream.close(); } std::string compName = filename; if (compName.at(compName.size()-1) == '.') { compName = compName.substr(0, compName.size() - 1); } isDir = MXADir::isDirectory(filepath); DREAM3D_REQUIRE_EQUAL(isDir, false); isFile = MXADir::isFile(filepath); DREAM3D_REQUIRE_EQUAL(isFile, true); exists = MXADir::exists(filepath); DREAM3D_REQUIRE_EQUAL(exists, true); std::string fn = MXAFileInfo::filename(filepath); DREAM3D_REQUIRE_EQUAL(fn, compName); std::string ext = MXAFileInfo::extension(filepath); DREAM3D_REQUIRE_EQUAL(ext, extension); // Now try to delete the file std::cout << "|-- Delete: '" << filepath << "'" << std::endl; ok = MXADir::remove(filepath); DREAM3D_REQUIRE_EQUAL(ok, true); exists = MXADir::exists(filepath); DREAM3D_REQUIRE_EQUAL(exists, false); std::cout << "|-- Delete Again:" << std::endl; ok = MXADir::remove(filepath); DREAM3D_REQUIRE_EQUAL(ok, false); }
/* Write new configuration boolean property to the Fort's * configuration file. * * Returns true on success, false on failure. */ bool SettingsParser::setBoolean(QString property, bool value) { bool retval = false; QList<QString> *lines = readAllConfigurationLines(); QString valueStr; if(value) valueStr = "true"; else valueStr = "false"; QString setting = property + "=" + valueStr; QFile file(_settingsPath); if(file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { QTextStream outStream(&file); bool found = false; for(int i = 0; i < lines->count(); i++) { QString line = lines->at(i); QStringList tokens = line.split("="); if(tokens.length() > 0) { if(tokens[0].compare(setting.split("=")[0]) != 0) outStream << line + "\n"; else if(tokens[0].compare(setting.split("=")[0]) == 0) { outStream << setting + "\n"; found = true; } } } if(!found) outStream << setting + "\n"; file.close(); retval = true; } delete lines; return retval; }
void Widget::on_pushButton_clicked() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save Plot to File"), "data.csv", tr("Comma Separated Values (*.csv)")); QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream outStream(&file); for(int i = 0; i < plotData.size(); ++i) { outStream << plotData.xs[i] << ", " << plotData.ys[i] << '\n'; } }
bool ccTorus::toFile_MeOnly(QFile& out) const { if (!ccGenericPrimitive::toFile_MeOnly(out)) return false; //parameters (dataVersion>=21) QDataStream outStream(&out); outStream << m_insideRadius; outStream << m_outsideRadius; outStream << m_rectSection; outStream << m_rectSectionHeight; outStream << m_angle_rad; return true; }