vg
tools for working with variation graphs
|
#include <option.hpp>
Public Member Functions | |
BaseOption ()=delete | |
virtual | ~BaseOption ()=default |
BaseOption (Configurable *owner, const string &long_opt, const string &short_opts, const Value &default_value, const string &description) | |
BaseOption< Value, Parser > & | operator= (const BaseOption< Value, Parser > &other)=default |
BaseOption< Value, Parser > & | operator= (const Value &other) |
operator Value & () | |
virtual const string & | get_long_option () const |
virtual const string & | get_short_options () const |
virtual const string & | get_description () const |
virtual string | get_default_value () const |
virtual bool | has_argument () const |
virtual void | parse () |
virtual void | parse (const string &arg) |
Public Member Functions inherited from vg::OptionInterface | |
virtual | ~OptionInterface ()=default |
Protected Attributes | |
string | long_opt |
What is the options's long option name. More... | |
string | short_opts |
What is the option's short option name. More... | |
string | description |
How is this option described to the user? More... | |
Value | value |
Value | default_value |
The correct user entry point is one of the Option<> specializations, not this class.
Represents a configurable parameter for a class that we might want to expose on the command line.
We need to allow these to be defined with default values in the class's header, but be overridable by simple assignment of a value of the right type. But we also need to be able to interrogate an instance of the class to get all its options that need to be filled in and their help text, and ideally to choose short options to assign to them that don't conflict.
So our approach is to have the class keep track of all its option objects, and to have the options register themselves at construction time with a passed this pointer (since this is in scope in the class body in the header).
Option instances MUST exist as MEMBERS of classes that inherit from Configurable! They can't live in vectors or anything, or the magic code that tracks them as the enclosing object moves won't work!
We'll have an assignment operator from the wrapped type to make setting options manually easy.
We also have magical conversion to the wrapped type.
We wrap all the type-specific parsing into a parser template. You could specify your own if you want custom parsing logic for like a map or something.
|
delete |
No default constructor.
|
virtualdefault |
Default destructor.
|
inline |
Make a new BaseOption that lives in a class, with the given name, short option characters, and default value.
|
inlinevirtual |
Get the default value as a string.
Implements vg::OptionInterface.
|
inlinevirtual |
Get the description, like "number of foos to bar per frobnitz".
Implements vg::OptionInterface.
|
inlinevirtual |
Get the long oiption text without –, like "foos-to-bar".
Implements vg::OptionInterface.
|
inlinevirtual |
Gets a list of short option characters that the option wants, in priority order. If none of these are available, the option will be automatically assigned some other free character.
Implements vg::OptionInterface.
|
inlinevirtual |
Returns true if the option takes an argument, and false otherwise.
Implements vg::OptionInterface.
|
inline |
Conversion to the wrapped type.
|
default |
Assignment from an Option of the correct type.
|
inline |
Assignment from an unwrapped value.
|
inlinevirtual |
Called for no-argument options when the parser encounters them.
Implements vg::OptionInterface.
|
inlinevirtual |
Called for argument-having options when the parser encounters them. The passed reference is only valid during the function call, so the option should make a copy.
Implements vg::OptionInterface.
|
protected |
We also keep the default value around, in case we somehow get assigned and then get asked to report our metadata. TODO: do this as a string instead?
|
protected |
How is this option described to the user?
|
protected |
What is the options's long option name.
|
protected |
What is the option's short option name.
|
protected |
We keep a value of our chosen type. It just has to be copyable and assignable.