#include <QBuffer.h>
There's little more to say than that this class works with a QByteArray to provide an i/o device working directly with memory. It auto-extends the array if needed etc. It's also thread-safe so multiple threads can use the i/o device at once.
Note that QBuffer ignores CR/LF translation (IO_Translate). Anything dealing with files in TnFOX does though, so the conversion can be done then.
Since there is no reference counted sharing in TnFOX, buffer() and setBuffer() return and take references.
Public Types | |
enum | CRLFType { Default, Unix, MacOS, MSDOS } |
enum | UnicodeType { NoTranslation, UTF8, UTF16, UTF16LE, UTF32, UTF32LE } |
typedef FXfval | Offset |
Public Member Functions | |
QBuffer (FXuval len=0, bool fastbuffer=false) | |
QBuffer (QByteArray &buffer) | |
bool | isNull () const |
QByteArray & | buffer () const |
void | setBuffer (QByteArray &buffer) |
virtual bool | open (FXuint mode) |
virtual void | close () |
virtual void | flush () |
virtual FXfval | size () const |
virtual void | truncate (FXfval size) |
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 | getch () |
virtual int | putch (int c) |
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 |
virtual FXfval | at () const |
virtual bool | at (FXfval newpos) |
virtual bool | atEnd () const |
virtual const FXACL & | permissions () const |
virtual void | setPermissions (const FXACL &) |
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) |
FXfval | shredData (FXfval offset, FXfval len=(FXfval)-1) |
Static Public Member Functions | |
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 | |
FXAPI FXStream & | operator<< (FXStream &s, const QBuffer &i) |
FXAPI FXStream & | operator>> (FXStream &s, QBuffer &i) |
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::QBuffer::QBuffer | ( | FXuval | len = 0 , |
|
bool | fastbuffer = false | |||
) | [explicit] |
Constructs a new instance using an internal QByteArray of length len. Setting /em fastbuffer to true sets the internal QByteArray to use a directly managed malloc() buffer which can offer superior performance at the cost of the QByteArray no longer behaving correctly
FX::QBuffer::QBuffer | ( | QByteArray & | buffer | ) | [explicit] |
Constructs a new instance using buffer as the memory array.
bool FX::QBuffer::isNull | ( | ) | const |
Returns true if the device has never been used.
QByteArray& FX::QBuffer::buffer | ( | ) | const |
Returns the byte array being addressed by this device.
void FX::QBuffer::setBuffer | ( | QByteArray & | buffer | ) |
Sets the byte array being addressed by this device. Closes the old buffer first.
virtual bool FX::QBuffer::open | ( | FXuint | mode | ) | [virtual] |
virtual void FX::QBuffer::close | ( | ) | [virtual] |
virtual void FX::QBuffer::flush | ( | ) | [virtual] |
virtual FXfval FX::QBuffer::size | ( | ) | const [virtual] |
virtual void FX::QBuffer::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 FXuval FX::QBuffer::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::QBuffer::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::QBuffer::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::QBuffer::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::QBuffer::getch | ( | ) | [virtual] |
virtual int FX::QBuffer::putch | ( | int | c | ) | [virtual] |
virtual int FX::QBuffer::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 FXfval FX::QIODevice::at | ( | ) | const [virtual, inherited] |
Returns the current file pointer within the device
Reimplemented in FX::QBZip2Device, FX::QFile, FX::QGZipDevice, FX::QIODeviceS, FX::QLocalPipe, FX::QMemMap, FX::QPipe, and FX::QSSLDevice.
virtual bool FX::QIODevice::at | ( | FXfval | newpos | ) | [virtual, inherited] |
Sets the current file pointer
Reimplemented in FX::QBZip2Device, FX::QFile, FX::QGZipDevice, FX::QIODeviceS, FX::QLocalPipe, FX::QMemMap, FX::QPipe, and FX::QSSLDevice.
virtual bool FX::QIODevice::atEnd | ( | ) | const [virtual, inherited] |
Returns true if there is no more data available to be read from the device.
Reimplemented in FX::QBZip2Device, FX::QFile, FX::QGZipDevice, FX::QIODeviceS, FX::QLocalPipe, FX::QMemMap, FX::QPipe, and FX::QSSLDevice.
virtual const FXACL& FX::QIODevice::permissions | ( | ) | const [virtual, inherited] |
Returns the ACL for this device.
Reimplemented in FX::QBlkSocket, FX::QFile, FX::QMemMap, FX::QPipe, and FX::QSSLDevice.
virtual void FX::QIODevice::setPermissions | ( | const FXACL & | ) | [virtual, inherited] |
Sets the ACL for this device.
Reimplemented in FX::QFile, FX::QMemMap, FX::QPipe, 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.
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 a buffer to stream s.
Reads all available contents of the stream s to a buffer, replacing its current contents.
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