vg
tools for working with variation graphs
Public Member Functions | Public Attributes | List of all members
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. More...
 
virtual TickChainLinkchain (TickChainLink &next)
 Chain through all options. More...
 
template<typename T , typename Spec = ValueArgSpec<T, Receiver>>
void add_option (const std::string &name, char short_option, T Receiver::*dest, 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. More...
 
template<typename T , typename Spec = ValueArgSpec<T, Receiver>>
void add_option (const std::string &name, T Receiver::*dest, 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. More...
 
template<typename T >
void add_range (const std::string &name, char short_option, T Receiver::*dest, T default_value, const std::string &help, const ValidatorFunction< T > &validator=[](const T &ignored) {})
 Add a new option that handles range values. More...
 
template<typename T >
void add_range (const std::string &name, T Receiver::*dest, T default_value, const std::string &help, const ValidatorFunction< T > &validator=[](const T &ignored) {})
 Add a new option that handles range values. More...
 
void 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) {})
 Add a new option that is a boolean flag. More...
 
void add_flag (const std::string &name, bool Receiver::*dest, bool default_value, const std::string &help, const ValidatorFunction< bool > &validator=[](const bool &ignored) {})
 Add a new option that is a boolean flag. More...
 
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 void print_options (ostream &out, bool slug=false) const
 Print all options set, one per line. More...
 
void apply (Receiver &receiver) const
 Apply all flags to the receiver. More...
 
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. More...
 
virtual void make_short_options (std::string &dest) const
 Add to string input for getopt_long. More...
 
- Public Member Functions inherited from vg::subcommand::BaseOptionGroup
virtual ~BaseOptionGroup ()=default
 
template<typename 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. More...
 

Public Attributes

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

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

◆ add_flag() [2/2]

template<typename Receiver >
void 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.

◆ add_option() [1/2]

template<typename Receiver >
template<typename T , typename Spec = ValueArgSpec<T, Receiver>>
void vg::subcommand::OptionGroup< Receiver >::add_option ( const std::string &  name,
char  short_option,
T Receiver::*  dest,
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>>
void vg::subcommand::OptionGroup< Receiver >::add_option ( const std::string &  name,
T Receiver::*  dest,
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 >
void vg::subcommand::OptionGroup< Receiver >::add_range ( const std::string &  name,
char  short_option,
T Receiver::*  dest,
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,
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.

◆ 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 void vg::subcommand::OptionGroup< Receiver >::print_options ( ostream &  out,
bool  slug = false 
) const
inlinevirtual

Print all options set, one per line.

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 correspondign option, if we have that option. If so, return true.

Implements vg::subcommand::BaseOptionGroup.

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

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.

◆ 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: