Cross-Platform C++

ot::auxil
class BooleanOption

#include "ot/auxil/BooleanOption.h"

ot::auxil::BasicOption ot::auxil::CommandLineOption A command line option which has boolean (true or false) semantics. Each time this option appears on the command line as a short option, its value is negated. This means that if an option starts out with a default value of false, it will become true the first time it is specified on the command line. However, if it is specified a second time, it reverts back to false and so on.

When the long option name is employed, the option value is set to true unless the prefix 'no' appears at the front of the name. E.g. --nocopy will set the option with the long name 'copy' to false..

BooleanOptions cannot take an argument.

See also:
CommandLineParser



Constructor/Destructor Summary
BooleanOption(const String& longName, CharType shortName, bool bDefault)
         Constructs a BooleanOption.

Method Summary
 virtual String getArgument() const
         Returns the value of this boolean option.
 bool getValue() const
         Returns this option's value.
 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.

Methods inherited from class ot::auxil::BasicOption
getLongName(), getShortName(), isPresent(), testShortOption(CharType)

Constructor/Destructor Detail

BooleanOption

 BooleanOption(const String& longName,
               CharType shortName,
               bool bDefault)
Constructs a BooleanOption.

Parameters:
longName - the long name of this option
shortName - the short name of this option. Specify 0 to indicate there is no short name for this option.
bDefault - default value to report if the option is not specified on the command line
Exceptions:
IllegalArgumentException - if longName starts with '--'

Method Detail

getArgument

virtual String getArgument() const
Returns the value of this boolean option. See the class description for details of how this value is derived.

Returns:
true or false.

getValue

bool getValue() const
Returns this option's value.

Returns:
true if the option is set; 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.


Cross-Platform C++

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

Copyright © 2000-2005 ElCel Technology   Trademark Acknowledgements