vg
tools for working with variation graphs
Loading...
Searching...
No Matches
vg::subcommand::OptionGroup< Receiver > Struct Template Reference

#include <options.hpp>

Inheritance diagram for vg::subcommand::OptionGroup< Receiver >:
vg::subcommand::BaseOptionGroup vg::subcommand::TickChainLink

Public Member Functions

virtual ~OptionGroup ()=default
 OptionGroup (const std::string &heading)
 Make an option group woith the given heading.
virtual TickChainLink & chain (TickChainLink &next)
 Chain through all options.
virtual void reset_chain ()
 Reset the chain to its initial values.
virtual bool tick_chain ()
void attach_option (BaseArgSpec< Receiver > *spec)
template<typename T, typename Spec = ValueArgSpec<T, Receiver>>
Spec * add_option (const std::string &name, char short_option, T Receiver::*dest, const T &default_value, const std::string &help, const ValidatorFunction< T > &validator=[](const T &ignored) {})
 Add a new option that goes to the given field, with the given default.
template<typename T, typename Spec = ValueArgSpec<T, Receiver>>
Spec * add_option (const std::string &name, T Receiver::*dest, const T &default_value, const std::string &help, const ValidatorFunction< T > &validator=[](const T &ignored) {})
 Add a new option that goes to the given field, with the given default.
template<typename T>
RangeArgSpec< T, Receiver > * add_range (const std::string &name, char short_option, T Receiver::*dest, const T &default_value, const std::string &help, const ValidatorFunction< T > &validator=[](const T &ignored) {})
 Add a new option that handles range values.
template<typename T>
void add_range (const std::string &name, T Receiver::*dest, const T &default_value, const std::string &help, const ValidatorFunction< T > &validator=[](const T &ignored) {})
 Add a new option that handles range values.
std::pair< FlagArgSpec< Receiver > *, NegationFlagArgSpec< Receiver > * > add_flag (const std::string &name, char short_option, bool Receiver::*dest, bool default_value, const std::string &help, const ValidatorFunction< bool > &validator=[](const bool &ignored) {})
std::pair< FlagArgSpec< Receiver > *, NegationFlagArgSpec< Receiver > * > add_flag (const std::string &name, bool Receiver::*dest, bool default_value, const std::string &help, const ValidatorFunction< bool > &validator=[](const bool &ignored) {})
virtual bool parse (int option_id, const char *optarg)
virtual bool preset (const BaseValuation &entry)
virtual bool set (const BaseValuation &entry)
virtual bool query (BaseValuation &entry) const
virtual bool print_options (ostream &out, OptionFormat format=OptionFormat::CLI) const
 Print all options set.
void apply (Receiver &receiver) const
 Apply all flags to the receiver.
virtual std::vector< std::pair< std::string, std::string > > get_help () const
virtual void make_long_options (std::vector< struct option > &dest) const
 Add to non-null-terminated input for getopt_long.
virtual void make_short_options (std::string &dest) const
 Add to string input for getopt_long.
Public Member Functions inherited from vg::subcommand::BaseOptionGroup
virtual ~BaseOptionGroup ()=default
template<typename T>
T get_option_value (const std::string &option) const
template<typename T>
void set_option_value (const std::string &option, const T &value)
 Allow the user to manually set an option value.

Public Attributes

std::string heading
 Heading we will appear under in the help.
std::vector< std::unique_ptr< BaseArgSpec< Receiver > > > args
std::unordered_map< int, size_t > id_to_index
 Map from option ID to option index.
std::unordered_map< std::string, size_t > option_to_index
 Map from long option to option index, to allow applying presets.

Additional Inherited Members

Detailed Description

template<typename Receiver>
struct vg::subcommand::OptionGroup< Receiver >

Represents a set of command-line options that can be applied to an object. Internal values can be ranges that can be ticked. Comes with a heading.

Constructor & Destructor Documentation

◆ ~OptionGroup()

template<typename Receiver>
virtual vg::subcommand::OptionGroup< Receiver >::~OptionGroup ( )
virtualdefault

◆ OptionGroup()

template<typename Receiver>
vg::subcommand::OptionGroup< Receiver >::OptionGroup ( const std::string & heading)
inline

Make an option group woith the given heading.

Member Function Documentation

◆ add_flag() [1/2]

template<typename Receiver>
std::pair< FlagArgSpec< Receiver > *, NegationFlagArgSpec< Receiver > * > vg::subcommand::OptionGroup< Receiver >::add_flag ( const std::string & name,
bool Receiver::* dest,
bool default_value,
const std::string & help,
const ValidatorFunction< bool > & validator = [](const bool& ignored) {} )
inline

Add a new option that is a boolean flag, and auto-generate a negation counterpart (–no-XXX for –XXX, or –XXX for –no-XXX).

◆ add_flag() [2/2]

template<typename Receiver>
std::pair< FlagArgSpec< Receiver > *, NegationFlagArgSpec< Receiver > * > vg::subcommand::OptionGroup< Receiver >::add_flag ( const std::string & name,
char short_option,
bool Receiver::* dest,
bool default_value,
const std::string & help,
const ValidatorFunction< bool > & validator = [](const bool& ignored) {} )
inline

Add a new option that is a boolean flag, and auto-generate a negation counterpart (–no-XXX for –XXX, or –XXX for –no-XXX).

◆ add_option() [1/2]

template<typename Receiver>
template<typename T, typename Spec = ValueArgSpec<T, Receiver>>
Spec * vg::subcommand::OptionGroup< Receiver >::add_option ( const std::string & name,
char short_option,
T Receiver::* dest,
const T & default_value,
const std::string & help,
const ValidatorFunction< T > & validator = [](const T& ignored) {} )
inline

