vg
tools for working with variation graphs
Public Member Functions | Protected Member Functions | List of all members
handlegraph::TriviallySerializable Class Referenceabstract

#include <trivially_serializable.hpp>

Inheritance diagram for handlegraph::TriviallySerializable:
handlegraph::Serializable

Public Member Functions

 TriviallySerializable ()=default
 
virtual ~TriviallySerializable ()=default
 
virtual void dissociate ()=0
 
virtual void serialize (const std::function< void(const void *, size_t)> &iteratee) const =0
 
virtual void serialize (int fd)=0
 
virtual void deserialize (int fd)=0
 
virtual void serialize (int fd) const
 
virtual void serialize (const std::string &filename) const
 
virtual void serialize (const std::string &filename)
 
virtual void deserialize (const std::string &filename)
 
virtual void serialize (std::ostream &out) const
 
virtual void serialize (std::ostream &out)
 
virtual void deserialize (std::istream &in)
 
- Public Member Functions inherited from handlegraph::Serializable
virtual ~Serializable ()=default
 
virtual uint32_t get_magic_number () const =0
 

Protected Member Functions

int open_fd (const std::string &filename) const
 Helper to open a file descriptor with error checking. More...
 
void close_fd (int fd) const
 Helper to close a file descriptor with error checking. More...
 
- Protected Member Functions inherited from handlegraph::Serializable
virtual void serialize_members (std::ostream &out) const =0
 Underlying implementation for "serialize" method. More...
 
virtual void deserialize_members (std::istream &in)=0
 Underlying implementation to "deserialize" method. More...
 

Detailed Description

Interface for objects that can use identical in-memory and serialized representations.

The representation begins with the serialized 4-byte magic number, followed by user data. Length is implicit in either stream length or file size, and can be grown.

If serialization or deserialization throws, it is safe to destroy the object, but not to do anything else with it.

Modifying a file that an object has been loaded from or saved to, either on disk or through another associated object, is undefined behavior. To prevent modifications to an object from modifying the last file loaded or saved to, use dissociate().

Constructor & Destructor Documentation

◆ TriviallySerializable()

handlegraph::TriviallySerializable::TriviallySerializable ( )
default

Make a new TriviallySerializable. Should really only be called by constructors of inheriting types.

◆ ~TriviallySerializable()

virtual handlegraph::TriviallySerializable::~TriviallySerializable ( )
virtualdefault

Destroy a TriviallySerializable object and any associated memory mappings.

Member Function Documentation

◆ close_fd()

void handlegraph::TriviallySerializable::close_fd ( int  fd) const
protected

Helper to close a file descriptor with error checking.

◆ deserialize() [1/3]

void handlegraph::TriviallySerializable::deserialize ( const std::string &  filename)
virtual

Sets the contents of this object to the contents of a serialized object from a file. The serialized object must be from the same implementation of this interface as is calling deserialize(). Can only be called on an empty object. If the file is a normal writeable file, future modifications to the object will affect the file until dissociate() is called or another normal file is associated.

Reimplemented from handlegraph::Serializable.

◆ deserialize() [2/3]

virtual void handlegraph::TriviallySerializable::deserialize ( int  fd)
pure virtual

Sets the contents of this object to the contents of a serialized object from an open file descriptor. The serialized object must be from the same implementation of this interface as is calling deserialize(). Can only be called on an empty object If the file is a normal writeable file, future modifications to the object will affect the file until dissociate() is called or another normal file is associated.

Assumes that the file entirely belongs to this object.

◆ deserialize() [3/3]

void handlegraph::TriviallySerializable::deserialize ( std::istream &  in)
virtual

Sets the contents of this object to the contents of a serialized object from an istream. The serialized object must be from the same implementation of the interface as is calling deserialize(). Can only be called on an empty object. May result in a write-back link to a file opened as standard input if that stream is passed.

Reimplemented from handlegraph::Serializable.

◆ dissociate()

virtual void handlegraph::TriviallySerializable::dissociate ( )
pure virtual

Break the write-back link between this object and the file it was loaded from, if any. Future modifications to the object will not affect the file, although future modifications to the file may still affect the object.

◆ open_fd()

int handlegraph::TriviallySerializable::open_fd ( const std::string &  filename) const
protected

Helper to open a file descriptor with error checking.

◆ serialize() [1/7]

virtual void handlegraph::TriviallySerializable::serialize ( const std::function< void(const void *, size_t)> &  iteratee) const
pure virtual

Serialize as blocks of data shown to the given function. The pointer must not be null. The blocks must include the magic number.

◆ serialize() [2/7]

void handlegraph::TriviallySerializable::serialize ( const std::string &  filename)
virtual

Write the contents of this object to a named file. Makes sure to include a leading magic number. If the file is nonexistent or a normal file, future modifications to the object will affect the file until dissociate() is called or another normal file is associated.

Reimplemented from handlegraph::Serializable.

◆ serialize() [3/7]

void handlegraph::TriviallySerializable::serialize ( const std::string &  filename) const
virtual

Write the contents of this object to a named file. Makes sure to include a leading magic number. Does not affect any existing write-back links.

Reimplemented from handlegraph::Serializable.

◆ serialize() [4/7]

void handlegraph::TriviallySerializable::serialize ( int  fd) const
virtual

Write the contents of this object to an open file descriptor. Makes sure to include a leading magic number.

Assumes that the file entirely belongs to this object.

◆ serialize() [5/7]

virtual void handlegraph::TriviallySerializable::serialize ( int  fd)
pure virtual

Write the contents of this object to an open file descriptor. Makes sure to include a leading magic number. If the file is a normal file, future modifications to the object will affect the file until dissociate() is called or another normal file is associated.

Assumes that the file entirely belongs to this object.

◆ serialize() [6/7]

void handlegraph::TriviallySerializable::serialize ( std::ostream &  out)
virtual

Dump the magic number and user data to the given stream. May result in a write-back link to a file opened as standard output or standard error if those streams are passed.

Reimplemented from handlegraph::Serializable.

◆ serialize() [7/7]

void handlegraph::TriviallySerializable::serialize ( std::ostream &  out) const
virtual

Dump the magic number and user data to the given stream. Does not affect any backing file link.

Reimplemented from handlegraph::Serializable.


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