#include <matcher.hpp>
Inheritance diagram for commandl::matcher:
Public Methods | |
matcher () | |
virtual | ~matcher ()=0 |
virtual argument * | match (const std::string &) const=0 |
virtual std::string | usage_key (const std::string &) const=0 |
virtual std::vector< std::string > | usage_keys (const std::vector< std::string > &) const=0 |
virtual std::map< std::string, argument * > | keys () const |
This method returns a copy of the map of unique keys to arguments. More... | |
virtual void | set_arguments (const std::vector< argument * > &) |
This method allows you to give the matcher a new set of arguments to resolve keys and match against. More... | |
virtual std::map< std::string, argument * > | resolve_keys (const std::vector< argument * > &)=0 |
virtual matcher * | clone () const=0 |
Protected Attributes | |
std::map< std::string, argument * > | Keys |
The map of unique keys to arguments. More... |
The concept of a separate matcher arose because I felt that an argument shouldn't really be concerned with that activity. And it also allows you to change whether your program would match on the first character of a key or the whole string of the key just by changing which matcher object you use, and not changing all of the argument objects. This also allows you to write your own matchers, which can be arbitrarily complex. An external matcher just separates and encapsulates the activity of determining whether a given string matches any of the keys of the various arguments that the matcher knows about.
A commandl::matcher object knows about and uses commandl::argument objects. Conversely, it is used by commandl::parser objects.
This class contains a number of pure virtual methods that must be overridden by derived classes.
It is suggested that derived matchers have a constructor that takes a vector of argument* and then calls the resolve_keys method on them.
The match method is the primary method of the matcher class, and when given a string the matcher determines whether there is an appropriate match, and either returns the corresponding argument* from its Keys or throws a matcher_exception if it cannot find a match.
The usage_key and usage_keys methods are intended to allow a user of the matcher to pass in a string (or a vector of same), and the matcher will return a string (or a vector of same) that the matcher would use as a key. It is mostly meant for the usage statement and other human-readable outputs.
The resolve_keys method returns a map of keys to arguments, and is the primary method that should be called upon construction of a new matcher. It sets up the keys and can throw a matcher_exception if it discovers a duplicate key according to its rules.
The clone method is intended to allow users of a matcher to easily create a copy of a pointer to a matcher object for polymorphism reasons.
|
|
|
|
|
Implemented in commandl::char_matcher, and commandl::whole_matcher. |
|
This method returns a copy of the map of unique keys to arguments.
|
|
Implemented in commandl::char_matcher, and commandl::whole_matcher. |
|
Implemented in commandl::char_matcher, and commandl::whole_matcher. |
|
This method allows you to give the matcher a new set of arguments to resolve keys and match against.
|
|
Implemented in commandl::char_matcher, and commandl::whole_matcher. |
|
Implemented in commandl::char_matcher, and commandl::whole_matcher. |
|
The map of unique keys to arguments.
|