code::StartupOptions Class Reference

List of all members.

Detailed Description

Handles command-line arguments passed in via main().

All executables accepting command-line options should use this class.

StartupOptions currently only handles single-character options. Values can be passed in this way:

 myApp -i /my/input/path
 myApp -i=/my/input/path
 myApp -i="/my/input/path"
 myApp -d <i>(no argument needed; this enables a boolean setting)</i>

StartupOptions can also build a `usage' printout that will be called whenever "myApp --help" is invoked or (optionally) whenever the application is invoked without arguments.

Author:
Jason Lynn
Version:
Id
code_StartupOptions.h,v 1.15 2011/09/23 16:37:32 Valliappa.Lakshmanan Exp


Public Member Functions

 StartupOptions ()
void showUsage () const
void addBoolArg (char optionLetter, const std::string &description)
void addStrArg (char optionLetter, const std::string &description)
void parseCommandLine (int &num_args, char **&args, bool show_usage_if_no_args=false)
 StartupOptions (const std::string &letters_for_all_possible_options, int &argc, char **&argv, bool show_usage_if_no_args=false)
 Deprecated constructor.
std::string get (char opt_prefix) const
bool get_bool (char opt_prefix) const
double get_double (char opt_prefix, double defaultValue=0) const
 ~StartupOptions ()

Static Public Member Functions

static bool removeArg (int &argc, char **&argv, const std::string &optionToRemove, int defaultValue, int &setme)
 Removes the specified option from the command-line array.
static bool removeArg (int &argc, char **&argv, const std::string &optionToRemove, std::string &setme)
 Removes the specified option from the command-line array.


Constructor & Destructor Documentation

code::StartupOptions::StartupOptions (  )  [inline]

code::StartupOptions::StartupOptions ( const std::string &  letters_for_all_possible_options,
int &  argc,
char **&  argv,
bool  show_usage_if_no_args = false 
)

Deprecated constructor.

This loads in the possible options and parses the command line. However it's not recommended because it doesn't let the caller provide option descriptions for showUsage().

Parameters:
options contains all the option letters. If the option letter is followed by a ':' then it's a string type; otherwise, it's a bool. for example, "cb:" expects user input like "-c -b foo".
argc argument count passed into the app's main() function.
argv argument array passed into the app's main() function.

code::StartupOptions::~StartupOptions (  )  [inline]


Member Function Documentation

void code::StartupOptions::addBoolArg ( char  optionLetter,
const std::string &  description 
)

void code::StartupOptions::addStrArg ( char  optionLetter,
const std::string &  description 
)

std::string code::StartupOptions::get ( char  opt_prefix  )  const

bool code::StartupOptions::get_bool ( char  opt_prefix  )  const

double code::StartupOptions::get_double ( char  opt_prefix,
double  defaultValue = 0 
) const

void code::StartupOptions::parseCommandLine ( int &  num_args,
char **&  args,
bool  show_usage_if_no_args = false 
)

static bool code::StartupOptions::removeArg ( int &  argc,
char **&  argv,
const std::string &  optionToRemove,
std::string &  setme 
) [static]

Removes the specified option from the command-line array.

Parameters:
argc number of arguments in `argv'
argv array of command-line arguments
optionToRemove the left-hand-side of the `=' token; i.e., "--configFile"
setme is set to the value found on the right-hand-side of the `=' token.
Returns:
true if optionToRemove was found

static bool code::StartupOptions::removeArg ( int &  argc,
char **&  argv,
const std::string &  optionToRemove,
int  defaultValue,
int &  setme 
) [static]

Removes the specified option from the command-line array.

Parameters:
argc number of arguments in `argv'
argv array of command-line arguments
optionToRemove the left-hand-side of the `=' token; i.e., "--configFile"
defaultValue the value to use if user passed option isn't found or can't be parsed.
setme is set to the value found on the right-hand-side of the `=' token, or defaultValue.
Returns:
true if optionToRemove was found

void code::StartupOptions::showUsage (  )  const [inline]


Generated on Fri May 4 13:40:13 2012 for WDSS-IIw2 by  doxygen 1.4.7