mitk::NavigationToolStorageDeserializer::NavigationToolStorageDeserializer(mitk::DataStorage::Pointer dataStorage) { m_DataStorage = dataStorage; //create temp directory for this reader m_tempDirectory = mitk::StandardFileLocations::GetInstance()->GetOptionDirectory() + Poco::Path::separator() + "tempNavigationToolDeserializer"; Poco::File myFile(m_tempDirectory); myFile.createDirectory(); }
// Return my individual prefix: If I'm installed as `/usr/local/bin/ddd', // return `/usr/local'. static string myPrefix() { string my_dir = dirname(myFile()); if (my_dir.contains('/')) return dirname(my_dir); else return my_dir + "/.."; }
QString readFileAsQString(const QString &myFilePath) { QFile myFile(myFilePath); myFile.open(QIODevice::ReadOnly); QTextStream textStream(&myFile); return textStream.readAll(); }
void Graph::CreateNodes() { //pull in text file to "myFile" and parse out nodes //also, put neighbors into the vector of ints inside //each node to create edges later vector<int> nodevalues; int temp; ifstream myFile("map2.txt"); string line; int linenum = 0; Node* n; while (getline (myFile, line)) { linenum++; istringstream linestream(line); string item; int itemnum = 0; while (getline (linestream, item, ',')) { itemnum++; if (itemnum < 5) { temp = atoi(item.c_str()); nodevalues.push_back(temp); if (itemnum == 4) n = new Node(nodevalues[0], Vector3(nodevalues[1], nodevalues[2], nodevalues[3])); } else if (itemnum > 4) { temp = atoi(item.c_str()); n->neighbors.push_back(temp); } } // end while nodes.push_back(n); nodevalues.clear(); } //Drawing da nodes Vector3 tempPos; for(int i = 0; i < (int)nodes.size(); i++) { tempPos = nodes[i]->position; gMyGameWorld->CreateSphere(GLB->circID); gMyGameWorld->SetSpherePosition(GLB->circID, tempPos.x, tempPos.y, tempPos.z); gMyGameWorld->SetSphereColor(GLB->circID, 255, 255, 255); gMyGameWorld->SetSphereScale(GLB->circID, 0.4); if (i < 10) gMyGameWorld->AddSphereText(GLB->circID, "\n\n ", i); else gMyGameWorld->AddSphereText(GLB->circID, "\n\n ", i); nodes.at(i)->SphereID = GLB->circID; GLB->circID++; } }
void ShapeHistoFromTable(TString fileIn = "input.txt", TString fileOutRoot = "output.root", TString fileOutPlot = "output.pdf", Int_t iMark = 20 , Int_t iColor = 3) { vector<float> x; Int_t npt = 0; float a; // read data file ifstream in; in.open(fileIn); while ( kTRUE ) { in >> a; x.push_back(a); if ( ! in.good() ) break; // cout << "# " << npt << " x = " << x[npt] << endl; npt++; } const Int_t ndim = npt; Double_t xx[ndim]; TH1F myHisto("myHisto","myHisto",ndim,0.,float(ndim)); for (Int_t i=0;i<npt;i++) { xx[i] = x[i]; // cout << "# " << i << " x = " << xx[i] << endl; myHisto.Fill(i+0.5,xx[i]); } myHisto.Print("all"); in.close(); TFile myFile(fileOutRoot,"RECREATE"); myHisto.Write(); myFile.Close(); printf(" found %d points\n", npt); TCanvas* c1 = new TCanvas("c1", "c1", 0, 0, 500, 500); c1->cd(); myHisto.Draw(""); c1->Print(fileOutPlot); }
void write_graph_bin(idx nv, idx ne,const idx *xadj,const idx *adj,const wt *ew,const char *filename){ std::ofstream myFile (filename, std::ios::out | std::ios::binary); myFile.write((char *) &nv, sizeof(idx)); myFile.write((char *) &ne, sizeof(idx)); myFile.write((char *) xadj, sizeof(idx) * (nv + 1)); myFile.write((char *) adj, sizeof(idx) * (ne)); myFile.write((char *) ew, sizeof(wt) * (ne)); myFile.close(); }
/** * [both::get_element Realiza a leitura de um elemento] * @param position [valor referente ao ponteiro de acesso ai elemento de interesse] * @param path_file [Caminho para o arquivo binário que contem o elemento] * @return [Dados contidos na posição acessada] */ Person both::get_element(int position, const std::string path_file) { Person pessoa; std::ifstream myFile(path_file, std::ios_base::in|std::ios_base::binary); if (myFile.is_open()) { myFile.seekg(position, std::ios_base::beg); myFile.read(reinterpret_cast<char *>(&pessoa), SIZE_PERSON); // Faço a leitura } return pessoa; }
/** * [both::file_exists Verifica se o arquivo existe ou não] * @param path_file [Caminho para o arquivo] * @return [true caso exista e false caso não exista] */ bool both::file_exists(const std::string path_file) { std::ifstream myFile(path_file, std::ios_base::in); if (myFile.is_open()) { return true; } else { return false; } }
void SearchIndex::run(string searchKey, string fileName, int records){ //-------------------------------------------------------------- //Preconditions: A key string values, a string containing a filename // of an index file, and the total number of records // //Postconditions: The integer value of the search key is returned // if found, else 0 is returned to the calling code // //Variables used: myFile: fstream object that accesses prog5.idx // infile: fstream object to the data file prog5.dat // sKey: integer value of the search key // offset: integer containing the RRN (offset) // keyArr[]: an integer array used to store keys // item: used to reference a Record object // bsearchResult: integer containing the result // of the binarySearchMethod // //-------------------------------------------------------------- fstream myFile(fileName.c_str(), ios::in); fstream infile("../instr/prog5.dat", ios::in); int sKey; sKey = convert(searchKey); int n=0; int key, offset; int keyArr[records]; int i = 0; Record item; while (myFile >> key >> offset) { while(i!=offset){ i++; } //Creates Item objects and writes the information contained within the object to the output file keyArr[i] = key; i=0; n++; } int bSearchResult = binarySearch(keyArr, records, sKey); if (bSearchResult > 0) { getRecord(bSearchResult); } else { cout << "Key not found, please try again." << endl; } }
QString QgsMapLayer::saveSldStyle( const QString &theURI, bool &theResultFlag ) { QString errorMsg; QDomDocument myDocument; exportSldStyle( myDocument, errorMsg ); if ( !errorMsg.isNull() ) { theResultFlag = false; return errorMsg; } QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this ); // check if the uri is a file or ends with .sld, // which indicates that it should become one QString filename; if ( vlayer->providerType() == "ogr" ) { QStringList theURIParts = theURI.split( "|" ); filename = theURIParts[0]; } else if ( vlayer->providerType() == "delimitedtext" ) { filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile(); } else { filename = theURI; } QFileInfo myFileInfo( filename ); if ( myFileInfo.exists() || filename.endsWith( ".sld", Qt::CaseInsensitive ) ) { QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name if ( !myDirInfo.isWritable() ) { return tr( "The directory containing your dataset needs to be writable!" ); } // now construct the file name for our .sld style file QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".sld"; QFile myFile( myFileName ); if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) ) { QTextStream myFileStream( &myFile ); // save as utf-8 with 2 spaces for indents myDocument.save( myFileStream, 2 ); myFile.close(); theResultFlag = true; return tr( "Created default style file as %1" ).arg( myFileName ); } } theResultFlag = false; return tr( "ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename ); }
void QgsSymbol::setNamedPointSymbol( QString name ) { if ( name.startsWith( "svg:" ) ) { // do some sanity checking for svgs... QString myTempName = name; myTempName.replace( "svg:", "" ); QFile myFile( myTempName ); if ( !myFile.exists() ) { QgsDebugMsg( "\n\n\n *** Svg Symbol not found on fs ***" ); QgsDebugMsg( "Name: " + name ); //see if we can resolve the problem... // QStringList svgPaths = QgsApplication::svgPaths(); for ( int i = 0; i < svgPaths.size(); i++ ) { QgsDebugMsg( "SvgPath: " + svgPaths[i] ); QFileInfo myInfo( myTempName ); QString myFileName = myInfo.fileName(); // foo.svg QString myLowestDir = myInfo.dir().dirName(); QString myLocalPath = svgPaths[i] + "/" + myLowestDir + "/" + myFileName; QgsDebugMsg( "Alternative svg path: " + myLocalPath ); if ( QFile( myLocalPath ).exists() ) { name = "svg:" + myLocalPath; QgsDebugMsg( "Svg found in alternative path" ); } else if ( myInfo.isRelative() ) { QFileInfo pfi( QgsProject::instance()->fileName() ); if ( pfi.exists() && QFile( pfi.canonicalPath() + QDir::separator() + myTempName ).exists() ) { name = "svg:" + pfi.canonicalPath() + QDir::separator() + myTempName; QgsDebugMsg( "Svg found in alternative path" ); break; } else { QgsDebugMsg( "Svg not found in project path" ); } } else { //couldnt find the file, no happy ending :-( QgsDebugMsg( "Computed alternate path but no svg there either" ); } } } } mPointSymbolName = name; mCacheUpToDate = mCacheUpToDate2 = false; }
void DependencyExporter::exportUpdateCanvasSize(XSI::CString outputFile, const char *data, unsigned int dataLength){ std::string htmlData(data,dataLength); htmlData = replace(htmlData, "width=\"1000\"", replace("width=\"1000\"","1000", toString(this->width))); htmlData = replace(htmlData, "height=\"500\"", replace("height=\"500\"","500", toString(this->height))); data = htmlData.c_str(); dataLength = htmlData.length(); std::ofstream myFile (outputFile.GetWideString(), std::ios::out | std::ios::binary); myFile.write (data, dataLength); myFile.close(); }
void writeFile(const char * filename, int32_t maxNum) { std::ofstream myFile(filename, std::ofstream::binary); if (debug) printf("Writing file...\r"); // Write data to file for (int32_t i=0; i<maxNum; ++i) { myFile.write(reinterpret_cast<char*>( &i ), sizeof(int32_t)); } myFile.close(); if (debug) printf("Writing file... Finished\n"); }
int VoiceWriteRecognition::Save() { int chunksize, pcmsize, NumSamples, subchunk1size; int audioFormat = 1; int numChannels = 1; int bitsPerSample = BYTERATE; NumSamples = ((long)(NUMPTS / sampleRate) * 1000); pcmsize = sizeof(PCMWAVEFORMAT); ; subchunk1size = 16; int byteRate = sampleRate*numChannels*bitsPerSample / 8; int blockAlign = numChannels*bitsPerSample / 8; int subchunk2size = pWaveHdr1->dwBufferLength*numChannels; chunksize = (36 + subchunk2size); fstream myFile("test.wav", ios::out | ios::binary); // write the wav file per the wav file format myFile.seekp(0, ios::beg); myFile.write("RIFF", 4); // chunk id myFile.write((char*)&chunksize, 4); // chunk size (36 + SubChunk2Size)) myFile.write("WAVE", 4); // format myFile.write("fmt ", 4); // subchunk1ID myFile.write((char*)&subchunk1size, 4); // subchunk1size (16 for PCM) myFile.write((char*)&audioFormat, 2); // AudioFormat (1 for PCM) myFile.write((char*)&numChannels, 2); // NumChannels myFile.write((char*)&sampleRate, 4); // sample rate myFile.write((char*)&byteRate, 4); // byte rate (SampleRate * NumChannels * BitsPerSample/8) myFile.write((char*)&blockAlign, 2); // block align (NumChannels * BitsPerSample/8) myFile.write((char*)&bitsPerSample, 2); // bits per sample myFile.write("data", 4); // subchunk2ID myFile.write((char*)&subchunk2size, 4); // subchunk2size (NumSamples * NumChannels * BitsPerSample/8) myFile.write(pWaveHdr1->lpData, pWaveHdr1->dwBufferLength); // data myFile.close(); //TO DO: Realize buffer for automatic recognition /* unsigned int* buf = new unsigned int[10]; fstream myFile2("test.wav", ios::in | ios::binary); myFile2.seekp(45, ios::beg); myFile2.read((char*)buf, 80); // myFile2.close(); double bbuf = ((double)(short)buf) / 32768; */ return 1; }
std::streampos getSize(const char * filename) { std::ifstream myFile(filename, std::ifstream::binary); if (myFile) { myFile.seekg(0, std::ios_base::end); std::streampos size = myFile.tellg(); myFile.close(); return size; } else return -1; }
string CToolKit::GetFileCid(const string &sFileName) { string sCid; const int BLOCKLEN=20*1024; try { CMyFile myFile(sFileName); myFile.FOpen("r"); struct stat *pStat = myFile.GetStatBuf(); int nSize = pStat->st_size; if (nSize < 3*BLOCKLEN) { WriteRunInfo::WriteLog("filesize is too short, nsize is %d", nSize); return ""; } string sData; //读取文件前面20k char pBuf[BLOCKLEN] = {0}; myFile.FRead(pBuf, BLOCKLEN); sData.append(pBuf, BLOCKLEN); //中间20k int nCenterPos = nSize/3; myFile.FSeek(nCenterPos); myFile.FRead(pBuf, BLOCKLEN); sData.append(pBuf, BLOCKLEN); //后面20k int nEnd = nSize - BLOCKLEN; myFile.FSeek(nEnd); myFile.FRead(pBuf, BLOCKLEN); sData.append(pBuf, BLOCKLEN); unsigned char cid[20]; ctx_sha1 hash; hash.update((unsigned char*)sData.c_str(), sData.length()); hash.finish(cid); char sTmpCid[50] = {0}; char *pEnd = sTmpCid; for (int i=0; i < 20; i++) { //pEnd += sprintf(pEnd, "%02X", cid[i]); pEnd += snprintf(pEnd, sizeof(sTmpCid)-(pEnd - sTmpCid), "%02X", cid[i]); } sCid = string(sTmpCid); } catch (CMyException &e) { WriteRunInfo::WriteLog("error is %s", e.GetErrMsg().c_str()); return ""; } return sCid; }
//runs after all tests void TestQgsOgrProvider::cleanupTestCase() { QgsApplication::exitQgis(); QString myReportFile = QDir::tempPath() + "/qgistest.html"; QFile myFile( myReportFile ); if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) ) { QTextStream myQTextStream( &myFile ); myQTextStream << mReport; myFile.close(); } }
// barebones .OFF file reader, throws away texture coordinates, normals, etc. // stores results in input coords array, packed [x0,y0,z0,x1,y1,z1,...] and // faces array packed [T0a,T0b,T0c,T1a,T1b,T1c,...] void DegradeAnObject::load_obj(const char *filename){ std::string line; std::ifstream myFile (filename); if(myFile.is_open()) { readFromThisObject(myFile, "", 0); myFile.close(); } std::reverse(minFacets.begin(), minFacets.end()); std::reverse(names.begin(), names.end()); std::reverse(coords.begin(), coords.end()); std::reverse(faces.begin(), faces.end()); }
void MainWindow::getTextFile() { QFile myFile(":/file.txt"); myFile.open(QIODevice::ReadOnly); QTextStream textStream(&myFile); QString line = textStream.readAll(); myFile.close(); ui->textEdit->setPlainText(line); QTextCursor textCursor = ui->textEdit->textCursor(); textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); }
void WComm::fileSend(char *fpath) { // Extract only filename from given path. char filename[50]; int i=strlen(fpath); for(;i>0;i--)if(fpath[i-1]=='\\')break; for(int j=0;i<=(int)strlen(fpath);i++)filename[j++]=fpath[i]; //////////////////////////////////////// ifstream myFile (fpath, ios::in|ios::binary|ios::ate); int size = (int)myFile.tellg(); myFile.close(); char filesize[10];itoa(size,filesize,10); send( m_socket, filename, strlen(filename), 0 ); char rec[32] = "";recv( m_socket, rec, 32, 0 ); send( m_socket, filesize, strlen(filesize), 0 ); recv( m_socket, rec, 32, 0 ); FILE *fr = fopen(fpath, "rb"); while(size > 0) { char buffer[1030]; if(size>=1024) { fread(buffer, 1024, 1, fr); send( m_socket, buffer, 1024, 0 ); recv( m_socket, rec, 32, 0 ); } else { fread(buffer, size, 1, fr); buffer[size]='\0'; send( m_socket, buffer, size, 0 ); recv( m_socket, rec, 32, 0 ); } size -= 1024; } fclose(fr); }
void Sound::LoadOptions() { std::ifstream myFile ("options.txt", std::ios::in); std::string str; std::getline( myFile, str); if(str == "" || str == "1") bSoundEnabled=true; else bSoundEnabled=false; myFile.close(); }
void DependencyExporter::exportFile(XSI::CString directory, std::string fileName, const char *data, unsigned int dataLength){ XSI::CString outputFile = directory + fileName.c_str(); bool updateCanvasSize = fileName.compare("index.html")==0; if (updateCanvasSize){ exportUpdateCanvasSize(outputFile, data, dataLength); return; } std::ofstream myFile (outputFile.GetWideString(), std::ios::out | std::ios::binary); myFile.write (data, dataLength); myFile.close(); }
mitk::NavigationToolStorageDeserializer::~NavigationToolStorageDeserializer() { //remove temp directory Poco::File myFile(m_tempDirectory); try { if (myFile.exists()) myFile.remove(); } catch(...) { MITK_ERROR << "Can't remove temp directory " << m_tempDirectory << "!"; } }
void MapConstructor::loadMap(std::string const& fileName) { std::ifstream myFile(fileName.c_str()); std::string line; if (!myFile.is_open()) throw BombermanError::FileError(errno, ": file cannot be opened\n"); while (getline(myFile, line)) { convertLine(line); } myFile.close(); }
AboutZino::AboutZino(QWidget* parent, Qt::WFlags fl) : QDialog (parent,fl), AboutZinoBase() { //required by Qt4 to initialise the ui setupUi(this); readSettings(); qDebug("Reading license file"); QFile myFile(":/LICENSE.txt"); QTextStream myStream(&myFile); QApplication::setOverrideCursor(Qt::WaitCursor); teLicense->setPlainText(myStream.readAll()); QApplication::restoreOverrideCursor(); }
// will be called after the last testfunction was executed. void cleanupTestCase() { QgsApplication::exitQgis(); QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html"; QFile myFile( myReportFile ); if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) ) { QTextStream myQTextStream( &myFile ); myQTextStream << mReport; myFile.close(); //QDesktopServices::openUrl( "file:///" + myReportFile ); } }
void write_edgelist_bin( size_t ne, const idx *edge_begins, const idx *edge_ends, const wt *ew, const char *filename){ std::ofstream myFile (filename, std::ios::out | std::ios::binary); myFile.write((char *) &ne, sizeof(idx)); myFile.write((char *) edge_begins, sizeof(idx) * (ne)); myFile.write((char *) edge_ends, sizeof(idx) * (ne)); myFile.write((char *) ew, sizeof(wt) * (ne)); myFile.close(); }
void FindCrap::getTextFile(){ QFile myFile(":/crap.txt"); // ":/" is needed in every case. myFile.open(QIODevice::ReadOnly); // only reading file QTextStream textStream(&myFile); // knows which file that is being created into stream QString line = textStream.readAll(); // reads entire stream and stores myFile.close(); // Always close stuff in c++ because memory management ui->textEdit->setPlainText(line); // displays in plain text in text area. (larger) QTextCursor textCursor = ui->textEdit->textCursor(); // Stores cursor in variable, textCursor function returns cursor of your mouse and stores in textCursor textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); // allows user to see the words they are looking for? (Questionable) }
void SeperateGoodBadTowers(TString fileName) { ifstream myFile(fileName); ofstream goodFile("goodTowers.txt"); ofstream badFile("badTowers.txt"); goodFile << "cell_ID\t" << "Chi2" << endl; badFile << "cell_ID\t" << "Chi2" << endl; int good, bad; good = bad = 0; if(myFile.is_open()) { string line = ""; std::getline(myFile,line); double a,b,c; a = b = c = 0.5; const Int_t cutoff = 300; while(myFile >> a >> b >> c) { Double_t index, chi1, chi2; index = a; chi1 = b; chi2 = c; if(chi1 < 0) { cout << "Throwing away: " << index << "\t" << chi1 << endl; continue; } if(chi1 < cutoff) { cout << "Good Tower: " << index << "\t" << chi1 << endl; goodFile << index << "\t" << chi1 << endl; good++; continue; } if(chi1 > cutoff) { cout << "Bad Tower: " << index << "\t" << chi1 << endl; badFile << index << "\t" << chi1 << endl; bad++; continue; } } myFile.close(); badFile.close(); goodFile.close(); }
void Widget::on_cipherTextErr_clicked() { DWORD blockLen = 0; HCRYPTPROV hCryptProv; HCRYPTKEY hKey; BYTE *srcData, *newData, *blockData1, *blockData2; QVector<int> values; QFile myFile(fName); plot->clear(); if (myFile.exists()) myFile.open(QIODevice::ReadOnly); else { QMessageBox::critical(0, "Ошибка", "Файл не выбран", QMessageBox::Ok); return; } CryptAcquireContext(&hCryptProv, NULL, MS_DEF_RSA_SCHANNEL_PROV, PROV_RSA_SCHANNEL, CRYPT_VERIFYCONTEXT); CryptGenKey(hCryptProv, CALG_AES_256, 0, &hKey); CryptDecrypt(hKey, 0, true, 0, NULL, &blockLen); srcData = new BYTE[block * blockLen]; newData = new BYTE[block * blockLen]; blockData1 = new BYTE[blockLen]; blockData2 = new BYTE[blockLen]; myFile.read((char*)srcData, block * blockLen); myFile.close(); memcpy((char*)newData, (char*)srcData, block * blockLen); newData[0] = -newData[0]; for (uint i = 0; i < (block * blockLen); i++) { CryptDecrypt(hKey, 0, i < 2, 0, srcData + i, &blockLen); CryptDecrypt(hKey, 0, i < 2, 0, newData + i, &blockLen); } for(uint i = 0; i < (block * blockLen); i += blockLen) { int k = 0; memcpy(blockData1, srcData + i, blockLen); memcpy(blockData2, newData + i, blockLen); for (uint j = i; j < (i + blockLen); j++) k += trueBitsCount(srcData[j] ^ newData[j]); values.push_back(k); } delete[] newData; delete[] srcData; delete[] blockData1; delete[] blockData2; CryptReleaseContext(hCryptProv, 0); CryptDestroyKey(hKey); DrawPlot(plot, values); plot->show(); }