#include <Pt/Arg.h>
Public Member Functions | |
| Arg (bool def=false) | |
| default constructor. Initializes value. | |
| Arg (int &argc, char *argv[], char ch, bool def=false) | |
| extract parameter. | |
| Arg (int &argc, char *argv[], const char *str, bool def=false) | |
| bool | set (int &argc, char *argv[], char ch) |
| Use this constructor to extract a bool-parameter. | |
| bool | set (int &argc, char *argv[], const char *str) |
| Setter for long-options. | |
| bool | isTrue () const |
| returns true, if options is set. | |
| bool | isFalse () const |
| returns true, if options is not set. | |
| operator bool () const | |
| convertible to bool. | |
| bool | isSet () const |
| returns true, if option is explicitly set | |
example:
Arg<bool> debug(argc, argv, 'd'); if (debug) std::cout << "debug-mode is set" << std::endl;
| Arg | ( | bool | def = false |
) |
| def | initial value |
| Arg | ( | int & | argc, | |
| char * | argv[], | |||
| char | ch, | |||
| bool | def = false | |||
| ) |
| argc | 1. parameter of main | |
| argv | 2. of main | |
| ch | optioncharacter | |
| def | default-value |
Arg<unsigned> offset(argc, argv, 'o', 0); unsigned value = offset.getValue();
| bool set | ( | int & | argc, | |
| char * | argv[], | |||
| char | ch | |||
| ) |
As a special case options can be grouped. The parameter is recognized also in a argument, which starts with a '-' and contains somewhere the given character.
example:
Arg<bool> debug(argc, argv, 'd'); Arg<bool> ignore(argc, argv, 'i');
Arguments debug and ignore are both set when the program is called with:
prog -id
prog -i -d
Options can also switched off with a following '-' like this:
prog -d-
In the program use:
Arg<bool> debug(argc, argv, 'd'); if (debug.isSet()) { if (debug) std::cout << "you entered -d" << std::endl; else std::cout << "you entered -d-" << std::endl; } else std::cout << "no -d option given" << std::endl;
This is useful, if a program defaults to some enabled feature, which can be disabled.
| bool set | ( | int & | argc, | |
| char * | argv[], | |||
| const char * | str | |||
| ) |