vg
tools for working with variation graphs
|
#include <option.hpp>
Public Member Functions | |
ConfigurableParser (const char *base_short_options=nullptr, const struct option *base_long_options=nullptr, function< void(int)> handle_base_option=[](int c) { throw runtime_error("Invalid option: "+string(1,(char) c));}) | |
void | register_configurable (Configurable *configurable) |
void | print_help (ostream &out) const |
void | parse (int argc, char **argv) |
Private Attributes | |
vector< struct option > | long_options |
Holds all the long option structs for options we have. More... | |
set< int > | available_short_options |
string | short_options |
map< int, OptionInterface * > | options_by_code |
Keep a map from assigned character to actual option. More... | |
map< OptionInterface *, int > | codes_by_option |
set< string > | long_options_used |
And a set of long options used so we can detect collisions. More... | |
vector< Configurable * > | configurables |
function< void(int)> | handle_base_option |
Handle an option not assigned to an Option object. More... | |
Actual implementation class that connects a bunch of Configurable things to getopt.
TODO: right now every option must have a long option and a char short option. In theory we can use any int as an ID for a long option. We should support long options with untypeable or non-char option IDs.
vg::ConfigurableParser::ConfigurableParser | ( | const char * | base_short_options = nullptr , |
const struct option * | base_long_options = nullptr , |
||
function< void(int)> | handle_base_option = [](int c) { throw runtime_error("Invalid option: " + string(1, (char) c)); } |
||
) |
Constructor that sets up our magic option assigning code. Makes a parser that will parse the given base Getopt null-terminated long and short options with Getopt and call the given function with each.
The base option handler, if specified, should error on unrecognized options.
void vg::ConfigurableParser::parse | ( | int | argc, |
char ** | argv | ||
) |
Parse the options with getopt. Uses the existing value of the global optind, and updates the global optind, just as getopt would.
void vg::ConfigurableParser::print_help | ( | ostream & | out | ) | const |
Print option descriptions for registered Configurables to the given stream.
void vg::ConfigurableParser::register_configurable | ( | Configurable * | configurable | ) |
Register a Configurable thing and allocate characters for all its options. The Configurable is not allowed to move after registration.
|
private |
Holds all the available short option characters that have not been assigned. Stored as ints so we can check ints against it safely.
|
private |
And a reverse map for when we look up assigned codes for printing. TODO: No forgery!
|
private |
And a vector of Configurables in the order registered so we can interrogate them and group their options when printing help.
|
private |
Handle an option not assigned to an Option object.
|
private |
Holds all the long option structs for options we have.
|
private |
And a set of long options used so we can detect collisions.
|
private |
Keep a map from assigned character to actual option.
|
private |
Holds the short options string (with colons) for the short options we have.