FX::FXStream Class Reference

#include <FXStream.h>

Inheritance diagram for FX::FXStream:

FX::FXStreamBase FX::FXBZFileStream FX::FXFileStream FX::FXGZFileStream FX::FXMemoryStream List of all members.

Detailed Description

File format helper (Qt compatible).

FXStream is a modified version of FOX's FXStream - it is mostly API compatible but admittedly reflects the biggest divergence of API between FOX and TnFOX at the time of writing. Both share the purpose of serialising and deserialising data to and from a stored format and indeed via loadObject() and saveObject() can transfer entire window trees to and from storage.

Most use is simple - set which QIODevice it should use, and then use the << and >> operators to store and load respectively. position() lets you set or read the current offset into the file. Most classes in TnFOX (as well as FOX) provide overloads for these operators, so your << and >> overloads merely need to call << and >> on each of your data members you wish to save. Use load() and save() for blocks of individual units for efficiency.

Previous to FOX v1.1.31, FOX used FXStream mostly for dumping application state and its FXStream was not designed for general purpose file i/o. TnFOX uses FXStream for IPC which can traverse networks and CPU types, so it needs FXStream to be fast and always generate data in a universally understood format. You can of course use swapBytes() based on a flag within your data structure to avoid unnecessary endian conversions (and indeed this is what TnFOX's IPC classes do based on endian types on each end of the communications channel).

Since FOX v1.1.31, FXStream incorporates buffering and more general purpose facilities. The buffering in particular is left out because that's for the i/o device classes to implement if they want to. More importantly, IPC just would not work if a write to a pipe was coalesced into a larger packet sent sometime later.

Difference from FOX's FXStream & Qt's QDataStream

Endian translation is performed for you on big endian machines by default (simply because numerically more computers in the world are little endian, therefore we want to cost the least performance for the most people). Normal FOX always saves in native format and converts on load - and Qt is big endian by default.

Lastly, QDataStream's printable data format is unsupported. You don't need it with a decent debugger anyway (and it's ridiculously slow).

Useful tip:

Look into QBuffer's ability to dump itself onto a stream. This lets you very conveniently prepare parts of an overall image into separate sections. I've personally found that if you keep your end file image in a set of ordered nested QPtrList's & QBuffer's, writing it out is as simple as:

FXStream s;
QValueList<QPtrListOrBufferHolder> filedata;
s << filedata;
QValueList invokes the << operator on each of its members and so it recurses down calling each in turn. All QTL thunks provided in TnFOX provide default stream operators which require a null constructor in the type to compile.

Definition at line 147 of file FXStream.h.

Public Types

enum  ByteOrder { BigEndian, LittleEndian }

Public Member Functions

 FXStream (QIODevice *dev=0, const FXObject *cont=NULL)
QIODevicedevice () const
void setDevice (QIODevice *dev)
FXDEPRECATEDEXT void unsetDevice ()
bool atEnd () const
int byteOrder () const
void setByteOrder (int b)
FXDEPRECATEDEXT FXStreamreadBytes (char *&s, FXuint &l)
FXStreamreadRawBytes (char *buffer, FXuval len)
FXStreamreadRawBytes (FXuchar *buffer, FXuval len)
FXDEPRECATEDEXT FXStreamwriteBytes (const char *s, FXuint l)
FXStreamwriteRawBytes (const char *buffer, FXuval len)
FXStreamwriteRawBytes (const FXuchar *buffer, FXuval len)
FXfval rewind (FXint amount)
FXDEPRECATEDEXT FXStream (const FXObject *cont)
FXDEPRECATEDEXT bool open (FXStreamDirection save_or_load, FXuval size=8192, FXuchar *data=NULL)
virtual FXDEPRECATEDEXT bool flush ()
virtual bool close ()
FXDEPRECATEDEXT FXuval getSpace () const
FXDEPRECATEDEXT void setSpace (FXuval sp)
FXDEPRECATEDEXT FXStreamStatus status () const
bool eof () const
FXDEPRECATEDEXT void setError (FXStreamStatus err)
FXDEPRECATEDEXT FXStreamDirection direction () const
FXDEPRECATEDEXT const FXObjectcontainer () const
FXlong position () const
virtual bool position (FXlong offset, FXWhence whence=FXFromStart)
void swapBytes (FXint s)
bool swapBytes () const
void setBigEndian (bool big)
bool isBigEndian () const
FXStreamsave (const FXuchar *p, unsigned long n)
FXStreamsave (const FXchar *p, unsigned long n)
FXStreamsave (const FXushort *p, unsigned long n)
FXStreamsave (const FXshort *p, unsigned long n)
FXStreamsave (const FXuint *p, unsigned long n)
FXStreamsave (const FXint *p, unsigned long n)
FXStreamsave (const FXfloat *p, unsigned long n)
FXStreamsave (const FXdouble *p, unsigned long n)
FXStreamsave (const FXlong *p, unsigned long n)
FXStreamsave (const FXulong *p, unsigned long n)
FXStreamload (FXuchar *p, unsigned long n)
FXStreamload (FXchar *p, unsigned long n)
FXStreamload (FXushort *p, unsigned long n)
FXStreamload (FXshort *p, unsigned long n)
FXStreamload (FXuint *p, unsigned long n)
FXStreamload (FXint *p, unsigned long n)
FXStreamload (FXfloat *p, unsigned long n)
FXStreamload (FXdouble *p, unsigned long n)
FXStreamload (FXlong *p, unsigned long n)
FXStreamload (FXulong *p, unsigned long n)
FXStreamsaveObject (const FXObject *v)
FXStreamloadObject (FXObject *&v)
FXStreamaddObject (const FXObject *v)
virtual ~FXStream ()

Protected Member Functions

virtual FXuval writeBuffer (FXuval count)
virtual FXuval readBuffer (FXuval count)

Protected Attributes

const FXObjectparent
FXlong pos
FXStreamDirection dir
FXStreamStatus code
FXuint seq
bool owns
bool swap


struct Generic::hasSerialise
struct Generic::hasDeserialise
FXStreamoperator<< (FXStream &s, const FXuchar &v)
FXStreamoperator<< (FXStream &s, const FXchar &v)
FXStreamoperator<< (FXStream &s, const FXushort &_v)
FXStreamoperator<< (FXStream &s, const FXshort &v)
FXStreamoperator<< (FXStream &s, const FXuint &_v)
FXStreamoperator<< (FXStream &s, const FXint &v)
FXStreamoperator<< (FXStream &s, const FXfloat &_v)
FXStreamoperator<< (FXStream &s, const FXdouble &_v)
FXStreamoperator<< (FXStream &s, const FXlong &v)
FXStreamoperator<< (FXStream &s, const FXulong &_v)
FXStreamoperator<< (FXStream &s, const char *v)
FXStreamoperator<< (FXStream &s, const bool &_v)
FXStreamoperator>> (FXStream &s, FXuchar &v)
FXStreamoperator>> (FXStream &s, FXchar &v)
FXStreamoperator>> (FXStream &s, FXushort &v)
FXStreamoperator>> (FXStream &s, FXshort &v)
FXStreamoperator>> (FXStream &s, FXuint &v)
FXStreamoperator>> (FXStream &s, FXint &v)
FXStreamoperator>> (FXStream &s, FXfloat &v)
FXStreamoperator>> (FXStream &s, FXdouble &v)
FXStreamoperator>> (FXStream &s, FXlong &v)
FXStreamoperator>> (FXStream &s, FXulong &v)
FXStreamoperator>> (FXStream &s, bool &v)

The documentation for this class was generated from the following file:
(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:36:31 2009 for TnFOX by doxygen v1.4.7