Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Data Fields
CommandOption Class Reference

CommandOption is the base class for all command line options. More...

#include <cmdoptns.h>

Inheritance diagram for CommandOption:
Inheritance graph
[legend]
Collaboration diagram for CommandOption:
Collaboration graph
[legend]

Public Types

enum  OptionType { hasArg, noArg, trailing, collect }
 OptionType is for denoting what type of option this is, with an arg, without an arg or the trailing args. More...
 

Public Member Functions

virtual ~CommandOption ()
 A virtual destructor just in case. More...
 
 CommandOption (const char *inOptionName, const char *inOptionLetter, const char *inDescription, OptionType inOptionType, bool inRequired=false, CommandOption **ppNext=&defaultCommandOptionList)
 CommandOption contructor. More...
 
virtual void foundOption (CommandOptionParse *cop, const char *value=0)
 foundOption is called by the CommandOptionParse object during the parsing of the command line options. More...
 
virtual void foundOption (CommandOptionParse *cop, const char **value, int num)
 foundOption is called by the CommandOptionParse object during the parsing of the command line options. More...
 
virtual void parseDone (CommandOptionParse *cop)
 Once parsing of command line options is complete, this method is called. More...
 
virtual void performTask (CommandOptionParse *cop)
 Once CommandOption objects have completed parsing and there are no errors they may have some specific tasks to perform. More...
 
virtual bool hasValue ()
 For fields with the required flag set, this method is used to determine if the Option has satisfied it's required status. More...
 

Data Fields

const char * optionName
 Long option name, these will be preceded with "--" on the command line. More...
 
const char * optionLetter
 option letter, these will be preceded with "-" on the command line. More...
 
const char * description
 A short description of the option for Usage messages. More...
 
OptionType optionType
 This command option's OptionType. More...
 
bool required
 True if this parameter is required. More...
 
CommandOptionnext
 This next CommandOption in this list of options or nil if no more options exist. More...
 

Detailed Description

CommandOption is the base class for all command line options.

Command line options can be defined statically and used when constructing a command line parser onject using makeCommandOptionParse. This serves only as a base class to CommandOptionWithArg, CommandOptionRest or CommandOptionNoArg which can also be used to derive more complex classes or even entire applications.

Author
Gianni Mariani giann.nosp@m.i@ma.nosp@m.riani.nosp@m..ws

Definition at line 76 of file cmdoptns.h.

Member Enumeration Documentation

OptionType is for denoting what type of option this is, with an arg, without an arg or the trailing args.

Option type

Enumerator
hasArg 

This option is associated with a value.

noArg 

This option is a flag only.

trailing 

Remaining of the command line arguments.

collect 

Collect values that are not a value to an option.

Definition at line 103 of file cmdoptns.h.

Constructor & Destructor Documentation

virtual CommandOption::~CommandOption ( )
virtual

A virtual destructor just in case.

CommandOption::CommandOption ( const char *  inOptionName,
const char *  inOptionLetter,
const char *  inDescription,
OptionType  inOptionType,
bool  inRequired = false,
CommandOption **  ppNext = &defaultCommandOptionList 
)

CommandOption contructor.

Note the default values for required and ppNext.

Parameters
inOptionNamelong option name
inOptionLettershort letter name
inDescriptionshort description of the option
inOptionTypethe type of this option
inRequiredtrue if option is required
ppNextthe linked list header

Member Function Documentation

virtual void CommandOption::foundOption ( CommandOptionParse cop,
const char *  value = 0 
)
virtual

foundOption is called by the CommandOptionParse object during the parsing of the command line options.

Parameters
coppointer to the command option parser
valuethe value of this option

Reimplemented in CommandOptionNoArg, and CommandOptionWithArg.

virtual void CommandOption::foundOption ( CommandOptionParse cop,
const char **  value,
int  num 
)
virtual

foundOption is called by the CommandOptionParse object during the parsing of the command line options.

Parameters
coppointer to the command option parser
valuean array of values of this option
numnumber of values in the array

Reimplemented in CommandOptionWithArg.

virtual bool CommandOption::hasValue ( )
virtual

For fields with the required flag set, this method is used to determine if the Option has satisfied it's required status.

The default methods simply returns true if any values have been found. This could be specialized to return true based on some other criteria.

Reimplemented in CommandOptionWithArg.

virtual void CommandOption::parseDone ( CommandOptionParse cop)
virtual

Once parsing of command line options is complete, this method is called.

This can be used to perform last minute checks on the options collected.

Parameters
coppointer to the command option parser
virtual void CommandOption::performTask ( CommandOptionParse cop)
virtual

Once CommandOption objects have completed parsing and there are no errors they may have some specific tasks to perform.

PerformTask must return.

Parameters
coppointer to the command option parser

Field Documentation

const char* CommandOption::description

A short description of the option for Usage messages.

e.g. Usage: mycommand : blah -f, –file <DESCRIPTION here>

Definition at line 96 of file cmdoptns.h.

CommandOption* CommandOption::next

This next CommandOption in this list of options or nil if no more options exist.

Definition at line 137 of file cmdoptns.h.

const char* CommandOption::optionLetter

option letter, these will be preceded with "-" on the command line.

e.g. -f foo.x

Definition at line 89 of file cmdoptns.h.

const char* CommandOption::optionName

Long option name, these will be preceded with "--" on the command line.

e.g. –file foo.x

Definition at line 83 of file cmdoptns.h.

OptionType CommandOption::optionType

This command option's OptionType.

Definition at line 125 of file cmdoptns.h.

bool CommandOption::required

True if this parameter is required.

If the parameter is not supplied and required is true, an error will be flagged in the option processor.

Definition at line 131 of file cmdoptns.h.


The documentation for this class was generated from the following file: