vg
tools for working with variation graphs
Static Public Member Functions | Static Private Member Functions | List of all members
vg::io::VPKG Class Reference

#include <vpkg.hpp>

Static Public Member Functions

template<typename... Wanted>
static tuple< unique_ptr< Wanted >... > try_load_first (istream &in, const string &filename="")
 
template<typename... Wanted>
static tuple< unique_ptr< Wanted >... > try_load_first (const string &filename)
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_one (istream &in, const string &filename="")
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_one (const string &filename)
 
template<typename Wanted >
static unique_ptr< Wanted > load_one (istream &in, const string &filename="")
 
template<typename Wanted >
static unique_ptr< Wanted > load_one (const string &filename)
 
template<typename Have >
static void save (const Have &have, ostream &out)
 
template<typename Have >
static void save (const Have &have, const string &filename)
 
static void with_save_stream (ostream &to, const string &tag, const function< void(ostream &)> &use_stream)
 

Static Private Member Functions

template<typename FirstPriority , typename SecondPriority , typename... Rest>
static tuple< unique_ptr< FirstPriority >, unique_ptr< SecondPriority >, unique_ptr< Rest >... > try_load_first_bare (istream &in, const string &filename, bool &found)
 
template<typename Only >
static tuple< unique_ptr< Only > > try_load_first_bare (istream &in, const string &filename, bool &found)
 
template<typename FirstPriority , typename SecondPriority , typename... Rest>
static tuple< unique_ptr< FirstPriority >, unique_ptr< SecondPriority >, unique_ptr< Rest >... > try_load_first_encapsulated (MessageIterator &it, bool &found)
 
template<typename Only >
static tuple< unique_ptr< Only > > try_load_first_encapsulated (MessageIterator &it, bool &found)
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_bare (istream &in, const string &filename="")
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_encapsulated (istream &in)
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_encapsulated (MessageIterator &it)
 
static void with_putback (istream &in, const function< void(istream &)> &callback)
 
template<typename T >
static string describe ()
 

Detailed Description

Interface for reading/writing files.

Originally designed for Protobuf-based type-tagged files with optional BGZIP compression.

Now mostly used for files identified by prefixes or sniffing functions.

Allows you to load e.g. a HandleGraph from a file with the implementation being auto-selected based on what is in the file.

Member Function Documentation

◆ describe()

template<typename T >
static string vg::io::VPKG::describe ( )
inlinestaticprivate

Return a string to represent the given type. Should be demangled and human-readable.

◆ load_one() [1/2]

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::load_one ( const string &  filename)
inlinestatic

Load an object of the given type from a file by name. The stream may be VPKG with the appropriate tag, or a bare non-VPKG stream understood by the loader. Tagged messages that can't be used to load the thing we are looking for are skipped. Ends the program with an error if the object could not be found in the file. Supports "-" for standard input.

◆ load_one() [2/2]

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::load_one ( istream &  in,
const string &  filename = "" 
)
inlinestatic

Load an object of the given type from a stream. The stream may be VPKG with the appropriate tag, or a bare non-VPKG stream understood by the loader. Tagged messages that can't be used to load the thing we are looking for are skipped. Ends the program with an error if the object could not be found in the stream.

May consume trailing data from the stream.

◆ save() [1/2]

template<typename Have >
static void vg::io::VPKG::save ( const Have &  have,
const string &  filename 
)
inlinestatic

◆ save() [2/2]

template<typename Have >
static void vg::io::VPKG::save ( const Have &  have,
ostream &  out 
)
inlinestatic

Save an object to the given stream, using the appropriate saver.

◆ try_load_bare()

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::try_load_bare ( istream &  in,
const string &  filename = "" 
)
inlinestaticprivate

Load an object of the given type from a stream. The stream has to be a bare non-VPKG stream understood by the loader. Returns the loaded object, or null if no loader liked the input.

filename is optional, and can be used by callback code that may, for some reason, want to link the stream back to a path (cough cough GFA loader cough cough).

◆ try_load_encapsulated() [1/2]

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::try_load_encapsulated ( istream &  in)
inlinestaticprivate

Load an object of the given type from a stream. The stream has to be a VPKG type-tagged message stream. Returns the loaded object, or null if the messages have incompatible type tags. If the messages have incompatible tags, some may be consumed from the stream. Throws an exception if the input is not a VPKG type-tagged message stream.

◆ try_load_encapsulated() [2/2]

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::try_load_encapsulated ( MessageIterator it)
inlinestaticprivate

Load an object of the given type from an iterator of type-tagged messages. Returns the loaded object, or null if the messages have incompatible type tags. If the messages have incompatible tags, the iterator will not be advanced.

