SHORE API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
shore::program Class Referenceabstract

Program base class. More...

Public Types

typedef av_parser::usage_error usage_error
 May be thrown to indicate that the help page should be displayed (usually from the virtual sanity_check() method).
 

Public Member Functions

 program ()
 Constructor.
 
virtual ~program ()
 Destructor.
 
programoperator() (int ac, char **av)
 Run the program and process any uncaught exceptions.
 
programoperator() (const std::string &command, const std::vector< std::string > &args)
 Run the program and process any uncaught exceptions.
 
int status () const
 Get the return status of the program.
 
template<class T >
void add_option (const std::string &longshort, T *target, const std::string &info, const std::string &aux_info=std::string())
 Add a new cmd line option.
 
template<class T >
void add_option (const std::string &longshort, T *target, const std::string &info, const OptionFlags def, const std::string &aux_info=std::string())
 Add a new cmd line option.
 
template<class T >
void add_option (const std::string &longshort, const std::string &conflicts_with, T *target, const std::string &info, const std::string &aux_info=std::string())
 Add a new cmd line option.
 
template<class T >
void add_option (const std::string &longshort, const std::string &conflicts_with, T *target, const std::string &info, const OptionFlags def, const std::string &aux_info=std::string())
 Add a new cmd line option. More...
 
template<typename T >
void add_residualargs (T *const target, const std::string &name, const OptionFlags def)
 Provide parsers for non-option command line arguments; if not provided, specifying a non-opt. arg throws a usage_error. More...
 
template<typename T >
void add_residualargs (T *const target, const std::string &name="FILES", const std::string &conflicts_with=std::string(), const OptionFlags def=shore::OPT_NOTSET, typename boost::disable_if< boost::is_const< T > >::type *dummy=0)
 Provide parsers for non-option command line arguments; if not provided, specifying a non-opt. arg throws a usage_error. More...
 
void add_residualargs (const std::string &opt_id, const std::string &name)
 Specify that non-option arguments are euivalent to an option. More...
 
void set_configfile (const std::string &fn)
 Set a configuration file that is parsed before parsing the command line.
 
void set_optiongroup (const std::string &g=std::string())
 Set the group that new options are added to; set an empty group name to hide options in the usage.
 
void set_description (const std::string &desc)
 Set up a program description to be diplayed along with the help message.
 
virtual const std::string & get_description () const
 Get program description to be diplayed along with the help message.
 
void set_usage_description (const std::string &desc)
 
void set_title (const std::string &t)
 
void set_programname (const std::string &name)
 Set the name of the program (av[0] by default).
 
const std::string & get_programname () const
 Get the name of the program (av[0] by default).
 
void set_helpcmd (const std::string &cmd)
 Set a command to display an extended help.
 
bool is_altered (const void *const ptr) const
 Test if a given value was redefined through a command line option.
 
size_t num_altered () const
 Get the number of altered command line options.
 
const std::string & get_commandline () const
 Get the command line string passed to the program.
 
av_parserget_optionparser ()
 Get a reference to the option parser.
 
shore::uncaught_handlerget_uncaught_handler ()
 Get a pointer to the uncaught exception handler. More...
 
const av_parserget_optionparser () const
 Get a reference to the option parser.
 
void set_show_extended_help (const bool f)
 Show a detailed help page instead of running the program.
 
void set_show_usage_description (const bool f)
 
virtual void show_usage () const
 Display a help message on the command line.
 
std::string startup_message () const
 
std::string shutdown_message () const
 

Static Public Attributes

static std::string TMPDIR
 The global temporary file directory.
 

Protected Member Functions

void allow_mpi ()
 Must be called in the contructor to indicate that the program supports message passing interface parallelization.
 
virtual int main ()=0
 The program main method that subclasses must implement.
 
virtual void sanity_check ()
 Subclasses should override this to check the commandline options.
 
virtual void basic_sanity_check ()
 Displays the usage if no arguments were given to the program and stdin is a tty. Override to change this behavior.
 

Friends

class shore::uncaught_handler
 

Detailed Description

Program base class.

Handles command line option parsing, displaying of a usage page, and reporting of fatal errors.

After parsing the command line, the virtual main() method is called and all exception thrown by main are reported. Subclasses can provide command line options via add_option().

Member Function Documentation

template<class T >
void shore::program::add_option ( const std::string &  longshort,
const std::string &  conflicts_with,
T *  target,
const std::string &  info,
const OptionFlags  def,
const std::string &  aux_info = std::string() 
)
inline

Add a new cmd line option.

Parameters
longshortOption string and option character, comma separated.
conflicts_withOptions that conflict with / require this one.
targetThe value that is set by this option.
infoDescription of the option.
defOptional / mandatory / not set...
aux_infoMore detailed description of the option.
template<typename T >
void shore::program::add_residualargs ( T *const  target,
const std::string &  name,
const OptionFlags  def 
)
inline

Provide parsers for non-option command line arguments; if not provided, specifying a non-opt. arg throws a usage_error.

Parameters
targetThe value that is set by this command line argument.
nameName displayed in the usage.
defOptional / mandatory / not set...
template<typename T >
void shore::program::add_residualargs ( T *const  target,
const std::string &  name = "FILES",
const std::string &  conflicts_with = std::string(),
const OptionFlags  def = shore::OPT_NOTSET,
typename boost::disable_if< boost::is_const< T > >::type *  dummy = 0 
)
inline

Provide parsers for non-option command line arguments; if not provided, specifying a non-opt. arg throws a usage_error.

Parameters
targetThe value that is set by this command line argument.
nameName displayed in the usage.
conflicts_withOptions that conflict with / require this one.
defOptional / mandatory / not set...
void shore::program::add_residualargs ( const std::string &  opt_id,
const std::string &  name 
)

Specify that non-option arguments are euivalent to an option.

Parameters
opt_idIdentifier of the option
nameName displayed in the usage.
shore::uncaught_handler* shore::program::get_uncaught_handler ( )

Get a pointer to the uncaught exception handler.

If the program is not running, returns null.


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