FBB::Arg(3bobcat)

Command Line Arguments
(libbobcat-dev_6.02.02)

2005-2022

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_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.

These values are used when defining long options (like --version), which are defined as objects of the (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:

To define long options use the following procedure:

Objects of the class LongOptions are normally used internally by the Arg object, but they can also be used outside of the Arg object. For that situation the following members are available:

CONSTRUCTORS

Since the class Arg is a singleton there are no public constructors. Instead, static members are available to initialize and to access the single FBB::Arg object.

STATIC MEMBERS

All initialize members initialize the FBB::Arg singleton, and can only be called once. An exception is thrown when called multiple times. All initialize members return a reference to the initialized Arg singleton object.

All initialize members define the parameters argc and argv which are interpreted as main's argc and argv parameters. When an argv element points to two consecutive dashes (--) then that element is ignored, and all of argv's subsequent elements are considered arguments instead of options.

OVERLOADED OPERATOR

NON-STATIC MEMBER FUNCTIONS

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;
using namespace std;

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 + size(longOptions);
}

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() << '\n';
    return 1;
}
    

FILES

bobcat/arg - defines the class interface

SEE ALSO

bobcat(7)

BUGS

None Reported.

BOBCAT PROJECT FILES

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).