]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tempfile.tex
Doc mods, sash window bug
[wxWidgets.git] / docs / latex / wx / tempfile.tex
CommitLineData
7f561143
VZ
1% automatically generated by HelpGen from tempfile.tex at 10/Jan/99 19:24:44
2\section{\class{wxTempFile}}\label{wxtempfile}
3
4wxTempFile provides a relatively safe way to replace the contents of the
5existing file. The name is explained by the fact that it may be also used as
6just a temporary file if you don't replace the old file contents.
7
8Usually, when a program replaces the contents of some file it first opens it for
9writing, thus losing all of the old data and then starts recreating it. This
10approach is not very safe because during the regeneration of the file bad things
11may happen: the program may find that there is an internal error preventing it
12from completing file generation, the user may interrupt it (especially if file
13generation takes long time) and, finally, any other external interrupts (power
14supply failure or a disk error) will leave you without either the original file
15or the new one.
16
17wxTempFile addresses this problem by creating a temporary file which is meant to
18replace the original file - but only after it is fully written. So, if the user
19interrupts the program during the file generation, the old file won't be lost.
20Also, if the program discovers itself that it doesn't want to replace the old
21file there is no problem - in fact, wxTempFile will {\bf not} replace the old
22file by default, you should explicitly call \helpref{Commit}{wxtempfilecommit}
23to do it. Calling \helpref{Discard}{wxtempfilediscard} explicitly discards any
24modifications: it closes and deletes the temporary file and leaves the original
25file unchanged. If you don't call neither of Commit() and Discard(), the
26destructor will call Discard() automatically.
27
28To summarize: if you want to replace another file, create an instance of
29wxTempFile passing the name of the file to be replaced to the constructor (you
30may also use default constructor and pass the file name to
31\helpref{Open}{wxtempfileopen}). Then you can \helpref{write}{wxtempfilewrite}
32to wxTempFile using \helpref{wxFile}{wxfile}-like functions and later call
33Commit() to replace the old file (and close this one) or call Discard() to cancel
34the modifications.
35
36\wxheading{Derived from}
37
38No base class
39
40\wxheading{See also:}
41
42\helpref{wxFile}{wxfile}
43
44\latexignore{\rtfignore{\wxheading{Members}}}
45
46\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfilector}
47\func{}{wxTempFile}{\void}
48
49Default constructor - \helpref{Open}{wxtempfileopen} must be used to open the
50file.
51
52\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfile}
53\func{}{wxTempFile}{\param{const wxString\& }{strName}}
54
55Associates wxTempFile with the file to be replaced and opens it. You should use
56\helpref{IsOpened}{wxtempfileisopened} to verify if the constructor succeeded.
57
58\membersection{wxTempFile::Open}\label{wxtempfileopen}
59\func{bool}{Open}{\param{const wxString\& }{strName}}
60
61Open the temporary file (strName is the name of file to be replaced), returns
62TRUE on success, FALSE if an error occured.
63
64\membersection{wxTempFile::IsOpened}\label{wxtempfileisopened}
65\constfunc{bool}{IsOpened}{\void}
66
67Returns TRUE if the file was successfully opened.
68
69\membersection{wxTempFile::Write}\label{wxtempfilewrite}
70\func{bool}{Write}{\param{const void }{*p}, \param{size\_t }{n}}
71
72Write to the file, return TRUE on success, FALSE on failure.
73
74\membersection{wxTempFile::Write}\label{wxtempfilewrites}
75\func{bool}{Write}{\param{const wxString\& }{str}}
76
77Write to the file, return TRUE on success, FALSE on failure.
78
79\membersection{wxTempFile::Commit}\label{wxtempfilecommit}
80\func{bool}{Commit}{\void}
81
82Validate changes: deletes the old file of name m\_strName and renames the new
83file to the old name. Returns TRUE if both actions succeeded. If FALSE is
84returned it may unfortunately mean two quite different things: either that
85either the old file couldn't be deleted or that the new file couldn't be renamed
86to the old name.
87
88\membersection{wxTempFile::Discard}\label{wxtempfilediscard}
89\func{void}{Discard}{\void}
90
91Discard changes: the old file contents is not changed, temporary file is
92deleted.
93
94\membersection{wxTempFile::\destruct{wxTempFile}}\label{wxtempfiledtor}
95\func{}{\destruct{wxTempFile}}{\void}
96
97Destructor calls \helpref{Discard()}{wxtempfilediscard} if temporary file
98is still opened.
99