#include <parser.hpp>
Public Methods | |
parser (const std::vector< argument * > &, const matcher &, const policy &) | |
This is one of the many constructors for parser. More... | |
parser (const std::vector< argument * > &, const matcher &) | |
This constructor uses a default policy object. More... | |
parser (const std::vector< argument * > &) | |
This constructor uses both a default policy object and a default matcher object. More... | |
parser (const parser &) | |
This constructor is a copy constructor allowing a new parser object to be created from an existing parser object. More... | |
virtual | ~parser () |
This destructor takes care of cleaning things up. More... | |
virtual std::string | name () const |
Returns the Name for this parser. More... | |
virtual unsigned long | stop_position () const |
Returns the Position where the parser stopped. More... | |
virtual std::map< unsigned long, std::string > | elements_without_prefixes () const |
Returns the elements without valid prefixes. More... | |
virtual std::map< unsigned long, std::string > | elements_without_keys () const |
Returns the elements without matching keys. More... | |
virtual std::map< unsigned long, std::string > | elements_after_stop () const |
Returns the elements after the Stop_Position. More... | |
virtual std::ostream & | usage (std::ostream &=std::cout) const |
Returns a complete usage statement based on the parser's Arguments. More... | |
virtual std::ostream & | usage (argument *, std::ostream &=std::cout) const |
Returns a usage statement for the given argument_ptr. More... | |
virtual std::ostream & | short_usage (std::ostream &=std::cout) const |
Returns a short usage statement based on the parser's Arguments. More... | |
virtual std::ostream & | short_usage (argument *, std::ostream &=std::cout) const |
Returns a short usage statement for the given argument_ptr. More... | |
virtual void | set_name (const std::string &) |
This simply sets a string that the parser will use as the name of this program in usage statements. More... | |
virtual void | exceptions (bool=true) |
Determines whether this parser will throw exceptions or not. More... | |
virtual bool | parse (int, char **, std::ostream &=std::cout) |
This is the main argument parsing method for this class. More... | |
virtual bool | parse (std::vector< std::string >, std::ostream &=std::cout) |
This is the method that will parse the passed container. More... | |
virtual parser & | operator= (const parser &) |
Protected Methods | |
virtual std::pair< std::string, std::string > | separate_prefix_from (std::string) |
Identifies a prefix in the passed string and returns a pair. More... | |
virtual std::pair< std::string::size_type, std::string > | find_assignment_in (std::string) |
Identifies an assignment operator in a string. More... | |
virtual void | identify_prefix_and_key (std::string) |
This method determines if there is a prefix and key in a string. More... | |
virtual void | parse_required_values (std::string, std::string, std::string, std::string, commandl::argument *, std::vector< std::string >::iterator &, std::vector< std::string >::iterator) |
If the argument requires values, this method parses it. More... | |
virtual void | parse_optional_values (std::string, std::string, std::string, std::string, commandl::argument *, std::vector< std::string >::iterator &, std::vector< std::string >::iterator) |
If the argument has optional values, this method parses it. More... | |
virtual void | parse_character_keys (std::string, std::string, std::vector< std::string >::iterator &, std::vector< std::string >::iterator, bool=false) |
This method will recursively break up a token to try and find keys amongst the leading characters. More... | |
Protected Attributes | |
std::vector< argument * > | Arguments |
This is the vector of argument* that parser will parse for. More... | |
matcher * | Matcher_ptr |
This is the matcher* that parser will use to match arguments. More... | |
policy | Policy |
This is the policy object that parser will use. More... | |
bool | Throws_Exceptions |
This determines whether parser throws commandl exceptions or not. More... | |
std::string | Name |
unsigned long int | Position |
This is a counter for how far along the parser is. More... | |
unsigned long int | Stop_Position |
This is the position at which the parser stopped parsing. More... | |
std::vector< std::string > | Elements |
This is the vector of Elements that parser is currently parsing. More... | |
std::map< unsigned long, std::string > | Elements_without_prefixes |
std::map< unsigned long, std::string > | Elements_without_keys |
std::map< unsigned long, std::string > | Elements_after_stop |
The parser is the heavy workhorse of the commandl library. Once you have set up all the other kinds of objects, it is the parser that uses them all to do the work. It is highly flexible (because of the other classes that it depends on), and configurable. It can be configured to either throw exceptions or not. My guess is that the commandl::parser class will probably be the least subclassed, but I could very well be wrong.
|
This is one of the many constructors for parser.
|
|
This constructor uses a default policy object.
|
|
This constructor uses both a default policy object and a default matcher object.
|
|
This constructor is a copy constructor allowing a new parser object to be created from an existing parser object.
|
|
This destructor takes care of cleaning things up.
|
|
Returns the elements after the Stop_Position.
If parsing is stopped before all of the elements are parsed, then the remaining elements can be retrieved via this method. The map contains their Positions and the elements themselves.
|
|
Returns the elements without matching keys.
If the parser's Policy allows it, when elements that do not match a key are found, they are placed in this map, indexed by their Position.
|
|
Returns the elements without valid prefixes.
If the parser's Policy allows it, when elements that do not have a valid prefix are found, they are placed in this map, indexed by their Position.
|
|
Determines whether this parser will throw exceptions or not.
The default behavior is for the parser to not throw any exceptions when parse() is called. If there is a failure within that operation, the parse() method will simply return false. However, if you'd like to get more information, you can always set this on, and get the exceptions out of the parse() method that may allow you more refined control.
|
|
Identifies an assignment operator in a string.
This method searches for a valid assignment operator within the string. If it identifies one it returns the position of that assignment operator and string that is the operator that was found. If it doesn't find one, it still returns a pair where the location is string::npos, and the opertor is the empty string.
|
|
This method determines if there is a prefix and key in a string.
This method either returns quietly, or throws if it cannot identify a valid prefix and a valid key within the given string.
|
|
Returns the Name for this parser.
|
|
|
|
This is the method that will parse the passed container.
This method does the work of parsing the elements based on this object's matcher and policy. This library will not terminate your program, that's your job. As such, it is highly recommended that you check the return value of this method (or turn on exceptions and catch them via the exceptions() method), and do something appropriate (maybe calling the usage() statement and exiting) if the value is false.
|
|
This is the main argument parsing method for this class.
This library will not terminate your program, that's your job. As such, it is highly recommended that you check the return value of this method (or turn on exceptions and catch them via the exceptions() method), and do something appropriate (maybe calling the usage() statement and exiting) if the value is false. This class does little more than convert the char** into a proper STL container and pass it to a different version of parse.
|
|
This method will recursively break up a token to try and find keys amongst the leading characters.
For example, this method would could take the token "fbar" and depending on the Policy would interpret in in different ways:
|
|
If the argument has optional values, this method parses it.
|
|
If the argument requires values, this method parses it.
|
|
Identifies a prefix in the passed string and returns a pair.
The returned pair's first element is the prefix, and the second element is the non-prefix part of the passed in string. If this method cannot find a prefix, it will throw.
|
|
This simply sets a string that the parser will use as the name of this program in usage statements.
This value doesn't affect the parsing at all.
|
|
Returns a short usage statement for the given argument_ptr.
This method places a short usage statement about the given argument. This method is written such that it can easily be used in a standard ostream inserter sequence, if desired.
|
|
Returns a short usage statement based on the parser's Arguments.
This method places a short, one-line, usage statement on the given ostream. It consists of the information for all of the Arguments that this parser knows about. This method is written such that it can easily be used in a standard ostream inserter sequence, if desired.
|
|
Returns the Position where the parser stopped.
For most cases, this will be the last Position. However, if the parser came across a stop_arg, then parsing would have terminated sooner.
|
|
Returns a usage statement for the given argument_ptr.
This method places a full usage statement about the given argument. This method is written such that it can easily be used in a standard ostream inserter sequence, if desired.
|
|
Returns a complete usage statement based on the parser's Arguments.
This method places a full usage statement on the given ostream. It consists of the information for all of the Arguments that this parser knows about. This method is written such that it can easily be used in a standard ostream inserter sequence, if desired.
|
|
This is the vector of argument* that parser will parse for.
|
|
This is the vector of Elements that parser is currently parsing.
|
|
If there were any elements after the parser was told to stop parsing they will be in this map. They are stored as the position of the element, and the element itself. |
|
If the Policy allows for it, this map contains the parsed elements that did not have matching keys. They are stored as the position of an element without a matching key, and the element itself. |
|
If the Policy allows for it, this map contains the parsed elements that did not have valid prefixes. They are stored as the position of an element without a valid prefix, and the element itself. |
|
This is the matcher* that parser will use to match arguments.
|
|
Optional name of the program, can be set in parser for nice usage statements. |
|
This is the policy object that parser will use.
|
|
This is a counter for how far along the parser is.
|
|
This is the position at which the parser stopped parsing.
|
|
This determines whether parser throws commandl exceptions or not.
|