Add a new option that goes to the given field, with the given default.

◆ add_option() [2/2]

template<typename Receiver>
template<typename T, typename Spec = ValueArgSpec<T, Receiver>>
Spec * vg::subcommand::OptionGroup< Receiver >::add_option ( const std::string & name,
T Receiver::* dest,
const T & default_value,
const std::string & help,
const ValidatorFunction< T > & validator = [](const T& ignored) {} )
inline

Add a new option that goes to the given field, with the given default.

◆ add_range() [1/2]

template<typename Receiver>
template<typename T>
RangeArgSpec< T, Receiver > * vg::subcommand::OptionGroup< Receiver >::add_range ( const std::string & name,
char short_option,
T Receiver::* dest,
const T & default_value,
const std::string & help,
const ValidatorFunction< T > & validator = [](const T& ignored) {} )
inline

Add a new option that handles range values.

◆ add_range() [2/2]

template<typename Receiver>
template<typename T>
void vg::subcommand::OptionGroup< Receiver >::add_range ( const std::string & name,
T Receiver::* dest,
const T & default_value,
const std::string & help,
const ValidatorFunction< T > & validator = [](const T& ignored) {} )
inline

Add a new option that handles range values.

◆ apply()

template<typename Receiver>
void vg::subcommand::OptionGroup< Receiver >::apply ( Receiver & receiver) const
inline

Apply all flags to the receiver.

◆ attach_option()

template<typename Receiver>
void vg::subcommand::OptionGroup< Receiver >::attach_option ( BaseArgSpec< Receiver > * spec)
inline

Take ownership of the given allocated BaseArgSpec, and attach it as part of the group. TODO: Should this be private?

◆ chain()

template<typename Receiver>
virtual TickChainLink & vg::subcommand::OptionGroup< Receiver >::chain ( TickChainLink & next)
inlinevirtual

Chain through all options.

Reimplemented from vg::subcommand::TickChainLink.

◆ get_help()

template<typename Receiver>
virtual std::vector< std::pair< std::string, std::string > > vg::subcommand::OptionGroup< Receiver >::get_help ( ) const
inlinevirtual

Get help, in the form of pairs of options and descriptions. Headings are descriptions without options.

Implements vg::subcommand::BaseOptionGroup.

◆ make_long_options()

template<typename Receiver>
virtual void vg::subcommand::OptionGroup< Receiver >::make_long_options ( std::vector< struct option > & dest) const
inlinevirtual

Add to non-null-terminated input for getopt_long.

Implements vg::subcommand::BaseOptionGroup.

◆ make_short_options()

template<typename Receiver>
virtual void vg::subcommand::OptionGroup< Receiver >::make_short_options ( std::string & dest) const
inlinevirtual

Add to string input for getopt_long.

Implements vg::subcommand::BaseOptionGroup.

◆ parse()

template<typename Receiver>
virtual bool vg::subcommand::OptionGroup< Receiver >::parse ( int option_id,
const char * optarg )
inlinevirtual

Parse the given option ID, with the given value if needed. Return true if we matched the ID, and false otherwise.

Implements vg::subcommand::BaseOptionGroup.

◆ preset()

template<typename Receiver>
virtual bool vg::subcommand::OptionGroup< Receiver >::preset ( const BaseValuation & entry)
inlinevirtual

Apply a preset value to its option. Returns true if it was found, and false otherwies.

Implements vg::subcommand::BaseOptionGroup.

◆ print_options()

template<typename Receiver>
virtual bool vg::subcommand::OptionGroup< Receiver >::print_options ( ostream & out,
OptionFormat format = OptionFormat::CLI ) const
inlinevirtual

Print all options set.

Implements vg::subcommand::BaseOptionGroup.

◆ query()

template<typename Receiver>
virtual bool vg::subcommand::OptionGroup< Receiver >::query ( BaseValuation & entry) const
inlinevirtual

Fill in entry with the value of the corresponding option, if we have that option. If so, return true.

Implements vg::subcommand::BaseOptionGroup.

◆ reset_chain()

template<typename Receiver>
virtual void vg::subcommand::OptionGroup< Receiver >::reset_chain ( )
inlinevirtual

Reset the chain to its initial values.

Reimplemented from vg::subcommand::TickChainLink.

◆ set()

template<typename Receiver>
virtual bool vg::subcommand::OptionGroup< Receiver >::set ( const BaseValuation & entry)
inlinevirtual

Apply a value to its option. Returns true if it was found, and false otherwies.

Implements vg::subcommand::BaseOptionGroup.

◆ tick_chain()

template<typename Receiver>
virtual bool vg::subcommand::OptionGroup< Receiver >::tick_chain ( )
inlinevirtual

Tick the chain. Return true if there's still a value for the chain, and false if the chain is out of values. Should be called on the last item in the chain. May delegate to a different item (for e.g. groups).

Reimplemented from vg::subcommand::TickChainLink.

Member Data Documentation

◆ args

template<typename Receiver>
std::vector<std::unique_ptr<BaseArgSpec<Receiver> > > vg::subcommand::OptionGroup< Receiver >::args

Holds the argument definitions and parsing destinations. Because they are chained up and point to each other, they can't move.

◆ heading

template<typename Receiver>
std::string vg::subcommand::OptionGroup< Receiver >::heading

Heading we will appear under in the help.

◆ id_to_index

template<typename Receiver>
std::unordered_map<int, size_t> vg::subcommand::OptionGroup< Receiver >::id_to_index

Map from option ID to option index.

◆ option_to_index

template<typename Receiver>
std::unordered_map<std::string, size_t> vg::subcommand::OptionGroup< Receiver >::option_to_index

Map from long option to option index, to allow applying presets.


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