Public Member Functions | Static Public Attributes | Protected Types | Protected Attributes | Static Protected Attributes
vsl_b_ostream Class Reference

A binary output adaptor for any vcl_ostream. More...

#include <vsl_binary_io.h>

Inheritance diagram for vsl_b_ostream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 vsl_b_ostream (vcl_ostream *os)
 Create this adaptor using an existing stream.
vcl_ostream & os () const
 A reference to the adaptor's stream.
virtual ~vsl_b_ostream ()
 Virtual destructor.
bool operator! () const
 Returns true if the underlying stream has its fail bit set.
virtual void clear_serialisation_records ()
 Clear the stream's record of any serialisation operations.
virtual unsigned long add_serialisation_record (void *pointer, int other_data=0)
 Adds an object pointer to the serialisation records.
virtual unsigned long get_serial_number (void *pointer) const
 Returns a unique identifier for the object.
virtual int get_serialisation_other_data (void *pointer) const
 Set the user-defined data associated with the object.
virtual int set_serialisation_other_data (void *pointer, int other_data)
 Modify the user-defined data associated with the object.

Static Public Attributes

static const vcl_streamoff header_length = 6
 The length of the b_stream header.

Protected Types

typedef vcl_map< void
*, vcl_pair< unsigned long,
int >, vcl_less< void * > > 
serialisation_records_type
 The type of the serialisation records.

Protected Attributes

vcl_ostream * os_
 The member stream.
serialisation_records_type serialisation_records_
 The serialisation records.

Static Protected Attributes

static const unsigned short version_no_ = 1
 The version number of the IO scheme.

Detailed Description

A binary output adaptor for any vcl_ostream.

Currently the main use of this is to encourage streams to be opened in binary mode (ie. without CR/LF conversion)

This class also provide basic support for serialisation. This allows an object which has multiple pointers to it to be saved only once. During reloading, the pointers can be all set up again to point to the single object. vsl_b_ostream does not do the serialisation itself, but instead keeps records of unique identifiers to allow the user's code to perform serialisation safely. For instance, a smart pointer type object will have to know how to safely save whatever it is pointing to.

Definition at line 34 of file vsl_binary_io.h.


Member Typedef Documentation

typedef vcl_map<void *, vcl_pair<unsigned long, int>, vcl_less<void *> > vsl_b_ostream::serialisation_records_type [protected]

The type of the serialisation records.

Definition at line 106 of file vsl_binary_io.h.


Constructor & Destructor Documentation

vsl_b_ostream::vsl_b_ostream ( vcl_ostream *  o_s)

Create this adaptor using an existing stream.

The stream (os) must be open (i.e. ready to receive insertions) so that the IO version and magic number can be written by this constructor. User is responsible for deleting os after deleting the adaptor

The stream (os) must be open (i.e. ready to be written to) so that the IO version number can be written by this constructor. User is responsible for deleting os after deleting the adaptor

Definition at line 448 of file vsl_binary_io.cxx.

virtual vsl_b_ostream::~vsl_b_ostream ( ) [inline, virtual]

Virtual destructor.

Definition at line 48 of file vsl_binary_io.h.


Member Function Documentation

unsigned long vsl_b_ostream::add_serialisation_record ( void *  pointer,
int  other_data = 0 
) [virtual]

Adds an object pointer to the serialisation records.

Returns a unique identifier for the object.

pointer must be non-null, so you should handle null pointers separately.

You can optionally add some user-defined integer with each record If error checking is on, and the object pointer is null or already in the records, this function will abort()

Definition at line 488 of file vsl_binary_io.cxx.

void vsl_b_ostream::clear_serialisation_records ( ) [virtual]

Clear the stream's record of any serialisation operations.

Calling this function while outputting serialisable things to stream, will mean that a second copy of an object may get stored to the stream.

Definition at line 473 of file vsl_binary_io.cxx.

unsigned long vsl_b_ostream::get_serial_number ( void *  pointer) const [virtual]

Returns a unique identifier for the object.

Returns 0 if there is no record of the object.

Definition at line 500 of file vsl_binary_io.cxx.

int vsl_b_ostream::get_serialisation_other_data ( void *  pointer) const [virtual]

Set the user-defined data associated with the object.

If there is no record of the object, this function will return 0. However a retval of 0 does not necessarily imply that the object is unrecorded.

Definition at line 518 of file vsl_binary_io.cxx.

bool vsl_b_ostream::operator! ( ) const

Returns true if the underlying stream has its fail bit set.

Definition at line 464 of file vsl_binary_io.cxx.

vcl_ostream & vsl_b_ostream::os ( ) const

A reference to the adaptor's stream.

Definition at line 457 of file vsl_binary_io.cxx.

int vsl_b_ostream::set_serialisation_other_data ( void *  pointer,
int  other_data 
) [virtual]

Modify the user-defined data associated with the object.

If there is no record of the object, this function will abort.

Definition at line 535 of file vsl_binary_io.cxx.


Member Data Documentation

const vcl_streamoff vsl_b_ostream::header_length = 6 [static]

The length of the b_stream header.

You can move to this offset from the start of the file to get to the first real data item.

Definition at line 87 of file vsl_binary_io.h.

vcl_ostream* vsl_b_ostream::os_ [protected]

The member stream.

Definition at line 91 of file vsl_binary_io.h.

The serialisation records.

Records a pointer, a unique identifier, and an integer (user_defined data.)

Definition at line 111 of file vsl_binary_io.h.

const unsigned short vsl_b_ostream::version_no_ = 1 [static, protected]

The version number of the IO scheme.

Definition at line 114 of file vsl_binary_io.h.


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