libpsynth 0.2.1
Public Types | Public Member Functions
psynth::base::arg_parser Class Reference

Class for parsing program arguments. More...

#include <arg_parser.hpp>

Inheritance diagram for psynth::base::arg_parser:
Inheritance graph
[legend]
Collaboration diagram for psynth::base::arg_parser:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::list< const char * >
::iterator 
iterator
 Iterator for the arguments that where not parsed.
typedef std::list< const char * >
::const_iterator 
const_iterator
 ConstIterator for the arguments that where not parse.

Public Member Functions

void add (unsigned char flag, const char *str, int *data)
 Adds an int option.
void add (unsigned char flag, const char *str, float *data)
 Adds a float option.
void add (unsigned char flag, const char *str, bool *data)
 Adds a bool option.
void add (unsigned char flag, const char *str, std::string *data)
 Adds a string option.
void add (unsigned char flag, const char *str, const char **data)
 Adds a cstring option.
void add (unsigned char flag, const char *str, option *op)
 Adds an user defined option.
void parse (int argc, const char *argv[])
 Parse the command line arguments using the defined options.
iterator begin ()
 Returns an iterator to the first free argument.
const_iterator begin () const
 Returns a const_iterator to the first free argument.
iterator end ()
 Returns an Iterator to the end of free arguments list.
const_iterator end () const
 Returns a ConstIterator to the end of free arguments list.
size_t free_args () const
 Return the number of free arguments.
bool has_free_args () const
 Returns whether there are any free arguments.

Detailed Description

Class for parsing program arguments.

You register options that individual arguments. It includes some wrapper functions to add options to parse arguments of basic data types.

See also:
option

Member Typedef Documentation

ConstIterator for the arguments that where not parse.

typedef std::list<const char*>::iterator psynth::base::arg_parser::iterator

Iterator for the arguments that where not parsed.


Member Function Documentation

void psynth::base::arg_parser::add ( unsigned char  flag,
const char *  str,
int *  data 
) [inline]

Adds an int option.

Parameters:
flagShort version of the option.
strLong version of the option.
void psynth::base::arg_parser::add ( unsigned char  flag,
const char *  str,
float *  data 
) [inline]

Adds a float option.

Parameters:
flagShort version of the option.
strLong version of the option.
dataWhere to store the passed value.
void psynth::base::arg_parser::add ( unsigned char  flag,
const char *  str,
std::string *  data 
) [inline]

Adds a string option.

Parameters:
flagShort version of the option.
strLong version of the option.
dataWhere to store the passed value.
void psynth::base::arg_parser::add ( unsigned char  flag,
const char *  str,
const char **  data 
) [inline]

Adds a cstring option.

Parameters:
flagShort version of the option.
strLong version of the option.
dataWhere to store the passed value.
void psynth::base::arg_parser::add ( unsigned char  flag,
const char *  str,
bool *  data 
) [inline]

Adds a bool option.

Parameters:
flagShort version of the option.
strLong version of the option.
dataWhere to store the passed value.
void psynth::base::arg_parser::add ( unsigned char  flag,
const char *  str,
option op 
)

Adds an user defined option.

If the option is null an empty option is added -produces no result but avoids exceptions.

Parameters:
flagShort version of the option.
strLong version of the option.
opThe option to associate to and .
See also:
Option
iterator psynth::base::arg_parser::begin ( ) [inline]

Returns an iterator to the first free argument.

const_iterator psynth::base::arg_parser::begin ( ) const [inline]

Returns a const_iterator to the first free argument.

iterator psynth::base::arg_parser::end ( ) [inline]

Returns an Iterator to the end of free arguments list.

const_iterator psynth::base::arg_parser::end ( ) const [inline]

Returns a ConstIterator to the end of free arguments list.

size_t psynth::base::arg_parser::free_args ( ) const [inline]

Return the number of free arguments.

bool psynth::base::arg_parser::has_free_args ( ) const [inline]

Returns whether there are any free arguments.

void psynth::base::arg_parser::parse ( int  argc,
const char *  argv[] 
)

Parse the command line arguments using the defined options.

Any arguments that had no option associated are added to the free arguments list, which can be later iterated.

Parameters:
argcNumber of command line arguments.
argvArray of command line arguments.
Exceptions:
Aarg_parser_error if there was an option threw an exception, containing the problematic option in the what ().

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