wxffilewxffile implements buffered file i/o. this is a very small class designed to minimize the overhead of using it - in fact, there is hardly any overhead at all, but using it brings you automatic error checking and hides differences between platforms and compilers. it wraps inside it a file * handle used by standard c io library (also known as stdio). derived from none. include files <wx/ffile.h>
members
wxffile::wxffile
wxffile::wxffilewxffile() default constructor. wxffile(const char* filename, const char* mode = "r") opens a file with the given mode. as there is no way to return whether the operation was successful or not from the constructor you should test the return value of isopened to check that it didn't fail. wxffile(file* fp) opens a file with the given file pointer, which has already been opened. parameters filename
mode
fp
wxffile::~wxffile~wxffile() destructor will close the file. nb: it is not virtual so you should not derive from wxffile!
wxffile::attachvoid attach(file* fp) attaches an existing file pointer to the wxffile object. the descriptor should be already opened and it will be closed by wxffile object.
wxffile::closebool close() closes the file and returns true on success.
wxffile::detachvoid detach() get back a file pointer from wxffile object -- the caller is responsible for closing the file if this descriptor is opened. isopened() will return false after call to detach().
wxffile::fpfile * fp() const returns the file pointer associated with the file.
wxffile::eofbool eof() const returns true if the an attempt has been made to read past the end of the file. note that the behaviour of the file descriptor based class wxfile is different as wxfile::eof will return true here as soon as the last byte of the file has been read. also note that this method may only be called for opened files and may crash if the file is not opened. see also
wxffile::errorreturns true if an error has occurred on this file, similar to the standard ferror() function. please note that this method may only be called for opened files and may crash if the file is not opened. see also
wxffile::flushbool flush() flushes the file and returns true on success.
wxffile::getkindwxfilekind getkind() const returns the type of the file. possible return values are:
enum wxfilekind { wxfile_kind_unknown, wxfile_kind_disk, // a file supporting seeking to arbitrary offsets wxfile_kind_terminal, // a tty wxfile_kind_pipe // a pipe }; wxffile::isopenedbool isopened() const returns true if the file is opened. most of the methods of this class may only be used for an opened file.
wxffile::lengthwxfileoffset length() const returns the length of the file.
wxffile::openbool open(const char* filename, const char* mode = "r") opens the file, returning true if successful. parameters filename
mode
wxffile::readsize_t read(void* buffer, size_t count) reads the specified number of bytes into a buffer, returning the actual number read. parameters buffer
count
return value the number of bytes read.
wxffile::readallbool readall(wxstring * str, wxmbconv& conv = wxconvutf8) reads the entire contents of the file into a string. parameters str
conv
return value true if file was read successfully, false otherwise.
wxffile::seekbool seek(wxfileoffset ofs, wxseekmode mode = wxfromstart) seeks to the specified position and returns true on success. parameters ofs
mode
wxffile::seekendbool seekend(wxfileoffset ofs = 0) moves the file pointer to the specified number of bytes before the end of the file and returns true on success. parameters ofs
wxffile::tellwxfileoffset tell() const returns the current position.
wxffile::writesize_t write(const void* buffer, size_t count) writes the specified number of bytes from a buffer. parameters buffer
count
return value number of bytes written.
wxffile::writebool write(const wxstring& s, wxmbconv& conv = wxconvutf8) writes the contents of the string to the file, returns true on success. the second argument is only meaningful in unicode build of wxwidgets when conv is used to convert s to multibyte representation.
|