Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

commandl::matcher Class Reference

The class from which all matchers descend. More...

#include <matcher.hpp>

Inheritance diagram for commandl::matcher:

commandl::char_matcher commandl::whole_matcher List of all members.

Public Methods

 matcher ()
virtual ~matcher ()=0
virtual argumentmatch (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...


Detailed Description

The class from which all matchers descend.

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.


Constructor & Destructor Documentation

commandl::matcher::matcher  
 

commandl::matcher::~matcher   [pure virtual]
 


Member Function Documentation

virtual matcher* commandl::matcher::clone   const [pure virtual]
 

Implemented in commandl::char_matcher, and commandl::whole_matcher.

std::map< std::string, commandl::argument * > commandl::matcher::keys   const [inline, virtual]
 

This method returns a copy of the map of unique keys to arguments.

Returns:
A map of keys to argument*.

virtual argument* commandl::matcher::match const std::string &    const [pure virtual]
 

Implemented in commandl::char_matcher, and commandl::whole_matcher.

virtual std::map<std::string, argument*> commandl::matcher::resolve_keys const std::vector< argument * > &    [pure virtual]
 

Implemented in commandl::char_matcher, and commandl::whole_matcher.

void commandl::matcher::set_arguments const std::vector< argument * > &    arguments [virtual]
 

This method allows you to give the matcher a new set of arguments to resolve keys and match against.

Parameters:
A  vector of argument*

virtual std::string commandl::matcher::usage_key const std::string &    const [pure virtual]
 

Implemented in commandl::char_matcher, and commandl::whole_matcher.

virtual std::vector<std::string> commandl::matcher::usage_keys const std::vector< std::string > &    const [pure virtual]
 

Implemented in commandl::char_matcher, and commandl::whole_matcher.


Member Data Documentation

std::map<std::string, argument*> commandl::matcher::Keys [protected]
 

The map of unique keys to arguments.


The documentation for this class was generated from the following files:
Generated on Sat Apr 5 21:17:28 2003 for commandl Library by doxygen1.2.15