vg
tools for working with variation graphs
Public Member Functions | Protected Attributes | List of all members
vg::BaseOption< Value, Parser > Class Template Reference

#include <option.hpp>

Inheritance diagram for vg::BaseOption< Value, Parser >:
vg::OptionInterface

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
 

Detailed Description

template<typename Value, typename Parser = OptionValueParser<Value>>
class vg::BaseOption< Value, Parser >

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.

Constructor & Destructor Documentation

◆ BaseOption() [1/2]

template<typename Value , typename Parser = OptionValueParser<Value>>
vg::BaseOption< Value, Parser >::BaseOption ( )
delete

No default constructor.

◆ ~BaseOption()

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual vg::BaseOption< Value, Parser >::~BaseOption ( )
virtualdefault

Default destructor.

◆ BaseOption() [2/2]

template<typename Value , typename Parser = OptionValueParser<Value>>
vg::BaseOption< Value, Parser >::BaseOption ( Configurable owner,
const string &  long_opt,
const string &  short_opts,
const Value &  default_value,
const string &  description 
)
inline

Make a new BaseOption that lives in a class, with the given name, short option characters, and default value.

Member Function Documentation

◆ get_default_value()

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual string vg::BaseOption< Value, Parser >::get_default_value ( ) const
inlinevirtual

Get the default value as a string.

Implements vg::OptionInterface.

◆ get_description()

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual const string& vg::BaseOption< Value, Parser >::get_description ( ) const
inlinevirtual

Get the description, like "number of foos to bar per frobnitz".

Implements vg::OptionInterface.

◆ get_long_option()

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual const string& vg::BaseOption< Value, Parser >::get_long_option ( ) const
inlinevirtual

Get the long oiption text without –, like "foos-to-bar".

Implements vg::OptionInterface.

◆ get_short_options()

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual const string& vg::BaseOption< Value, Parser >::get_short_options ( ) const
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.

◆ has_argument()

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual bool vg::BaseOption< Value, Parser >::has_argument ( ) const
inlinevirtual

Returns true if the option takes an argument, and false otherwise.

Implements vg::OptionInterface.

◆ operator Value &()

template<typename Value , typename Parser = OptionValueParser<Value>>
vg::BaseOption< Value, Parser >::operator Value & ( )
inline

Conversion to the wrapped type.

◆ operator=() [1/2]

template<typename Value , typename Parser = OptionValueParser<Value>>
BaseOption<Value, Parser>& vg::BaseOption< Value, Parser >::operator= ( const BaseOption< Value, Parser > &  other)
default

Assignment from an Option of the correct type.

◆ operator=() [2/2]

template<typename Value , typename Parser = OptionValueParser<Value>>
BaseOption<Value, Parser>& vg::BaseOption< Value, Parser >::operator= ( const Value &  other)
inline

Assignment from an unwrapped value.

◆ parse() [1/2]

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual void vg::BaseOption< Value, Parser >::parse ( )
inlinevirtual

Called for no-argument options when the parser encounters them.

Implements vg::OptionInterface.

◆ parse() [2/2]

template<typename Value , typename Parser = OptionValueParser<Value>>
virtual void vg::BaseOption< Value, Parser >::parse ( const string &  arg)
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.

Member Data Documentation

◆ default_value

template<typename Value , typename Parser = OptionValueParser<Value>>
Value vg::BaseOption< Value, Parser >::default_value
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?

◆ description

template<typename Value , typename Parser = OptionValueParser<Value>>
string vg::BaseOption< Value, Parser >::description
protected

How is this option described to the user?

◆ long_opt

template<typename Value , typename Parser = OptionValueParser<Value>>
string vg::BaseOption< Value, Parser >::long_opt
protected

What is the options's long option name.

◆ short_opts

template<typename Value , typename Parser = OptionValueParser<Value>>
string vg::BaseOption< Value, Parser >::short_opts
protected

What is the option's short option name.

◆ value

template<typename Value , typename Parser = OptionValueParser<Value>>
Value vg::BaseOption< Value, Parser >::value
protected

We keep a value of our chosen type. It just has to be copyable and assignable.


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