Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | Private Member Functions | Friends
vul_arg< T > Class Template Reference

parse command-line arguments. More...

#include <vul_arg.h>

Inheritance diagram for vul_arg< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 vul_arg (char const *option_string=0, char const *helpstring=0, T default_value=T())
 Construct a vul_arg<T> with command-line switch and default value.
 vul_arg (vul_arg_info_list &l, char const *option_string=0, char const *helpstring=0, T default_value=T())
 As above, but add the arg to the list l, on which parse() can be called later.
 vul_arg (char const *option_string, char const *helpstring, required_option_type dummy)
 Dummy parameter to be passed during construction. It sets a flag as required.
 vul_arg (vul_arg_info_list &l, char const *option_string, char const *helpstring, required_option_type dummy)
 As above, but add the arg to the list l, on which parse() can be called later.
T & operator() ()
 return the arg's current value, whether the default or the one from the command line.
T const & operator() () const
int parse (char **argv)
 returns number of args chomped, or -1 on failure.
vcl_ostream & print_value (vcl_ostream &s)
 print.
char const * option ()
char const * help ()
bool set () const
 Returns true if arg was set on the command line.

Static Public Member Functions

static void parse_deprecated (int &argc, char **&argv, bool warn_about_unrecognized_arguments=true)
 The main static method.
static void include_deprecated (vul_arg_info_list &l)
 Add another vul_arg_info_list to the current one.
static void add_to_current (vul_arg_base *a)
static void set_help_option (char const *str)
static void set_help_description (char const *str)
static void set_help_precis (char const *str)
static void display_usage (char const *msg=0)
static void display_usage_and_exit (char const *msg=0)

Public Attributes

value_
char const * type_
 Static text describing type of option (e.g. bool or double).

Static Public Attributes

static required_option_type is_required

Protected Attributes

bool set_
 After parsing, true iff value was set on command line.
bool required_
 if true, this flag must be set on command line.
vcl_string option_
 Option flag including "-" or "--".
vcl_string help_
 Description of argument.

Private Member Functions

void settype ()

Friends

class vul_arg_info_list

Detailed Description

template<class T>
class vul_arg< T >

parse command-line arguments.

Definition at line 129 of file vul_arg.h.


Constructor & Destructor Documentation

template<class T>
vul_arg< T >::vul_arg ( char const *  option_string = 0,
char const *  helpstring = 0,
default_value = T() 
) [inline]

Construct a vul_arg<T> with command-line switch and default value.

Command line switch option_string, and default value default_value. Add this argument to the global list of arguments that vul_arg_base::parse() uses when it eventually gets the command line.

If option_string is null, then the argument is assigned to the first plain word in the command line (warning: this causes problems for T=char *, but that just means that you have to have a help string if you want a default... good)

Definition at line 146 of file vul_arg.h.

template<class T>
vul_arg< T >::vul_arg ( vul_arg_info_list l,
char const *  option_string = 0,
char const *  helpstring = 0,
default_value = T() 
) [inline]

As above, but add the arg to the list l, on which parse() can be called later.

Definition at line 154 of file vul_arg.h.

template<class T>
vul_arg< T >::vul_arg ( char const *  option_string,
char const *  helpstring,
required_option_type  dummy 
) [inline]

Dummy parameter to be passed during construction. It sets a flag as required.

Construct a vul_arg<T> that user must set in command line. Note that a default value does not make sense. Add this argument to the global list of arguments that vul_arg_base::parse() uses when it eventually gets the command line.

As in the previous constructors, if option_string is null, then the argument is assigned to the first plain word in the command line. However, this constructor adds a new option, allowing us to declare a non-null flag, which can appears anywhere, and that is REQUIRED.

Note that the parameters are not optional. This interface has been chosen to ensure backward compatibility. is_required

Definition at line 174 of file vul_arg.h.

template<class T>
vul_arg< T >::vul_arg ( vul_arg_info_list l,
char const *  option_string,
char const *  helpstring,
required_option_type  dummy 
) [inline]

As above, but add the arg to the list l, on which parse() can be called later.

Definition at line 181 of file vul_arg.h.


Member Function Documentation

void vul_arg_base::add_to_current ( vul_arg_base a) [static, inherited]

Definition at line 90 of file vul_arg.cxx.

void vul_arg_base::display_usage ( char const *  msg = 0) [static, inherited]

Definition at line 116 of file vul_arg.cxx.

void vul_arg_base::display_usage_and_exit ( char const *  msg = 0) [static, inherited]

Definition at line 122 of file vul_arg.cxx.

char const * vul_arg_base::help ( ) [inherited]

Definition at line 47 of file vul_arg.cxx.

void vul_arg_base::include_deprecated ( vul_arg_info_list l) [static, inherited]

Add another vul_arg_info_list to the current one.

This allows for the inclusion of different sets of arguments into the main program, from different libraries.

Definition at line 84 of file vul_arg.cxx.

template<class T>
T& vul_arg< T >::operator() ( ) [inline]

return the arg's current value, whether the default or the one from the command line.

Definition at line 189 of file vul_arg.h.

template<class T>
T const& vul_arg< T >::operator() ( ) const [inline]

Definition at line 190 of file vul_arg.h.

char const * vul_arg_base::option ( ) [inherited]

Definition at line 44 of file vul_arg.cxx.

template<class T>
int vul_arg< T >::parse ( char **  argv) [inline, virtual]

returns number of args chomped, or -1 on failure.

Implements vul_arg_base.

Definition at line 194 of file vul_arg.h.

void vul_arg_base::parse_deprecated ( int &  argc,
char **&  argv,
bool  warn_about_unrecognized_arguments = true 
) [static, inherited]

The main static method.

Definition at line 96 of file vul_arg.cxx.

template<class T>
vcl_ostream& vul_arg< T >::print_value ( vcl_ostream &  s) [inline, virtual]

print.

Implements vul_arg_base.

Definition at line 197 of file vul_arg.h.

bool vul_arg_base::set ( ) const [inherited]

Returns true if arg was set on the command line.

Definition at line 72 of file vul_arg.cxx.

void vul_arg_base::set_help_description ( char const *  str) [static, inherited]

Definition at line 111 of file vul_arg.cxx.

void vul_arg_base::set_help_option ( char const *  str) [static, inherited]

Definition at line 101 of file vul_arg.cxx.

void vul_arg_base::set_help_precis ( char const *  str) [static, inherited]

Definition at line 106 of file vul_arg.cxx.

template<class T>
void vul_arg< T >::settype ( ) [inline, private]

Definition at line 132 of file vul_arg.h.


Friends And Related Function Documentation

friend class vul_arg_info_list [friend, inherited]

Definition at line 52 of file vul_arg.h.


Member Data Documentation

vcl_string vul_arg_base::help_ [protected, inherited]

Description of argument.

Definition at line 75 of file vul_arg.h.

Definition at line 39 of file vul_arg.h.

vcl_string vul_arg_base::option_ [protected, inherited]

Option flag including "-" or "--".

Definition at line 73 of file vul_arg.h.

bool vul_arg_base::required_ [protected, inherited]

if true, this flag must be set on command line.

Definition at line 71 of file vul_arg.h.

bool vul_arg_base::set_ [protected, inherited]

After parsing, true iff value was set on command line.

Definition at line 69 of file vul_arg.h.

char const* vul_arg_base::type_ [inherited]

Static text describing type of option (e.g. bool or double).

Definition at line 66 of file vul_arg.h.

template<class T>
T vul_arg< T >::value_

Definition at line 134 of file vul_arg.h.


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