]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tempfile.tex
Added AdvanceSelection, ShowWindowMenu and keyboard handling
[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
954b8ae6
JS
40\wxheading{Include files}
41
42<wx/file.h>
43
a7af285d
VZ
44\wxheading{Library}
45
46\helpref{wxBase}{librarieslist}
47
7f561143
VZ
48\wxheading{See also:}
49
e1265174
MW
50\helpref{wxFile}{wxfile}\\
51\helpref{wxTempFileOutputStream}{wxtempfileoutputstream}
7f561143
VZ
52
53\latexignore{\rtfignore{\wxheading{Members}}}
54
55\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfilector}
b2cf617c 56
7f561143
VZ
57\func{}{wxTempFile}{\void}
58
59Default constructor - \helpref{Open}{wxtempfileopen} must be used to open the
60file.
61
62\membersection{wxTempFile::wxTempFile}\label{wxtempfilewxtempfile}
b2cf617c 63
7f561143
VZ
64\func{}{wxTempFile}{\param{const wxString\& }{strName}}
65
b2cf617c 66Associates wxTempFile with the file to be replaced and opens it. You should use
7f561143
VZ
67\helpref{IsOpened}{wxtempfileisopened} to verify if the constructor succeeded.
68
69\membersection{wxTempFile::Open}\label{wxtempfileopen}
b2cf617c 70
7f561143
VZ
71\func{bool}{Open}{\param{const wxString\& }{strName}}
72
cc81d32f 73Open the temporary file, returns {\tt true} on success, {\tt false} if an error
44b62d54
VZ
74occurred.
75
76{\it strName} is the name of file to be replaced. The temporary file is always
77created in the directory where {\it strName} is. In particular, if
78{\it strName} doesn't include the path, it is created in the current directory
79and the program should have write access to it for the function to succeed.
7f561143
VZ
80
81\membersection{wxTempFile::IsOpened}\label{wxtempfileisopened}
44b62d54 82
7f561143
VZ
83\constfunc{bool}{IsOpened}{\void}
84
cc81d32f 85Returns {\tt true} if the file was successfully opened.
7f561143 86
e1265174
MW
87\membersection{wxTempFile::Length}\label{wxtempfilelength}
88
89\constfunc{wxFileOffset}{Length}{\void}
90
91Returns the length of the file.
92
93\membersection{wxTempFile::Seek}\label{wxtempfileseek}
94
95\func{wxFileOffset}{Seek}{\param{wxFileOffset }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}
96
97Seeks to the specified position.
98
99\membersection{wxTempFile::Tell}\label{wxtempfiletell}
100
101\constfunc{wxFileOffset}{Tell}{\void}
102
103Returns the current position or wxInvalidOffset if file is not opened or if another
104error occurred.
105
7f561143 106\membersection{wxTempFile::Write}\label{wxtempfilewrite}
b2cf617c 107
7f561143
VZ
108\func{bool}{Write}{\param{const void }{*p}, \param{size\_t }{n}}
109
cc81d32f 110Write to the file, return {\tt true} on success, {\tt false} on failure.
7f561143
VZ
111
112\membersection{wxTempFile::Write}\label{wxtempfilewrites}
b2cf617c 113
5487ff0f 114\func{bool}{Write}{\param{const wxString\& }{str}, \param{const wxMBConv\&}{ conv = wxConvUTF8}}
7f561143 115
cc81d32f 116Write to the file, return {\tt true} on success, {\tt false} on failure.
7f561143 117
fc2171bd 118The second argument is only meaningful in Unicode build of wxWidgets when
1facd32a
VS
119{\it conv} is used to convert {\it str} to multibyte representation.
120
7f561143 121\membersection{wxTempFile::Commit}\label{wxtempfilecommit}
b2cf617c 122
7f561143
VZ
123\func{bool}{Commit}{\void}
124
125Validate changes: deletes the old file of name m\_strName and renames the new
cc81d32f 126file to the old name. Returns {\tt true} if both actions succeeded. If {\tt false} is
7f561143
VZ
127returned it may unfortunately mean two quite different things: either that
128either the old file couldn't be deleted or that the new file couldn't be renamed
129to the old name.
130
131\membersection{wxTempFile::Discard}\label{wxtempfilediscard}
b2cf617c 132
7f561143
VZ
133\func{void}{Discard}{\void}
134
135Discard changes: the old file contents is not changed, temporary file is
136deleted.
137
138\membersection{wxTempFile::\destruct{wxTempFile}}\label{wxtempfiledtor}
b2cf617c 139
7f561143
VZ
140\func{}{\destruct{wxTempFile}}{\void}
141
142Destructor calls \helpref{Discard()}{wxtempfilediscard} if temporary file
143is still opened.
144