cxxtools::Arg< T > Class Template Reference

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

#include <cxxtools/arg.h>

Inheritance diagram for cxxtools::Arg< T >:
cxxtools::ArgBaseT< T > cxxtools::ArgBase

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 "&ndash;".
 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.
- Public Member Functions inherited from cxxtools::ArgBaseT< T >
const T & getValue () const
 returns the value.
 operator T () const
 Read and extract commandline parameters from argc/argv.
ArgBaseT< T > & operator= (const T &value)
- Public Member Functions inherited from cxxtools::ArgBase
 ArgBase ()
bool isSet () const
 returns true if the option was found and the default value was not used

Additional Inherited Members

- Protected Member Functions inherited from cxxtools::ArgBaseT< T >
 ArgBaseT (const T &def)
bool extract (const char *str, int &argc, char *argv[], int i, int n)
- Static Protected Member Functions inherited from cxxtools::ArgBase
static void removeArg (int &argc, char *argv[], int pos, int n)
- Protected Attributes inherited from cxxtools::ArgBase
bool m_isset

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 "&ndash;".

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: