Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXStream Class Reference

A stream is a way to serialize data and objects into a byte stream. More...

#include <FXStream.h>

Inheritance diagram for FX::FXStream:
FX::FXFileStream FX::FXMemoryStream

Public Member Functions

 FXStream (const FXObject *cont=nullptr)
 Construct stream with given container object. More...
 
FXbool open (FXStreamDirection save_or_load, FXuchar *data=nullptr, FXuval size=8192UL, FXbool owned=false)
 Open stream for reading (FXStreamLoad) or for writing (FXStreamSave). More...
 
virtual FXbool flush ()
 Flush buffer.
 
virtual FXbool close ()
 Close; return true if OK.
 
FXuval getSpace () const
 Get available buffer space.
 
void setSpace (FXuval sp)
 Set available buffer space.
 
void setOwned (FXbool owned)
 Set buffer ownership flag.
 
FXbool isOwned () const
 Get buffer ownership flag.
 
FXStreamStatus status () const
 Get status code.
 
FXbool eof () const
 Return true if at end of file or error.
 
void setError (FXStreamStatus err)
 Set status code.
 
FXStreamDirection direction () const
 Obtain stream direction.
 
const FXObjectcontainer () const
 Get parent object.
 
FXlong position () const
 Get position.
 
virtual FXbool position (FXlong offset, FXWhence whence=FXFromStart)
 Move to position relative to head, tail, or current location.
 
void swapBytes (FXbool s)
 Change swap bytes flag.
 
FXbool swapBytes () const
 Get state of the swap bytes flag.
 
void setBigEndian (FXbool big)
 Set stream to big endian mode if true. More...
 
FXbool isBigEndian () const
 Return true if big endian mode.
 
FXStreamoperator<< (const FXuchar &v)
 Save single items to stream.
 
FXStreamoperator<< (const FXchar &v)
 
FXStreamoperator<< (const FXbool &v)
 
FXStreamoperator<< (const FXushort &v)
 
FXStreamoperator<< (const FXshort &v)
 
FXStreamoperator<< (const FXuint &v)
 
FXStreamoperator<< (const FXint &v)
 
FXStreamoperator<< (const FXfloat &v)
 
FXStreamoperator<< (const FXdouble &v)
 
FXStreamoperator<< (const FXlong &v)
 
FXStreamoperator<< (const FXulong &v)
 
FXStreamsave (const FXuchar *p, FXuval n)
 Save arrays of items to stream.
 
FXStreamsave (const FXchar *p, FXuval n)
 
FXStreamsave (const FXbool *p, FXuval n)
 
FXStreamsave (const FXushort *p, FXuval n)
 
FXStreamsave (const FXshort *p, FXuval n)
 
FXStreamsave (const FXuint *p, FXuval n)
 
FXStreamsave (const FXint *p, FXuval n)
 
FXStreamsave (const FXfloat *p, FXuval n)
 
FXStreamsave (const FXdouble *p, FXuval n)
 
FXStreamsave (const FXlong *p, FXuval n)
 
FXStreamsave (const FXulong *p, FXuval n)
 
FXStreamoperator>> (FXuchar &v)
 Load single items from stream.
 
FXStreamoperator>> (FXchar &v)
 
FXStreamoperator>> (FXbool &v)
 
FXStreamoperator>> (FXushort &v)
 
FXStreamoperator>> (FXshort &v)
 
FXStreamoperator>> (FXuint &v)
 
FXStreamoperator>> (FXint &v)
 
FXStreamoperator>> (FXfloat &v)
 
FXStreamoperator>> (FXdouble &v)
 
FXStreamoperator>> (FXlong &v)
 
FXStreamoperator>> (FXulong &v)
 
FXStreamload (FXuchar *p, FXuval n)
 Load arrays of items from stream.
 
FXStreamload (FXchar *p, FXuval n)
 
FXStreamload (FXbool *p, FXuval n)
 
FXStreamload (FXushort *p, FXuval n)
 
FXStreamload (FXshort *p, FXuval n)
 
FXStreamload (FXuint *p, FXuval n)
 
FXStreamload (FXint *p, FXuval n)
 
FXStreamload (FXfloat *p, FXuval n)
 
FXStreamload (FXdouble *p, FXuval n)
 
FXStreamload (FXlong *p, FXuval n)
 
FXStreamload (FXulong *p, FXuval n)
 
FXStreamsaveObject (const FXObject *v)
 Save object.
 
FXStreamloadObject (FXObject *&v)
 Load object.
 
FXStreamaddObject (const FXObject *v)
 Add object without saving or loading.
 
template<class TYPE >
FXStreamoperator>> (TYPE *&obj)
 Load object.
 
template<class TYPE >
FXStreamoperator<< (const TYPE *obj)
 Save object.
 
virtual ~FXStream ()
 Destructor.
 

Protected Member Functions

virtual FXuval writeBuffer (FXuval count)
 Write at least count bytes from the buffer; returns number of bytes available to be written.
 
virtual FXuval readBuffer (FXuval count)
 Read at least count bytes into the buffer; returns number of bytes available to be read.
 

Protected Attributes

FXHash hash
 
const FXObjectparent
 
FXuchar * begptr
 
FXuchar * endptr
 
FXuchar * wrptr
 
FXuchar * rdptr
 
FXlong pos
 
FXStreamDirection dir
 
FXStreamStatus code
 
FXuint seq
 
FXbool owns
 
FXbool swap
 

Detailed Description

A stream is a way to serialize data and objects into a byte stream.

Each item of data that is saved or loaded from the stream may be byte-swapped, thus allowing little-endian machines to read data produced on big endian ones and vice-versa. Data is serialized exactly as-is. There are no tags or other markers inserted into the stream; thus, the stream may be used to save or load arbitrary binary data. Objects derived from FXObjects may be serialized also; whenever a reference to an object is serialized, a table is consulted to determine if the same object has been encountered previously; if not, the object is added to the table and then its contents are serialized. If the object has been encountered before, only a reference to the object is serialized. When loading back a serialized object, new instances are constructed using the default constructor, and subsequently the object's contents are loaded. A special container object may be passed in which is placed in the table as if it had been encountered before; this will cause only references to this object to be saved. The container object is typically the top-level document object which manages all objects contained by it. Additional objects may be added using addObject(); these will not be actually saved or loaded.

Constructor & Destructor Documentation

◆ FXStream()

FX::FXStream::FXStream ( const FXObject cont = nullptr)

Construct stream with given container object.

The container object is an object that will itself not be saved to or loaded from the stream, but which may be referenced by other objects. These references will be properly saved and restored.

Member Function Documentation

◆ open()

FXbool FX::FXStream::open ( FXStreamDirection  save_or_load,
FXuchar *  data = nullptr,
FXuval  size = 8192UL,
FXbool  owned = false 
)

Open stream for reading (FXStreamLoad) or for writing (FXStreamSave).

An initial buffer size may be given, which must be at least 16 bytes. If data is not NULL, it is expected to point to an external data buffer of length size; otherwise stream will use an internally managed buffer.

◆ setBigEndian()

void FX::FXStream::setBigEndian ( FXbool  big)

Set stream to big endian mode if true.

Byte swapping will be enabled if the machine native byte order is not equal to the desired byte order.


The documentation for this class was generated from the following file:

Copyright © 1997-2022 Jeroen van der Zijp