]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/file.tex
Chnaged includes to work without precompiled headers
[wxWidgets.git] / docs / latex / wx / file.tex
CommitLineData
a660d684
KB
1\section{\class{wxFile}}\label{wxfile}
2
247aba10
VZ
3A wxFile performs raw file I/O. This is a very small class designed to
4minimize the overhead of using it - in fact, there is hardly any overhead at
5all, but using it brings you automatic error checking and hides differences
e694c22c
VZ
6between platforms and compilers. wxFile also automatically closes the file in
7its destructor making it unnecessary to worry about forgetting to do it.
a660d684
KB
8
9\wxheading{Derived from}
10
11None.
12
954b8ae6
JS
13\wxheading{Include files}
14
15<wx/file.h>
16
247aba10
VZ
17\wxheading{Constants}
18
19wx/file.h defines the following constants:
6be663cf 20
247aba10
VZ
21\begin{verbatim}
22#define wxS_IRUSR 00400
23#define wxS_IWUSR 00200
24#define wxS_IXUSR 00100
25
26#define wxS_IRGRP 00040
27#define wxS_IWGRP 00020
28#define wxS_IXGRP 00010
29
30#define wxS_IROTH 00004
31#define wxS_IWOTH 00002
32#define wxS_IXOTH 00001
33
34// default mode for the new files: corresponds to umask 022
35#define wxS_DEFAULT (wxS_IRUSR | wxS_IWUSR | wxS_IRGRP | wxS_IWGRP | wxS_IROTH | wxS_IWOTH)
36\end{verbatim}
247aba10
VZ
37
38These constants define the file access rights and are used with
39\helpref{wxFile::Create}{wxfilecreate} and \helpref{wxFile::Open}{wxfileopen}.
40
41The {\it OpenMode} enumeration defines the different modes for opening a file,
6be663cf
JS
42it's defined inside wxFile class so its members should be specified with {\it wxFile::} scope
43resolution prefix. It is also used with \helpref{wxFile::Access}{wxfileaccess} function.
247aba10 44
6be663cf
JS
45\twocolwidtha{7cm}
46\begin{twocollist}\itemsep=0pt%
247aba10
VZ
47\twocolitem{{\bf wxFile::read}}{Open file for reading or test if it can be opened for reading with Access()}
48\twocolitem{{\bf wxFile::write}}{Open file for writing deleting the contents of the file if it already exists
49or test if it can be opened for writing with Access()}
50\twocolitem{{\bf wxFile::read\_write}}{Open file for reading and writing; can not be used with Access()}
51\twocolitem{{\bf wxFile::write\_append}}{Open file for appending: the file is opened for writing, but the old
52contents of the file is not erased and the file pointer is initially placed at the end of the file;
53can not be used with Access()}
54\end{twocollist}
55
56Other constants defined elsewhere but used by wxFile functions are wxInvalidOffset which represents an
57invalid value of type {\it off\_t} and is returned by functions returning {\it off\_t} on error and the seek
58mode constants used with \helpref{Seek()}{wxfileseek}:
59
60\twocolwidtha{7cm}
6be663cf 61\begin{twocollist}\itemsep=0pt%
247aba10
VZ
62\twocolitem{{\bf wxFromStart}}{Count offset from the start of the file}
63\twocolitem{{\bf wxFromCurrent}}{Count offset from the current position of the file pointer}
64\twocolitem{{\bf wxFromEnd}}{Count offset from the end of the file (backwards)}
65\end{twocollist}
66
a660d684
KB
67\latexignore{\rtfignore{\wxheading{Members}}}
68
69\membersection{wxFile::wxFile}\label{wxfileconstr}
70
71\func{}{wxFile}{\void}
72
73Default constructor.
74
75\func{}{wxFile}{\param{const char*}{ filename}, \param{wxFile::OpenMode}{ mode = wxFile::read}}
76
247aba10
VZ
77Opens a file with the given mode. As there is no way to return whether the
78operation was successful or not from the constructor you should test the
79return value of \helpref{IsOpened}{wxfileisopened} to check that it didn't
80fail.
a660d684
KB
81
82\func{}{wxFile}{\param{int}{ fd}}
83
e694c22c 84Associates the file with the given file descriptor, which has already been opened.
a660d684
KB
85
86\wxheading{Parameters}
87
88\docparam{filename}{The filename.}
89
90\docparam{mode}{The mode in which to open the file. May be one of {\bf wxFile::read}, {\bf wxFile::write} and {\bf wxFile::read\_write}.}
91
247aba10 92\docparam{fd}{An existing file descriptor (see \helpref{Attach()}{wxfileattach} for the list of predefined descriptors)}
a660d684
KB
93
94\membersection{wxFile::\destruct{wxFile}}
95
96\func{}{\destruct{wxFile}}{\void}
97
247aba10 98Destructor will close the file.
a660d684 99
e694c22c 100NB: it is not virtual so you should use wxFile polymorphically.
247aba10
VZ
101
102\membersection{wxFile::Access}\label{wxfileaccess}
6be663cf
JS
103
104\func{static bool}{Access}{\param{const char *}{ name}, \param{OpenMode}{ mode}}
a660d684 105
247aba10
VZ
106This function verifies if we may access the given file in specified mode. Only
107values of wxFile::read or wxFile::write really make sense here.
108
109\membersection{wxFile::Attach}\label{wxfileattach}
6be663cf 110
a660d684
KB
111\func{void}{Attach}{\param{int}{ fd}}
112
247aba10
VZ
113Attaches an existing file descriptor to the wxFile object. Example of predefined
114file descriptors are 0, 1 and 2 which correspond to stdin, stdout and stderr (and
28c9c76e 115have symbolic names of {\bf wxFile::fd\_stdin}, {\bf wxFile::fd\_stdout} and {\bf wxFile::fd\_stderr}).
247aba10
VZ
116
117The descriptor should be already opened and it will be closed by wxFile
118object.
a660d684
KB
119
120\membersection{wxFile::Close}\label{wxfileclose}
121
122\func{void}{Close}{\void}
123
124Closes the file.
125
126\membersection{wxFile::Create}\label{wxfilecreate}
127
247aba10 128\func{bool}{Create}{\param{const char*}{ filename}, \param{bool}{ overwrite = FALSE}, \param{int }{access = wxS\_DEFAULT}}
a660d684
KB
129
130Creates a file for writing. If the file already exists, setting {\bf overwrite} to TRUE
131will ensure it is overwritten.
132
247aba10 133\membersection{wxFile::Detach}\label{wxfiledetach}
6be663cf 134
247aba10
VZ
135\func{void}{Detach}{\void}
136
137Get back a file descriptor from wxFile object - the caller is responsible for closing the file if this
138descriptor is opened. \helpref{IsOpened()}{wxfileisopened} will return FALSE after call to Detach().
139
140\membersection{wxFile::fd}\label{wxfilefd}
6be663cf 141
247aba10
VZ
142\constfunc{int}{fd}{\void}
143
144Returns the file descriptor associated with the file.
145
a660d684
KB
146\membersection{wxFile::Eof}\label{wxfileeof}
147
148\constfunc{bool}{Eof}{\void}
149
c53a2bb3
VZ
150Returns TRUE if the end of the file has been reached.
151
152Note that the behaviour of the file pointer based class
153\helpref{wxFFile}{wxffile} is different as \helpref{wxFFile::Eof}{wxffileeof}
154will return TRUE here only if an attempt has been made to read
155{\it past} the last byte of the file, while wxFile::Eof() will return TRUE
156even before such attempt is made if the file pointer is at the last position
157in the file.
158
159Note also that this function doesn't work on unseekable file descriptors
160(examples include pipes, terminals and sockets under Unix) and an attempt to
161use it will result in an error message in such case.
a660d684
KB
162
163\membersection{wxFile::Exists}\label{wxfileexists}
164
165\func{static bool}{Exists}{\param{const char*}{ filename}}
166
e694c22c
VZ
167Returns TRUE if the given name specifies an existing regular file (not a
168directory or a link)
a660d684
KB
169
170\membersection{wxFile::Flush}\label{wxfileflush}
171
172\func{bool}{Flush}{\void}
173
247aba10
VZ
174Flushes the file descriptor.
175
176Note that wxFile::Flush is not implemented on some Windows compilers
177due to a missing fsync function, which reduces the usefulness of this function
178(it can still be called but it will do nothing on unsupported compilers).
a660d684
KB
179
180\membersection{wxFile::IsOpened}\label{wxfileisopened}
181
182\constfunc{bool}{IsOpened}{\void}
183
184Returns TRUE if the file has been opened.
185
186\membersection{wxFile::Length}\label{wxfilelength}
187
188\constfunc{off\_t}{Length}{\void}
189
190Returns the length of the file.
191
192\membersection{wxFile::Open}\label{wxfileopen}
193
194\func{bool}{Open}{\param{const char*}{ filename}, \param{wxFile::OpenMode}{ mode = wxFile::read}}
195
196Opens the file, returning TRUE if successful.
197
198\wxheading{Parameters}
199
200\docparam{filename}{The filename.}
201
202\docparam{mode}{The mode in which to open the file. May be one of {\bf wxFile::read}, {\bf wxFile::write} and {\bf wxFile::read\_write}.}
203
204\membersection{wxFile::Read}\label{wxfileread}
205
206\func{off\_t}{Read}{\param{void*}{ buffer}, \param{off\_t}{ count}}
207
208Reads the specified number of bytes into a buffer, returning the actual number read.
209
210\wxheading{Parameters}
211
212\docparam{buffer}{A buffer to receive the data.}
213
214\docparam{count}{The number of bytes to read.}
215
216\wxheading{Return value}
217
247aba10 218The number of bytes read, or the symbol {\bf wxInvalidOffset} (-1) if there was an error.
a660d684
KB
219
220\membersection{wxFile::Seek}\label{wxfileseek}
221
842d6c94 222\func{off\_t}{Seek}{\param{off\_t }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}
a660d684
KB
223
224Seeks to the specified position.
225
226\wxheading{Parameters}
227
228\docparam{ofs}{Offset to seek to.}
229
842d6c94 230\docparam{mode}{One of {\bf wxFromStart}, {\bf wxFromEnd}, {\bf wxFromCurrent}.}
a660d684
KB
231
232\wxheading{Return value}
233
247aba10 234The actual offset position achieved, or wxInvalidOffset on failure.
a660d684
KB
235
236\membersection{wxFile::SeekEnd}\label{wxfileseekend}
237
238\func{off\_t}{SeekEnd}{\param{off\_t }{ofs = 0}}
239
240Moves the file pointer to the specified number of bytes before the end of the file.
241
242\wxheading{Parameters}
243
244\docparam{ofs}{Number of bytes before the end of the file.}
245
246\wxheading{Return value}
247
247aba10 248The actual offset position achieved, or wxInvalidOffset on failure.
a660d684
KB
249
250\membersection{wxFile::Tell}\label{wxfiletell}
251
252\constfunc{off\_t}{Tell}{\void}
253
247aba10
VZ
254Returns the current position or wxInvalidOffset if file is not opened or if another
255error occured.
a660d684
KB
256
257\membersection{wxFile::Write}\label{wxfilewrite}
258
259\func{bool}{Write}{\param{const void*}{ buffer}, \param{off\_t}{ count}}
260
261Writes the specified number of bytes from a buffer.
262
263\wxheading{Parameters}
264
265\docparam{buffer}{A buffer containing the data.}
266
267\docparam{count}{The number of bytes to write.}
268
269\wxheading{Return value}
270
271TRUE if the operation was successful.
272
247aba10 273\membersection{wxFile::Write}\label{wxfilewrites}
6be663cf 274
294e9a7a 275\func{bool}{Write}{\param{const wxString\& }{s}}
a660d684 276
6be663cf
JS
277Writes the contents of the string to the file, returns TRUE on success.
278
842d6c94
RR
279\section{\class{wxFFile}}\label{wxffile}
280
281A wxFFile performs raw file I/O. This is a very small class designed to
282minimize the overhead of using it - in fact, there is hardly any overhead at
283all, but using it brings you automatic error checking and hides differences
284between platforms and compilers.
285
286\wxheading{Derived from}
287
288None.
289
290\wxheading{Include files}
291
292<wx/ffile.h>
293
294\twocolwidtha{7cm}
295\begin{twocollist}\itemsep=0pt%
296\twocolitem{{\bf wxFromStart}}{Count offset from the start of the file}
297\twocolitem{{\bf wxFromCurrent}}{Count offset from the current position of the file pointer}
298\twocolitem{{\bf wxFromEnd}}{Count offset from the end of the file (backwards)}
299\end{twocollist}
300
301\latexignore{\rtfignore{\wxheading{Members}}}
302
303\membersection{wxFFile::wxFFile}\label{wxffileconstr}
304
305\func{}{wxFFile}{\void}
306
307Default constructor.
308
309\func{}{wxFFile}{\param{const char*}{ filename}, \param{const char*}{ mode = "r"}}
310
311Opens a file with the given mode. As there is no way to return whether the
312operation was successful or not from the constructor you should test the
313return value of \helpref{IsOpened}{wxffileisopened} to check that it didn't
314fail.
315
316\func{}{wxFFile}{\param{FILE*}{ fp}}
317
318Opens a file with the given file pointer, which has already been opened.
319
320\wxheading{Parameters}
321
322\docparam{filename}{The filename.}
323
324\docparam{mode}{The mode in which to open the file using standard C strings.}
325
326\docparam{fp}{An existing file descriptor, such as stderr.}
327
328\membersection{wxFFile::\destruct{wxFFile}}
329
330\func{}{\destruct{wxFFile}}{\void}
331
332Destructor will close the file.
333
334NB: it is not virtual so you should {\it not} derive from wxFFile!
335
336\membersection{wxFFile::Attach}\label{wxffileattach}
337
338\func{void}{Attach}{\param{FILE*}{ fp}}
339
340Attaches an existing file pointer to the wxFFile object.
341
342The descriptor should be already opened and it will be closed by wxFFile
343object.
344
345\membersection{wxFFile::Close}\label{wxffileclose}
346
347\func{bool}{Close}{\void}
348
349Closes the file and returns TRUE on success.
350
351\membersection{wxFFile::Detach}\label{wxffiledetach}
352
353\func{void}{Detach}{\void}
354
355Get back a file pointer from wxFFile object - the caller is responsible for closing the file if this
356descriptor is opened. \helpref{IsOpened()}{wxffileisopened} will return FALSE after call to Detach().
357
358\membersection{wxFFile::fp}\label{wxffilefp}
359
360\constfunc{FILE *}{fp}{\void}
361
362Returns the file pointer associated with the file.
363
364\membersection{wxFFile::Eof}\label{wxffileeof}
365
366\constfunc{bool}{Eof}{\void}
367
368Returns TRUE if the an attempt has been made to read {\it past}
369the end of the file.
370
371Note that the behaviour of the file descriptor based class
372\helpref{wxFile}{wxfile} is different as \helpref{wxFile::Eof}{wxfileeof}
373will return TRUE here as soon as the last byte of the file has been
374read.
375
376\membersection{wxFFile::Flush}\label{wxffileflush}
377
378\func{bool}{Flush}{\void}
379
380Flushes the file and returns TRUE on success.
381
382\membersection{wxFFile::IsOpened}\label{wxffileisopened}
383
384\constfunc{bool}{IsOpened}{\void}
385
386Returns TRUE if the file has been opened.
387
388\membersection{wxFFile::Length}\label{wxffilelength}
389
390\constfunc{size\_t}{Length}{\void}
391
392Returns the length of the file.
393
394\membersection{wxFFile::Open}\label{wxffileopen}
395
396\func{bool}{Open}{\param{const char*}{ filename}, \param{const char*}{ mode = "r"}}
397
398Opens the file, returning TRUE if successful.
399
400\wxheading{Parameters}
401
402\docparam{filename}{The filename.}
403
404\docparam{mode}{The mode in which to open the file.}
405
406\membersection{wxFFile::Read}\label{wxffileread}
407
408\func{size\_t}{Read}{\param{void*}{ buffer}, \param{off\_t}{ count}}
409
410Reads the specified number of bytes into a buffer, returning the actual number read.
411
412\wxheading{Parameters}
413
414\docparam{buffer}{A buffer to receive the data.}
415
416\docparam{count}{The number of bytes to read.}
417
418\wxheading{Return value}
419
420The number of bytes read.
421
422\membersection{wxFFile::Seek}\label{wxffileseek}
423
424\func{bool}{Seek}{\param{long }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}
425
426Seeks to the specified position and returs TRUE on success.
427
428\wxheading{Parameters}
429
430\docparam{ofs}{Offset to seek to.}
431
432\docparam{mode}{One of {\bf wxFromStart}, {\bf wxFromEnd}, {\bf wxFromCurrent}.}
433
434\membersection{wxFFile::SeekEnd}\label{wxffileseekend}
435
436\func{bool}{SeekEnd}{\param{long }{ofs = 0}}
437
438Moves the file pointer to the specified number of bytes before the end of the file
439and returns TRUE on success.
440
441\wxheading{Parameters}
442
443\docparam{ofs}{Number of bytes before the end of the file.}
444
445\membersection{wxFFile::Tell}\label{wxffiletell}
446
447\constfunc{size\_t}{Tell}{\void}
448
449Returns the current position.
450
451\membersection{wxFFile::Write}\label{wxffilewrite}
452
605d715d 453\func{size\_t}{Write}{\param{const void*}{ buffer}, \param{size\_t}{ count}}
842d6c94
RR
454
455Writes the specified number of bytes from a buffer.
456
457\wxheading{Parameters}
458
459\docparam{buffer}{A buffer containing the data.}
460
461\docparam{count}{The number of bytes to write.}
462
463\wxheading{Return value}
464
465Number of bytes written.
466
467\membersection{wxFFile::Write}\label{wxffilewrites}
468
469\func{bool}{Write}{\param{const wxString\& }{s}}
470
471Writes the contents of the string to the file, returns TRUE on success.
472