Describes one possible command line/config file option. More...
#include <options_description.hpp>
Public Types | |
enum | match_result { no_match, full_match, approximate_match } |
Public Member Functions | |
option_description () | |
option_description (const char *name, const value_semantic *s) | |
Initializes the object with the passed data. More... | |
option_description (const char *name, const value_semantic *s, const char *description) | |
Initializes the class with the passed data. More... | |
virtual | ~option_description () |
match_result | match (const std::string &option, bool approx, bool long_ignore_case, bool short_ignore_case) const |
Given 'option', specified in the input source, returns 'true' if 'option' specifies *this. More... | |
const std::string & | key (const std::string &option) const |
Returns the key that should identify the option, in particular in the variables_map class. More... | |
std::string | canonical_display_name (int canonical_option_style=0) const |
Returns the canonical name for the option description to enable the user to recognised a matching option. More... | |
const std::string & | long_name () const |
const std::string & | description () const |
Explanation of this option. More... | |
shared_ptr< const value_semantic > | semantic () const |
Semantic of option's value. More... | |
std::string | format_name () const |
Returns the option name, formatted suitably for usage message. More... | |
std::string | format_parameter () const |
Returns the parameter name and properties, formatted suitably for usage message. More... | |
Describes one possible command line/config file option.
There are two kinds of properties of an option. First describe it syntactically and are used only to validate input. Second affect interpretation of the option, for example default value for it or function that should be called when the value is finally known. Routines which perform parsing never use second kind of properties – they are side effect free.
boost::program_options::option_description::option_description | ( | ) |
boost::program_options::option_description::option_description | ( | const char * | name, |
const value_semantic * | s | ||
) |
Initializes the object with the passed data.
Note: it would be nice to make the second parameter auto_ptr, to explicitly pass ownership. Unfortunately, it's often needed to create objects of types derived from 'value_semantic': options_description d; d.add_options()("a", parameter<int>("n")->default_value(1)); Here, the static type returned by 'parameter' should be derived from value_semantic.
Alas, derived->base conversion for auto_ptr does not really work, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2000/n1232.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#84
So, we have to use plain old pointers. Besides, users are not expected to use the constructor directly.
The 'name' parameter is interpreted by the following rules:
boost::program_options::option_description::option_description | ( | const char * | name, |
const value_semantic * | s, | ||
const char * | description | ||
) |
Initializes the class with the passed data.
|
virtual |
std::string boost::program_options::option_description::canonical_display_name | ( | int | canonical_option_style = 0 | ) | const |
Returns the canonical name for the option description to enable the user to recognised a matching option.
1) For short options ('-', '/'), returns the short name prefixed. 2) For long options ('–' / '-') returns the long name prefixed 3) All other cases, returns the long name (if present) or the short name, unprefixed.
const std::string& boost::program_options::option_description::description | ( | ) | const |
Explanation of this option.
std::string boost::program_options::option_description::format_name | ( | ) | const |
Returns the option name, formatted suitably for usage message.
std::string boost::program_options::option_description::format_parameter | ( | ) | const |
Returns the parameter name and properties, formatted suitably for usage message.
const std::string& boost::program_options::option_description::key | ( | const std::string & | option | ) | const |
Returns the key that should identify the option, in particular in the variables_map class.
The 'option' parameter is the option spelling from the input source. If option name contains '*', returns 'option'. If long name was specified, it's the long name, otherwise it's a short name with prepended '-'.
const std::string& boost::program_options::option_description::long_name | ( | ) | const |
match_result boost::program_options::option_description::match | ( | const std::string & | option, |
bool | approx, | ||
bool | long_ignore_case, | ||
bool | short_ignore_case | ||
) | const |
Given 'option', specified in the input source, returns 'true' if 'option' specifies *this.
shared_ptr<const value_semantic> boost::program_options::option_description::semantic | ( | ) | const |
Semantic of option's value.