◆ try_load_first() [1/2]

template<typename... Wanted>
static tuple<unique_ptr<Wanted>...> vg::io::VPKG::try_load_first ( const string &  filename)
inlinestatic

Allocate and load the first available type from the given stream. Returns a tuple where at most one item is filled, and that item is the first type we could successfully load out of the template parameters.

If any type is to be loaded from type-tagged messages, it must come first, or its type-tagged messages may be skipped when looking for higher-priority types.

◆ try_load_first() [2/2]

template<typename... Wanted>
static tuple<unique_ptr<Wanted>...> vg::io::VPKG::try_load_first ( istream &  in,
const string &  filename = "" 
)
inlinestatic

Allocate and load an available type from the given stream. Returns a tuple where at most one item is filled, and that item is the first type we could successfully load out of the template parameters, except that bare loaders are prioritized over encapsulated ones.

filename is optional, and can be used by callback code that may, for some reason, want to link the stream back to a path (cough cough GFA loader cough cough)

◆ try_load_first_bare() [1/2]

template<typename FirstPriority , typename SecondPriority , typename... Rest>
static tuple<unique_ptr<FirstPriority>, unique_ptr<SecondPriority>, unique_ptr<Rest>...> vg::io::VPKG::try_load_first_bare ( istream &  in,
const string &  filename,
bool &  found 
)
inlinestaticprivate

Allocate and load the first available type from the given stream, using a bare loader. Returns a tuple where at most one item is filled, and that item is the first type we could successfully load out of the template parameters. Sets found to true if anything is successfully loaded.

filename is optional, and can be used by callback code that may, for some reason, want to link the stream back to a path (cough cough GFA loader cough cough)

◆ try_load_first_bare() [2/2]

template<typename Only >
static tuple<unique_ptr<Only> > vg::io::VPKG::try_load_first_bare ( istream &  in,
const string &  filename,
bool &  found 
)
inlinestaticprivate

Allocate and load the first available type from the given stream, using a bare loader. Returns a tuple where at most one item is filled, and that item is the first type we could successfully load out of the template parameters. Sets found to true if anything is successfully loaded.

filename is optional, and can be used by callback code that may, for some reason, want to link the stream back to a path (cough cough GFA loader cough cough)

◆ try_load_first_encapsulated() [1/2]

template<typename FirstPriority , typename SecondPriority , typename... Rest>
static tuple<unique_ptr<FirstPriority>, unique_ptr<SecondPriority>, unique_ptr<Rest>...> vg::io::VPKG::try_load_first_encapsulated ( MessageIterator it,
bool &  found 
)
inlinestaticprivate

Allocate and load the first available type from the given iterator, using a bare loader. Returns a tuple where at most one item is filled, and that item is the first type we could successfully load out of the template parameters. Sets found to true if anything is successfully loaded.

◆ try_load_first_encapsulated() [2/2]

template<typename Only >
static tuple<unique_ptr<Only> > vg::io::VPKG::try_load_first_encapsulated ( MessageIterator it,
bool &  found 
)
inlinestaticprivate

Allocate and load the first available type from the given iterator, using a VPKG-encapsulated loader. Returns a tuple where at most one item is filled, and that item is the first type we could successfully load out of the template parameters. Sets found to true if anything is successfully loaded.

◆ try_load_one() [1/2]

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::try_load_one ( const string &  filename)
inlinestatic

Load an object of the given type from a file by name. The stream may be VPKG with the appropriate tag, or a bare non-VPKG stream understood by the loader. Returns null if the object could not be found in the file. Supports "-" for standard input.

◆ try_load_one() [2/2]

template<typename Wanted >
static unique_ptr<Wanted> vg::io::VPKG::try_load_one ( istream &  in,
const string &  filename = "" 
)
inlinestatic

Load an object of the given type from a file. The stream may be VPKG with the appropriate tag, or a bare non-VPKG stream understood by the loader.

Tagged messages that can't be used to load the thing we are looking for may or may not be consumed, so you should not call this function in a loop over types on the same stream.

filename is optional, and can be used by callback code that may, for some reason, want to link the stream back to a path (cough cough GFA loader cough cough)

◆ with_putback()

static void vg::io::VPKG::with_putback ( istream &  in,
const function< void(istream &)> &  callback 
)
inlinestaticprivate

Run the given callback with a version of the given stream that allows putback.

◆ with_save_stream()

void vg::io::VPKG::with_save_stream ( ostream &  to,
const string &  tag,
const function< void(ostream &)> &  use_stream 
)
static

Lower-level function used to get direct access to a stream tagged with the given tag, in the given type-tagged message output file.


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