creativity  v1.3.0
Agent-based model of creativity and piracy
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
creativity::cmdargs::CmdArgs Class Reference

This class handles command line argument parsing. More...

#include <creativity/cmdargs/CmdArgs.hpp>

Public Member Functions

void parse (int argc, char const *const *argv)
 Parses options and verifies them. More...
 
template<typename T , typename A >
std::enable_if< not std::is_unsigned< T >::value, boost::program_options::typed_value< std::vector< T, A > > * >::type value (std::vector< T, A > &store)
 Takes a std::vector of values for options that store multiple values. More...
 
template<typename T , typename A >
std::enable_if< std::is_unsigned< T >::value, boost::program_options::typed_value< std::vector< Validation< T > > > * >::type value (std::vector< T, A > &store)
 Takes a std::vector of values for options that store multiple values. More...
 
virtual std::string version () const
 Returns a version string.
 
virtual std::string versionSuffix () const
 Returns a per-executable suffix to add to the generic version string. More...
 
virtual std::string usage () const
 Returns a usage string such as "Usage: program [ARGS]". More...
 
virtual std::string help () const
 Returns a argument help message.
 

Static Public Member Functions

template<typename T >
static std::enable_if< not std::is_unsigned< T >::value and not std::is_same< T, bool >::value, boost::program_options::typed_value< T > *>::type value (T &store)
 Creates an option value object without any special validation wrapper class. More...
 
template<typename T >
static std::enable_if< std::is_unsigned< T >::value and not std::is_same< T, bool >::value, boost::program_options::typed_value< Validation< T > > * >::type value (T &storage)
 Creates an option value object around an unsigned primitive type, with automatic value storage and default value. More...
 
static boost::program_options::typed_value< bool > * value (bool &store)
 Creates an option value for a boolean value, that is, for an switch without an argument, with default value as given in store.
 
template<typename V >
static boost::program_options::typed_value< V > * value (typename V::value_type &store)
 Creates an option value object with explicit validation wrapper class V. More...
 
template<typename V , typename A >
static boost::program_options::typed_value< std::vector< V > > * value (std::vector< typename V::value_type, A > &store)
 Creates an option value object around a vector of options with validation wrapper class V applied to each element of the vector. More...
 
template<long minimum, long denom = 1, typename T >
static boost::program_options::typed_value< Min< T, minimum, denom > > * min (T &store)
 Shortcut for value<Min<T, n, d>>(val) with T last (so that it can be inferred from val)
 
template<long maximum, long denom = 1, typename T >
static boost::program_options::typed_value< Max< T, maximum, denom > > * max (T &store)
 Shortcut for value<Max<T, n, d>>(val) with T last (so that it can be inferred from val)
 
template<long min, long max, long denom = 1, typename T >
static boost::program_options::typed_value< Range< T, min, max, denom > > * range (T &store)
 Shortcut for value<Range<T, a, b, d>>(val) with T last (so that it can be inferred from val)
 
template<long lower, long denom = 1, typename T >
static boost::program_options::typed_value< Above< T, lower, denom > > * above (T &store)
 Shortcut for value<Above<T, a, d>>(val) with T last (so that it can be inferred from val)
 
template<long upper, long denom = 1, typename T >
static boost::program_options::typed_value< Below< T, upper, denom > > * below (T &store)
 Shortcut for value<Below<T, b, d>>(val) with T last (so that it can be inferred from val)
 

Protected Member Functions

 CmdArgs ()=default
 Default constructor is protected; use a suitable subclass.
 
virtual void addOptions ()
 Adds options. More...
 
virtual void postParse (boost::program_options::variables_map &vars)
 Does nothing; subclasses should override if needed to deal with argument values. More...
 

Protected Attributes

std::string prog_name_
 The program name, populated by parse(). More...
 
boost::program_options::options_description options_
 The options descriptions variable for all options.
 
boost::program_options::options_description invisible_
 Like options_, but for hidden options that aren't to be displayed in –help output.
 
boost::program_options::positional_options_description positional_
 Positional options object.
 

Detailed Description

This class handles command line argument parsing.

Most options are supported both by the cli interface (to specify simulation settings) and by the gui (to specify simulation defaults).

Todo:
Argument output isn't quite right because boost::p_a doesn't know about the utf8 strings being used, so alignment fails. Figure out a way to fix that, perhaps by using std::wstring.
Todo:
Add settings plus colour setting arguments to a file (~/.creativity-settings.rc).

Member Function Documentation

§ addOptions()

virtual void creativity::cmdargs::CmdArgs::addOptions ( )
protectedvirtual

Adds options.

This method is called automatically by parse() before parsing arguments if nothing has been set in the options_ object; the default implementation adds –help and –version options. Subclasses should override and enhance to also populate options_ appropriately.

Reimplemented in creativity::cmdargs::SeriesGraphs, creativity::cmdargs::Results, creativity::cmdargs::Series, creativity::cmdargs::Data, creativity::cmdargs::SeriesQuantiles, creativity::cmdargs::Simulator, creativity::cmdargs::Info, creativity::cmdargs::GUI, and creativity::cmdargs::CLI.

§ parse()

