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

commandl::policy Class Reference

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

#include <policy.hpp>

Inheritance diagram for commandl::policy:

commandl::traditional_policy List of all members.

Public Methods

 policy (std::vector< std::string >, std::vector< std::string >, std::bitset< 8 >, std::pair< std::string, std::string >=std::make_pair(std::string("["), std::string("]")), std::pair< std::string, std::string >=std::make_pair(std::string("<"), std::string(">")))
 policy ()
virtual std::vector< std::string > prefixes () const
 Returns the vector of prefixes allowed for this policy. More...

virtual std::vector< std::string > assignments () const
 Returns the vector of assignments allowed for this policy. More...

virtual std::pair< std::string,
std::string > 
optional_brackets () const
 Returns the pair of strings that are intended to enclose optional elements in a usage statement. More...

virtual std::pair< std::string,
std::string > 
value_brackets () const
 Returns the pair of strings that are intended to enclose value elements in a usage statement. More...

virtual bool is_empty_valid_prefix () const
 Is the empty string a valid prefix? More...

virtual bool is_empty_valid_assignment () const
 Is the empty string a valid assignment? More...

virtual bool is_token_separator_assignment () const
 Is the token separator a valid assignment? More...

virtual bool no_prefix_keep_going () const
 No prefix has been found on the element, should parsing continue? More...

virtual bool no_prefix_keep_element () const
 No prefix has been found on the element, should element be kept? More...

virtual bool no_key_keep_going () const
 No key has been found in the element, should parsing continue? More...

virtual bool no_key_keep_element () const
 No key has been found in the element, should element be kept? More...

virtual bool ignore_prefix_if_value_required () const
 If a value is required, should the next element be taken? More...

virtual void add_prefix (const std::string &)
 Adds a string to the end of this policy's list of valid prefixes. More...

virtual void add_assignment (const std::string &)
 Adds a string to the end of this policy's list of valid assignments. More...

virtual void set_optional_brackets (const std::pair< std::string, std::string > &)
 Sets the pair used to enclose optional elements. More...

virtual void set_value_brackets (const std::pair< std::string, std::string > &)
 Sets the pair used to enclose value elements. More...

virtual void is_empty_valid_prefix (bool)
 Sets whether the empty string is a valid prefix. More...

virtual void is_empty_valid_assignment (bool)
 Sets whether the empty string is a valid assignment. More...

virtual void is_token_separator_assignment (bool)
 Sets whether the boundary between elements is a valid assignment. More...

virtual void no_prefix_keep_going (bool)
 Sets whether to keep going or stop if no prefix is found. More...

virtual void no_prefix_keep_element (bool)
 Sets whether an element with no prefix should be kept. More...

virtual void no_key_keep_going (bool)
 Sets whether to keep going or stop if no key is found. More...

virtual void no_key_keep_element (bool)
 Sets whether an element with no key should be kept. More...

virtual void ignore_prefix_if_value_required (bool)
 Sets whether elements with a valid prefix should be consumed by preceding arguments with required values. More...


Protected Attributes

std::vector< std::string > Prefixes
std::vector< std::string > Assignments
std::pair< std::string, std::string > Optional_Brackets
 The strings that will bracket option elements in usage statements. More...

std::pair< std::string, std::string > Value_Brackets
 The strings that will bracket value elements in usages statements. More...

bool Empty_Is_Prefix
 Is the empty string a valid prefix? More...

bool Empty_Is_Assignment
 Is the empty string a valid assignment? More...

bool Separator_Is_Assignment
 Is the boundary between tokens a valid assignment? More...

bool No_Prefix_Keep_Going
 Should the parser keep going if there is an element with no prefix? More...

bool No_Prefix_Keep_Element
 If there is an element with no prefix, should it be kept? More...

bool No_Key_Keep_Going
 Should the parser keep going if there is an element with no valid key? More...

bool No_Key_Keep_Element
 If there is an element with no key, should it be kept? More...

bool Ignore_Prefix

Detailed Description

The class from which all policies descend.

