OW_NAMESPACE::CmdLineParser Class Reference

Do command line parsing. More...

#include <OW_CmdLineParser.hpp>

Collaboration diagram for OW_NAMESPACE::CmdLineParser:

Collaboration graph
[legend]
List of all members.

Public Types

enum  EArgumentTypeFlag { E_NO_ARG, E_REQUIRED_ARG, E_OPTIONAL_ARG }
enum  EErrorCodes { E_INVALID_OPTION, E_MISSING_ARGUMENT, E_INVALID_NON_OPTION_ARG, E_MISSING_OPTION }
enum  EAllowNonOptionArgsFlag { E_NON_OPTION_ARGS_ALLOWED, E_NON_OPTION_ARGS_INVALID }

Public Member Functions

 CmdLineParser (int argc, char const *const *const argv, const Option *options, EAllowNonOptionArgsFlag allowNonOptionArgs)
String getOptionValue (int id, const char *defaultValue="") const
 Read out a string option.
String mustGetOptionValue (int id, const char *exceptionMessage="") const
 Read out a string option.
StringArray getOptionValueList (int id) const
 Read out all occurences of a string option.
StringArray mustGetOptionValueList (int id, const char *exceptionMessage="") const
 Read out all occurences of a string option.
bool isSet (int id) const
 Read out a boolean option or check for the presence of string option.
size_t getNonOptionCount () const
 Read the number of arguments that aren't options (but, for example, filenames).
String getNonOptionArg (size_t n) const
 Read out an non-option argument.
StringArray getNonOptionArgs () const
 Read out the non-option args.

Static Public Member Functions

static String getUsage (const Option *options, unsigned int maxColumns=80)
 Generate a usage string for the options.

Private Types

typedef SortedVectorMap< int,
StringArray
optionsMap_t

Private Attributes

optionsMap_t m_parsedOptions
StringArray m_nonOptionArgs

Classes

struct  Option

Detailed Description

Do command line parsing.

Thread safety: read/write Copy semantics: Value Exception safety: Strong

Definition at line 55 of file OW_CmdLineParser.hpp.


Member Typedef Documentation

typedef SortedVectorMap<int, StringArray> OW_NAMESPACE::CmdLineParser::optionsMap_t [private]
 

Definition at line 180 of file OW_CmdLineParser.hpp.


Member Enumeration Documentation

enum OW_NAMESPACE::CmdLineParser::EAllowNonOptionArgsFlag
 

Enumerator:
E_NON_OPTION_ARGS_ALLOWED 
E_NON_OPTION_ARGS_INVALID 

Definition at line 84 of file OW_CmdLineParser.hpp.

enum OW_NAMESPACE::CmdLineParser::EArgumentTypeFlag
 

Enumerator:
E_NO_ARG 
E_REQUIRED_ARG 
E_OPTIONAL_ARG 

Definition at line 58 of file OW_CmdLineParser.hpp.

enum OW_NAMESPACE::CmdLineParser::EErrorCodes
 

Enumerator:
E_INVALID_OPTION 
E_MISSING_ARGUMENT 
E_INVALID_NON_OPTION_ARG 
E_MISSING_OPTION 

Definition at line 66 of file OW_CmdLineParser.hpp.


Constructor & Destructor Documentation

OW_NAMESPACE::CmdLineParser::CmdLineParser int  argc,
char const *const *const   argv,
const Option options,
EAllowNonOptionArgsFlag  allowNonOptionArgs
 

Parameters:
argc Count of pointers in argv. Pass value from main().
argv Arguments. Pass value from main(). Value is not saved.
options An array of Option terminated by a final entry that has a '' shortopt && 0 longopt. Value is not saved.
allowNonOptionArgs Indicate whether the presense of non-option arguments is an error.
Exceptions:
CmdLineParserException if the given command line is invalid.

Definition at line 85 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::String::c_str(), E_INVALID_OPTION, E_MISSING_ARGUMENT, E_NO_ARG, E_OPTIONAL_ARG, E_REQUIRED_ARG, OW_NAMESPACE::String::length(), OW_NAMESPACE::CmdLineParser::Option::longopt, m_parsedOptions, OW_ASSERT, OW_THROW_ERR, OW_NAMESPACE::CmdLineParser::Option::shortopt, OW_NAMESPACE::String::substring(), and val.


Member Function Documentation

