Public Member Functions | Protected Types | Protected Attributes
vsl_b_istream Class Reference

An adaptor for any vcl_istream to make it suitable for binary input. More...

#include <vsl_binary_io.h>

Inheritance diagram for vsl_b_istream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 vsl_b_istream (vcl_istream *is)
 Create this adaptor using an existing stream.
vcl_istream & is () const
 A reference to the adaptor's stream.
virtual ~vsl_b_istream ()
 Virtual destructor.so that it can be overloaded.
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 void add_serialisation_record (unsigned long serial_number, void *pointer, int other_data=0)
 Adds record of object's unique serial number, and location in memory.
virtual void * get_serialisation_pointer (unsigned long serial_number) const
 Returns the pointer to the object identified by the unique serial number.
virtual int get_serialisation_other_data (unsigned long serial_number) const
 Returns the user defined data associated with the unique serial number.
virtual int set_serialisation_other_data (unsigned long serial_number, int other_data)
 Modify the user-defined data associated with the unique serial number.
unsigned short version_no () const
 Return the version number of the IO format of the file being read.

Protected Types

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

Protected Attributes

vcl_istream * is_
 The member stream.
serialisation_records_type serialisation_records_
 The serialisation records,.
unsigned short version_no_

Detailed Description

An adaptor for any vcl_istream to make it suitable for binary input.

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

This class also provide basic support for serialisation. During loading, multiple pointers to one object 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 160 of file vsl_binary_io.h.


Member Typedef Documentation

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

The type of the serialisation records.

Definition at line 218 of file vsl_binary_io.h.


Constructor & Destructor Documentation

vsl_b_istream::vsl_b_istream ( vcl_istream *  i_s)

Create this adaptor using an existing stream.

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

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

Definition at line 568 of file vsl_binary_io.cxx.

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

Virtual destructor.so that it can be overloaded.

Definition at line 173 of file vsl_binary_io.h.


Member Function Documentation

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

Adds record of object's unique serial number, and location in memory.

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

Adding a null pointer or one that already exists will cause the function to abort(), if debugging is turned on;

You can also store a single integer as other data. Interpretation of this data is entirely up to the client code.

Definition at line 634 of file vsl_binary_io.cxx.

void vsl_b_istream::clear_serialisation_records ( ) [virtual]

Clear the stream's record of any serialisation operations.

Calling this function while inputting serialisable things from a stream, could cause errors during loading unless the records were cleared at a similar point during output.

Definition at line 621 of file vsl_binary_io.cxx.

int vsl_b_istream::get_serialisation_other_data ( unsigned long  serial_number) const [virtual]

Returns the user defined data associated with the unique serial number.

Returns 0 if no record has been added.

Definition at line 661 of file vsl_binary_io.cxx.

void * vsl_b_istream::get_serialisation_pointer ( unsigned long  serial_number) const [virtual]

Returns the pointer to the object identified by the unique serial number.

Returns 0 if no record has been added.

Definition at line 644 of file vsl_binary_io.cxx.

vcl_istream & vsl_b_istream::is ( ) const

A reference to the adaptor's stream.

Definition at line 598 of file vsl_binary_io.cxx.

bool vsl_b_istream::operator! ( ) const

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

Definition at line 612 of file vsl_binary_io.cxx.

int vsl_b_istream::set_serialisation_other_data ( unsigned long  serial_number,
int  other_data 
) [virtual]

Modify the user-defined data associated with the unique serial number.

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

Definition at line 678 of file vsl_binary_io.cxx.

unsigned short vsl_b_istream::version_no ( ) const

Return the version number of the IO format of the file being read.

Definition at line 606 of file vsl_binary_io.cxx.


Member Data Documentation

vcl_istream* vsl_b_istream::is_ [protected]

The member stream.

Definition at line 214 of file vsl_binary_io.h.

The serialisation records,.

The record takes a unique identifier of the object (which would be stored on the stream) and returns the pointer to the object, and an other_data integer.

Definition at line 224 of file vsl_binary_io.h.

unsigned short vsl_b_istream::version_no_ [protected]

Definition at line 227 of file vsl_binary_io.h.


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