Classes | Functions
core/vul/vul_arg.h File Reference

Command-line arguments. More...

#include <vcl_vector.h>
#include <vcl_string.h>
#include <vcl_list.h>
#include <vcl_iosfwd.h>
#include <vxl_config.h>

Go to the source code of this file.

Classes

class  vul_arg_base
 This is the base class for the templated vul_arg<T>s. More...
struct  vul_arg_base::required_option_type
class  vul_arg< T >
 parse command-line arguments. More...
class  vul_arg_info_list
 a helper for vul_arg::parse. More...

Functions

template<class T >
void settype (vul_arg< T > &)
template<class T >
void print_value (vcl_ostream &, vul_arg< T > const &)
template<class T >
int parse (vul_arg< T > *, char **)
void vul_arg_parse (int &argc, char **&argv, bool warn_about_unrecognized_arguments=true)
 parse command-line arguments.
void vul_arg_include (vul_arg_info_list &l)
 Add an externally supplied list of args to the global list.
void vul_arg_display_usage_and_exit (char const *msg=0)
 Print all args, and usage messages.

Detailed Description

Command-line arguments.

Author:
Andrew W. Fitzgibbon, Oxford RRG
Date:
05 Feb 98
    Modifications
     PDA (Manchester) 21/03/2001: Tidied up the documentation
     Feb.2002 - Peter Vanroose - brief doxygen comment placed on single line
   

Definition in file vul_arg.h.


Function Documentation

template<class T >
int parse ( vul_arg< T > *  ,
char **   
)
template<class T >
void print_value ( vcl_ostream &  ,
vul_arg< T > const &   
)
template<class T >
void settype ( vul_arg< T > &  )
void vul_arg_display_usage_and_exit ( char const *  msg = 0)

Print all args, and usage messages.

Definition at line 65 of file vul_arg.cxx.

void vul_arg_include ( vul_arg_info_list l)

Add an externally supplied list of args to the global list.

Definition at line 59 of file vul_arg.cxx.

void vul_arg_parse ( int &  argc,
char **&  argv,
bool  warn_about_unrecognized_arguments 
)

parse command-line arguments.

vul_arg_parse simplifies the parsing of command-line arguments by combining the variables with the option specifications. To get a variable, you simply name it along with its flag, a help string, and an optional default value:

      vul_arg<double> threshold("-t", "Intensity threshold", 1.25);

Repeat this for any other arguments and then ask the base class to parse the lot:

      vul_arg_parse(argc,argv);

Now parameters such as threshold above can be referred to and will have either the default value or the one supplied on the command line.

The big design decision here was whether or not the args should collect themselves into a global pool, so that the static vul_arg_base::parse can find them, or whether there should be a local argPool which is passed to each arg in order that it may add itself. That would give a syntax like

      vul_arg_info_list args;
      vul_arg<double> threshold(args, "-t", 1.25);
                                ^^^^^ passing args in
      args.parse(argc, argv, true);

The latter is "better" but the former is easier to use so I chose it.

Added by Geoff: call to vul_arg_base::set_help_option("-?") means that a program call with something like aprog -? will display usage info derived from the argument list. Note: default is -? but can be anything.

Definition at line 51 of file vul_arg.cxx.