Policy objects are pretty much just data storage objects. They contain a number of boolean values and other basic information like what the acceptable prefix tokens are (or if no prefix token is required), what the assignment operators are (or if no assignment operator is needed), and things like whether the parser should keep going if a token doesn't match and if it should keep track of those things which don't match. Handy, but simple was the idea here.


Constructor & Destructor Documentation

commandl::policy::policy std::vector< std::string >   ,
std::vector< std::string >   ,
std::bitset< 8 >   ,
std::pair< std::string, std::string >    = std::make_pair(std::string("["), std::string("]")),
std::pair< std::string, std::string >    = std::make_pair(std::string("<"), std::string(">"))
 

commandl::policy::policy  
 


Member Function Documentation

void commandl::policy::add_assignment const std::string &    new_assignment [virtual]
 

Adds a string to the end of this policy's list of valid assignments.

Parameters:
A  string which will be added as a valid assignment operator.

void commandl::policy::add_prefix const std::string &    new_prefix [virtual]
 

Adds a string to the end of this policy's list of valid prefixes.

Parameters:
A  string which will be added as a valid prefix.

std::vector< std::string > commandl::policy::assignments   const [virtual]
 

Returns the vector of assignments allowed for this policy.

The returned vector contains all of the strings which are valid assignments for this policy.

Returns:
A vector of strings.

void commandl::policy::ignore_prefix_if_value_required bool    ignore_prefix [virtual]
 

Sets whether elements with a valid prefix should be consumed by preceding arguments with required values.

Parameters:
A  Boolean.

bool commandl::policy::ignore_prefix_if_value_required   const [virtual]
 

If a value is required, should the next element be taken?

When the parser has matched a key with an argument, and the argument requires a value, but the next element that could be considered as a value begins with a valid prefix, what should be done? If this returns true, then that next element is taken as a value (even though it starts with a prefix). If this returns false, then the required value for the argument is not given (most likely causing an exception), but the element with a prefix remains in the list of un-parsed elements.

Returns:
A boolean.

void commandl::policy::is_empty_valid_assignment bool    is_valid [virtual]
 

Sets whether the empty string is a valid assignment.

Parameters:
A  Boolean.

bool commandl::policy::is_empty_valid_assignment   const [virtual]
 

Is the empty string a valid assignment?

This is most commonly true when you want the key and the value in the same element without having to specify an explicit assignment character. For example, if the element is "-afoo", and the key is "a", and you would like "foo" to be recognized as the value, then this should be true.

Returns:
A boolean.

void commandl::policy::is_empty_valid_prefix bool    is_valid [virtual]
 

Sets whether the empty string is a valid prefix.

Parameters:
A  Boolean.

bool commandl::policy::is_empty_valid_prefix   const [virtual]
 

Is the empty string a valid prefix?

Usually this is no, but sometimes you'd like to eliminate the need for a special prefix character when parsing elements based purely on position.

Returns:
A boolean.

void commandl::policy::is_token_separator_assignment bool    sep_is_assign [virtual]
 

Sets whether the boundary between elements is a valid assignment.

Parameters:
A  Boolean.

bool commandl::policy::is_token_separator_assignment   const [virtual]
 

Is the token separator a valid assignment?

Instead of explicitly naming an assignment character like "=" in the following "-a=foo", you'd like to just say "-a foo", where "-a" would be one element and "foo" would be the next. In this case you would want the token separator to be considered an assignment, so the the separation between "-a" and "foo" would be considered an assignment assigning the value "foo" to the key "a".

Returns:
A boolean.

void commandl::policy::no_key_keep_element bool    keep_element [virtual]
 

Sets whether an element with no key should be kept.

Parameters:
A  Boolean.

bool commandl::policy::no_key_keep_element   const [virtual]
 

No key has been found in the element, should element be kept?

When the parser has found a matching prefix, but no matching key, and no_key_keep_going() returns true, should the element be kept by the parser or ignored?

Returns:
A boolean.

void commandl::policy::no_key_keep_going bool    keep_going [virtual]
 

Sets whether to keep going or stop if no key is found.

Parameters:
A  Boolean.

bool commandl::policy::no_key_keep_going   const [virtual]
 

No key has been found in the element, should parsing continue?

