vg
tools for working with variation graphs
|
#include <registry.hpp>
Classes | |
struct | Tables |
Static Public Member Functions | |
static bool | register_everything () |
template<typename Message > | |
static void | register_protobuf (const string &tag) |
template<typename Handled , typename... Bases> | |
static void | register_loader_saver (const string &tag, load_function_t loader, save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_loader_saver (const std::vector< std::string > &tags, load_function_t loader, save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader_saver (const string &tag, bare_load_function_t loader, bare_save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader_saver_with_magic (const string &tag, const string &magic, bare_load_function_t loader, bare_save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader_saver_with_magics (const string &tag, const vector< string > &magics, bare_load_function_t loader, bare_save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader_saver_with_header_check (const string &tag, function< bool(istream &)> sniff_header, bare_load_function_with_filename_t loader, bare_save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader_saver_with_magic_and_filename (const string &tag, const string &magic, bare_load_function_with_filename_t loader, bare_save_function_t saver) |
template<typename Handled , typename... Bases> | |
static void | register_loader (const string &tag, load_function_t loader) |
template<typename Handled , typename... Bases> | |
static void | register_loader (const std::vector< std::string > &tags, load_function_t loader) |
static bool | is_valid_tag (const string &tag) |
template<typename Message > | |
static const string & | get_protobuf_tag () |
template<typename Message > | |
static bool | check_protobuf_tag (const string &tag) |
static bool | sniff_magic (istream &stream, const string &magic) |
template<typename Want > | |
static const load_function_t * | find_loader (const string &tag) |
template<typename Want > | |
static const vector< pair< bare_load_function_with_filename_t, function< bool(istream &)> > > * | find_bare_loaders () |
template<typename Have > | |
static const pair< string, save_function_t > * | find_saver () |
Static Public Attributes | |
static const size_t | MAX_TAG_LENGTH = 25 |
Static Private Member Functions | |
static Tables & | get_tables () |
::google::protobuf::util::TypeResolver & | get_resolver () |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader (bare_load_function_t loader, function< bool(istream &)> sniff_header=nullptr) |
template<typename Handled , typename... Bases> | |
static void | register_bare_loader_with_filename (bare_load_function_with_filename_t loader, function< bool(istream &)> sniff_header=nullptr) |
template<typename Handled > | |
static void | register_saver (const string &tag, save_function_t saver) |
A registry mapping between tag strings for serialized message groups and the Protobuf types or serialization/deserialization handlers to use for them. All registration anmd lookup is done through static methods. Static methods are safe to call from other static initialization code.
We handle two kinds of registration right now:
|
static |
Check to see if the given tag is expected when deserializing Protobuf messages of the given tag.
|
static |
Look up the appropriate loader functions to use to load an object of the given type from a bare stream. If there are any registered, return a pointer to a vector of functions and their possibly empty stream prefixes that they require. The caller has to call the appropriate function and and cast the result to the right type. If there are no functions available, returns nullptr.
|
static |
Look up the appropriate loader function to use to load an object of the given type from data with the given tag. If there is one registered, return a pointer to it. The caller has to call it and cast the result to the right type. If there isn't, returns nullptr.
|
static |
Look up the appropriate saver function to use to save an object of the given type. If there is one registered, return a pointer to a pair of the tag to use and the function. The caller has to call it and cast the result to the right type. If there isn't, returns nullptr.
|
static |
Get the correct tag to use when serializing Protobuf messages of the given type.
|
staticprivate |
Get a single shared Protobuf resolver we will use for the duration of the program. The Protobuf docs say the resolver must be thread safe.
|
staticprivate |
Get or create the registry tables in which things are registerd.
|
static |
Determine if the given tag string loaded from a file is a valid/possible tag, or if it should be interpreted as message data from a pre-tags VG file instead. Only tag values literally registered with the registry are valid. NOT thread-safe to run simultaneously with tag registrations.
|
staticprivate |
Register a load function for loading the given types from demultiplexed streams. If a header sniffing function is provided, the function will also be used on the whole input stream if it matches the function, skipping demultiplexing of type-tagged messages.
|
static |
Register a loading function and a saving function with the given tag for the given object type and list of base classes. The functions operate on bare streams; conversion to type-tagged messages of chunks of stream data is performed automatically.
Because, without a magic value or header check function, we can't reject type-tagged message files, loaders registered with this function won't actually be used when a non-type-tagged file is loaded. See register_bare_loader_saver_with_magic(), or use register_bare_loader_saver_with_header_check() with an always true check function if you do not need to load type-tagged messages.
|
static |
Generealization of register_bare_loader_saver_with_magic, where user can supply their own header-checking function. Check function must peek/get/unget and may not seek/tell.
|
static |
Like register_bare_loader_saver(), except that additionally the function will be used when attempting to load any of the base classes when the file begins with the specified magic bytes. Type-tagged files with the given tag that do not match the magic will be decoded into a stream and loaded with the loader.
|
static |
Generalization of register_bare_loader_saver_with_magic that can also take a filename
|
static |
Like register_bare_loader_saver_with_magic(), except that multiple magic values are supported.
|
staticprivate |
Slight generalization of above that allows filename to be passed alongside the input stream.
|
static |
Register everything. Main entry point. When you have new things to register, add calls to your function to this method. Returns true on success.
|
static |
Register a loading function for the given collection of tags. If "" appears in the list of tags, the loader can be deployed on untagged message groups (for backward compatibility).
|
static |
Register a load function for a tag. The empty tag means it can run on untagged message groups. If any Bases are passed, we will use this loader to load when one of those types is requested and this tag is encountered.
|
static |
Register a loading function and a saving function with the given collection of tags for the given object type and list of base classes. The first tag in the collection will be used for saving. If "" appears in the list of tags, the loader can be deployed on untagged message groups (for backward compatibility).
|
static |
Register a loading function and a saving function with the given tag for the given object type and the given base classes.
|
static |
Register a Protobuf Message type to be associated with the given string tag. By default, Protobuf types use the name string from the Protobuf library as a tag. But this can and should be overridden with something short that will never change.
|
staticprivate |
Register a save function to save a type with a given tag. The empty tag is not permitted.
|
static |
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.
|
static |
To help with telling messages from tags, we enforce a max tag length. If we ever allow tags of 139 bytes or longer, we risk having uncompressed files starting with the gzip magic number.