Cross-Platform C++

ot::auxil
class BasicOption

#include "ot/auxil/BasicOption.h"

ot::auxil::CommandLineOption ot::auxil::BooleanOption A basic command line option. This class is used to represent a simple command line option that can be specified:- Options of this type cannot appear more than once on the same command line; a CommandLineException is thrown during the parsing of the command line if a second instance of the same option is detected.

See also:
CommandLineParser



Constructor/Destructor Summary
BasicOption(const String& longName, CharType shortName, ArgumentType argType)
         Constructs a new BasicOption.

Method Summary
 virtual String getArgument() const
         Returns the argument specified on the command line for this option.
 const String& getLongName() const
         Returns the long name for this option.
 CharType getShortName() const
         Returns the short name for this option.
 bool isPresent() const
         Returns a boolean flag indicating if this option has been specified on the command line.
 virtual void setPresent(const String& howSpecified, OptionType optionTypeUsed, const String& argument)
         Called by the CommandLineParser once it has determined that this CommandLineOption has been specified on the command line being parsed.
 virtual ArgumentType testLongOption(const String& option) const
         Called by the CommandLineParser to test if a long option contained within the command line matches the long option name accepted by this CommandLineOption.
 virtual ArgumentType testShortOption(CharType option) const
         Called by the CommandLineParser to test if a short option contained within the command line matches the short option name accepted by this CommandLineOption.

Constructor/Destructor Detail

BasicOption

 BasicOption(const String& longName,
             CharType shortName,
             ArgumentType argType)
Constructs a new BasicOption.

Parameters:
longName - the long name for this option.
shortName - the short name for this option. A value of 0 (zero) indicates that there is no short name for this option.
eArgumentType - flag indicating whether or not an argument should follow this option when specified on the command line.

Method Detail

getArgument

virtual String getArgument() const
Returns the argument specified on the command line for this option.

Returns:
the option's argument or an empty String if no argument was provided.

getLongName

const StringgetLongName() const
Returns the long name for this option. See CommandLineParser doe a description of long and short option names.


getShortName

CharType getShortName() const
Returns the short name for this option. See CommandLineParser doe a description of long and short option names.


isPresent

bool isPresent() const
Returns a boolean flag indicating if this option has been specified on the command line.

Returns:
true if the option has been provided; false otherwise.

setPresent

virtual void setPresent(const String& howSpecified,
                        OptionType optionTypeUsed,
                        const String& argument)
Called by the CommandLineParser once it has determined that this CommandLineOption has been specified on the command line being parsed. It is usual practice for the implementation to store the fact that a command option has been specified together with any associated argument. The application can then interrogate the object later on to see which options have been specified by the user.

Parameters:
howSpecified - the option as it appears on the command line.
optionTypeUsed - an indication if the option was recognised as a short or long option.
argument - the value of the option's argument (if specified)
Exceptions:
CommandLineException - if the option is invalid and parsing should stop.

testLongOption

virtual ArgumentType testLongOption(const String& option) const
Called by the CommandLineParser to test if a long option contained within the command line matches the long option name accepted by this CommandLineOption. In this case, the implementation should only check that the supplied option matches the first n characters of this option's long name (where n is the length of the supplied option string). This is to allow for long option abreviation.

If the passed option name does match, a value from the CommandLineOption::ArgumentType enumeration is returned to indicate whether an argument is expected for this option.

Parameters:
option - the option as contained within the command line being parsed.
Returns:
One of the values from the CommandLineOption::ArgumentType enumeration. If the option does not match then notknown is returned.

testShortOption

virtual ArgumentType testShortOption(CharType option) const
Called by the CommandLineParser to test if a short option contained within the command line matches the short option name accepted by this CommandLineOption. If the passed option name does match, a value from the CommandLineOption::ArgumentType enumeration is returned to indicate whether an argument is expected for this option.

Parameters:
option - the option as contained within the command line being parsed.
Returns:
One of the values from the CommandLineOption::ArgumentType enumeration. If the option does not match then notknown is returned.


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2005 ElCel Technology   Trademark Acknowledgements