/** Create a file (may be on a supported remote filesystem). \param path Path to file to create. \param asBinary Whether the file should be written in binary mode. \return Pointer to the created stream, or NULL. */ std::ostream *createFile(const std::string& path, bool asBinary) { ostream *ofs(nullptr); #ifdef PDAL_ARBITER_ENABLED arbiter::Arbiter a; const bool remote(a.hasDriver(path) && a.isRemote(path)); if (remote) { try { ofs = new ArbiterOutStream(tempFilename(path), path, asBinary ? ios::out | ios::binary : ios::out); } catch (arbiter::ArbiterError) {} if (ofs && !ofs->good()) { delete ofs; ofs = nullptr; } } else #endif ofs = FileUtils::createFile(path, asBinary); return ofs; }
/** Open a file (potentially on a remote filesystem). \param path Path (potentially remote) of file to open. \param asBinary Whether the file should be opened binary. \return Pointer to stream opened for input. */ std::istream *openFile(const std::string& path, bool asBinary) { #ifdef PDAL_ARBITER_ENABLED arbiter::Arbiter a; if (a.hasDriver(path) && a.isRemote(path)) { try { return new ArbiterInStream(tempFilename(path), path, asBinary ? ios::in | ios::binary : ios::in); } catch (arbiter::ArbiterError) { return nullptr; } } #endif return FileUtils::openFile(path, asBinary); }
void WekaClassifier::saveAsOutput(const std::string &filename) const { // convert to DT std::string tempfile = tempFilename(); outputDescriptionToFile(tempfile); int numInitialLinesToRemove = 3; std::ifstream in(tempfile.c_str()); std::ofstream out(filename.c_str()); std::string line; std::getline(in,line); outputHeader(out); out << std::endl; while (in.good()) { if (numInitialLinesToRemove > 0) numInitialLinesToRemove--; else out << line << std::endl; std::getline(in,line); } in.close(); out.close(); remove(tempfile.c_str()); }
// Save the document bool ctConfigToolDoc::OnSaveDocument(const wxString& filename) { wxBusyCursor cursor; const wxString strOldPath(GetFilename()); // Do some backing up first // This is the backup filename wxString backupFilename(filename); backupFilename += wxT(".bak"); // This is the temporary copy of the backup wxString tempFilename(filename); tempFilename += wxT(".tmp"); if (wxFileExists(tempFilename)) wxRemoveFile(tempFilename); bool leaveBackup = true; bool saved = DoSave(tempFilename); if (saved) { // Remove the old .bak file if (wxFileExists(backupFilename)) { wxRemoveFile(backupFilename); } // Copy the old file to the .bak if (leaveBackup) { if (wxFileExists(filename)) { if (!wxRenameFile(filename, backupFilename)) { wxCopyFile(filename, backupFilename); wxRemoveFile(filename); } } } else { if (wxFileExists(filename)) wxRemoveFile(filename); } // Finally, copy the temporary file to the proper filename if (!wxRenameFile(tempFilename, filename)) { wxCopyFile(tempFilename, filename); wxRemoveFile(tempFilename); } Modify(false); ((ctConfigToolView*)GetFirstView())->OnChangeFilename(); SetDocumentSaved(true); SetFilename(filename); wxGetApp().GetSettings().m_lastFilename = filename; } else { SetFilename(strOldPath); } wxGetApp().GetMainFrame()->UpdateFrameTitle(); return saved; }