FBB::Arg(3bobcat)
Command Line Arguments
(libbobcat-dev_4.08.06-x.tar.gz)
2005-2018
NAME
FBB::Arg - A singleton class interfacing command line arguments
SYNOPSIS
#include <bobcat/arg>
Linking option: -lbobcat
DESCRIPTION
Singleton class (see Gamma et al., 1995) built around getopt()(3)
and getopt_long()(3). The class handles short- and long command-line
options,
NAMESPACE
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
INHERITS FROM
-
ENUMERATION
The FBB::Arg::Type enumeration is defined by the FBB::Arg
class. It is used to specify whether or not long options require arguments. It
defines the following values: None, Required, Optional.
- None: the long option does not use an argument;
- Required: the long option requires an argument value;
- Optional: the long option may optionally be provided with an
argument value;
These values are used when constructing objects of the following (nested)
class FBB::Arg::LongOption.
THE NESTED CLASS FBB::Arg::LongOption
Long options are defined using objects of the nested class
FBB::Arg::LongOption. This class provides the following constructors:
- FBB::Arg::LongOption(char const *name, FBB::Arg::Type type =
FBB::Arg::None):
This constructor is used to define a long option for which no
corresponding short option is defined. The parameter name is the
name of the long option (without prefixing the -- characters,
which are required when specifying the long option).
- FBB::Arg::LongOption(char const *name, int optionChar):
This constructor is used to define a long option for which a
corresponding short option is defined. The parameter name is the
name of the long option (without prefixing the -- characters,
which are required when specifying the long option).
In a program, long options may be specified as follows:
CONSTRUCTORS
Since the class is a Singleton there are no public
constructors. Instead, static members are offered for initializing and
accessing the single FBB::Arg object.
STATIC MEMBERS
OVERLOADED OPERATOR
- char const *operator[](size_t idx) const:
Returns argument[idx], after having removed all specified options.
It returns 0 if no arg[x] is available. The program's name
(argv[0]) is NOT counted here: index 0 refers to the first
ARGUMENT, e.g., the program's argv[1].
NON-STATIC MEMBER FUNCTIONS
- char const **argPointers():
Returns argv-like set of pointers to all remaining arguments. The
last element is guaranteed to be a 0-pointer. The first nArg()
elements point to the respective values of the NTBS arguments that
were passed to the program.
- std::string const &basename() const:
Returns the program's basename.
- size_t beyondDashes() const:
Returns the index of the first argument after a -- argument or
returns nArgs() if no -- argument was encountered.
A -- argument ends Arg's argument processing, and all arguments
beyond the first -- argument are kept `as is'. The
beyondDashes member returns the index of the first argument beyond
the -- argument, which itself is removed from the remaining set of
arguments.
- void help() const:
If the member versionHelp (see below) has been called then this
member calls the usage function that was passed to
versionHelp. If versionHelp has not been called (i.e., if no
usage function has been specified) an FBB::Exception is
thrown.
- size_t nArgs() const:
Returns the number of arguments left after option-removal. The
program name argv[0] is NOT counted here.
- size_t nLongOptions() const:
Returns the number of long options not having short option synonyms If
long options are multiply specified, then each specification is
counted.
- size_t nOptions() const:
Returns the number of specified single character options. If short
options have long option synonyms, then these long option synonyms are
counted as if they were specified as single character options. If
single character options (or their long option synonyms) are multiply
specified, then each specification is separately counted.
- size_t option(int option) const:
Returns the number of times `option' was specified (or its long option
synonym, if defined).
- size_t option(std::string const &options) const:
Returns the number of times each of the options specified in the `option'
argument were specified (or their long option synonyms). Note that
each character in options must specify a single-character option.
- size_t option(string *value, int option) const:
Returns the number of times the provided option (or its long option
synonym) was present. If the return value is non-zero then the value
of the first occurrence of this option is stored in *value, which
is left untouched if `option' was not present. The parameter value
may be initialized to 0 if the option does not have a value or if the
option's value should not be stored.
- size_t option(size_t idx, string *value, int option) const:
Returns the number of times the provided option (or its long option
synonym) was present. If the return value is non-zero then the value
of the idxth occurrence (0-based offset) of this option is stored
in *value, which is left untouched if `option' was not present or
if idx is or exceeds the number of specifications of the provided
option. 0 may be specified for value if the option does not have a
value or if the value should not be stored.
- size_t option(size_t *idx, string *value, int option) const:
Returns the number of times the provided option (or its long option
synonym) was present. If the return value is non-zero then the offset
(within the series of option specifications) of the first option
having a non-empty option value is returned in *idx, while its
option value is stored in *value. Both *value and *idx are
left untouched if `option' was not present. 0 may be specified for
value if the option does not have a value or if the value should
not be stored.
- size_t option(string *value, char const *longOption) const:
Returns the number of times the specified long option (not having a
single-character synonym) was present. Its value is then stored in
*value, which is left untouched if the long option was not
present. 0 may be specified for value if the option does not have
a value or if the value should not be stored.
- size_t option(size_t idx, string *value,
char const * longOption) const:
Returns the number of times the provided long option (not having a
single-character synonym) was present. If the return value is non-zero
then the value of the idxth occurrence (0-based offset) of this
long option is stored in *value, which is left untouched if the
long option was not present or if idx is or exceeds the number of
specifications of the provided long option.