Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
A stream is a way to serialize data and objects into a byte stream. More...
#include <FXStream.h>
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 FXObject * | container () 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. | |
FXStream & | operator<< (const FXuchar &v) |
Save single items to stream. | |
FXStream & | operator<< (const FXchar &v) |
FXStream & | operator<< (const FXbool &v) |
FXStream & | operator<< (const FXushort &v) |
FXStream & | operator<< (const FXshort &v) |
FXStream & | operator<< (const FXuint &v) |
FXStream & | operator<< (const FXint &v) |
FXStream & | operator<< (const FXfloat &v) |
FXStream & | operator<< (const FXdouble &v) |
FXStream & | operator<< (const FXlong &v) |
FXStream & | operator<< (const FXulong &v) |
FXStream & | save (const FXuchar *p, FXuval n) |
Save arrays of items to stream. | |
FXStream & | save (const FXchar *p, FXuval n) |
FXStream & | save (const FXbool *p, FXuval n) |
FXStream & | save (const FXushort *p, FXuval n) |
FXStream & | save (const FXshort *p, FXuval n) |
FXStream & | save (const FXuint *p, FXuval n) |
FXStream & | save (const FXint *p, FXuval n) |
FXStream & | save (const FXfloat *p, FXuval n) |
FXStream & | save (const FXdouble *p, FXuval n) |
FXStream & | save (const FXlong *p, FXuval n) |
FXStream & | save (const FXulong *p, FXuval n) |
FXStream & | operator>> (FXuchar &v) |
Load single items from stream. | |
FXStream & | operator>> (FXchar &v) |
FXStream & | operator>> (FXbool &v) |
FXStream & | operator>> (FXushort &v) |
FXStream & | operator>> (FXshort &v) |
FXStream & | operator>> (FXuint &v) |
FXStream & | operator>> (FXint &v) |
FXStream & | operator>> (FXfloat &v) |
FXStream & | operator>> (FXdouble &v) |
FXStream & | operator>> (FXlong &v) |
FXStream & | operator>> (FXulong &v) |
FXStream & | load (FXuchar *p, FXuval n) |
Load arrays of items from stream. | |
FXStream & | load (FXchar *p, FXuval n) |
FXStream & | load (FXbool *p, FXuval n) |
FXStream & | load (FXushort *p, FXuval n) |
FXStream & | load (FXshort *p, FXuval n) |
FXStream & | load (FXuint *p, FXuval n) |
FXStream & | load (FXint *p, FXuval n) |
FXStream & | load (FXfloat *p, FXuval n) |
FXStream & | load (FXdouble *p, FXuval n) |
FXStream & | load (FXlong *p, FXuval n) |
FXStream & | load (FXulong *p, FXuval n) |
FXStream & | saveObject (const FXObject *v) |
Save object. | |
FXStream & | loadObject (FXObject *&v) |
Load object. | |
FXStream & | addObject (const FXObject *v) |
Add object without saving or loading. | |
template<class TYPE > | |
FXStream & | operator>> (TYPE *&obj) |
Load object. | |
template<class TYPE > | |
FXStream & | operator<< (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 FXObject * | parent |
FXuchar * | begptr |
FXuchar * | endptr |
FXuchar * | wrptr |
FXuchar * | rdptr |
FXlong | pos |
FXStreamDirection | dir |
FXStreamStatus | code |
FXuint | seq |
FXbool | owns |
FXbool | swap |
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.
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.
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.
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.
Copyright © 1997-2022 Jeroen van der Zijp |