Public Types | Public Member Functions | Static Public Member Functions | List of all members
G::Arg Class Reference

A class which holds a represention of the argc/argv command line array, and supports simple command-line parsing. More...

#include <garg.h>

Public Types

typedef size_t size_type
 

Public Member Functions

 Arg (int argc, char *argv[])
 Constructor taking argc/argv. More...
 
 Arg ()
 Default constructor for Windows. More...
 
void parse (HINSTANCE hinstance, const std::string &command_line)
 Windows only. More...
 
void reparse (const std::string &command_line)
 Reinitialises the object with the given command-line. More...
 
 ~Arg ()
 Destructor. More...
 
size_type c () const
 Returns the number of tokens in the command line, including the program name. More...
 
std::string v (size_type i) const
 Returns the i'th argument. More...
 
std::string prefix () const
 Returns the basename of v(0) without any extension. More...
 
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. More...
 
size_type index (const std::string &sw, size_type sw_args=0U) const
 Returns the index of the given switch. More...
 
bool remove (const std::string &sw, size_type sw_args=0U)
 Removes the given switch and its arguments. More...
 
void removeAt (size_type sw_index, size_type sw_args=0U)
 Removes the given argument and the following 'sw_args' ones. More...
 
Argoperator= (const Arg &)
 Assignment operator. More...
 
 Arg (const Arg &)
 Copy constructor. More...
 

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, and supports simple command-line parsing.

In some environments the argv(0) path is fixed up so that it refers to the running executable, regardless of what the parent process specified in the exec() call. Refer to the various implementations of G::Arg::setExe().

See also
G::GetOpt

Definition at line 46 of file garg.h.

Member Typedef Documentation

typedef size_t 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

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

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

Definition at line 131 of file garg.cpp.

Referenced by filter_main().

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 124 of file garg.cpp.

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

Assignment operator.

Definition at line 57 of file garg.cpp.

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.

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

Returns the basename of v(0) without any extension.

Typically used as a prefix in error messages.

Definition at line 142 of file garg.cpp.

Referenced by filter_main(), and main().

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

Definition at line 147 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.

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.

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.

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

Returns the i'th argument.

Precondition: i < c()

Definition at line 136 of file garg.cpp.

References G_ASSERT.

Referenced by filter_main().


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