Public Types |
enum | { REQUIRE_ORDER = 1,
PERMUTE_ARGS = 2,
RETURN_IN_ORDER = 3
} |
| Mutually exclusive ordering values. More...
|
enum | OPTION_ARG_MODE { NO_ARG = 0,
ARG_REQUIRED = 1,
ARG_OPTIONAL = 2
} |
| Mutually exclusive option argument mode used by long options. More...
|
Public Methods |
| ACE_Get_Opt (int argc, ACE_TCHAR **argv, const ACE_TCHAR *optstring, int skip_args=1, int report_errors=0, int ordering=PERMUTE_ARGS, int long_only=0) |
| Constructor initializes the command line to be parsed. More...
|
| ~ACE_Get_Opt (void) |
| Default dtor. More...
|
int | operator() (void) |
| Scan elements of argv (whose length is argc) for short option characters given in optstring or long options (with no short option equivalents). More...
|
ACE_TCHAR * | opt_arg (void) const |
| For communication from operator() to the caller. More...
|
int & | opt_ind (void) |
| Index in argv of the next element to be scanned. More...
|
int | long_option (const ACE_TCHAR *name, OPTION_ARG_MODE has_arg=NO_ARG) |
| Adds a long option with no corresponding short option. More...
|
int | long_option (const ACE_TCHAR *name, int short_option, OPTION_ARG_MODE has_arg=NO_ARG) |
const ACE_TCHAR * | long_option (void) const |
| Returns the name of the long option found on the last call to operator() or 0 if none was found. More...
|
ACE_TCHAR ** | argv (void) const |
| Accessor for the internal argv_ pointer. More...
|
void | dump (void) const |
| Dump the state of an object. More...
|
const ACE_TCHAR * | optstring (void) const |
| Return the optstring. This is handy to verify that calls to long_option added short options as expected. More...
|
Public Attributes |
int | argc_ |
ACE_TCHAR ** | argv_ |
int | optind |
int | opterr |
ACE_TCHAR * | optarg |
Private Methods |
int | nextchar_i (void) |
| Updates nextchar_. More...
|
int | long_option_i (void) |
| Handles long options. More...
|
int | short_option_i (void) |
| Handles short options. More...
|
void | permute_args (void) |
| If permuting args, this functions manages the nonopt_start_ and nonopt_end_ indexes and makes calls to permute to actually reorder the <argv>-elements. More...
|
int | permute (void) |
| Handles reordering <argv>-elements. More...
|
| ACE_Get_Opt (const ACE_Get_Opt &) |
ACE_Get_Opt & | operator= (const ACE_Get_Opt &) |
Private Attributes |
ACE_TString | optstring_ |
| Holds the option string. More...
|
int | long_only_ |
| Treat all options as long options. More...
|
int | has_colon_ |
| Keeps track of whether or not a colon was passed in <optstring>. This is used to determine the return value when required arguments are missing. More...
|
ACE_TCHAR * | nextchar_ |
| The next char to be scanned in the option-element in which the last option character we returned was found. More...
|
int | ordering_ |
| Keeps track of ordering mode (default <PERMUTE_ARGS>). More...
|
int | nonopt_start_ |
| Index of the first non-option <argv>-element found (only valid when permuting). More...
|
int | nonopt_end_ |
| Index of the <argv>-element following the last non-option element (only valid when permuting). More...
|
ACE_Get_Opt_Long_Option * | long_option_ |
| Points to the long_option found on last call to <operator()>. More...
|
ACE_Array< ACE_Get_Opt_Long_Option *> | long_opts_ |
| Array of long options. More...
|
| ACE_ALLOC_HOOK_DECLARE |
| Declare the dynamic allocation hooks. More...
|
This is a C++ wrapper for getopt(3c) and getopt_long(3c).
|
Constructor initializes the command line to be parsed.
All information for parsing must be supplied to this constructor. -
Parameters:
-
argc |
The number of argv elements to parse. |
argv |
Command line tokens, such as would be passed to main() . |
optstring |
Nul-terminated string containing the legitimate short option characters. A single colon ":" in optstring means that the previous character is an option that requires an argument. A double colon "::" signifies the argument is optional. The argument is taken from the rest of the current argv element, or from the following argv element (only valid for required arguments; optional arguments must always reside in the same argv element). The argument value, if any is returned by the opt_arg() method. optstring can be extended by adding long options with corresponding short options via the long_option() method. If the short option already appears in optstring, the argument characteristics must match, otherwise it is added. See long_option() for more information. If 'W', followed by a semi-colon ';' appears in optstring, then any time a 'W' appears on the command line, the following argument is treated as a long option. For example, if the command line contains "program -W foo", "foo" is treated as a long option, that is, as if "program --foo" had been passed. |
skip_args |
Optional (default 1). The specified number of initial elements in argv are skipped before parsing begins. Thus, the default prevents argv[0] (usually the command name) from being parsed. argc includes all argv elements, including any skipped elements. |
report_errors |
Optional, if non-zero then parsing errors cause an error message to be displayed from the operator() method before it returns. The error message is suppressed if this argument is 0. |
ordering |
Optional (default is PERMUTE_ARGS) ; refers to how the argv elements are processed.
- REQUIRE_ORDER means that processing stops and
EOF is returned as soon as a non-option argument is found. opt_ind() will return the index of the next argv element so the program can continue processing the rest of the argv elements. - PERMUTE_ARGS (default) means the argv elements are reordered dynamically (permuted) so that all options appear first. When the last option has been processed,
EOF is returned and opt_ind() returns the index into the next non-option element. - RETURN_IN_ORDER means each argv element is processed in the order is it seen. If the element is not recognized as an option, '1' is returned and
opt_arg() refers to the argv element found.
|
long_only |
Optional. If non-zero, then all options are treated as long options. If a long option is not recognized, the class tries to find a matching short option. |
Multiple short options can be combined as long as only the last one can takes an argument. For example, if optstring is defined as "abc :" or "abc ::" then the command line "program -abcxxx" short options a, b, and c are found with "xxx" as the argument for c. However, if the command line is specified as "program -acb" only options a and c are found with "b" as the argument for c. Also, for options with optional arguments, that is, those followed by "::", the argument must be in the same argv element, so "program -abc xxx" will only find "xxx" as the argument for c if optstring is specified as "abc :" not "abc ::". |