class options_utils::optmap

A argument option handler, based on the Command pattern.

Public Methods

[more] optmap(const char* usage = "")
The very simple constructor for an optmap object.
[more]optmap& add(const char* o, cmd* h)
Adds an option that invokes the command handler.
[more]optmap& alias(const char* new_opt, const char* old_opt)
Adds an alias for an option
[more]bool parse(int argc, const char** argv)
Parse the command line.
[more]int n()
Gets the index for the first non option argument
[more]void usage(bool abort = true)
display a usage string and abort()
[more]const char* get_arg()
get the argument of an option; mainly for cmd implementations

Public Members

[more]struct cmd
The base for all option handlers.


Documentation

A argument option handler, based on the Command pattern. Each option is associated with a handling command object.

The map keeps the reverse association as well, to allow printing of a using line.

ostruct cmd
The base for all option handlers.

To handle a new kind of commands, just derive a class from this an overload the methods to do the work.

ovirtual bool do_cmd(optmap* om) = 0
Performing the work associated with the option.

To obtain an argument see get_arg

Returns:
true if the parsing was succesfull

ovirtual std::string arg()
return the name of the argument needed by usage

o optmap(const char* usage = "")
The very simple constructor for an optmap object. Please note that copying of optmaps are not supported.
Parameters:
- usage The tail of the usage string to follow the options

ooptmap& add(const char* o, cmd* h)
Adds an option that invokes the command handler.

This is the low level work horse for all the add methods. All the other adds works by adding appropriate cmd objects for doing the work.

Parameters:
o - The option name. If the length of the option is 1 it will be an old fashion option, otherwise it will be a GNU stype long option (--long-opt).
h - The pointer to the handler. The optmap assumes ownership of the pointer and delete it in the destructor.
Returns:
*this

ooptmap& alias(const char* new_opt, const char* old_opt)
Adds an alias for an option

obool parse(int argc, const char** argv)
Parse the command line.
Returns:
true if the parse is valid, false otherwise.

oint n()
Gets the index for the first non option argument

ovoid usage(bool abort = true)
display a usage string and abort()

oconst char* get_arg()
get the argument of an option; mainly for cmd implementations


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.