Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
ProgramOptions::OptionContext Class Reference

A (logically grouped) list of unique options. More...

#include <program_options.h>

List of all members.

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

OptionContextadd (const OptionGroup &group)
 Adds the given group of options to this context.
OptionContextadd (const OptionContext &other)
 Adds all groups (and their options) from other to this context.
OptionContextaddAlias (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.
OptionOutputdescription (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 OptionGroupfindGroup (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 OptionGrouptryFindGroup (const std::string &caption) const
 ~OptionContext ()

Private Types

typedef std::vector< OptionGroupGroupList
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.

Detailed Description

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.


Member Typedef Documentation

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.

Definition at line 174 of file program_options.h.

Definition at line 178 of file program_options.h.

Definition at line 173 of file program_options.h.


Member Enumeration Documentation

Enumerator:
find_name 
find_prefix 
find_name_or_prefix 
find_alias 

Definition at line 220 of file program_options.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

Adds the given group of options to this context.

Note:
If this object already contains a group with the same caption as group, the groups are merged.
Exceptions:
DuplicateOptionif 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.

Adds all groups (and their options) from other to this context.

Exceptions:
DuplicateOptionif an option in other has the same short or long name as one of the options in this context.
See also:
OptionContext& add(const OptionGroup&);

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.

Exceptions:
DuplicateOptionif an option with the name aliasName already exists.

Definition at line 339 of file program_options.cpp.

Assigns any default values to all options not in exclude.

Exceptions:
ValueErrorif some default value is actually invalid for its option.

Definition at line 482 of file program_options.cpp.

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.

Writes a formatted description of options in this context.

Definition at line 426 of file program_options.cpp.

Definition at line 213 of file program_options.h.

Returns the option with the given key.

Note:
The second parameter defines how key is interpreted:
  • find_name: search for an option whose name equals key.
  • find_prefix: search for an option whose name starts with the given key.
  • find_alias: search for an option whose alias equals key.
If second parameter is find_alias, a starting '-' in key is valid but not required.
Exceptions:
UnknownOptionif no option matches key.
AmbiguousOptionif 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.

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.

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.


Friends And Related Function Documentation

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.


Member Data Documentation

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.


The documentation for this class was generated from the following files:


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:41