⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tempfile.tex

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 TEX
字号:
% automatically generated by HelpGen from tempfile.tex at 10/Jan/99 19:24:44\section{\class{wxTempFile}}\label{wxtempfile}wxTempFile provides a relatively safe way to replace the contents of theexisting file. The name is explained by the fact that it may be also used asjust a temporary file if you don't replace the old file contents.Usually, when a program replaces the contents of some file it first opens it forwriting, thus losing all of the old data and then starts recreating it. Thisapproach is not very safe because during the regeneration of the file bad thingsmay happen: the program may find that there is an internal error preventing itfrom completing file generation, the user may interrupt it (especially if filegeneration takes long time) and, finally, any other external interrupts (powersupply failure or a disk error) will leave you without either the original fileor the new one.wxTempFile addresses this problem by creating a temporary file which is meant toreplace the original file - but only after it is fully written. So, if the userinterrupts the program during the file generation, the old file won't be lost.Also, if the program discovers itself that it doesn't want to replace the oldfile there is no problem - in fact, wxTempFile will {\bf not} replace the oldfile by default, you should explicitly call \helpref{Commit}{wxtempfilecommit} to do it. Calling \helpref{Discard}{wxtempfilediscard} explicitly discards anymodifications: it closes and deletes the temporary file and leaves the originalfile unchanged. If you don't call neither of Commit() and Discard(), thedestructor will call Discard() automatically.To summarize: if you want to replace another file, create an instance ofwxTempFile passing the name of the file to be replaced to the constructor (youmay also use default constructor and pass the file name to \helpref{Open}{wxtempfileopen}). Then you can \helpref{write}{wxtempfilewrite} to wxTempFile using \helpref{wxFile}{wxfile}-like functions and later callCommit() to replace the old file (and close this one) or call Discard() to cancelthe modifications.\wxheading{Derived from}No base class\wxheading{Include files}<wx/file.h>\wxheading{See also:}\helpref{wxFile}{wxfile}\\\helpref{wxTempFileOutputStream}{wxtempfileoutputstream}\latexignore{\rtfignore{\wxheading{Members}}}\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfilector}\func{}{wxTempFile}{\void}Default constructor - \helpref{Open}{wxtempfileopen} must be used to open thefile.\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfile}\func{}{wxTempFile}{\param{const wxString\& }{strName}}Associates wxTempFile with the file to be replaced and opens it. You should use \helpref{IsOpened}{wxtempfileisopened} to verify if the constructor succeeded.\membersection{wxTempFile::Open}\label{wxtempfileopen}\func{bool}{Open}{\param{const wxString\& }{strName}}Open the temporary file, returns {\tt true} on success, {\tt false} if an erroroccurred.{\it strName} is the name of file to be replaced. The temporary file is alwayscreated in the directory where {\it strName} is. In particular, if {\it strName} doesn't include the path, it is created in the current directoryand the program should have write access to it for the function to succeed.\membersection{wxTempFile::IsOpened}\label{wxtempfileisopened}\constfunc{bool}{IsOpened}{\void}Returns {\tt true} if the file was successfully opened.\membersection{wxTempFile::Length}\label{wxtempfilelength}\constfunc{wxFileOffset}{Length}{\void}Returns the length of the file.\membersection{wxTempFile::Seek}\label{wxtempfileseek}\func{wxFileOffset}{Seek}{\param{wxFileOffset }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}Seeks to the specified position.\membersection{wxTempFile::Tell}\label{wxtempfiletell}\constfunc{wxFileOffset}{Tell}{\void}Returns the current position or wxInvalidOffset if file is not opened or if anothererror occurred.\membersection{wxTempFile::Write}\label{wxtempfilewrite}\func{bool}{Write}{\param{const void }{*p}, \param{size\_t }{n}}Write to the file, return {\tt true} on success, {\tt false} on failure.\membersection{wxTempFile::Write}\label{wxtempfilewrites}\func{bool}{Write}{\param{const wxString\& }{str}, \param{wxMBConv\&}{ conv = wxConvLibc}}Write to the file, return {\tt true} on success, {\tt false} on failure.The second argument is only meaningful in Unicode build of wxWidgets when{\it conv} is used to convert {\it str} to multibyte representation.\membersection{wxTempFile::Commit}\label{wxtempfilecommit}\func{bool}{Commit}{\void}Validate changes: deletes the old file of name m\_strName and renames the newfile to the old name. Returns {\tt true} if both actions succeeded. If {\tt false} isreturned it may unfortunately mean two quite different things: either thateither the old file couldn't be deleted or that the new file couldn't be renamedto the old name.\membersection{wxTempFile::Discard}\label{wxtempfilediscard}\func{void}{Discard}{\void}Discard changes: the old file contents is not changed, temporary file isdeleted.\membersection{wxTempFile::\destruct{wxTempFile}}\label{wxtempfiledtor}\func{}{\destruct{wxTempFile}}{\void}Destructor calls \helpref{Discard()}{wxtempfilediscard} if temporary fileis still opened.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -