FBB::Arg(3bobcat)
Command Line Arguments
(libbobcat-dev_4.08.03-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 has the following values intended for public use: None, Required,
Optional. These values are used when constructing objects of the nested class
FBB::Arg::LongOption, see below.
CONSTRUCTORS
Since the class is a Singleton, no public constructors are
available. Instead, static members are offered to initialize and access the
single FBB::Arg object. See below.
STATIC MEMBERS
OVERLOADED OPERATOR
- char const *operator[](size_t idx) const:
Returns argument[idx], after having removed all specified options.
0 is returned if no arg[x] is available. The program 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
THE NESTED CLASS FBB::Arg::LongOption
Long options are defined using objects of the nested class
FBB::Arg::LongOption. This class offers the following constructors:
- FBB::Arg::LongOption(char const *name, FBB::Arg::Type type = 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:
EXAMPLE
The following example illustrates defining long options and shows an
initialization. It is not a full-fledched example in the sense of a small
runnable program.
#include <bobcat/arg>
using namespace FBB;
namespace // the anonymous namespace can be used here
{
Arg::LongOption longOptions[] =
{
Arg::LongOption{"debug"},
Arg::LongOption{"filenames", 'f'},
Arg::LongOption{"help", 'h'},
Arg::LongOption{"version", 'v'},
};
auto longEnd = longOptions + sizeof(longOptions) / sizeof(longOptions[0]);
}
int main(int argc, char **argv)
try
{
Arg &arg = Arg::initialize("df:hv",
longOptions, longEnd, argc, argv);
// code using arg, etc.
}
catch(Exception const &err) // handle exceptions
{
cerr << err.what() << endl;
return err.which();
}
catch(int x)
{
return x;
}
FILES
bobcat/arg - defines the class interface
SEE ALSO
bobcat(7)
BUGS
None Reported.
DISTRIBUTION FILES
- bobcat_4.08.03-x.dsc: detached signature;
- bobcat_4.08.03-x.tar.gz: source archive;
- bobcat_4.08.03-x_i386.changes: change log;
- libbobcat1_4.08.03-x_*.deb: debian package holding the
libraries;
- libbobcat1-dev_4.08.03-x_*.deb: debian package holding the
libraries, headers and manual pages;
- http://sourceforge.net/projects/bobcat: public archive location;
BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
COPYRIGHT
This is free software, distributed under the terms of the
GNU General Public License (GPL).
AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl).