void CProfileViewer::SaveToFile() { // Open the file, if necessary. If this method is called several times, // the profile results will be appended to the previous ones from the same // run. if (! m->outputStream.is_open()) { // Open the file. (It will be closed when the CProfileViewer // destructor is called.) OsPath path = psLogDir()/"profile.txt"; m->outputStream.open(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); if (m->outputStream.fail()) { LOGERROR(L"Failed to open profile log file"); return; } else { LOGMESSAGERENDER(L"Profiler snapshot saved to '%ls'", path.string().c_str()); } } time_t t; time(&t); m->outputStream << "================================================================\n\n"; m->outputStream << "PS profiler snapshot - " << asctime(localtime(&t)); std::vector<AbstractProfileTable*> tables = m->rootTables; sort(tables.begin(), tables.end(), SortByName); for_each(tables.begin(), tables.end(), WriteTable(m->outputStream)); m->outputStream << "\n\n================================================================\n"; m->outputStream.flush(); }
int Table::ReadTableConsole(const char* sFileName) { int ndim; int dim[MAXDIMENS]; int s; double rs; int i, j; printf("Number of Dimensions :: "); if(!scanf("%d", &s)) { return 0; } if(s > MAXDIMENS) { printf("Increase MAXDIMENS!\n"); return 0; } ndim = s; //read the dimensions for(i=0; i<ndim; i++) { printf("Index %d :: ", i+1); if(!scanf("%d", &s)) { return 0; } dim[i] = s; } if(!Alloc(dim, ndim)) { return 0; } int NotFinished = 1; GetFirst(); for(i=0; i<Total; i++) { printf("("); for(j=0; j<nDimens-1; j++) { printf("%d,", Index[j]+1); } printf("%d) :: ", Index[nDimens-1]+1); if(!scanf("%lf", &rs)) { return 0; } Data[i] = rs; if(NotFinished) { NotFinished = GetNext(); } } return WriteTable(sFileName); }
bool GlueFile::CreateGlueFile(const std::string gluefilename) { AMJU_CALL_STACK; std::ios_base::openmode mode = ios::out | ios::binary; #ifdef MSVC m_gluefile.open(gluefilename.c_str(), mode); #else m_gluefile.open(gluefilename.c_str(), mode); #endif if (!m_gluefile.is_open()) { return false; } m_filename = gluefilename; // Set up the GlueFile format. As the file is empty, it's easy. // The number of files is zero, and the positon of the table is // at position 8, i.e. following these two uint32s. But there's no table. m_tablePos = BASE; WriteTable(); return true; }
void IO_UncertSimResults::WriteTableArray(const DC_TableArray& tableArray) { WriteInt(tableArray.Size()); for (int i = 0; i < tableArray.Size(); i++) WriteTable(tableArray[i]); }
bool GlueFile::AddItem(const std::string& filename) { AMJU_CALL_STACK; string lowname = ToLower(filename); // Convert \ to / // So we can add files in subdirs in DOS, which uses "\", and use "/" to // retrieve the subdirs lowname = Replace(lowname, "\\", "/"); // Check for sub-file already existing. if (m_table.find(lowname) != m_table.end()) { // Sub-file already exists std::string s = "GLUE FILE: file already exists in glue file: "; s += filename; ReportError(s); return false; } // Stick the contents of the file onto the end of the final sub-file. // Then update the number of files, the table position, and // rewrite the table. // Get the new sub-file size. struct stat buf; if (stat(filename.c_str(), &buf) != 0) { // Couldn't get info for the sub-file. std::string s = "GLUE FILE: failed to stat file: "; s += filename; ReportError(s); return false; } uint32 subfilesize = buf.st_size; // Open the new sub-file for reading. ifstream subfile; subfile.open(filename.c_str(), ios::in | ios::binary); if (!subfile.is_open()) { std::string s = "GLUE FILE: failed to open file for reading: "; s += filename; ReportError(s); return false; } // Work out where the new sub-file should go in the GlueFile. // It's the position of the final sub-file plus its size. uint32 newpos = BASE; FileList::reverse_iterator rit = m_filenames.rbegin(); if (rit != m_filenames.rend()) { string last = *rit; uint32 lastsize = (m_table[last]).first; uint32 lastpos = (m_table[last]).second; newpos = lastpos + lastsize; } // Seek to the new position. m_gluefile.seekg(newpos); // Write the new sub-file to the GlueFile. #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: Writing file " << filename.c_str() << " starting at pos: " << newpos << " size: " << subfilesize << "\n"; #endif unsigned char* filebuf = new unsigned char[subfilesize]; subfile.read((char*)filebuf, subfilesize); m_gluefile.write((char*)filebuf, subfilesize); delete [] filebuf; // Add the new sub-file to the table. m_table[lowname] = make_pair(subfilesize, newpos); // This reorders m_table, so we also maintain a list of the files // in the order in which they were added to the glue file. m_filenames.push_back(lowname); // New table position m_tablePos += subfilesize; // Rewrite the table. WriteTable(); return true; }