ionflux.org | Impressum

Ionflux::Tools::CLArgs Class Reference
[Command line parsing]

Command line argument parser. More...

#include <CLArgs.hpp>

Collaboration diagram for Ionflux::Tools::CLArgs:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CLArgs ()
 Constructor.
 CLArgs (int argc, char *argv[])
 Constructor.
virtual ~CLArgs ()
 Destructor.
virtual void setArgs (int argc, char *argv[])
 Set command line arguments.
virtual CLOptiongetOption (const std::string &searchOption)
 Get an option.
virtual bool isSet (const std::string &checkOption)
 Check whether an option is set.
virtual void getParams (CLParams &target)
 Get parameters.
virtual void setCheckOptions (bool newCheckOptions)
 Set option checking status.
virtual void addAcceptableOption (const std::string &newOption, bool newAcceptValue)
 Add acceptable option.
virtual bool getCheckOptions ()
 Get option checking status.
virtual CLAcceptableOptiongetAcceptableOption (const std::string &searchOption)
 Get acceptable option record.
virtual bool isAcceptable (const std::string &checkOption)
 Check for acceptable option.
virtual bool acceptsValue (const std::string &checkOption)
 Check for acceptable option value.
virtual std::vector< std::string > & getInvalidOptions ()
 Get invalid options.
virtual bool optionsOK ()
 Get option validation status.
virtual void clearAcceptableOptions ()
 Clears the list of acceptable command line options.
virtual void clearOptions ()
 Clears the list of command line options.
virtual void clearParams ()
 Clears the list of command line parameters.
virtual void printDebugInfo ()
 Print debug information.
virtual ReportergetLog ()
 Get Console output/logging facility.

Static Public Attributes

static const TokenType TT_OPTION
 Token type: Option marker.
static const TokenType TT_ASSIGN
 Token type: Assignment operator.
static const CLOption OPTION_NOT_SET
 Option: Not set.

Protected Member Functions

virtual bool addOption (CLOption *newOption)
 Add option.
virtual void parse ()
 Parse command line arguments.

Protected Attributes

Ionflux::Tools::Reporter log
 Console output/logging.
std::vector< std::string > args
 Command line arguments.
std::vector< CLOption * > options
 Command line options.
CLParams params
 Command line parameters.
std::vector< CLAcceptableOption * > acceptable
 Acceptable command line options.
bool checkOptions
 Check options flag.
std::vector< std::string > invalidOptions
 Invalid options.

Detailed Description

Command line argument parser.

A command line argument parser which recognizes the following types of options and parameters:

-o Single-character option (switch).
--option Multi-character option (switch).
-o <value> Single-character option with value.
--option <value> Multi-character option with value.
-abc Concatenated single-character options (multiple switches).
-abc <value> Concatenated single-character options with value.
option=<value> Assignment option.
<parameter> Command line parameter.


Constructor & Destructor Documentation

Ionflux::Tools::CLArgs::CLArgs  ) 
 

Constructor.

Construct new CLArgs object.

Ionflux::Tools::CLArgs::CLArgs int  argc,
char *  argv[]
 

Constructor.

Construct new CLArgs object.

Parameters:
argc Number of arguments.
argv Argument vector.

Ionflux::Tools::CLArgs::~CLArgs  )  [virtual]
 

Destructor.

Destruct CLArgs object.


Member Function Documentation

bool Ionflux::Tools::CLArgs::acceptsValue const std::string &  checkOption  )  [virtual]
 

Check for acceptable option value.

Checks whether an option accepts a value.

Parameters:
checkOption Option identifier.
Returns:
true if the option accepts a value, false otherwise.

void Ionflux::Tools::CLArgs::addAcceptableOption const std::string &  newOption,
bool  newAcceptValue
[virtual]
 

Add acceptable option.

Adds an option to the list of options accepted by the command line parser.

Note:
You must set acceptable options before handing the command line arguments to the parser, i.e. call addAcceptableOption() for each acceptable option before calling setArgs().
Parameters:
newOption Option identifier.
newAcceptValue Whether the option can accept a value.

bool Ionflux::Tools::CLArgs::addOption CLOption newOption  )  [protected, virtual]
 

Add option.

Adds an option if it is acceptable.

Note:
If the option cannot be added, it will be deleted. You should therefore not use the pointer again if addOption() returns false.
Parameters:
newOption Command line option.
Returns:
true if the option was added successfully, false if the option could not be added and has been deleted.

