G::Arg Class Reference

A class which holds a represention of the argc/argv command line array. More...

#include <garg.h>

List of all members.

Public Types

typedef unsigned int size_type

Public Member Functions

 Arg (int argc, char *argv[])
 Constructor taking argc/argv.
 Arg ()
 Default constructor for Windows.
void parse (HINSTANCE hinstance, const std::string &command_line)
 Windows only.
void reparse (const std::string &command_line)
 Reinitialises the object with the given command-line.
 ~Arg ()
 Destructor.
size_type c () const
 Returns the number of tokens in the command line, including the program name.
std::string v (size_type i) const
 Returns the i'th argument.
std::string prefix () const
 Returns the basename of v(0) without any extension.
bool contains (const std::string &sw, size_type sw_args=0U, bool case_sensitive=true) const
 < An exception-free version of prefix() which can be used in main() outside of the outermost try block.
size_type index (const std::string &sw, size_type sw_args=0U) const
 Returns the index of the given switch.
bool remove (const std::string &sw, size_type sw_args=0U)
 Removes the given switch and its arguments.
void removeAt (size_type sw_index, size_type sw_args=0U)
 Removes the given argument and the following 'sw_args' ones.
Argoperator= (const Arg &)
 Assignment operator.
 Arg (const Arg &)
 Copy constructor.

Static Public Member Functions

static const char * prefix (char *argv[])


Detailed Description

A class which holds a represention of the argc/argv command line array.

In some environments the argv(0) path is fixed up so that it refers to the calling executable regardless of what the exec()ing process specified.

Also supports simple command line parsing.

See also:
G::GetOpt

Definition at line 46 of file garg.h.


Member Typedef Documentation

typedef unsigned int G::Arg::size_type

Definition at line 49 of file garg.h.


Constructor & Destructor Documentation

G::Arg::Arg ( int  argc,
char *  argv[] 
)

Constructor taking argc/argv.

Should not be used in a shared object or dll.

Definition at line 29 of file garg.cpp.

References G_ASSERT.

G::Arg::Arg (  ) 

Default constructor for Windows.

Initialise (once) with parse().

Definition at line 44 of file garg.cpp.

G::Arg::~Arg (  ) 

Destructor.

Definition at line 40 of file garg.cpp.

G::Arg::Arg ( const Arg other  ) 

Copy constructor.

Definition at line 51 of file garg.cpp.


Member Function Documentation

void G::Arg::parse ( HINSTANCE  hinstance,
const std::string &  command_line 
)

Windows only.

Parses the given command line, splitting it up into an array of tokens.

void G::Arg::reparse ( const std::string &  command_line  ) 

Reinitialises the object with the given command-line.

The command-line should not contain the program name: the v(0) value and prefix() are unchanged.

G::Arg::size_type G::Arg::c (  )  const

Returns the number of tokens in the command line, including the program name.

Definition at line 130 of file garg.cpp.

Referenced by filter_main().

std::string G::Arg::v ( size_type  i  )  const

Returns the i'th argument.

Precondition: i < c()

Definition at line 135 of file garg.cpp.

References G_ASSERT.

Referenced by filter_main().

std::string G::Arg::prefix (  )  const

const char * G::Arg::prefix ( char *  argv[]  )  [static]

Definition at line 146 of file garg.cpp.

bool G::Arg::contains ( const std::string &  sw,
size_type  sw_args = 0U,
bool  case_sensitive = true 
) const

< An exception-free version of prefix() which can be used in main() outside of the outermost try block.

Returns true if the command line contains the given switch with enough command line arguments left to satisfy the given number of switch arguments.

Definition at line 75 of file garg.cpp.

G::Arg::size_type G::Arg::index ( const std::string &  sw,
size_type  sw_args = 0U 
) const

Returns the index of the given switch.

Returns zero if not present.

Definition at line 123 of file garg.cpp.

bool G::Arg::remove ( const std::string &  sw,
size_type  sw_args = 0U 
)

Removes the given switch and its arguments.

Returns false if the switch does not exist.

Definition at line 102 of file garg.cpp.

References removeAt().

void G::Arg::removeAt ( size_type  sw_index,
size_type  sw_args = 0U 
)

Removes the given argument and the following 'sw_args' ones.

Definition at line 111 of file garg.cpp.

References G_ASSERT.

Referenced by remove().

G::Arg & G::Arg::operator= ( const Arg rhs  ) 

Assignment operator.

Definition at line 57 of file garg.cpp.

References m_array, and m_prefix.


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

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5