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

An adapter for a std::ofstream to make it suitable for binary IO. More...

#include <vsl_binary_io.h>

Inheritance diagram for vsl_b_ofstream:
Inheritance graph
[legend]

Public Member Functions

 vsl_b_ofstream (const std::string &filename, std::ios::openmode mode=std::ios::out|std::ios::trunc)
 Create this adaptor from a file. More...
 
 vsl_b_ofstream (const char *filename, std::ios::openmode mode=std::ios::out|std::ios::trunc)
 Create this adaptor from a file. More...
 
 ~vsl_b_ofstream () override
 Virtual destructor. More...
 
void close ()
 Close the stream. More...
 
std::ostream & os () const
 A reference to the adaptor's stream. 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 unsigned long add_serialisation_record (void *pointer, int other_data=0)
 Adds an object pointer to the serialisation records. More...
 
virtual unsigned long get_serial_number (void *pointer) const
 Returns a unique identifier for the object. More...
 
virtual int get_serialisation_other_data (void *pointer) const
 Set the user-defined data associated with the object. More...
 
virtual int set_serialisation_other_data (void *pointer, int other_data)
 Modify the user-defined data associated with the object. More...
 

Static Public Attributes

static constexpr std::streamoff header_length = 6
 The length of the b_stream header. More...
 

Protected Types

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

Protected Attributes

std::ostream * os_
 The member stream. More...
 
serialisation_records_type serialisation_records_
 The serialisation records. More...
 

Static Protected Attributes

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

Detailed Description

An adapter for a std::ofstream to make it suitable for binary IO.

Definition at line 125 of file vsl_binary_io.h.

Member Typedef Documentation

◆ serialisation_records_type

typedef std::map<void *, std::pair<unsigned long, int>, std::less<void *> > vsl_b_ostream::serialisation_records_type
protectedinherited

The type of the serialisation records.

Definition at line 112 of file vsl_binary_io.h.

Constructor & Destructor Documentation

◆ vsl_b_ofstream() [1/2]

vsl_b_ofstream::vsl_b_ofstream ( const std::string &  filename,
std::ios::openmode  mode = std::ios::out | std::ios::trunc 
)
inline

Create this adaptor from a file.

The adapter will delete the internal stream automatically on destruction.

Definition at line 130 of file vsl_binary_io.h.

◆ vsl_b_ofstream() [2/2]

vsl_b_ofstream::vsl_b_ofstream ( const char *  filename,
std::ios::openmode  mode = std::ios::out | std::ios::trunc 
)
inline

Create this adaptor from a file.

The adapter will delete the internal stream automatically on destruction.

Definition at line 136 of file vsl_binary_io.h.

◆ ~vsl_b_ofstream()

vsl_b_ofstream::~vsl_b_ofstream ( )
override

Virtual destructor.

destructor.

Definition at line 310 of file vsl_binary_io.cxx.

Member Function Documentation

◆ add_serialisation_record()

unsigned long vsl_b_ostream::add_serialisation_record ( void *  pointer,
int  other_data = 0 
)
virtualinherited

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

◆ clear_serialisation_records()

void vsl_b_ostream::clear_serialisation_records ( )
virtualinherited

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. Calling this function may be required if you change the state of your program whilst you are writing to the same vsl_b_ostream. If the program is at any risk of reallocating the same memory to two different objects controlled by a smart pointer, then calling this function between writing then will prevent them being confused.

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

◆ close()

void vsl_b_ofstream::close ( )

Close the stream.

Definition at line 317 of file vsl_binary_io.cxx.

◆ get_serial_number()

unsigned long vsl_b_ostream::get_serial_number ( void *  pointer) const
virtualinherited

Returns a unique identifier for the object.

Returns 0 if there is no record of the object.

Definition at line 260 of file vsl_binary_io.cxx.

◆ get_serialisation_other_data()

int vsl_b_ostream::get_serialisation_other_data ( void *  pointer) const
virtualinherited

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

◆ operator!()

bool vsl_b_ostream::operator! ( ) const
inherited

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

Definition at line 224 of file vsl_binary_io.cxx.

◆ os()

std::ostream & vsl_b_ostream::os ( ) const
inherited

A reference to the adaptor's stream.

Definition at line 217 of file vsl_binary_io.cxx.

◆ set_serialisation_other_data()

int vsl_b_ostream::set_serialisation_other_data ( void *  pointer,
int  other_data 
)
virtualinherited

Modify the user-defined data associated with the object.

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

Definition at line 295 of file vsl_binary_io.cxx.

Member Data Documentation

◆ header_length

constexpr std::streamoff vsl_b_ostream::header_length = 6
staticinherited

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

◆ os_

std::ostream* vsl_b_ostream::os_
protectedinherited

The member stream.

Definition at line 97 of file vsl_binary_io.h.

◆ serialisation_records_

serialisation_records_type vsl_b_ostream::serialisation_records_
protectedinherited

The serialisation records.

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

Definition at line 117 of file vsl_binary_io.h.

◆ version_no_

constexpr unsigned short vsl_b_ostream::version_no_ = 1
staticprotectedinherited

The version number of the IO scheme.

Definition at line 120 of file vsl_binary_io.h.


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