String OW_NAMESPACE::CmdLineParser::getNonOptionArg size_t  n  )  const
 

Read out an non-option argument.

Parameters:
n The 0-based index of the argument. Valid values are 0 to count()-1.

Definition at line 367 of file OW_CmdLineParser.cpp.

References m_nonOptionArgs.

StringArray OW_NAMESPACE::CmdLineParser::getNonOptionArgs  )  const
 

Read out the non-option args.

Definition at line 374 of file OW_CmdLineParser.cpp.

References m_nonOptionArgs.

size_t OW_NAMESPACE::CmdLineParser::getNonOptionCount  )  const
 

Read the number of arguments that aren't options (but, for example, filenames).

Definition at line 360 of file OW_CmdLineParser.cpp.

References m_nonOptionArgs, and OW_NAMESPACE::Array< T >::size().

String OW_NAMESPACE::CmdLineParser::getOptionValue int  id,
const char *  defaultValue = ""
const
 

Read out a string option.

Parameters:
id The id of the option.
defaultValue The return value if the option wasn't set.
Returns:
The value of the option, if given, otherwise defaultValue. If the option was specified more than once, the value from the last occurence will be returned.

Definition at line 302 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::end(), OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::find(), and m_parsedOptions.

StringArray OW_NAMESPACE::CmdLineParser::getOptionValueList int  id  )  const
 

Read out all occurences of a string option.

Parameters:
id The id of the option.
Returns:
The value of the option, if given, otherwise an empty StringArray.

Definition at line 328 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::end(), OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::find(), and m_parsedOptions.

String OW_NAMESPACE::CmdLineParser::getUsage const Option options,
unsigned int  maxColumns = 80
[static]
 

Generate a usage string for the options.

e.g.: "Options:\n" " -1, --one first description\n" " -2, --two [arg] second description (default is optional)\n" " -3, --three <arg> third description\n"

[arg] is used for E_OPTIONAL_ARG options, and <arg> for E_REQUIRED_ARG options.

Parameters:
options An array of Option terminated by a final entry that has a '' shortopt && 0 longopt.
maxColumns Wrap the descriptions so no line of the usage string exceeds the specified number of columns.

Definition at line 194 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::CmdLineParser::Option::shortopt.

bool OW_NAMESPACE::CmdLineParser::isSet int  id  )  const
 

Read out a boolean option or check for the presence of string option.

Definition at line 353 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::count(), and m_parsedOptions.

String OW_NAMESPACE::CmdLineParser::mustGetOptionValue int  id,
const char *  exceptionMessage = ""
const
 

Read out a string option.

Parameters:
id The id of the option.
Returns:
The value of the option. If the option was specified more than once, the value from the last occurence will be returned.
Parameters:
exceptionMessage If an exception is thrown this string will be used as the exception message.
Exceptions:
CmdLineParserException with code E_MISSING_OPTION if the option wasn't specified.

Definition at line 315 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::end(), OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::find(), and m_parsedOptions.

StringArray OW_NAMESPACE::CmdLineParser::mustGetOptionValueList int  id,
const char *  exceptionMessage = ""
const
 

Read out all occurences of a string option.

Parameters:
id The id of the option.
Returns:
The value of the option.
Parameters:
exceptionMessage If an exception is thrown this string will be used as the exception message.
Exceptions:
CmdLineParserException with code E_MISSING_OPTION if the option wasn't specified.

Definition at line 341 of file OW_CmdLineParser.cpp.

References OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::end(), OW_NAMESPACE::SortedVectorMap< Key, T, Compare >::find(), and m_parsedOptions.


Member Data Documentation

StringArray OW_NAMESPACE::CmdLineParser::m_nonOptionArgs [private]
 

Definition at line 182 of file OW_CmdLineParser.hpp.

Referenced by getNonOptionArg(), getNonOptionArgs(), and getNonOptionCount().

optionsMap_t OW_NAMESPACE::CmdLineParser::m_parsedOptions [private]
 

Definition at line 181 of file OW_CmdLineParser.hpp.

Referenced by CmdLineParser(), getOptionValue(), getOptionValueList(), isSet(), mustGetOptionValue(), and mustGetOptionValueList().


The documentation for this class was generated from the following files:
Generated on Thu Feb 9 09:13:32 2006 for openwbem by  doxygen 1.4.6