cxxtools::Arg< T > Class Template Reference

Read and extract commandline parameters from argc/argv. More...

#include <cxxtools/arg.h>

Public Member Functions

 Arg (const T &def=T())
 default constructor.
 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())
 GNU defines long options starting with --.
 Arg (int &argc, char *argv[])
bool set (int &argc, char *argv[], char ch)
 extract parameter.
bool set (int &argc, char *argv[], const char *str)
 GNU defines long options starting with "&ndash;".
bool set (int &argc, char *argv[])
 Reads next parameter and removes it.

Detailed Description

template<typename T>
class cxxtools::Arg< T >

Read and extract commandline parameters from argc/argv.

Programs usually need some parameters. Usually they start with a '-' followed by a single character and optionally a value. Arg<T> extracts these and other parameters.

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;
}

Constructor & Destructor Documentation

template<typename T>
cxxtools::Arg< T >::Arg ( const T &  def = T())
inlineexplicit

default constructor.

Initializes value.

Parameters
definitial value
template<typename T>
cxxtools::Arg< T >::Arg ( int &  argc,
char *  argv[],
char  ch,
const T &  def = T() 
)
inline

extract parameter.

Parameters
argc1. parameter of main
argv2. of main
choptioncharacter
defdefault-value

example:

cxxtools::Arg<unsigned> offset(argc, argv, 'o', 0);
unsigned value = offset.getValue();
template<typename T>
cxxtools::Arg< T >::Arg ( int &  argc,
char *  argv[],
const char *  str,
const T &  def = T() 
)
inline

GNU defines long options starting with --.

This (and more) is supported here. Instead of giving a single option-character, you specify a string.

example:

cxxtools::Arg<int> option_number(argc, argv, "--number", 0);
std::cout << "number =" << option_number.getValue() << std::endl;
template<typename T>
cxxtools::Arg< T >::Arg ( int &  argc,
char *  argv[] 
)
inline

Member Function Documentation

template<typename T>
bool cxxtools::Arg< T >::set ( int &  argc,
char *  argv[],
char  ch 
)
inline

extract parameter.

Parameters
argc1. parameter of main
argv2. of main
choptioncharacter

example:

offset.set(argc, argv, 'o');
unsigned value = offset.getValue();
template<typename T>
bool cxxtools::Arg< T >::set ( int &  argc,
char *  argv[],
const char *  str 
)
inline

GNU defines long options starting with "&ndash;".

This (and more) is supported here. Instead of giving a single option-character, you specify a string.

example:

cxxtools::Arg<int> option_number;
number.set(argc, argv, "--number");
std::cout << "number =" << option_number.getValue() << std::endl;
template<typename T>
bool cxxtools::Arg< T >::set ( int &  argc,
char *  argv[] 
)
inline

Reads next parameter and removes it.


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