]>
Commit | Line | Data |
---|---|---|
f3845e88 VZ |
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 | %% Name: ffile.tex | |
3 | %% Purpose: wxFFile documentation | |
4 | %% Author: Vadim Zeitlin | |
5 | %% Modified by: | |
6 | %% Created: 14.01.02 (extracted from file.tex) | |
7 | %% RCS-ID: $Id$ | |
8 | %% Copyright: (c) Vadim Zeitlin | |
fc2171bd | 9 | %% License: wxWidgets license |
f3845e88 VZ |
10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
11 | ||
12 | \section{\class{wxFFile}}\label{wxffile} | |
13 | ||
14 | wxFFile implements buffered file I/O. This is a very small class designed to | |
15 | minimize the overhead of using it - in fact, there is hardly any overhead at | |
16 | all, but using it brings you automatic error checking and hides differences | |
17 | between platforms and compilers. It wraps inside it a {\tt FILE *} handle used | |
18 | by standard C IO library (also known as {\tt stdio}). | |
19 | ||
20 | \wxheading{Derived from} | |
21 | ||
22 | None. | |
23 | ||
24 | \wxheading{Include files} | |
25 | ||
26 | <wx/ffile.h> | |
27 | ||
28 | \twocolwidtha{7cm} | |
29 | \begin{twocollist}\itemsep=0pt% | |
30 | \twocolitem{{\bf wxFromStart}}{Count offset from the start of the file} | |
31 | \twocolitem{{\bf wxFromCurrent}}{Count offset from the current position of the file pointer} | |
32 | \twocolitem{{\bf wxFromEnd}}{Count offset from the end of the file (backwards)} | |
33 | \end{twocollist} | |
34 | ||
35 | \latexignore{\rtfignore{\wxheading{Members}}} | |
36 | ||
8cf8a85e | 37 | |
b236c10f | 38 | \membersection{wxFFile::wxFFile}\label{wxffilector} |
f3845e88 VZ |
39 | |
40 | \func{}{wxFFile}{\void} | |
41 | ||
42 | Default constructor. | |
43 | ||
44 | \func{}{wxFFile}{\param{const char*}{ filename}, \param{const char*}{ mode = "r"}} | |
45 | ||
46 | Opens a file with the given mode. As there is no way to return whether the | |
47 | operation was successful or not from the constructor you should test the | |
48 | return value of \helpref{IsOpened}{wxffileisopened} to check that it didn't | |
49 | fail. | |
50 | ||
51 | \func{}{wxFFile}{\param{FILE*}{ fp}} | |
52 | ||
53 | Opens a file with the given file pointer, which has already been opened. | |
54 | ||
55 | \wxheading{Parameters} | |
56 | ||
57 | \docparam{filename}{The filename.} | |
58 | ||
59 | \docparam{mode}{The mode in which to open the file using standard C strings. | |
60 | Note that you should use {\tt "b"} flag if you use binary files under Windows | |
61 | or the results might be unexpected due to automatic newline conversion done | |
62 | for the text files.} | |
63 | ||
64 | \docparam{fp}{An existing file descriptor, such as stderr.} | |
65 | ||
8cf8a85e | 66 | |
b236c10f | 67 | \membersection{wxFFile::\destruct{wxFFile}}\label{wxffiledtor} |
f3845e88 VZ |
68 | |
69 | \func{}{\destruct{wxFFile}}{\void} | |
70 | ||
71 | Destructor will close the file. | |
72 | ||
73 | NB: it is not virtual so you should {\it not} derive from wxFFile! | |
74 | ||
8cf8a85e | 75 | |
f3845e88 VZ |
76 | \membersection{wxFFile::Attach}\label{wxffileattach} |
77 | ||
78 | \func{void}{Attach}{\param{FILE*}{ fp}} | |
79 | ||
80 | Attaches an existing file pointer to the wxFFile object. | |
81 | ||
82 | The descriptor should be already opened and it will be closed by wxFFile | |
83 | object. | |
84 | ||
8cf8a85e | 85 | |
f3845e88 VZ |
86 | \membersection{wxFFile::Close}\label{wxffileclose} |
87 | ||
88 | \func{bool}{Close}{\void} | |
89 | ||
8cf8a85e VZ |
90 | Closes the file and returns \true on success. |
91 | ||
f3845e88 VZ |
92 | |
93 | \membersection{wxFFile::Detach}\label{wxffiledetach} | |
94 | ||
95 | \func{void}{Detach}{\void} | |
96 | ||
8cf8a85e VZ |
97 | Get back a file pointer from wxFFile object -- the caller is responsible for closing the file if this |
98 | descriptor is opened. \helpref{IsOpened()}{wxffileisopened} will return \false after call to Detach(). | |
99 | ||
f3845e88 VZ |
100 | |
101 | \membersection{wxFFile::fp}\label{wxffilefp} | |
102 | ||
103 | \constfunc{FILE *}{fp}{\void} | |
104 | ||
105 | Returns the file pointer associated with the file. | |
106 | ||
8cf8a85e | 107 | |
f3845e88 VZ |
108 | \membersection{wxFFile::Eof}\label{wxffileeof} |
109 | ||
110 | \constfunc{bool}{Eof}{\void} | |
111 | ||
8cf8a85e | 112 | Returns \true if the an attempt has been made to read {\it past} |
f3845e88 VZ |
113 | the end of the file. |
114 | ||
115 | Note that the behaviour of the file descriptor based class | |
116 | \helpref{wxFile}{wxfile} is different as \helpref{wxFile::Eof}{wxfileeof} | |
8cf8a85e | 117 | will return \true here as soon as the last byte of the file has been |
f3845e88 VZ |
118 | read. |
119 | ||
8cf8a85e VZ |
120 | Also note that this method may only be called for opened files and may crash if |
121 | the file is not opened. | |
122 | ||
123 | \wxheading{See also} | |
124 | ||
125 | \helpref{IsOpened}{wxffileisopened} | |
126 | ||
127 | ||
128 | \membersection{wxFFile::Error}\label{wxffileerror} | |
129 | ||
130 | Returns \true if an error has occured on this file, similar to the standard | |
131 | \texttt{ferror()} function. | |
132 | ||
133 | Please note that this method may only be called for opened files and may crash | |
134 | if the file is not opened. | |
135 | ||
136 | \wxheading{See also} | |
137 | ||
138 | \helpref{IsOpened}{wxffileisopened} | |
139 | ||
140 | ||
f3845e88 VZ |
141 | \membersection{wxFFile::Flush}\label{wxffileflush} |
142 | ||
143 | \func{bool}{Flush}{\void} | |
144 | ||
8cf8a85e VZ |
145 | Flushes the file and returns \true on success. |
146 | ||
f3845e88 | 147 | |
0912690b | 148 | \membersection{wxFFile::GetKind}\label{wxffilegetfilekind} |
3c70014d | 149 | |
0912690b | 150 | \constfunc{wxFileKind}{GetKind}{\void} |
3c70014d MW |
151 | |
152 | Returns the type of the file. Possible return values are: | |
153 | ||
154 | \begin{verbatim} | |
0912690b | 155 | enum wxFileKind |
3c70014d | 156 | { |
0912690b MW |
157 | wxFILE_KIND_UNKNOWN, |
158 | wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets | |
159 | wxFILE_KIND_TERMINAL, // a tty | |
160 | wxFILE_KIND_PIPE // a pipe | |
3c70014d MW |
161 | }; |
162 | ||
163 | \end{verbatim} | |
164 | ||
165 | ||
f3845e88 VZ |
166 | \membersection{wxFFile::IsOpened}\label{wxffileisopened} |
167 | ||
168 | \constfunc{bool}{IsOpened}{\void} | |
169 | ||
8cf8a85e VZ |
170 | Returns \true if the file is opened. Most of the methods of this class may only |
171 | be used for an opened file. | |
172 | ||
f3845e88 VZ |
173 | |
174 | \membersection{wxFFile::Length}\label{wxffilelength} | |
175 | ||
70a7bd90 | 176 | \constfunc{wxFileOffset}{Length}{\void} |
f3845e88 VZ |
177 | |
178 | Returns the length of the file. | |
179 | ||
8cf8a85e | 180 | |
f3845e88 VZ |
181 | \membersection{wxFFile::Open}\label{wxffileopen} |
182 | ||
183 | \func{bool}{Open}{\param{const char*}{ filename}, \param{const char*}{ mode = "r"}} | |
184 | ||
8cf8a85e | 185 | Opens the file, returning \true if successful. |
f3845e88 VZ |
186 | |
187 | \wxheading{Parameters} | |
188 | ||
189 | \docparam{filename}{The filename.} | |
190 | ||
191 | \docparam{mode}{The mode in which to open the file.} | |
192 | ||
8cf8a85e | 193 | |
f3845e88 VZ |
194 | \membersection{wxFFile::Read}\label{wxffileread} |
195 | ||
70a7bd90 | 196 | \func{size\_t}{Read}{\param{void*}{ buffer}, \param{size\_t}{ count}} |
f3845e88 VZ |
197 | |
198 | Reads the specified number of bytes into a buffer, returning the actual number read. | |
199 | ||
200 | \wxheading{Parameters} | |
201 | ||
202 | \docparam{buffer}{A buffer to receive the data.} | |
203 | ||
204 | \docparam{count}{The number of bytes to read.} | |
205 | ||
206 | \wxheading{Return value} | |
207 | ||
208 | The number of bytes read. | |
209 | ||
8cf8a85e | 210 | |
f3845e88 VZ |
211 | \membersection{wxFFile::Seek}\label{wxffileseek} |
212 | ||
70a7bd90 | 213 | \func{bool}{Seek}{\param{wxFileOffset }{ofs}, \param{wxSeekMode }{mode = wxFromStart}} |
f3845e88 | 214 | |
8cf8a85e | 215 | Seeks to the specified position and returns \true on success. |
f3845e88 VZ |
216 | |
217 | \wxheading{Parameters} | |
218 | ||
219 | \docparam{ofs}{Offset to seek to.} | |
220 | ||
221 | \docparam{mode}{One of {\bf wxFromStart}, {\bf wxFromEnd}, {\bf wxFromCurrent}.} | |
222 | ||
8cf8a85e | 223 | |
f3845e88 VZ |
224 | \membersection{wxFFile::SeekEnd}\label{wxffileseekend} |
225 | ||
70a7bd90 | 226 | \func{bool}{SeekEnd}{\param{wxFileOffset }{ofs = 0}} |
f3845e88 VZ |
227 | |
228 | Moves the file pointer to the specified number of bytes before the end of the file | |
8cf8a85e | 229 | and returns \true on success. |
f3845e88 VZ |
230 | |
231 | \wxheading{Parameters} | |
232 | ||
233 | \docparam{ofs}{Number of bytes before the end of the file.} | |
234 | ||
8cf8a85e | 235 | |
f3845e88 VZ |
236 | \membersection{wxFFile::Tell}\label{wxffiletell} |
237 | ||
70a7bd90 | 238 | \constfunc{wxFileOffset}{Tell}{\void} |
f3845e88 VZ |
239 | |
240 | Returns the current position. | |
241 | ||
8cf8a85e | 242 | |
f3845e88 VZ |
243 | \membersection{wxFFile::Write}\label{wxffilewrite} |
244 | ||
245 | \func{size\_t}{Write}{\param{const void*}{ buffer}, \param{size\_t}{ count}} | |
246 | ||
247 | Writes the specified number of bytes from a buffer. | |
248 | ||
249 | \wxheading{Parameters} | |
250 | ||
251 | \docparam{buffer}{A buffer containing the data.} | |
252 | ||
253 | \docparam{count}{The number of bytes to write.} | |
254 | ||
255 | \wxheading{Return value} | |
256 | ||
257 | Number of bytes written. | |
258 | ||
8cf8a85e | 259 | |
f3845e88 VZ |
260 | \membersection{wxFFile::Write}\label{wxffilewrites} |
261 | ||
d3c0ce34 | 262 | \func{bool}{Write}{\param{const wxString\& }{s}, \param{wxMBConv\&}{ conv = wxConvUTF8}} |
f3845e88 | 263 | |
8cf8a85e | 264 | Writes the contents of the string to the file, returns \true on success. |
f3845e88 | 265 | |
fc2171bd | 266 | The second argument is only meaningful in Unicode build of wxWidgets when |
f3845e88 VZ |
267 | {\it conv} is used to convert {\it s} to multibyte representation. |
268 | ||
269 |