E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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 (const G::StringArray &)
| Constructor taking an array of command-line arguments. More...
| Arg ()
| Default constructor. Initialise with parse().
void | parse (HINSTANCE hinstance, const std::string &command_line_tail)
| Parses the given command-line tail, splitting it up into an array of tokens. More...
void | parse (const std::string &command_line)
| Parses the given command line, splitting it up into an array of tokens. More...
void | reparse (const std::string &command_line_tail)
| Reinitialises the object with the given command-line tail. More...
| ~Arg ()
| Destructor.
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 &option, size_type option_args=0U, bool case_sensitive=true) const
| Returns true if the command line contains the given option with enough command line arguments left to satisfy the required number of option arguments. More...
size_type | index (const std::string &option, size_type option_args=0U) const
| Returns the index of the given option. Returns zero if not present.
bool | remove (const std::string &option, size_type option_args=0U)
| Removes the given option and its arguments. More...
void | removeAt (size_type option_index, size_type option_args=0U)
| Removes the given argument and the following 'option_args' ones.
StringArray | array (unsigned int shift=0U) const
| Returns the arguments a string array, including the program name in the first position. More...
Arg & | operator= (const Arg &)
| Assignment operator.
| Arg (const Arg &)
| Copy constructor.

## Static Public Member Functions
static std::string | v0 ()
| Returns a copy of argv[0] from the first call to the constructor that takes argc/argv. More...
static std::string | exe (bool do_throw=true)
| Returns Process::exe() or an absolute path constructed from v0(). More...
static const char * | prefix (char *argv[])
| An exception-free version of prefix() which can be used in main() outside of the outermost try block. More...

## Detailed Description

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

A copy of argv[0] is squirrelled away and made accessible via a static method.

See also
  G::GetOpt

Definition at line 43 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 34 of file garg.cpp.

G::Arg::Arg | ( | const G::StringArray & | args | ) |
| explicit

Constructor taking an array of command-line arguments.

The program name in the first position is expected but may be ignored.

Definition at line 49 of file garg.cpp.

## Member Function Documentation

G::StringArray G::Arg::array | ( | unsigned int | shift = `0U` | ) | const

Returns the arguments a string array, including the program name in the first position.

Definition at line 100 of file garg.cpp.

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

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

Definition at line 161 of file garg.cpp.

bool G::Arg::contains | ( | const std::string & | option,
|  | size_type | option_args = `0U`,
|  | bool | case_sensitive = `true`
| ) |  | const

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

(By convention an option starts with a dash, but that is not required here; it's just a string that is matched against command-line arguments.)

Definition at line 108 of file garg.cpp.

std::string G::Arg::exe | ( | bool | do_throw = `true` | ) |
| static

Returns Process::exe() or an absolute path constructed from v0().

Throws on error by default, or optionally returns the empty string. See also v0().

Definition at line 248 of file garg.cpp.

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

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

The v(0) value comes from the supplied instance handle.

Definition at line 68 of file garg.cpp.

void G::Arg::parse | ( | const std::string & | command_line | ) |

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

The command-line should start with the v(0) value.

Definition at line 75 of file garg.cpp.

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

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

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

Definition at line 179 of file garg.cpp.

bool G::Arg::remove | ( | const std::string & | option,
|  | size_type | option_args = `0U`
| ) |  |

Removes the given option and its arguments.

Returns false if the option does not exist.

Definition at line 132 of file garg.cpp.

void G::Arg::reparse | ( | const std::string & | command_line_tail | ) |

Reinitialises the object with the given command-line tail.

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

Definition at line 82 of file garg.cpp.

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

Returns the i'th argument.

Precondition: i < c()

Definition at line 166 of file garg.cpp.

std::string G::Arg::v0 | ( |  | ) |
| static

Returns a copy of argv[0] from the first call to the constructor that takes argc/argv.

Returns the empty string if that constructor overload has never been used. See also exe().

Definition at line 88 of file garg.cpp.

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

- /tmp/slackrepo/SBo/slackrepo.S3SYfd/build_emailrelay/emailrelay-2.0.1/src/glib/garg.h
- /tmp/slackrepo/SBo/slackrepo.S3SYfd/build_emailrelay/emailrelay-2.0.1/src/glib/garg.cpp