A binary output adaptor for any std::ostream. More...
#include <vsl_binary_io.h>

Public Member Functions | |
| vsl_b_ostream (std::ostream *os) | |
| Create this adaptor using an existing stream. More... | |
| std::ostream & | os () const |
| A reference to the adaptor's stream. More... | |
| virtual | ~vsl_b_ostream ()=default |
| Virtual destructor. 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... | |
A binary output adaptor for any std::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 37 of file vsl_binary_io.h.
|
protected |
The type of the serialisation records.
Definition at line 112 of file vsl_binary_io.h.
| vsl_b_ostream::vsl_b_ostream | ( | std::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 208 of file vsl_binary_io.cxx.
|
virtualdefault |
Virtual destructor.
|
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 248 of file vsl_binary_io.cxx.
|
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. 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.
|
virtual |
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.
|
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 278 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 224 of file vsl_binary_io.cxx.
| std::ostream & vsl_b_ostream::os | ( | ) | const |
A reference to the adaptor's stream.
Definition at line 217 of file vsl_binary_io.cxx.
|
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 295 of file vsl_binary_io.cxx.
|
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 93 of file vsl_binary_io.h.
|
protected |
The member stream.
Definition at line 97 of file vsl_binary_io.h.
|
protected |
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.
|
staticprotected |
The version number of the IO scheme.
Definition at line 120 of file vsl_binary_io.h.
1.8.15