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

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ ConfigurableParser()

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.

Member Function Documentation

◆ parse()

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.

◆ print_help()

void vg::ConfigurableParser::print_help ( ostream &  out) const

Print option descriptions for registered Configurables to the given stream.

◆ register_configurable()

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.

Member Data Documentation

◆ available_short_options

set<int> vg::ConfigurableParser::available_short_options
private

Holds all the available short option characters that have not been assigned. Stored as ints so we can check ints against it safely.

◆ codes_by_option

map<OptionInterface*, int> vg::ConfigurableParser::codes_by_option
private

And a reverse map for when we look up assigned codes for printing. TODO: No forgery!

◆ configurables

vector<Configurable*> vg::ConfigurableParser::configurables
private

And a vector of Configurables in the order registered so we can interrogate them and group their options when printing help.

◆ handle_base_option

function<void(int)> vg::ConfigurableParser::handle_base_option
private

Handle an option not assigned to an Option object.

◆ long_options

vector<struct option> vg::ConfigurableParser::long_options
private

Holds all the long option structs for options we have.

◆ long_options_used

set<string> vg::ConfigurableParser::long_options_used
private

And a set of long options used so we can detect collisions.

◆ options_by_code

map<int, OptionInterface*> vg::ConfigurableParser::options_by_code
private

Keep a map from assigned character to actual option.

◆ short_options

string vg::ConfigurableParser::short_options
private

Holds the short options string (with colons) for the short options we have.


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