Public Member Functions | Protected Types | Protected Attributes | List of all members
vsl_b_istream Class Reference

An adaptor for any std::istream to make it suitable for binary input. More...

#include <vsl_binary_io.h>

Inheritance diagram for vsl_b_istream:
Inheritance graph
[legend]

Public Member Functions

 vsl_b_istream (std::istream *is)
 Create this adaptor using an existing stream. More...
 
std::istream & is () const
 A reference to the adaptor's stream. More...
 
virtual ~vsl_b_istream ()=default
 Virtual destructor.so that it can be overloaded. More...
 
bool operator! () const
 Returns true if the underlying stream has its fail bit set. More...
 
virtual void clear_serialisation_records ()
 Clear the stream's record of any serialisation operations. More...
 
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. More...
 
virtual void * get_serialisation_pointer (unsigned long serial_number) const
 Returns the pointer to the object identified by the unique serial number. More...
 
virtual int get_serialisation_other_data (unsigned long serial_number) const
 Returns the user defined data associated with the unique serial number. More...
 
virtual int set_serialisation_other_data (unsigned long serial_number, int other_data)
 Modify the user-defined data associated with the unique serial number. More...
 
unsigned short version_no () const
 Return the version number of the IO format of the file being read. More...
 

Protected Types

typedef std::map< unsigned long, std::pair< void *, int >, std::less< unsigned long > > serialisation_records_type
 The type of the serialisation records. More...
 

Protected Attributes

std::istream * is_
 The member stream. More...
 
serialisation_records_type serialisation_records_
 The serialisation records,. More...
 
unsigned short version_no_
 

Detailed Description

An adaptor for any std::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 166 of file vsl_binary_io.h.

Member Typedef Documentation

◆ serialisation_records_type

typedef std::map<unsigned long, std::pair<void *, int>, std::less<unsigned long> > vsl_b_istream::serialisation_records_type
protected

The type of the serialisation records.

Definition at line 224 of file vsl_binary_io.h.

Constructor & Destructor Documentation

◆ vsl_b_istream()

vsl_b_istream::vsl_b_istream ( std::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 328 of file vsl_binary_io.cxx.

◆ ~vsl_b_istream()

virtual vsl_b_istream::~vsl_b_istream ( )
virtualdefault

Virtual destructor.so that it can be overloaded.

Member Function Documentation

◆ add_serialisation_record()

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 394 of file vsl_binary_io.cxx.

◆ clear_serialisation_records()

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 381 of file vsl_binary_io.cxx.

◆ get_serialisation_other_data()

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 421 of file vsl_binary_io.cxx.

◆ get_serialisation_pointer()

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 404 of file vsl_binary_io.cxx.

◆ is()

std::istream & vsl_b_istream::is ( ) const

A reference to the adaptor's stream.

Definition at line 358 of file vsl_binary_io.cxx.

◆ operator!()

bool vsl_b_istream::operator! ( ) const

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

Definition at line 372 of file vsl_binary_io.cxx.

◆ set_serialisation_other_data()

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 438 of file vsl_binary_io.cxx.

◆ version_no()

unsigned short vsl_b_istream::version_no ( ) const

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

Definition at line 366 of file vsl_binary_io.cxx.

Member Data Documentation

◆ is_

std::istream* vsl_b_istream::is_
protected

The member stream.

Definition at line 220 of file vsl_binary_io.h.

◆ serialisation_records_

serialisation_records_type vsl_b_istream::serialisation_records_
protected

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 230 of file vsl_binary_io.h.

◆ version_no_

unsigned short vsl_b_istream::version_no_
protected

Definition at line 233 of file vsl_binary_io.h.


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