Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::option::Arg Struct Reference

Functions for checking the validity of option arguments.

Every Option has such a function assigned in its Descriptor.

Descriptor usage[] = { {UNKNOWN, 0, "", "", Arg::None, ""}, ... };
static ArgStatus None(const Option &, bool)
For options that don't take an argument: Returns ARG_NONE.
Describes an option, its help text (usage) and how it should be parsed.

A CheckArg function has the following signature:

ArgStatus CheckArg(const Option& option, bool msg);
A parsed option from the command line together with its argument if it has one.
ArgStatus
Possible results when checking if an argument is valid for a certain option.
ArgStatus(* CheckArg)(const Option &option, bool msg)
Signature of functions that check if an argument is valid for a certain type of option.

It is used to check if a potential argument would be acceptable for the option. It will even be called if there is no argument. In that case option.arg will be NULL.

If msg is true and the function determines that an argument is not acceptable and that this is a fatal error, it should output a message to the user before returning ARG_ILLEGAL. If msg is false the function should remain silent (or you will get duplicate messages).

See ArgStatus for the meaning of the return values.

While you can provide your own functions, often the following pre-defined checks (which never return ARG_ILLEGAL) will suffice:

  • Arg::None For options that don't take an argument: Returns ARG_NONE.
  • Arg::Optional Returns ARG_OK if the argument is attached and ARG_IGNORE otherwise.

The following example code can serve as starting place for writing your own more complex CheckArg functions:

struct Arg: public option::Arg
{
static void printError(const char* msg1, const option::Option& opt, const char* msg2)
{
fprintf(stderr, "ERROR: %s", msg1);
fwrite(opt.name, opt.namelen, 1, stderr);
fprintf(stderr, "%s", msg2);
}
static option::ArgStatus Unknown(const option::Option& option, bool msg)
{
if (msg) printError("Unknown option '", option, "'\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Required(const option::Option& option, bool msg)
{
if (option.arg != 0)
return option::ARG_OK;
if (msg) printError("Option '", option, "' requires an argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus NonEmpty(const option::Option& option, bool msg)
{
if (option.arg != 0 && option.arg[0] != 0)
return option::ARG_OK;
if (msg) printError("Option '", option, "' requires a non-empty argument\n");
return option::ARG_ILLEGAL;
}
static option::ArgStatus Numeric(const option::Option& option, bool msg)
{
char* endptr = 0;
if (option.arg != 0 && strtol(option.arg, &endptr, 10)){};
if (endptr != option.arg && *endptr == 0)
return option::ARG_OK;
if (msg) printError("Option '", option, "' requires a numeric argument\n");
return option::ARG_ILLEGAL;
}
};
Option_t Option_t option
const char * name
The name of the option as used on the command line.
int namelen
The length of the option name.
Functions for checking the validity of option arguments.

Definition at line 904 of file OptionParser.h.

Static Public Member Functions

static ArgStatus None (const Option &, bool)
 For options that don't take an argument: Returns ARG_NONE.
 
static ArgStatus Optional (const Option &option, bool)
 Returns ARG_OK if the argument is attached and ARG_IGNORE otherwise.
 

#include </home/sftnight/build/workspace/root-makedoc-master/rootspi/rdoc/src/master/core/dictgen/res/OptionParser.h>

Inheritance diagram for ROOT::option::Arg:
[legend]

Member Function Documentation

◆ None()

static ArgStatus ROOT::option::Arg::None ( const Option ,
bool   
)
inlinestatic

For options that don't take an argument: Returns ARG_NONE.

Definition at line 907 of file OptionParser.h.

◆ Optional()

static ArgStatus ROOT::option::Arg::Optional ( const Option option,
bool   
)
inlinestatic

Returns ARG_OK if the argument is attached and ARG_IGNORE otherwise.

Definition at line 913 of file OptionParser.h.


The documentation for this struct was generated from the following file: