Slice Tools
  • Home
  • SourceForge Page


  • libFoundation
  • Home
  • Class Hierarchy
  • Class List
  • Class Members
  • Examples


  • SourceForge.net Logo
     

    Options Class Reference

    #include <Options.hh>

    List of all members.


    Detailed Description

    Class to simplify results of getopt and getopt_long.
    Examples:

    example-options.cc, and example-options.out.


    Public Member Functions

     Options (int argc, char **argv)
     Constructor takes command line options in standard argc, argv format.

     ~Options ()
     Deletes OptionResults.

    std::string getApplicationFilespec ()
     Returns the application filespec (argv[0]).

    std::string getApplicationName ()
     Returns application name.

    std::string getInvocation ()
     Returns invocation (application filespec with all arguments appended).

    void addOption (const char *optionName, int has_arg, const char *alias=NULL, const std::string &optionHelp="")
     Simple Interface for adding options (without setting result).

    void addOptionResult (const std::string &optionArgument, int *resultPointer, const std::string &optionHelp="")
     Creates an IntOptionResult, and calls parseArgument with it.

    void addOptionResult (const std::string &optionArgument, float *resultPointer, const std::string &optionHelp="")
     Creates an FloatOptionResult, and calls parseArgument with it.

    void addOptionResult (const std::string &optionArgument, std::string *resultPointer, const std::string &optionHelp="")
     Creates an StringOptionResult, and calls parseArgument with it.

    int hasOption (const std::string &optionName)
     Checks to see if an option is contained in options map.

    std::string getOption (const std::string &optionName)
     Gets the argument value for an option.

    std::string getNextOption ()
     Iterates through the list of arguments getting one argument name at a time.

    std::string getNextOtherData ()
     Iterates through non-option data.

    StringList getAllOtherData ()
     Gets all non-option data from the command line.

    void standardOptionsComplete ()
     Call after all of the standard options have been set.

    void printHelp ()
     Print help for each alias alphabetically, starting with the standard options.

    void parseOptions ()
     Wraps GNU getopt_long.


    Constructor & Destructor Documentation

    Options::Options int  argc,
    char **  argv
     

    Constructor takes command line options in standard argc, argv format.

    Initializes application name, filespec, and invocation

    Options::~Options  ) 
     

    Deletes OptionResults.

    Loops through standard option names and other other option names, because m_optionResults will have multiple names and aliases pointing to the same result


    Member Function Documentation

    void Options::addOption const char *  optionName,
    int  has_arg,
    const char *  alias = NULL,
    const std::string &  optionHelp = ""
     

    Simple Interface for adding options (without setting result).

    Builds an option result with no result pointer out of optionName and alias. Then inserts it into the map.

    Parameters:
    optionName Name of option to add
    has_arg Flag if option takes an option in getopt_long style
    alias Optional Additional name of argument (for specifing short and long names)
    optionHelp Help string for this option
    See also:
    insertOptionResult()

    verifyName()

    void Options::addOptionResult const std::string &  optionArgument,
    std::string *  resultPointer,
    const std::string &  optionHelp = ""
     

    Creates an StringOptionResult, and calls parseArgument with it.

    See also:
    addOptionResult(const char [], int *, const string &)
    Exceptions:
    InvalidOptionError If optionArgument is NULL
    Parameters:
    optionArgument Perl style option string
    resultPointer Pointer to float where result should be written
    optionHelp Help string for the option

    void Options::addOptionResult const std::string &  optionArgument,
    float *  resultPointer,
    const std::string &  optionHelp = ""
     

    Creates an FloatOptionResult, and calls parseArgument with it.

    See also:
    addOptionResult(const char [], int *, const string &)
    Exceptions:
    InvalidOptionError If optionArgument is NULL
    Parameters:
    optionArgument Perl style option string
    resultPointer Pointer to float where result should be written
    optionHelp Help string for the option

    void Options::addOptionResult const std::string &  optionArgument,
    int *  resultPointer,
    const std::string &  optionHelp = ""
     

    Creates an IntOptionResult, and calls parseArgument with it.

    optionArgument format is: name[|alias[...]][!][{=,:}{s,f,i}]
    name: Main name for option, only required argument
    |alias[...]: The list of aliases for the option separated by '|'
    ! Creates negative options as well, ie. "option" and "nooption"
    = means requires an argument
    : means argument is optional
    s means result type is string
    f means result type is float
    i means result type is integer

    if result type is integer 0 is set for negative option,
    1 is set for positive option and no value

    if result type is float 0.0 is set for negative option,
    1.0 is set for positive option and no value

    if result type is string "" is set for negative option,
    "1" is set for positive option and no value

    Exceptions:
    InvalidOptionError If optionArgument is NULL
    Parameters:
    optionArgument Perl style option string
    resultPointer Pointer to int where result should be written
    optionHelp Help string for the option
    Examples:
    example-options.cc.

    StringList Options::getAllOtherData  ) 
     

    Gets all non-option data from the command line.

    std::string Options::getApplicationFilespec  ) 
     

    Returns the application filespec (argv[0]).

    Examples:
    example-options.cc.

    std::string Options::getApplicationName  ) 
     

    Returns application name.

    Examples:
    example-options.cc.

    std::string Options::getInvocation  ) 
     

    Returns invocation (application filespec with all arguments appended).

    Examples:
    example-options.cc.

    std::string Options::getNextOption  ) 
     

    Iterates through the list of arguments getting one argument name at a time.

    Examples:
    example-options.cc.

    std::string Options::getNextOtherData  ) 
     

    Iterates through non-option data.

    Examples:
    example-options.cc.

    std::string Options::getOption const std::string &  optionName  ) 
     

    Gets the argument value for an option.

    Note: Returns "" for options not found which is identical to options that are defined but have no value. Use hasOption first to determine if option exists.

    Returns:
    Value of option or "" if not found or valueless
    Examples:
    example-options.cc.

    int Options::hasOption const std::string &  optionName  ) 
     

    Checks to see if an option is contained in options map.

    Parameters:
    optionName Name (or alias) or option to check
    Returns:
    An integer count of the number of times the option was set
    Examples:
    example-options.cc.

    void Options::parseOptions  ) 
     

    Wraps GNU getopt_long.

    Wraps calls to getopt_long and stores results in a map for easy access. The rest of the class aids this function either by setting up parameters or processing results.

    Exceptions:
    InvalidOptionError On option on commandline but not specified as valid
    MissingRequiredParameterError On option given but required parameter not found

    void Options::printHelp  ) 
     

    Print help for each alias alphabetically, starting with the standard options.

    void Options::standardOptionsComplete  ) 
     

    Call after all of the standard options have been set.


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