]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/ffile.h
Fix wxWebView documentation warnings.
[wxWidgets.git] / interface / wx / ffile.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: ffile.h
e54c96f1 3// Purpose: interface of wxFFile
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
1add55ae 9
23324ae1
FM
10/**
11 @class wxFFile
7c913512 12
1add55ae
FM
13 wxFFile implements buffered file I/O.
14
15 This is a very small class designed to minimize the overhead of using it - in fact,
16 there is hardly any overhead at all, but using it brings you automatic error checking
17 and hides differences between platforms and compilers.
18
19 It wraps inside it a @c FILE * handle used by standard C IO library (also known as @c stdio).
7c913512 20
23324ae1
FM
21 @library{wxbase}
22 @category{file}
7c913512 23
e54c96f1 24 @see wxFFile::IsOpened
23324ae1 25*/
7c913512 26class wxFFile
23324ae1
FM
27{
28public:
1add55ae
FM
29 wxFFile();
30
23324ae1
FM
31 /**
32 Opens a file with the given file pointer, which has already been opened.
3c4f71cc 33
1add55ae
FM
34 @param fp
35 An existing file descriptor, such as stderr.
36 */
37 wxFFile(FILE* fp);
38
39 /**
40 Opens a file with the given mode.
41 As there is no way to return whether the operation was successful or not from
42 the constructor you should test the return value of IsOpened() to check that it
43 didn't fail.
44
7c913512 45 @param filename
4cc4bfaf 46 The filename.
7c913512 47 @param mode
4cc4bfaf
FM
48 The mode in which to open the file using standard C strings.
49 Note that you should use "b" flag if you use binary files under Windows
50 or the results might be unexpected due to automatic newline conversion done
51 for the text files.
23324ae1 52 */
7c913512 53 wxFFile(const wxString& filename, const wxString& mode = "r");
1add55ae 54
23324ae1
FM
55
56 /**
57 Destructor will close the file.
1add55ae
FM
58
59 @note it is not virtual so you should @e not derive from wxFFile!
23324ae1
FM
60 */
61 ~wxFFile();
62
63 /**
64 Attaches an existing file pointer to the wxFFile object.
1add55ae
FM
65
66 The descriptor should be already opened and it will be closed by wxFFile object.
23324ae1 67 */
43c48e1e 68 void Attach(FILE* fp, const wxString& name = wxEmptyString);
23324ae1
FM
69
70 /**
71 Closes the file and returns @true on success.
72 */
73 bool Close();
74
75 /**
76 Get back a file pointer from wxFFile object -- the caller is responsible for
1add55ae
FM
77 closing the file if this descriptor is opened.
78
79 IsOpened() will return @false after call to Detach().
23324ae1
FM
80 */
81 void Detach();
82
83 /**
d13b34d3 84 Returns @true if an attempt has been made to read @e past
7c913512 85 the end of the file.
1add55ae
FM
86
87 Note that the behaviour of the file descriptor based class wxFile is different as
88 wxFile::Eof() will return @true here as soon as the last byte of the file has been read.
89
23324ae1
FM
90 Also note that this method may only be called for opened files and may crash if
91 the file is not opened.
3c4f71cc 92
1add55ae
FM
93 @todo THIS METHOD MAY CRASH? DOESN'T SOUND GOOD
94
4cc4bfaf 95 @see IsOpened()
23324ae1 96 */
328f5751 97 bool Eof() const;
23324ae1
FM
98
99 /**
100 Returns @true if an error has occurred on this file, similar to the standard
101 @c ferror() function.
1add55ae 102
23324ae1
FM
103 Please note that this method may only be called for opened files and may crash
104 if the file is not opened.
3c4f71cc 105
1add55ae
FM
106 @todo THIS METHOD MAY CRASH? DOESN'T SOUND GOOD
107
4cc4bfaf 108 @see IsOpened()
23324ae1 109 */
1add55ae 110 bool Error() const;
23324ae1
FM
111
112 /**
113 Flushes the file and returns @true on success.
114 */
115 bool Flush();
116
117 /**
1add55ae
FM
118 Returns the type of the file.
119
120 @see wxFileKind
23324ae1 121 */
328f5751 122 wxFileKind GetKind() const;
23324ae1 123
6ea6639c
VZ
124 /**
125 Returns the file name.
126
127 This is the name that was specified when the object was constructed or
128 to the last call to Open(). Notice that it may be empty if Attach() was
129 called without specifying the name.
130 */
131 const wxString& GetName() const;
132
23324ae1 133 /**
1add55ae
FM
134 Returns @true if the file is opened.
135
136 Most of the methods of this class may only be used for an opened file.
23324ae1 137 */
328f5751 138 bool IsOpened() const;
23324ae1
FM
139
140 /**
141 Returns the length of the file.
142 */
328f5751 143 wxFileOffset Length() const;
23324ae1
FM
144
145 /**
146 Opens the file, returning @true if successful.
3c4f71cc 147
7c913512 148 @param filename
4cc4bfaf 149 The filename.
7c913512 150 @param mode
4cc4bfaf 151 The mode in which to open the file.
23324ae1
FM
152 */
153 bool Open(const wxString& filename, const wxString& mode = "r");
154
155 /**
1add55ae 156 Reads the specified number of bytes into a buffer, returning the actual number read.
3c4f71cc 157
7c913512 158 @param buffer
4cc4bfaf 159 A buffer to receive the data.
7c913512 160 @param count
4cc4bfaf 161 The number of bytes to read.
3c4f71cc 162
d29a9a8a 163 @return The number of bytes read.
23324ae1
FM
164 */
165 size_t Read(void* buffer, size_t count);
166
167 /**
23324ae1 168 Reads the entire contents of the file into a string.
3c4f71cc 169
7c913512 170 @param str
4cc4bfaf 171 String to read data into.
7c913512 172 @param conv
4cc4bfaf
FM
173 Conversion object to use in Unicode build; by default supposes
174 that file contents is encoded in UTF-8.
3c4f71cc 175
d29a9a8a 176 @return @true if file was read successfully, @false otherwise.
23324ae1 177 */
1add55ae 178 bool ReadAll(wxString* str, const wxMBConv& conv = wxConvAuto());
23324ae1
FM
179
180 /**
181 Seeks to the specified position and returns @true on success.
3c4f71cc 182
7c913512 183 @param ofs
4cc4bfaf 184 Offset to seek to.
7c913512 185 @param mode
4cc4bfaf 186 One of wxFromStart, wxFromEnd, wxFromCurrent.
23324ae1
FM
187 */
188 bool Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart);
189
190 /**
191 Moves the file pointer to the specified number of bytes before the end of the
1add55ae 192 file and returns @true on success.
3c4f71cc 193
7c913512 194 @param ofs
4cc4bfaf 195 Number of bytes before the end of the file.
23324ae1
FM
196 */
197 bool SeekEnd(wxFileOffset ofs = 0);
198
199 /**
200 Returns the current position.
201 */
328f5751 202 wxFileOffset Tell() const;
23324ae1
FM
203
204 /**
23324ae1 205 Writes the contents of the string to the file, returns @true on success.
1add55ae 206
23324ae1 207 The second argument is only meaningful in Unicode build of wxWidgets when
1add55ae
FM
208 @a conv is used to convert @a str to multibyte representation.
209 */
210 bool Write(const wxString& str, const wxMBConv& conv = wxConvAuto());
211
212 /**
213 Writes the specified number of bytes from a buffer.
214
215 @param buffer
216 A buffer containing the data.
217 @param count
218 The number of bytes to write.
219
d29a9a8a 220 @return The number of bytes written.
23324ae1 221 */
1add55ae 222 size_t Write(const void* buffer, size_t count);
23324ae1
FM
223
224 /**
225 Returns the file pointer associated with the file.
226 */
328f5751 227 FILE* fp() const;
23324ae1 228};
e54c96f1 229