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