|
| | Args (ErrorHandler *errh=0) |
| | Construct an argument parser.
|
| |
| | Args (const Vector< String > &conf, ErrorHandler *errh=0) |
| | Construct an argument parser parsing a copy of conf.
|
| |
| | Args (const Element *context, ErrorHandler *errh=0) |
| | Construct an argument parser.
|
| |
| | Args (const Vector< String > &conf, const Element *context, ErrorHandler *errh=0) |
| | Construct an argument parser parsing a copy of conf.
|
| |
| | Args (const Args &x) |
| | Copy construct an argument parser.
|
| |
| Args & | operator= (const Args &x) |
| | Assign to a copy of x.
|
| |
| bool | empty () const |
| | Return true iff this parser has no arguments or results.
|
| |
| bool | results_empty () const |
| | Return true iff this parser has no results.
|
| |
| Args & | clear () |
| | Remove all arguments.
|
| |
| Args & | bind (Vector< String > &conf) |
| | Bind this parser's arguments to conf.
|
| |
| Args & | push_back (const String &arg) |
| | Append argument arg to this parser.
|
| |
| template<typename Iter > |
| Args & | push_back (Iter begin, Iter end) |
| | Append arguments in the range [begin, end) to this parser.
|
| |
| Args & | push_back_words (const String &str) |
| | Append the space-separated words in str to this parser.
|
| |
| Args & | push_back_args (const String &str) |
| | Append the comma-separated arguments in str to this parser.
|
| |
| Args & | reset () |
| | Reset the parse status for every argument.
|
| |
| template<typename T > |
| Args & | read (const char *keyword, T &x) |
| | Read an argument using its type's default parser.
|
| |
|
template<typename T > |
| Args & | read_m (const char *keyword, T &x) |
| |
|
template<typename T > |
| Args & | read_p (const char *keyword, T &x) |
| |
|
template<typename T > |
| Args & | read_mp (const char *keyword, T &x) |
| |
|
template<typename T > |
| Args & | read (const char *keyword, int flags, T &x) |
| |
| template<typename T , typename V > |
| Args & | read_or_set (const char *keyword, T &x, const V &default_value) |
| | Read an argument using the default parser, or set it to a default value if the argument is was not supplied.
|
| |
|
template<typename T , typename V > |
| Args & | read_or_set_p (const char *keyword, T &x, const V &default_value) |
| |
|
template<typename T , typename V > |
| Args & | read_or_set (const char *keyword, int flags, T &x, const V &default_value) |
| |
| Args & | validate (const char *keyword, bool present=false) |
| |
|
template<typename T > |
| Args & | validate (const char *keyword, T &x, const char *static_value) |
| |
|
template<typename T , typename V > |
| Args & | validate (const char *keyword, T &x, const V &static_value) |
| |
|
template<typename T , typename V > |
| Args & | validate_f (const char *keyword, T &x, int flags, const V &static_value) |
| |
|
template<typename T , typename V > |
| Args & | validate_p (const char *keyword, T &x, const V &static_value) |
| |
|
template<typename T , typename V > |
| Args & | validate_mp (const char *keyword, T &x, const V &static_value) |
| |
|
template<typename T > |
| Args & | validate_p (const char *keyword, T &x, const char *static_value) |
| |
|
template<typename T > |
| Args & | validate_mp (const char *keyword, T &x, const char *static_value) |
| |
| template<typename P , typename T > |
| Args & | read (const char *keyword, P parser, T &x) |
| | Read an argument using a specified parser.
|
| |
|
template<typename P , typename T > |
| Args & | read_m (const char *keyword, P parser, T &x) |
| |
|
template<typename P , typename T > |
| Args & | read_p (const char *keyword, P parser, T &x) |
| |
|
template<typename P , typename T > |
| Args & | read_mp (const char *keyword, P parser, T &x) |
| |
|
template<typename P , typename T > |
| Args & | read (const char *keyword, int flags, P parser, T &x) |
| |
| template<typename P , typename T , typename V > |
| Args & | read_or_set (const char *keyword, P parser, T &x, const V &default_value) |
| | Read an argument using a specified parser, or set it to a default value if the argument is was not supplied.
|
| |
|
template<typename P , typename T , typename V > |
| Args & | read_or_set_p (const char *keyword, P parser, T &x, const V &default_value) |
| |
|
template<typename P , typename T , typename V > |
| Args & | read_or_set (const char *keyword, int flags, P parser, T &x, const V &default_value) |
| |
| template<typename P , typename T1 , typename T2 > |
| Args & | read (const char *keyword, P parser, T1 &x1, T2 &x2) |
| | Read an argument using a specified parser with two results.
|
| |
|
template<typename P , typename T1 , typename T2 > |
| Args & | read_m (const char *keyword, P parser, T1 &x1, T2 &x2) |
| |
|
template<typename P , typename T1 , typename T2 > |
| Args & | read_p (const char *keyword, P parser, T1 &x1, T2 &x2) |
| |
|
template<typename P , typename T1 , typename T2 > |
| Args & | read_mp (const char *keyword, P parser, T1 &x1, T2 &x2) |
| |
|
template<typename P , typename T1 , typename T2 > |
| Args & | read (const char *keyword, int flags, P parser, T1 &x1, T2 &x2) |
| |
| template<typename P > |
| Args & | read_with (const char *keyword, P parser) |
| | Pass an argument to a specified parser.
|
| |
|
template<typename P > |
| Args & | read_m_with (const char *keyword, P parser) |
| |
|
template<typename P > |
| Args & | read_p_with (const char *keyword, P parser) |
| |
|
template<typename P > |
| Args & | read_mp_with (const char *keyword, P parser) |
| |
|
template<typename P > |
| Args & | read_with (const char *keyword, int flags, P parser) |
| |
| template<typename P , typename T > |
| Args & | read_with (const char *keyword, P parser, T &x) |
| | Pass an argument to a specified parser.
|
| |
|
template<typename P , typename T > |
| Args & | read_m_with (const char *keyword, P parser, T &x) |
| |
|
template<typename P , typename T > |
| Args & | read_p_with (const char *keyword, P parser, T &x) |
| |
|
template<typename P , typename T > |
| Args & | read_mp_with (const char *keyword, P parser, T &x) |
| |
|
template<typename P , typename T > |
| Args & | read_with (const char *keyword, int flags, P parser, T &x) |
| |
| template<typename P > |
| Args & | read_all_with (const char *keyword, P parser) |
| | Pass all matching arguments to a specified parser.
|
| |
|
template<typename P > |
| Args & | read_all_with (const char *keyword, int flags, P parser) |
| |
| template<typename P , typename T > |
| Args & | read_all_with (const char *keyword, P parser, T &x) |
| | Pass all matching arguments to a specified parser.
|
| |
|
template<typename P , typename T > |
| Args & | read_all_with (const char *keyword, int flags, P parser, T &x) |
| |
| template<typename P , typename T > |
| Args & | read_all (const char *keyword, P parser, Vector< T > &x) |
| | Pass all matching arguments to a specified parser.
|
| |
|
template<typename T > |
| Args & | read_all (const char *keyword, Vector< T > &x) |
| |
|
template<typename P , typename T > |
| Args & | read_all (const char *keyword, int flags, P parser, Vector< T > &x) |
| |
|
template<typename P , typename T > |
| Args & | read_all (const char *keyword, int flags, Vector< T > &x) |
| |
| bool | status () const |
| | Return the current parse status.
|
| |
| Args & | status (bool &x) |
| | Set x to the current parse status.
|
| |
| const Args & | status (bool &x) const |
| |
| bool | read_status () const |
| | Return true iff the last read request succeeded.
|
| |
| Args & | read_status (bool &x) |
| | Set x to the success status of the last read request.
|
| |
| const Args & | read_status (bool &x) const |
| |
| Args & | strip () |
| | Remove all arguments matched so far.
|
| |
| int | execute () |
| | Assign results.
|
| |
| int | consume () |
| | Assign results and remove matched arguments.
|
| |
| int | complete () |
| | Assign results if all arguments matched.
|
| |
| template<typename T > |
| T * | slot (T &x) |
| | Create and return a result slot for x.
|
| |
| template<typename T > |
| T * | initialized_slot (T &x) |
| | Create and return a result slot for x.
|
| |
| template<typename T , typename V > |
| Args & | set (T &x, const V &value) |
| | Add a result that assigns x to value.
|
| |
| | ArgContext (ErrorHandler *errh=0) |
| | Construct an argument context.
|
| |
| | ArgContext (const Element *context, ErrorHandler *errh=0) |
| | Construct an argument context.
|
| |
| const Element * | context () const |
| | Return the element context.
|
| |
| ErrorHandler * | errh () const |
| | Return the associated error handler.
|
| |
| String | error_prefix () const |
| | Return a prefix string associated with the current argument.
|
| |
| void | error (const char *fmt,...) const |
| | Report a parse error for the current argument.
|
| |
| void | warning (const char *fmt,...) const |
| | Report a parse warning for the current argument.
|
| |
| void | message (const char *fmt,...) const |
| | Report a message for the current argument.
|
| |
|
void | xmessage (const String &anno, const String &str) const |
| |
|
void | xmessage (const String &anno, const char *fmt, va_list val) const |
| |
Argument parser class.
never
Args parses Click configuration strings in a type-safe manner.
Args manages arguments and result slots. Arguments are strings to be parsed and result slots are parsed values.
The read() functions parse arguments into result slots.
int a_result;
args.
read(
"A", a_result);
Argument parser class.
Definition args.hh:249
Args & read(const char *keyword, T &x)
Read an argument using its type's default parser.
Definition args.hh:371
Args & push_back(const String &arg)
Append argument arg to this parser.
Definition args.cc:184
As arguments are parsed, Args marks them off and adds new result slots. Each result slot is paired with a variable belonging to the caller. However, the caller's variables aren't modified until the parse executes via complete(), consume(), or execute().
int a_result = 0;
args.
read(
"A", a_result);
assert(a_result == 0);
assert(a_result == 1);
int execute()
Assign results.
Definition args.cc:480
If Args encounters a parse error, then execution doesn't modify any of the caller's variables.
int a_result = 0, b_result = 0;
assert(a_result == 0 && b_result == 0);
Each read() function comes in five variants. read() reads an optional keyword argument. read_m() reads a mandatory keyword argument: if the argument was not supplied, Args will report a parse error. read_p() reads an optional positional argument. If the keyword was not supplied, but a positional argument was, that is used. read_mp() reads a mandatory positional argument. Positional arguments are parsed in order. The fifth variant of read() takes an integer flags argument; flags include Args::positional, Args::mandatory, and others, such as Args::deprecated.
The complete() execution method checks that every argument has been successfully parsed and reports an error if not. consume() doesn't check for completion, but removes parsed arguments from the argument set. Execution methods return 0 on success and <0 on failure. You can check the parse status before execution using status().
Args methods are designed to chain. All read() methods (and some others) return a reference to the Args itself. It is often possible to parse a whole set of arguments using a single temporary Args. For example:
int a, b;
click_chatter("Success! a=%d, b=%d", a, b);
int complete()
Assign results if all arguments matched.
Definition args.cc:510
Vector template.
Definition vector.hh:111
void push_back(value_argument_type v)
Append element v.
Definition vector.hh:399
The actual work of parsing is handled by parser objects. Many common variable types have default parsers defined by the DefaultArg<T> template. For example, the default parser for an integer value understands the common textual representations of integers. You can also pass a parser explicitly. For example:
int a, b, c;
Parser class for integers.
Definition args.hh:1130
Args generally calls a parser object's parse() method with three arguments:
-
const String &str: The string to be parsed.
-
T &result: A reference to the result. The parsed value, if any, should be stored here. (This points to storage local to Args, not to the caller's variable.)
-
Args &args: A reference to the calling Args object, for error reporting.
The parse() method should return true if the parse succeeds and false if it fails. Type-specific error messages should be reported using methods like args.error(). For generic errors, the parse() method can simply return false; Args will generate a "KEYWORD: parse error" message.
Most parsers are disciplined, meaning that they modify result only if the parse succeeds. This doesn't matter in the context of Args, but can matter to users who call a parse function directly.