#include <Pt/Arg.h>
Public Member Functions | |
| Arg (const T &def=T()) | |
| Default constructor. Initializes value. | |
| Arg (int &argc, char *argv[], char ch, const T &def=T()) | |
| extract parameter. | |
| Arg (int &argc, char *argv[], const char *str, const T &def=T()) | |
| definition of long options. | |
| Arg (int &argc, char *argv[]) | |
| bool | set (int &argc, char *argv[], char ch) |
| extract parameter. | |
| bool | set (int &argc, char *argv[], const char *str) |
| definition of long options. | |
| bool | set (int &argc, char *argv[]) |
| Reads next parameter and removes it. | |
| const T & | getValue () const |
| returns the value. | |
| operator T () const | |
| returns the value. | |
| bool | isSet () const |
| returns true, if the option was found and the default was not used. | |
This default class processes paramters with a value, which defines a input-extractor-operator operator>> (istream&, T&).
Options are removed from the option-list, so programs can easily check after all options are extracted, if there are parameters left.
example:
int main(int argc, char* argv[]) { cxxtools::Arg<int> option_n(argc, argv, 'n', 0); std::cout << "value for -n: " << option_n << endl; }
| Arg | ( | const T & | def = T() |
) |
| def | initial value |
| Arg | ( | int & | argc, | |
| char * | argv[], | |||
| char | ch, | |||
| const T & | def = T() | |||
| ) |
| 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();
| Arg | ( | int & | argc, | |
| char * | argv[], | |||
| const char * | str, | |||
| const T & | def = T() | |||
| ) |
GNU defines long options starting with "--". This (and more) is supported here. Instead of giving a single option-character, you specify a string.
example:
Arg<int> option_number(argc, argv, "--number", 0); std::cout << "number =" << option_number.getValue() << std::endl;
| bool set | ( | int & | argc, | |
| char * | argv[], | |||
| char | ch | |||
| ) |
| argc | 1. parameter of main | |
| argv | 2. of main | |
| ch | optioncharacter |
Arg<unsigned> offset;
offset.set(argc, argv, 'o');
unsigned value = offset.getValue();
| bool set | ( | int & | argc, | |
| char * | argv[], | |||
| const char * | str | |||
| ) |
GNU defines long options starting with "--". This (and more) is supported here. Instead of giving a single option-character, you specify a string.
example:
Arg<int> option_number;
number.set(argc, argv, "--number");
std::cout << "number =" << option_number.getValue() << std::endl;
| operator T | ( | ) | const |
Instead of calling getValue() the argument can be converted implicitly.
example:
void print(int i) { std::cout << i << std::endl; } int main(int argc, char* argv[]) { cxxtools::Arg<int> value(argc, argv, 'v', 0); print(value); // pass argument as a int to the function }