3
// Copyright 2002 Daniel Burrows
5
// Mad? They said I was mad. But I didn't listen. I didn't have to...
7
// Behold...the living horror of the object-oriented command-line parser!
9
#ifndef CMDLINE_PARSE_H
10
#define CMDLINE_PARSE_H
13
#include <std::string>
15
#include <sigc++/trackable.h>
17
// I'll parse arguments My Way, thank you.
19
// This provides a callback to parse the head of an input option stream.
22
// (a) Consume some number of arguments and return true (if there are
23
// appropriate arguments), or
25
class arg_parser:public sigc::trackable
28
virtual bool parse_arg(int argc, char *argv[], int &loc)=0;
31
// Caller is responsible for deleting the arg_parsers
32
bool parse_cmdline(std::vector<arg_parser *> parsers, int argc, char *argv[]);
34
// Factories for interesting basic arg_parsers. These generally take either
35
// a slot to call or a value to set.
37
// The standard '-x', '--blah' option. (no value) If longopt is NULL, there
38
// is no long option; if shortopt is \0, same.
39
arg_parser *dashopt(char shortopt, char *longopt,
40
sigc::slot0<void> callback);
42
// Same, sets "flag" to true if the option is seen.
43
arg_parser *dashopt(char shortopt, char *longopt, bool &flag);
45
// The general callback-based version; the multiple forms allow
46
// implicit conversions.
47
arg_parser *dashopt_witharg(char shortopt, char *longopt,
48
sigc::slot1<void, std::string> callback);
49
arg_parser *dashopt_witharg(char shortopt, char *longopt,
51
arg_parser *dashopt_witharg(char shortopt, char *longopt,
54
// This one just accumulates its arguments in the given vector.
55
// Useful as a "default rule".
56
arg_parser *arg_accumulate();