void creativity::cmdargs::CmdArgs::parse ( int  argc,
char const *const *  argv 
)

Parses options and verifies them.

Throws an std::exception-derived exception for various errors (such as invalid arguments or invalid argument types).

A suitable method such as addCliOptions() or addGuiOptions() must have been called first: otherwise there will be no recognized options to parse.

Options that can be stored directly in the CreativitySettings object passed to the constructor are assigned directly; other variable are accessible in the variables member.

The –help and –version arguments are handled internally: they print the requested info, then exit the program.

Parameters
argcthe argc as received by main
argvthe argv as received by main

§ postParse()

virtual void creativity::cmdargs::CmdArgs::postParse ( boost::program_options::variables_map &  vars)
protectedvirtual

Does nothing; subclasses should override if needed to deal with argument values.

This is called after checking for and handling –help or –version flags.

Parameters
varsthe parsed variables

Reimplemented in creativity::cmdargs::SeriesGraphs, creativity::cmdargs::Results, creativity::cmdargs::Series, creativity::cmdargs::Data, creativity::cmdargs::Simulator, creativity::cmdargs::Info, creativity::cmdargs::GUI, and creativity::cmdargs::CLI.

§ usage()

virtual std::string creativity::cmdargs::CmdArgs::usage ( ) const
virtual

Returns a usage string such as "Usage: program [ARGS]".

Called by help(). Subclasses should override to change the string as needed.

Reimplemented in creativity::cmdargs::SeriesGraphs, creativity::cmdargs::Results, creativity::cmdargs::Series, creativity::cmdargs::Data, creativity::cmdargs::SeriesQuantiles, creativity::cmdargs::Info, and creativity::cmdargs::GUI.

§ value() [1/6]

template<typename T >
static std::enable_if<not std::is_unsigned<T>::value and not std::is_same<T, bool>::value, boost::program_options::typed_value<T>* >::type creativity::cmdargs::CmdArgs::value ( T &  store)
inlinestatic

Creates an option value object without any special validation wrapper class.

This function participates only when T is not an unsigned type.

Parameters
storethe default value and the location to store a specified value.

§ value() [2/6]

template<typename T >
static std::enable_if<std::is_unsigned<T>::value and not std::is_same<T, bool>::value, boost::program_options::typed_value<Validation<T> >*>::type creativity::cmdargs::CmdArgs::value ( T &  storage)
inlinestatic

Creates an option value object around an unsigned primitive type, with automatic value storage and default value.

This function participates only when T is an unsigned type, and, functionally, will ensure that a negative value such as -3 is not accepted, but will not otherwise restrict the value.

§ value() [3/6]

template<typename V >
static boost::program_options::typed_value<V>* creativity::cmdargs::CmdArgs::value ( typename V::value_type &  store)
inlinestatic

Creates an option value object with explicit validation wrapper class V.

store is used for both the default and the location to store a command-line provided value.

Template Parameters
Va class that will throw during construction if the given value isn't valid; the class must expose a value type in value_type, which should match the given store value.
Parameters
storethe location of the default value and the location to store a given value

§ value() [4/6]

template<typename V , typename A >
static boost::program_options::typed_value<std::vector<V> >* creativity::cmdargs::CmdArgs::value ( std::vector< typename V::value_type, A > &  store)
inlinestatic

Creates an option value object around a vector of options with validation wrapper class V applied to each element of the vector.

store is used both for the default values and the location to store command-line provided values.

Template Parameters
Va class that will throw during construction if the given value isn't valid; the class must expose a value type in value_type, which must match the value_type of the given vector.
Parameters
storethe vector in which to store given values.

§ value() [5/6]

template<typename T , typename A >
std::enable_if<not std::is_unsigned<T>::value, boost::program_options::typed_value<std::vector<T, A> >*>::type creativity::cmdargs::CmdArgs::value ( std::vector< T, A > &  store)
inline

Takes a std::vector of values for options that store multiple values.

This function participates only when the vector stores non-unsigned types.

§ value() [6/6]

template<typename T , typename A >
std::enable_if<std::is_unsigned<T>::value, boost::program_options::typed_value<std::vector<Validation<T> > >*>::type creativity::cmdargs::CmdArgs::value ( std::vector< T, A > &  store)
inline

Takes a std::vector of values for options that store multiple values.

This function participates only when the vector stores unsigned types.

§ versionSuffix()

virtual std::string creativity::cmdargs::CmdArgs::versionSuffix ( ) const
virtual

Returns a per-executable suffix to add to the generic version string.

Typically something like " -- command-line interface". Called by the default version(). The default implementation returns an empty string.

Reimplemented in creativity::cmdargs::SeriesGraphs, creativity::cmdargs::Results, creativity::cmdargs::Series, creativity::cmdargs::Data, creativity::cmdargs::SeriesQuantiles, creativity::cmdargs::Info, creativity::cmdargs::GUI, and creativity::cmdargs::CLI.

Member Data Documentation

§ prog_name_

std::string creativity::cmdargs::CmdArgs::prog_name_
protected

The program name, populated by parse().

Inheritance diagram for creativity::cmdargs::CmdArgs:
[legend]

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