#include <QFile.h>
Not much to say about this - it works as you'd expect. It's also thread-safe so multiple threads can read and write from it (though the current file pointer is the same for both, so it probably doesn't help you much).
Most likely you'll prefer to use FX::QMemMap all the time as it offers superior performance and facilities in most cases. Indeed, QFile does no internal buffering as it is expected it will only be used rarely, mostly for small files with little i/o performed to them.
Like all file type i/o classes, QFile can perform automatic CR/LF translation as well as UTF-8 to UTF-16 and UTF-32 conversion. If you enable IO_Translate
, the file data is probed and its unicode type determined such that the file unicode type is transparently converted into UTF-8 and back into its original form. This allows your code to work exclusively in UTF-8 using the standard FX::FXString functions. You can set the type of output using setUnicodeTranslation().
For speed, QFile maintains its own record of file length which it manages. This normally isn't a problem, but when multiple QFile's are working on the same file (either in-process or across processes) then the internal count can become desynchronised with the actual length. If you want to reset the length, call reloadSize().
One major difference is default security, especially on NT. QFile like all TnFOX sets very conservative permissions on all things it creates - see FX::FXACL::default_(). Note that until the file is opened, permissions() returns what will be applied to the file on open() rather than the file itself - if you want the latter, use the static method.
Public Types | |
enum | CRLFType { Default, Unix, MacOS, MSDOS } |
enum | UnicodeType { NoTranslation, UTF8, UTF16, UTF16LE, UTF32, UTF32LE } |
typedef FXfval | Offset |
Public Member Functions | |
QFile (const FXString &name) | |
const FXString & | name () const |
void | setName (const FXString &name) |
bool | exists () const |
bool | remove () |
FXfval | reloadSize () |
virtual bool | open (FXuint mode) |
virtual void | close () |
virtual void | flush () |
virtual FXfval | size () const |
virtual void | truncate (FXfval size) |
virtual FXfval | at () const |
virtual bool | at (FXfval newpos) |
virtual bool | atEnd () const |
virtual const FXACL & | permissions () const |
virtual void | setPermissions (const FXACL &perms) |
virtual FXuval | readBlock (char *data, FXuval maxlen) |
virtual FXuval | writeBlock (const char *data, FXuval maxlen) |
virtual FXuval | readBlockFrom (char *data, FXuval maxlen, FXfval pos) |
virtual FXuval | writeBlockTo (FXfval pos, const char *data, FXuval maxlen) |
virtual int | ungetch (int c) |
FXuint | flags () const |
FXuint | mode () const |
FXuint | state () const |
CRLFType | crlfFormat () const |
void | setCRLFFormat (CRLFType type) |
UnicodeType | unicodeTranslation () const |
void | setUnicodeTranslation (UnicodeType type) |
bool | isBuffered () const |
bool | isRaw () const |
bool | isTranslated () const |
bool | isUTF16Translated () const |
bool | isUTF32Translated () const |
bool | isReadable () const |
bool | isWriteable () const |
bool | isWritable () const |
bool | isReadWrite () const |
bool | isClosed () const |
bool | isInactive () const |
bool | isOpen () const |
virtual bool | isSynchronous () const |
FXuval | readBlock (FXuchar *data, FXuval maxlen) |
FXuval | writeBlock (const FXuchar *data, FXuval maxlen) |
virtual FXuval | readLine (char *data, FXuval maxlen) |
FXuval | readBlockFrom (FXuchar *data, FXuval maxlen, FXfval pos) |
FXuval | writeBlockTo (FXfval pos, const FXuchar *data, FXuval maxlen) |
virtual int | getch () |
virtual int | putch (int c) |
FXfval | shredData (FXfval offset, FXfval len=(FXfval)-1) |
Static Public Member Functions | |
static QIODevice & | stdio (bool applyCRLFTranslation=false) |
static FXACL | permissions (const FXString &path) |
static void | setPermissions (const FXString &path, const FXACL &perms) |
static UnicodeType | determineUnicodeType (FXuchar *data, FXuval len) throw () |
static FXuval | applyCRLF (FXuchar *FXRESTRICT output, const FXuchar *FXRESTRICT input, FXuval outputlen, FXuval &inputlen, CRLFType crlftype=Default, UnicodeType utftype=NoTranslation) |
static FXuval | removeCRLF (FXuchar *FXRESTRICT output, const FXuchar *FXRESTRICT input, FXuval outputlen, FXuval &inputlen, UnicodeType utftype=NoTranslation) |
Protected Member Functions | |
void | setFlags (int f) |
void | setMode (int m) |
void | setState (int s) |
Protected Attributes | |
FXfval | ioIndex |
Friends | |
class | QMemMap |
class | FXProcess |
FXAPI FXStream & | operator<< (FXStream &s, QIODevice &i) |
FXAPI FXStream & | operator>> (FXStream &s, QIODevice &i) |
enum FX::QIODevice::CRLFType [inherited] |
enum FX::QIODevice::UnicodeType [inherited] |
The type of unicode translation you want.
FX::QFile::QFile | ( | const FXString & | name | ) |
Constructs a new instance, setting the file name to be used to name.
const FXString& FX::QFile::name | ( | ) | const |
Returns the file name being addressed by this device.
void FX::QFile::setName | ( | const FXString & | name | ) |
Sets the file name being addressed by this device. Closes the old file first.
bool FX::QFile::exists | ( | ) | const |
Returns true if the file name points to an existing file.
bool FX::QFile::remove | ( | ) |
Deletes the file name, closing the file first if open. Returns false if file doesn't exist.
FXfval FX::QFile::reloadSize | ( | ) |
Reloads the size of the file. See description above.
static QIODevice& FX::QFile::stdio | ( | bool | applyCRLFTranslation = false |
) | [static] |
virtual bool FX::QFile::open | ( | FXuint | mode | ) | [virtual] |
virtual void FX::QFile::close | ( | ) | [virtual] |
virtual void FX::QFile::flush | ( | ) | [virtual] |
virtual FXfval FX::QFile::size | ( | ) | const [virtual] |
virtual void FX::QFile::truncate | ( | FXfval | size | ) | [virtual] |
Truncates the data to the specified size. Extends the file if necessary & doesn't affect the current file pointer unless it is beyond the new file size, in which case it is moved to the end of the new file
Implements FX::QIODevice.
virtual FXfval FX::QFile::at | ( | ) | const [virtual] |
Returns the current file pointer within the device
Reimplemented from FX::QIODevice.
virtual bool FX::QFile::at | ( | FXfval | newpos | ) | [virtual] |
Sets the current file pointer
Reimplemented from FX::QIODevice.
virtual bool FX::QFile::atEnd | ( | ) | const [virtual] |
Returns true if there is no more data available to be read from the device.
Reimplemented from FX::QIODevice.
virtual const FXACL& FX::QFile::permissions | ( | ) | const [virtual] |
virtual void FX::QFile::setPermissions | ( | const FXACL & | ) | [virtual] |
Returns the permissions for the file at the specified path.
Sets the permissions for the file at the specified path.
virtual FXuval FX::QFile::readBlock | ( | char * | data, | |
FXuval | maxlen | |||
) | [virtual] |
Reads up to the specified quantity of bytes into the buffer, returning how much was actually read
Implements FX::QIODevice.
virtual FXuval FX::QFile::writeBlock | ( | const char * | data, | |
FXuval | maxlen | |||
) | [virtual] |
Writes up to the specified quantity of bytes from the buffer, returning how much was actually written. Note that less being written due to error is returned as an exception, but some devices may write less in a non-error situation.
Implements FX::QIODevice.
virtual FXuval FX::QFile::readBlockFrom | ( | char * | data, | |
FXuval | maxlen, | |||
FXfval | pos | |||
) | [virtual] |
Combines an at() and readBlock() together. Can be much more efficient than those two operations individually with some i/o devices, plus it's synchronous and thus threadsafe
Implements FX::QIODevice.
virtual FXuval FX::QFile::writeBlockTo | ( | FXfval | pos, | |
const char * | data, | |||
FXuval | maxlen | |||
) | [virtual] |
Combines an at() and writeBlock() together. Can be much more efficient than those two operations individually with some i/o devices, plus it's synchronous and thus threadsafe
Implements FX::QIODevice.
virtual int FX::QFile::ungetch | ( | int | c | ) | [virtual] |
FXuint FX::QIODevice::flags | ( | ) | const [inline, inherited] |
Returns the flags of this device.
FXuint FX::QIODevice::mode | ( | ) | const [inline, inherited] |
Returns the mode of this device
FXuint FX::QIODevice::state | ( | ) | const [inline, inherited] |
Returns the state of this device
CRLFType FX::QIODevice::crlfFormat | ( | ) | const [inline, inherited] |
Returns the CR/LF format of this device.
void FX::QIODevice::setCRLFFormat | ( | CRLFType | type | ) | [inline, inherited] |
Sets the CR/LF format for output of this device.
UnicodeType FX::QIODevice::unicodeTranslation | ( | ) | const [inline, inherited] |
Returns the unicode translation of this device.
void FX::QIODevice::setUnicodeTranslation | ( | UnicodeType | type | ) | [inline, inherited] |
Sets the unicode translation of this device.
bool FX::QIODevice::isBuffered | ( | ) | const [inline, inherited] |
Returns true if the device is buffered.
bool FX::QIODevice::isRaw | ( | ) | const [inline, inherited] |
Returns true if the device is unbuffered.
bool FX::QIODevice::isTranslated | ( | ) | const [inline, inherited] |
Returns true if the device is LR/CF translated.
bool FX::QIODevice::isUTF16Translated | ( | ) | const [inline, inherited] |
Returns true if the device is UTF-16 translated.
bool FX::QIODevice::isUTF32Translated | ( | ) | const [inline, inherited] |
Returns true if the device is UTF-32 translated.
bool FX::QIODevice::isReadable | ( | ) | const [inline, inherited] |
Returns true if the device is readable.
bool FX::QIODevice::isWriteable | ( | ) | const [inline, inherited] |
Returns true if the device is writeable.
bool FX::QIODevice::isReadWrite | ( | ) | const [inline, inherited] |
Returns true if the device is readable & writeable.
bool FX::QIODevice::isClosed | ( | ) | const [inline, inherited] |
Returns true if the device is closed.
bool FX::QIODevice::isOpen | ( | ) | const [inline, inherited] |
Returns true if the device is opened.
virtual bool FX::QIODevice::isSynchronous | ( | ) | const [inline, virtual, inherited] |
Returns true if this device is a synchronous device.
Reimplemented in FX::QIODeviceS, and FX::QSSLDevice.
virtual FXuval FX::QIODevice::readLine | ( | char * | data, | |
FXuval | maxlen | |||
) | [virtual, inherited] |
Reads data until an end-of-line or maxlen is exceeded.
virtual int FX::QIODevice::getch | ( | ) | [virtual, inherited] |
Reads a single byte. Returns -1 for no data found.
Reimplemented in FX::QBuffer, FX::QBZip2Device, FX::QGZipDevice, and FX::QMemMap.
virtual int FX::QIODevice::putch | ( | int | c | ) | [virtual, inherited] |
Writes a single byte.
Reimplemented in FX::QBuffer, FX::QBZip2Device, FX::QGZipDevice, and FX::QMemMap.
static UnicodeType FX::QIODevice::determineUnicodeType | ( | FXuchar * | data, | |
FXuval | len | |||
) | throw () [static, inherited] |
Looks at a sample of data and determines what kind of Unicode text it is, returning UnicodeType::NoTranslation if it isn't text. This routine isn't foolproof, but it's a good guess
static FXuval FX::QIODevice::applyCRLF | ( | FXuchar *FXRESTRICT | output, | |
const FXuchar *FXRESTRICT | input, | |||
FXuval | outputlen, | |||
FXuval & | inputlen, | |||
CRLFType | crlftype = Default , |
|||
UnicodeType | utftype = NoTranslation | |||
) | [static, inherited] |
Applies CR/LF and optional UTF-x translation returning bytes output. If outputlen would run out before inputlen can be exhausted it will return early (eg; if mid newline, or mid UTF-x sequence). You should rewind processing to the difference between entrant inputlen and returned inputlen.
static FXuval FX::QIODevice::removeCRLF | ( | FXuchar *FXRESTRICT | output, | |
const FXuchar *FXRESTRICT | input, | |||
FXuval | outputlen, | |||
FXuval & | inputlen, | |||
UnicodeType | utftype = NoTranslation | |||
) | [static, inherited] |
Removes CR/LF translation intelligently (ie; self-adjusts to MS-DOS, Unix and MacOS formats or any mixture of these) and can perform optional UTF-x translation, returning bytes output. If outputlen would run out before inputlen can be exhausted it will return early (eg; if mid newline, or mid UTF-x sequence). You should rewind processing to the difference between entrant inputlen and returned inputlen.
FXfval FX::QIODevice::shredData | ( | FXfval | offset, | |
FXfval | len = (FXfval)-1 | |||
) | [inherited] |
Destroys the len bytes of data from offset offset into the file. Restores the file pointer afterwards and returns how much data was shredded before end of file if encountered. You must have the device open for both reading and writing for this call to succeed.
void FX::QIODevice::setFlags | ( | int | f | ) | [inline, protected, inherited] |
Sets the flags.
void FX::QIODevice::setMode | ( | int | m | ) | [inline, protected, inherited] |
Sets the mode.
void FX::QIODevice::setState | ( | int | s | ) | [inline, protected, inherited] |
Sets the state.
Appends the contents of an i/o device to stream s
Reads all available contents of the stream s to an i/o device, replacing its current contents and resetting the file pointer to the start