1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxFFile documentation
4 %% Author: Vadim Zeitlin
6 %% Created: 14.01.02 (extracted from file.tex)
8 %% Copyright: (c) Vadim Zeitlin
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxFFile
}}\label{wxffile
}
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
}).
20 \wxheading{Derived from
}
24 \wxheading{Include files
}
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)
}
35 \latexignore{\rtfignore{\wxheading{Members
}}}
38 \membersection{wxFFile::wxFFile
}\label{wxffilector
}
40 \func{}{wxFFile
}{\void}
44 \func{}{wxFFile
}{\param{const char*
}{ filename
},
\param{const char*
}{ mode = "r"
}}
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
51 \func{}{wxFFile
}{\param{FILE*
}{ fp
}}
53 Opens a file with the given file pointer, which has already been opened.
55 \wxheading{Parameters
}
57 \docparam{filename
}{The filename.
}
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
64 \docparam{fp
}{An existing file descriptor, such as stderr.
}
67 \membersection{wxFFile::
\destruct{wxFFile
}}\label{wxffiledtor
}
69 \func{}{\destruct{wxFFile
}}{\void}
71 Destructor will close the file.
73 NB: it is not virtual so you should
{\it not
} derive from wxFFile!
76 \membersection{wxFFile::Attach
}\label{wxffileattach
}
78 \func{void
}{Attach
}{\param{FILE*
}{ fp
}}
80 Attaches an existing file pointer to the wxFFile object.
82 The descriptor should be already opened and it will be closed by wxFFile
86 \membersection{wxFFile::Close
}\label{wxffileclose
}
88 \func{bool
}{Close
}{\void}
90 Closes the file and returns
\true on success.
93 \membersection{wxFFile::Detach
}\label{wxffiledetach
}
95 \func{void
}{Detach
}{\void}
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().
101 \membersection{wxFFile::fp
}\label{wxffilefp
}
103 \constfunc{FILE *
}{fp
}{\void}
105 Returns the file pointer associated with the file.
108 \membersection{wxFFile::Eof
}\label{wxffileeof
}
110 \constfunc{bool
}{Eof
}{\void}
112 Returns
\true if the an attempt has been made to read
{\it past
}
115 Note that the behaviour of the file descriptor based class
116 \helpref{wxFile
}{wxfile
} is different as
\helpref{wxFile::Eof
}{wxfileeof
}
117 will return
\true here as soon as the last byte of the file has been
120 Also note that this method may only be called for opened files and may crash if
121 the file is not opened.
125 \helpref{IsOpened
}{wxffileisopened
}
128 \membersection{wxFFile::Error
}\label{wxffileerror
}
130 Returns
\true if an error has occurred on this file, similar to the standard
131 \texttt{ferror()
} function.
133 Please note that this method may only be called for opened files and may crash
134 if the file is not opened.
138 \helpref{IsOpened
}{wxffileisopened
}
141 \membersection{wxFFile::Flush
}\label{wxffileflush
}
143 \func{bool
}{Flush
}{\void}
145 Flushes the file and returns
\true on success.
148 \membersection{wxFFile::GetKind
}\label{wxffilegetfilekind
}
150 \constfunc{wxFileKind
}{GetKind
}{\void}
152 Returns the type of the file. Possible return values are:
158 wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
159 wxFILE_KIND_TERMINAL, // a tty
160 wxFILE_KIND_PIPE // a pipe
166 \membersection{wxFFile::IsOpened
}\label{wxffileisopened
}
168 \constfunc{bool
}{IsOpened
}{\void}
170 Returns
\true if the file is opened. Most of the methods of this class may only
171 be used for an opened file.
174 \membersection{wxFFile::Length
}\label{wxffilelength
}
176 \constfunc{wxFileOffset
}{Length
}{\void}
178 Returns the length of the file.
181 \membersection{wxFFile::Open
}\label{wxffileopen
}
183 \func{bool
}{Open
}{\param{const char*
}{ filename
},
\param{const char*
}{ mode = "r"
}}
185 Opens the file, returning
\true if successful.
187 \wxheading{Parameters
}
189 \docparam{filename
}{The filename.
}
191 \docparam{mode
}{The mode in which to open the file.
}
194 \membersection{wxFFile::Read
}\label{wxffileread
}
196 \func{size
\_t}{Read
}{\param{void*
}{ buffer
},
\param{size
\_t}{ count
}}
198 Reads the specified number of bytes into a buffer, returning the actual number read.
200 \wxheading{Parameters
}
202 \docparam{buffer
}{A buffer to receive the data.
}
204 \docparam{count
}{The number of bytes to read.
}
206 \wxheading{Return value
}
208 The number of bytes read.
211 \membersection{wxFFile::ReadAll
}\label{wxffilereadall
}
213 \func{bool
}{ReadAll
}{\param{wxString *
}{ str
},
\param{wxMBConv\&
}{ conv = wxConvUTF8
}}
215 Reads the entire contents of the file into a string.
217 \wxheading{Parameters
}
219 \docparam{str
}{String to read data into.
}
221 \docparam{conv
}{Conversion object to use in Unicode build; by default supposes
222 that file contents is encoded in UTF-
8.
}
224 \wxheading{Return value
}
226 \true if file was read successfully,
\false otherwise.
229 \membersection{wxFFile::Seek
}\label{wxffileseek
}
231 \func{bool
}{Seek
}{\param{wxFileOffset
}{ofs
},
\param{wxSeekMode
}{mode = wxFromStart
}}
233 Seeks to the specified position and returns
\true on success.
235 \wxheading{Parameters
}
237 \docparam{ofs
}{Offset to seek to.
}
239 \docparam{mode
}{One of
{\bf wxFromStart
},
{\bf wxFromEnd
},
{\bf wxFromCurrent
}.
}
242 \membersection{wxFFile::SeekEnd
}\label{wxffileseekend
}
244 \func{bool
}{SeekEnd
}{\param{wxFileOffset
}{ofs =
0}}
246 Moves the file pointer to the specified number of bytes before the end of the file
247 and returns
\true on success.
249 \wxheading{Parameters
}
251 \docparam{ofs
}{Number of bytes before the end of the file.
}
254 \membersection{wxFFile::Tell
}\label{wxffiletell
}
256 \constfunc{wxFileOffset
}{Tell
}{\void}
258 Returns the current position.
261 \membersection{wxFFile::Write
}\label{wxffilewrite
}
263 \func{size
\_t}{Write
}{\param{const void*
}{ buffer
},
\param{size
\_t}{ count
}}
265 Writes the specified number of bytes from a buffer.
267 \wxheading{Parameters
}
269 \docparam{buffer
}{A buffer containing the data.
}
271 \docparam{count
}{The number of bytes to write.
}
273 \wxheading{Return value
}
275 Number of bytes written.
278 \membersection{wxFFile::Write
}\label{wxffilewrites
}
280 \func{bool
}{Write
}{\param{const wxString\&
}{s
},
\param{wxMBConv\&
}{ conv = wxConvUTF8
}}
282 Writes the contents of the string to the file, returns
\true on success.
284 The second argument is only meaningful in Unicode build of wxWidgets when
285 {\it conv
} is used to convert
{\it s
} to multibyte representation.