When the parser has found a matching prefix, but no matching key, what should it do? This return value tells it to keep going, or stop.

Returns:
A boolean.

void commandl::policy::no_prefix_keep_element bool    keep_element [virtual]
 

Sets whether an element with no prefix should be kept.

Parameters:
A  Boolean.

bool commandl::policy::no_prefix_keep_element   const [virtual]
 

No prefix has been found on the element, should element be kept?

When the parser has found no matching prefixes that match the beginning of this element (including the empty string if valid), and no_prefix_keep_going() returns true, should the element be kept by the parser or ignored?

Returns:
A boolean.

void commandl::policy::no_prefix_keep_going bool    keep_going [virtual]
 

Sets whether to keep going or stop if no prefix is found.

Parameters:
A  Boolean.

bool commandl::policy::no_prefix_keep_going   const [virtual]
 

No prefix has been found on the element, should parsing continue?

When the parser has found no matching prefixes that match the beginning of this element (including the empty string if valid), what should it do? This return value tells it to keep going, or stop.

Returns:
A boolean.

std::pair< std::string, std::string > commandl::policy::optional_brackets   const [virtual]
 

Returns the pair of strings that are intended to enclose optional elements in a usage statement.

Returns:
A pair of strings.

std::vector< std::string > commandl::policy::prefixes   const [virtual]
 

Returns the vector of prefixes allowed for this policy.

The returned vector contains all of the strings which are valid prefixes for this policy.

Returns:
A vector of strings.

void commandl::policy::set_optional_brackets const std::pair< std::string, std::string > &    brackets [virtual]
 

Sets the pair used to enclose optional elements.

This doesn't really affect the parsing behavior at all, it's mostly to make usage statements look the way you want them to.

Parameters:
A  pair of strings that will be used to enclose optional elements.

void commandl::policy::set_value_brackets const std::pair< std::string, std::string > &    brackets [virtual]
 

Sets the pair used to enclose value elements.

This doesn't really affect the parsing behavior at all, it's mostly to make usage statements look the way you want them to.

Parameters:
A  pair of strings that will be used to enclose value elements.

std::pair< std::string, std::string > commandl::policy::value_brackets   const [virtual]
 

Returns the pair of strings that are intended to enclose value elements in a usage statement.

Returns:
A pair or strings.


Member Data Documentation

std::vector<std::string> commandl::policy::Assignments [protected]
 

This vector contains all of the strings that are valid assignments for this policy. Again, order is important, see Prefixes.

bool commandl::policy::Empty_Is_Assignment [protected]
 

Is the empty string a valid assignment?

bool commandl::policy::Empty_Is_Prefix [protected]
 

Is the empty string a valid prefix?

bool commandl::policy::Ignore_Prefix [protected]
 

In the case of arguments with required values, if the next element has a valid prefix, should it be taken as a value anyway?

bool commandl::policy::No_Key_Keep_Element [protected]
 

If there is an element with no key, should it be kept?

bool commandl::policy::No_Key_Keep_Going [protected]
 

Should the parser keep going if there is an element with no valid key?

bool commandl::policy::No_Prefix_Keep_Element [protected]
 

If there is an element with no prefix, should it be kept?

bool commandl::policy::No_Prefix_Keep_Going [protected]
 

Should the parser keep going if there is an element with no prefix?

std::pair<std::string, std::string> commandl::policy::Optional_Brackets [protected]
 

The strings that will bracket option elements in usage statements.

std::vector<std::string> commandl::policy::Prefixes [protected]
 

This vector contains all of the strings that are valid prefixes for this policy. Order is important, if you wanted both "--" and "-" to be valid prefixes for this policy, then "--" should be closer to the front of the vector of prefixes than just "-". If a potential key was foo, and the command line to parse had "--foo" in it, if "-" were before "--", then the parser would match the first "-" and use "-foo" as the key to pass to the matcher. Probably not the behavior that you want.

bool commandl::policy::Separator_Is_Assignment [protected]
 

Is the boundary between tokens a valid assignment?

std::pair<std::string, std::string> commandl::policy::Value_Brackets [protected]
 

The strings that will bracket value elements in usages statements.


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