cxxtools::Arg< bool > Class Template Reference

specialization for bool. More...

#include <cxxtools/arg.h>

Inheritance diagram for cxxtools::Arg< bool >:
cxxtools::ArgBase

Public Member Functions

 Arg (bool def=false)
 default constructor.
 Arg (int &argc, char *argv[], char ch, bool def=false)
 Use this constructor to extract a bool-parameter.
 Arg (int &argc, char *argv[], const char *str, bool def=false)
bool set (int &argc, char *argv[], char ch)
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
 convertable to bool.
- 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

- 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<>
class cxxtools::Arg< bool >

specialization for bool.

Often programs need some switches, which are switched on or off. Users just enter a option without parameter.

example:

cxxtools::Arg<bool> debug(argc, argv, 'd');
if (debug)
std::cout << "debug-mode is set" << std::endl;

Constructor & Destructor Documentation

cxxtools::Arg< bool >::Arg ( bool  def = false)
inline

default constructor.

Initializes value.

Parameters
definitial value
cxxtools::Arg< bool >::Arg ( int &  argc,
char *  argv[],
char  ch,
bool  def = false 
)
inline

Use this constructor to extract a bool-parameter.

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:

cxxtools::Arg<bool> debug(argc, argv, 'd');
cxxtools::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.

cxxtools::Arg< bool >::Arg ( int &  argc,
char *  argv[],
const char *  str,
bool  def = false 
)
inline

Member Function Documentation

bool cxxtools::Arg< bool >::isFalse ( ) const
inline

returns true, if options is not set.

bool cxxtools::Arg< bool >::isTrue ( ) const
inline

returns true, if options is set.

cxxtools::Arg< bool >::operator bool ( ) const
inline

convertable to bool.

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

Setter for long-options.

The option-parameter is defined with a string. This can extract long-options like:

prog --debug

with

Arg<bool> debug(argc, argv, "--debug");

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