Webmaster  |  Imprint 
Platinum
Platinum C++ Framework
Main  |  License  |  Documentation  |  Download  |  Support 

Arg< bool > Class Template Reference

specialization for bool. More...

#include <Pt/Arg.h>

List of all members.

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


Detailed Description

template<>
class Pt::Arg< bool >

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

example:

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

Constructor & Destructor Documentation

Arg ( bool  def = false  ) 

Parameters:
def initial value

Arg ( int &  argc,
char *  argv[],
char  ch,
bool  def = false 
)

Parameters:
argc 1. parameter of main
argv 2. of main
ch optioncharacter
def default-value
example:
             Arg<unsigned> offset(argc, argv, 'o', 0);
             unsigned value = offset.getValue();


Member Function Documentation

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 
)

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

              prog --debug

with

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

Copyright © 2003-2007 The Pt Development Team
Pt 1.0