Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

CommandLine Class Reference

#include <CommandLine.h>

List of all members.


Detailed Description

The CommandLine class represents the arguments specified in the command line.

It provides functions for parametered and flag-only options (i.e. arguments starting with slash or hyphen, followed by a pre-defined number of parameters), as well as enumerating the remaining arguments.

Author:
Thomas Jacob

Definition at line 22 of file CommandLine.h.

Public Member Functions

 CommandLine ()
 Creates a new CommandLine object.

void declareOption (const String &name, int expectedParameters)
 Declares an option to have a well-defined number of parameters.

const ArrayList< String > * getOptionParameters (const String &name) const
 Returns the actual parameters of an option.

const ArrayList< String > & getParameters () const
 Returns the parameters in the command line not being part of any option.

const StringgetProgramName () const
 Returns the name of the program (argv[0]).

bool hasOption (const String &name) const
 Returns whether a given option actually occurs in the command line.

void readFrom (int argc, const char **argv)
 Reads a given command line into this object.

void readFromDefault ()
 Reads the default command line (__argc and __argv) into this object.

 ~CommandLine ()
 Destroys the CommandLine object.


Private Attributes

StringKeyHashMap< Optionoptions
 A hashtable containing the found option names as keys and Option objects as values.

ArrayList< Stringparameters
 The parameters in the command line without the options.

String programName
 The name of the program.


Constructor & Destructor Documentation

CommandLine  ) 
 

Creates a new CommandLine object.

~CommandLine  ) 
 

Destroys the CommandLine object.


Member Function Documentation

void declareOption const String name,
int  expectedParameters
 

Declares an option to have a well-defined number of parameters.

Note:
It is not necessary to call this method for expected options that do not have any parameters.
Parameters:
name The name of the option, including the prefixing slash or hyphen.
expectedParameters The number of parameters expected for this option.

const ArrayList<String>* getOptionParameters const String name  )  const
 

Returns the actual parameters of an option.

For example, if the arguments are '/A /E a b c', and the option '/E' is defined with 2 expected parameters, this method returns 'a' and 'b'.

Parameters:
name The name of the option, including the prefixing slash or hyphen.
Returns:
The parameters of the option. If the option actually occurs in the command line, but it expects no parameters, or if the option has not been declared at all, this method returns an empty ArrayList. If the option does not occur in the command line, this method returns NULL.

const ArrayList<String>& getParameters  )  const
 

Returns the parameters in the command line not being part of any option.

const String& getProgramName  )  const
 

Returns the name of the program (argv[0]).

Returns:
The program name.

bool hasOption const String name  )  const
 

Returns whether a given option actually occurs in the command line.

Parameters:
name The name of the option, including the prefixing slash or hyphen.
Returns:
Whether the option actually occurs in the command line.

void readFrom int  argc,
const char **  argv
 

Reads a given command line into this object.

Note:
This method may be called only once for each CommandLine.
Parameters:
argc The number of command line arguments, as provided by the main function.
argv The command line arguments, as provided by the main function.

void readFromDefault  ) 
 

Reads the default command line (__argc and __argv) into this object.

Note:
This method may be called only once for each CommandLine.


Member Data Documentation

StringKeyHashMap<Option> options [private]
 

A hashtable containing the found option names as keys and Option objects as values.

Definition at line 75 of file CommandLine.h.

ArrayList<String> parameters [private]
 

The parameters in the command line without the options.

Definition at line 80 of file CommandLine.h.

String programName [private]
 

The name of the program.

This is the first element of the argv array.

Definition at line 86 of file CommandLine.h.


The documentation for this class was generated from the following file:
Generated on Tue Oct 3 00:23:39 2006 for ToolBox by doxygen 1.3.6