vg
tools for working with variation graphs
Static Public Member Functions | Private Types | 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 >... > load_all (istream &in)
 
template<typename... Wanted>
static tuple< unique_ptr< Wanted >... > load_all (const string &filename)
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_one (istream &in)
 
template<typename Wanted >
static unique_ptr< Wanted > try_load_one (const string &filename)
 
template<typename Wanted >
static unique_ptr< Wanted > load_one (istream &in)
 
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)
 

Private Types

enum  LoadProgress { LOAD_SUCCESS, LOAD_FINISHED, LOAD_SEARCHING }
 

Static Private Member Functions

template<typename... TupleTypes>
static tuple< unique_ptr< TupleTypes >... > to_tuple (deque< void * > items)
 
template<typename Pointed >
static unique_ptr< Pointed > extract_first (deque< void * > &pointers)
 
template<typename One >
static LoadProgress load_into_one (MessageIterator &it, size_t i, deque< void * > &dest)
 
template<typename T >
static string describe ()
 
template<typename T >
static std::enable_if< std::is_default_constructible< T >::value, unique_ptr< T > >::type make_default_or_null ()
 
template<typename T >
static std::enable_if<!std::is_default_constructible< T >::value, unique_ptr< T > >::type make_default_or_null ()
 
static bool sniff_magic (istream &stream, const string &magic)
 

Detailed Description

Interface for reading/writing type-tagged files.

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

Allows you to load multiple indexes or objects from the same file, as they are found.

Allows saving multiple indexes or objects to a file with one call.

Member Enumeration Documentation

◆ LoadProgress

Return type to represent whether the loader is making progress. Lets us know when we have loaded items vs. when nobody has anything to load so we can skip unwanted sections.

Enumerator
LOAD_SUCCESS 
LOAD_FINISHED 
LOAD_SEARCHING 

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.

◆ extract_first()

template<typename Pointed >
static unique_ptr<Pointed> vg::io::VPKG::extract_first ( deque< void * > &  pointers)
inlinestaticprivate

Pop off the first item in the given collection and wrap it in a typed unique_ptr.

◆ load_all() [1/2]

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

Allocate and load one or more objects from the given file on a single pass. Returns a tuple of pointers to loaded objects, or null if they could not be found. Only works on VPKG-formatted files. Supports "-" for standard input.

◆ load_all() [2/2]

template<typename... Wanted>
static tuple<unique_ptr<Wanted>...> vg::io::VPKG::load_all ( istream &  in)
inlinestatic

Allocate and load one or more objects from the given stream on a single pass. Returns a tuple of pointers to loaded objects, or null if they could not be found. Only works on VPKG-formatted files. TODO: Probably ought to fail if something isn't found!

◆ load_into_one()

template<typename One >
static LoadProgress vg::io::VPKG::load_into_one ( MessageIterator it,
size_t  i,
deque< void * > &  dest 
)
inlinestaticprivate

If the null slot at index i in the given collection of void*s can be filled with an object of type One from the given MessageIterator, fill it.

Returns LOAD_SUCCESS if it finds and loads something, LOAD_FINISHED if it is filled in or hits EOF, and LOAD_SEARCHING if it is still unfilled but can't be loaded from the current tag.

◆ 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)
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.

◆ make_default_or_null() [1/2]

template<typename T >
static std::enable_if<std::is_default_constructible<T>::value, unique_ptr<T> >::type vg::io::VPKG::make_default_or_null ( )
inlinestaticprivate

Return a new default-constructed instance of the given type, or a null pointer if it is not default constructible.

This version matches default-consttructable types.

◆ make_default_or_null() [2/2]

template<typename T >
static std::enable_if<!std::is_default_constructible<T>::value, unique_ptr<T> >::type vg::io::VPKG::make_default_or_null ( )
inlinestaticprivate

Return a new default-constructed instance of the given type, or a null pointer if it is not default constructible.

This version matches non-default-consttructable types.

◆ 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.

◆ sniff_magic()

bool vg::io::VPKG::sniff_magic ( istream &  stream,
const string &  magic 
)
staticprivate

Return true of the given stream starts with the given magic number prefix, and false otherwise. Returns the stream to its initial position regardless of the result.

◆ to_tuple()

template<typename... TupleTypes>
static tuple<unique_ptr<TupleTypes>...> vg::io::VPKG::to_tuple ( deque< void * >  items)
inlinestaticprivate

Given a collection of void pointers, give ownership of the objects they point to, if any, to unique_ptrs in a tuple.

◆ 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. Tagged messages that can't be used to load the thing we are looking for are skipped. 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)
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. This doesn't work for Protobuf messages directly, but it will work for e.g. vg::VG.

◆ 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: