A (logically grouped) list of unique options. More...
#include <program_options.h>
Public Types | |
enum | FindType { find_name = 1, find_prefix = 2, find_name_or_prefix = find_name|find_prefix, find_alias = 4 } |
typedef OptionList::const_iterator | option_iterator |
Type for identifying an option within a context. | |
typedef PrefixRange | OptionRange |
Public Member Functions | |
OptionContext & | add (const OptionGroup &group) |
Adds the given group of options to this context. | |
OptionContext & | add (const OptionContext &other) |
Adds all groups (and their options) from other to this context. | |
OptionContext & | addAlias (const std::string &aliasName, option_iterator option) |
Adds an alias name for the given option. | |
bool | assignDefaults (const ParsedOptions &exclude) const |
Assigns any default values to all options not in exclude. | |
option_iterator | begin () const |
const std::string & | caption () const |
std::string | defaults (std::size_t prefixSize=0) const |
Returns the default command-line of this context. | |
OptionOutput & | description (OptionOutput &out) const |
Writes a formatted description of options in this context. | |
option_iterator | end () const |
option_iterator | find (const char *key, FindType t=find_name) const |
Returns the option with the given key. | |
const OptionGroup & | findGroup (const std::string &caption) const |
OptionRange | findImpl (const char *key, FindType t, unsigned eMask=unsigned(-1)) const |
OptionRange | findImpl (const char *key, FindType t, unsigned eMask, const std::string &eCtx) const |
DescriptionLevel | getActiveDescLevel () const |
std::size_t | groups () const |
Returns the number of groups in this context. | |
OptionContext (const std::string &caption="", DescriptionLevel desc_default=desc_level_default) | |
void | setActiveDescLevel (DescriptionLevel level) |
Sets the description level to be used when generating description. | |
std::size_t | size () const |
Returns the number of options in this context. | |
option_iterator | tryFind (const char *key, FindType t=find_name) const |
const OptionGroup * | tryFindGroup (const std::string &caption) const |
~OptionContext () | |
Private Types | |
typedef std::vector< OptionGroup > | GroupList |
typedef Name2Key::const_iterator | index_iterator |
typedef std::size_t | key_type |
typedef std::map< std::string, key_type > | Name2Key |
typedef OptionGroup::OptionList | OptionList |
typedef std::pair < index_iterator, index_iterator > | PrefixRange |
Private Member Functions | |
size_t | findGroupKey (const std::string &name) const |
void | insertOption (size_t groupId, const SharedOptPtr &o) |
Private Attributes | |
std::string | caption_ |
DescriptionLevel | descLevel_ |
GroupList | groups_ |
Name2Key | index_ |
OptionList | options_ |
Friends | |
std::ostream & | operator<< (std::ostream &os, const OptionContext &ctx) |
Writes a formatted description of options in this context to os. |
A (logically grouped) list of unique options.
An option context stores a list of option groups. Options in a context have to be unique (w.r.t name and alias) within that context.
An OptionContext defines the granularity of option parsing and option lookup.
Definition at line 167 of file program_options.h.
typedef std::vector<OptionGroup> ProgramOptions::OptionContext::GroupList [private] |
Definition at line 171 of file program_options.h.
typedef Name2Key::const_iterator ProgramOptions::OptionContext::index_iterator [private] |
Definition at line 172 of file program_options.h.
typedef std::size_t ProgramOptions::OptionContext::key_type [private] |
Definition at line 169 of file program_options.h.
typedef std::map<std::string, key_type> ProgramOptions::OptionContext::Name2Key [private] |
Definition at line 170 of file program_options.h.
typedef OptionList::const_iterator ProgramOptions::OptionContext::option_iterator |
Type for identifying an option within a context.
Definition at line 177 of file program_options.h.
typedef OptionGroup::OptionList ProgramOptions::OptionContext::OptionList [private] |
Definition at line 174 of file program_options.h.
Definition at line 178 of file program_options.h.
typedef std::pair<index_iterator, index_iterator> ProgramOptions::OptionContext::PrefixRange [private] |
Definition at line 173 of file program_options.h.
Definition at line 220 of file program_options.h.
ProgramOptions::OptionContext::OptionContext | ( | const std::string & | caption = "" , |
DescriptionLevel | desc_default = desc_level_default |
||
) |
Definition at line 306 of file program_options.cpp.
Definition at line 310 of file program_options.cpp.
OptionContext & ProgramOptions::OptionContext::add | ( | const OptionGroup & | group | ) |
Adds the given group of options to this context.
DuplicateOption | if an option in group has the same short or long name as one of the options in this context. |
Definition at line 325 of file program_options.cpp.
OptionContext & ProgramOptions::OptionContext::add | ( | const OptionContext & | other | ) |
Adds all groups (and their options) from other to this context.
DuplicateOption | if an option in other has the same short or long name as one of the options in this context. |
Definition at line 357 of file program_options.cpp.
OptionContext & ProgramOptions::OptionContext::addAlias | ( | const std::string & | aliasName, |
option_iterator | option | ||
) |
Adds an alias name for the given option.
DuplicateOption | if an option with the name aliasName already exists. |
Definition at line 339 of file program_options.cpp.
bool ProgramOptions::OptionContext::assignDefaults | ( | const ParsedOptions & | exclude | ) | const |
Assigns any default values to all options not in exclude.
ValueError | if some default value is actually invalid for its option. |
Definition at line 482 of file program_options.cpp.
option_iterator ProgramOptions::OptionContext::begin | ( | ) | const [inline] |
Definition at line 212 of file program_options.h.
const std::string & ProgramOptions::OptionContext::caption | ( | ) | const |
Definition at line 312 of file program_options.cpp.
std::string ProgramOptions::OptionContext::defaults | ( | std::size_t | prefixSize = 0 | ) | const |
Returns the default command-line of this context.
Definition at line 446 of file program_options.cpp.
OptionOutput & ProgramOptions::OptionContext::description | ( | OptionOutput & | out | ) | const |
Writes a formatted description of options in this context.
Definition at line 426 of file program_options.cpp.
option_iterator ProgramOptions::OptionContext::end | ( | ) | const [inline] |
Definition at line 213 of file program_options.h.
OptionContext::option_iterator ProgramOptions::OptionContext::find | ( | const char * | key, |
FindType | t = find_name |
||
) | const |
Returns the option with the given key.
UnknownOption | if no option matches key. |
AmbiguousOption | if more than one option matches key. |
Definition at line 384 of file program_options.cpp.
const OptionGroup & ProgramOptions::OptionContext::findGroup | ( | const std::string & | caption | ) | const |
Definition at line 347 of file program_options.cpp.
size_t ProgramOptions::OptionContext::findGroupKey | ( | const std::string & | name | ) | const [private] |
Definition at line 318 of file program_options.cpp.
OptionRange ProgramOptions::OptionContext::findImpl | ( | const char * | key, |
FindType | t, | ||
unsigned | eMask = unsigned(-1) |
||
) | const [inline] |
Definition at line 243 of file program_options.h.
OptionContext::PrefixRange ProgramOptions::OptionContext::findImpl | ( | const char * | key, |
FindType | t, | ||
unsigned | eMask, | ||
const std::string & | eCtx | ||
) | const |
Definition at line 393 of file program_options.cpp.
DescriptionLevel ProgramOptions::OptionContext::getActiveDescLevel | ( | ) | const [inline] |
Definition at line 255 of file program_options.h.
std::size_t ProgramOptions::OptionContext::groups | ( | ) | const [inline] |
Returns the number of groups in this context.
Definition at line 218 of file program_options.h.
void ProgramOptions::OptionContext::insertOption | ( | size_t | groupId, |
const SharedOptPtr & | o | ||
) | [private] |
Definition at line 365 of file program_options.cpp.
Sets the description level to be used when generating description.
Once set, functions generating descriptions will only consider groups and options with description level <= std::min(level, desc_level_all).
Definition at line 315 of file program_options.cpp.
std::size_t ProgramOptions::OptionContext::size | ( | ) | const [inline] |
Returns the number of options in this context.
Definition at line 216 of file program_options.h.
OptionContext::option_iterator ProgramOptions::OptionContext::tryFind | ( | const char * | key, |
FindType | t = find_name |
||
) | const |
Behaves like find but returns end() instead of throwing UnknownOption or AmbiguousOption.
Definition at line 388 of file program_options.cpp.
const OptionGroup * ProgramOptions::OptionContext::tryFindGroup | ( | const std::string & | caption | ) | const |
Definition at line 352 of file program_options.cpp.
std::ostream& operator<< | ( | std::ostream & | os, |
const OptionContext & | ctx | ||
) | [friend] |
Writes a formatted description of options in this context to os.
Definition at line 476 of file program_options.cpp.
std::string ProgramOptions::OptionContext::caption_ [private] |
Definition at line 278 of file program_options.h.
Definition at line 279 of file program_options.h.
Definition at line 277 of file program_options.h.
Definition at line 275 of file program_options.h.
Definition at line 276 of file program_options.h.