ArgumentList Class Reference

a simple interface for processing command line arguments More...

#include <argumentlist.h>

List of all members.

Public Member Functions

 ArgumentList ()
 retrieve argument list from the qApp->argc() and argv() methods.
 ArgumentList (int argc, char *argv[])
 
Parameters:
argc number of arguments

 ArgumentList (const QStringList &argumentList)
bool getSwitch (QString option)
 finds and removes a switch from the string list, if it exists.
QString getSwitchArg (QString option, QString defaultRetVal=QString())
 finds/removes a switch and its accompanying argument from the string list, if the switch is found.


Detailed Description

a simple interface for processing command line arguments

An object which provides a simple interface to the command line arguments of a program. The methods getSwitch(QString) and getSwitchArg(QString) allow you to process and remove the switches and switched arguments in the command line, so that the remaining entries in the stringlist can be processed as a uniform list.
It also happens to be derived from QStringList, so you can use any of those methods on this object too.
This helps you avoid entirely using the C arrays in your application.


Usage.:

int main(int argc, char** argv) {
ArgumentList args(argc, argv);
bool verbose = args.getSwitch("-v");
// get all other switches
QString outputfile = args.getSwitchArg("-o", "default.out");
qout << args[0];  // prints the name of the executable
qout << args[1]; // prints the first unswitched argument
someObject.processEveryFile(args);
}

Author:
S. Alan Ezust sae@mcs.suffolk.edu
Since:
qt 3.2.1

Definition at line 45 of file argumentlist.h.


Constructor & Destructor Documentation

ArgumentList::ArgumentList (  ) 

retrieve argument list from the qApp->argc() and argv() methods.

Only works if a QApplication(argc, argv) was already created.

Definition at line 9 of file argumentlist.cpp.

ArgumentList::ArgumentList ( int  argc,
char *  argv[] 
) [inline]

Parameters:
argc number of arguments

Parameters:
argv an array of command line arguments, as supplied to main().
See also:
argsToStringList()

Definition at line 60 of file argumentlist.h.


Member Function Documentation

bool ArgumentList::getSwitch ( QString  option  ) 

finds and removes a switch from the string list, if it exists.

Parameters:
option the switch to search for
Returns:
true if the switch was found

Definition at line 22 of file argumentlist.cpp.

QString ArgumentList::getSwitchArg ( QString  option,
QString  defaultRetVal = QString() 
)

finds/removes a switch and its accompanying argument from the string list, if the switch is found.

Does nothing if the switch is not found.

Parameters:
option the switch to search for
defaultReturnValue the return value if option is not found in the stringlist
Returns:
the argument following option, or defaultValue if the option is not found.

Definition at line 33 of file argumentlist.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Sep 30 01:15:43 2009 for oopapidocs by  doxygen 1.5.1