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

#include <subcommand.hpp>

Public Member Functions

 Subcommand (std::string name, std::string description, CommandCategory category, int priority, std::function< int(int, char **)> main_function)
 
 Subcommand (std::string name, std::string description, CommandCategory category, std::function< int(int, char **)> main_function)
 
 Subcommand (std::string name, std::string description, std::function< int(int, char **)> main_function)
 
const std::string & get_name () const
 
const std::string & get_description () const
 
const CommandCategoryget_category () const
 
const int & get_priority () const
 
const int operator() (int argc, char **argv) const
 

Static Public Member Functions

static const Subcommandget (int argc, char **argv)
 
static void for_each (const std::function< void(const Subcommand &)> &lambda)
 
static void for_each (CommandCategory category, const std::function< void(const Subcommand &)> &lambda)
 

Private Member Functions

const std::function< int(int, char **)> & get_main () const
 

Static Private Member Functions

static std::map< std::string, Subcommand * > & get_registry ()
 

Private Attributes

std::string name
 
std::string description
 
CommandCategory category
 
int priority
 
std::function< int(int, char **)> main_function
 

Detailed Description

Represents a subcommand with a name, a description, and some functions. Registers itself on construction in a static registry, and provides static functions for enumerating through that registry.

Constructor & Destructor Documentation

◆ Subcommand() [1/3]

vg::subcommand::Subcommand::Subcommand ( std::string  name,
std::string  description,
CommandCategory  category,
int  priority,
std::function< int(int, char **)>  main_function 
)

Make and register a subcommand with the given name and description, in the given category, with the given priority (lower is better), which calls the given main function when invoked.

◆ Subcommand() [2/3]

vg::subcommand::Subcommand::Subcommand ( std::string  name,
std::string  description,
CommandCategory  category,
std::function< int(int, char **)>  main_function 
)

Make and register a subcommand with the given name and description, in the given category, with worst priority, which calls the given main function when invoked.

◆ Subcommand() [3/3]

vg::subcommand::Subcommand::Subcommand ( std::string  name,
std::string  description,
std::function< int(int, char **)>  main_function 
)

Make and register a subcommand with the given name and description, in the WIDGET category, with worst priority, which calls the given main function when invoked.

Member Function Documentation

◆ for_each() [1/2]

void vg::subcommand::Subcommand::for_each ( CommandCategory  category,
const std::function< void(const Subcommand &)> &  lambda 
)
static

Call the given lambda with each known subcommand in the given category, in order.

◆ for_each() [2/2]

void vg::subcommand::Subcommand::for_each ( const std::function< void(const Subcommand &)> &  lambda)
static

Call the given lambda with each known subcommand, in order.

◆ get()

const Subcommand * vg::subcommand::Subcommand::get ( int  argc,
char **  argv 
)
static

Get the appropriate subcommand to handle the given arguments, or nullptr if no matching subcommand is found.

◆ get_category()

const CommandCategory & vg::subcommand::Subcommand::get_category ( ) const

Get the category of a subcommand, which determines who might want to use it and why.

◆ get_description()

const std::string & vg::subcommand::Subcommand::get_description ( ) const

Get the description of a subcommand.

◆ get_main()

const std::function<int(int, char**)>& vg::subcommand::Subcommand::get_main ( ) const
private

Get the main function of a subcommand.

◆ get_name()

const std::string & vg::subcommand::Subcommand::get_name ( ) const

Get the name of a subcommand.

◆ get_priority()

const int & vg::subcommand::Subcommand::get_priority ( ) const

Get the priority level of a subcommand (lower is more important).

◆ get_registry()

std::map< std::string, Subcommand * > & vg::subcommand::Subcommand::get_registry ( )
staticprivate

Since we can't rely on a static member field being constructed before any static code that creates actual subcommands gets run, we rely on keeping the registry in a static variable inside a static method, so it gets constructed on first use. Note that at shutdown some of the poinbters in the registry may be to already-destructed static objects.

◆ operator()()

const int vg::subcommand::Subcommand::operator() ( int  argc,
char **  argv 
) const

Run the main function of a subcommand. Return the return code.

Member Data Documentation

◆ category

CommandCategory vg::subcommand::Subcommand::category
private

◆ description

std::string vg::subcommand::Subcommand::description
private

◆ main_function

std::function<int(int, char**)> vg::subcommand::Subcommand::main_function
private

◆ name

std::string vg::subcommand::Subcommand::name
private

◆ priority

int vg::subcommand::Subcommand::priority
private

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