void Ionflux::Tools::CLArgs::clearAcceptableOptions  )  [virtual]
 

Clears the list of acceptable command line options.

void Ionflux::Tools::CLArgs::clearOptions  )  [virtual]
 

Clears the list of command line options.

void Ionflux::Tools::CLArgs::clearParams  )  [virtual]
 

Clears the list of command line parameters.

CLAcceptableOption * Ionflux::Tools::CLArgs::getAcceptableOption const std::string &  searchOption  )  [virtual]
 

Get acceptable option record.

Get an acceptable option record.

Parameters:
searchOption Option identifier.
Returns:
A pointer to an acceptable option record, or 0 if the specified option is not found.

bool Ionflux::Tools::CLArgs::getCheckOptions  )  [virtual]
 

Get option checking status.

Returns the option checking status.

Returns:
true if the parser rejects options that are not explicitly set as acceptable, false otherwise.
See also:
addAcceptableOption()

std::vector< std::string > & Ionflux::Tools::CLArgs::getInvalidOptions  )  [virtual]
 

Get invalid options.

Get invalid options that have been encountered by the parser.

Returns:
Reference to the vector of invalid option identifiers.
See also:
optionsOK()

Reporter & Ionflux::Tools::CLArgs::getLog  )  [virtual]
 

Get Console output/logging facility.

Returns:
The console output/logging facility used by this object.

CLOption * Ionflux::Tools::CLArgs::getOption const std::string &  searchOption  )  [virtual]
 

Get an option.

Get an option.

Parameters:
searchOption Option to be returned.
Returns:
Pointer to an option, or 0 if the specified option is not set.

void Ionflux::Tools::CLArgs::getParams CLParams target  )  [virtual]
 

Get parameters.

Get command line parameters (values passed on the command line that do not qualify as options).

Parameters:
target Where to store the command line parameters.

bool Ionflux::Tools::CLArgs::isAcceptable const std::string &  checkOption  )  [virtual]
 

Check for acceptable option.

Checks whether an option should be accepted by the parser.

Parameters:
checkOption Option identifier.
Returns:
true if the option is acceptable, false otherwise.

bool Ionflux::Tools::CLArgs::isSet const std::string &  checkOption  )  [virtual]
 

Check whether an option is set.

Returns true if the specified option is set, false otherwise.

Parameters:
checkOption Option to be checked.
Returns:
true if the specified option is set, false otherwise.

bool Ionflux::Tools::CLArgs::optionsOK  )  [virtual]
 

Get option validation status.

Returns:
true if all options are acceptable, false otherwise.
See also:
getInvalidOptions()

void Ionflux::Tools::CLArgs::parse  )  [protected, virtual]
 

Parse command line arguments.

void Ionflux::Tools::CLArgs::printDebugInfo  )  [virtual]
 

Print debug information.

void Ionflux::Tools::CLArgs::setArgs int  argc,
char *  argv[]
[virtual]
 

Set command line arguments.

Sets the command line arguments in the standard format.

Parameters:
argc Number of arguments.
argv Argument vector.

void Ionflux::Tools::CLArgs::setCheckOptions bool  newCheckOptions  )  [virtual]
 

Set option checking status.

Sets whether the parser should reject options that are not explicitly set as acceptable.

Parameters:
newCheckOptions Whether the parser should reject options not set as acceptable.


Member Data Documentation

std::vector<CLAcceptableOption *> Ionflux::Tools::CLArgs::acceptable [protected]
 

Acceptable command line options.

std::vector<std::string> Ionflux::Tools::CLArgs::args [protected]
 

Command line arguments.

bool Ionflux::Tools::CLArgs::checkOptions [protected]
 

Check options flag.

std::vector<std::string> Ionflux::Tools::CLArgs::invalidOptions [protected]
 

Invalid options.

Ionflux::Tools::Reporter Ionflux::Tools::CLArgs::log [protected]
 

Console output/logging.

const CLOption Ionflux::Tools::CLArgs::OPTION_NOT_SET [static]
 

Option: Not set.

std::vector<CLOption *> Ionflux::Tools::CLArgs::options [protected]
 

Command line options.

CLParams Ionflux::Tools::CLArgs::params [protected]
 

Command line parameters.

const TokenType Ionflux::Tools::CLArgs::TT_ASSIGN [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 2, "=", false, 1}
Token type: Assignment operator.

const TokenType Ionflux::Tools::CLArgs::TT_OPTION [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 1, "-", false, 2}
Token type: Option marker.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:07:38 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6