clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Public Types | Public Member Functions | Friends | List of all members
ProgramOptions::OptionContext Class Reference

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

#include <program_options.h>

Collaboration diagram for ProgramOptions::OptionContext:
Collaboration graph

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. More...
 
typedef PrefixRange OptionRange
 

Public Member Functions

 OptionContext (const std::string &caption="", DescriptionLevel desc_default=desc_level_default)
 
 ~OptionContext ()
 
const std::string & caption () const
 
OptionContextadd (const OptionGroup &group)
 Adds the given group of options to this context. More...
 
OptionContextaddAlias (const std::string &aliasName, option_iterator option)
 Adds an alias name for the given option. More...
 
OptionContextadd (const OptionContext &other)
 Adds all groups (and their options) from other to this context. More...
 
option_iterator begin () const
 
option_iterator end () const
 
std::size_t size () const
 Returns the number of options in this context. More...
 
std::size_t groups () const
 Returns the number of groups in this context. More...
 
option_iterator find (const char *key, FindType t=find_name) const
 Returns the option with the given key. More...
 
option_iterator tryFind (const char *key, FindType t=find_name) 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
 
const OptionGroupfindGroup (const std::string &caption) const
 
const OptionGrouptryFindGroup (const std::string &caption) const
 
void setActiveDescLevel (DescriptionLevel level)
 Sets the description level to be used when generating description. More...
 
DescriptionLevel getActiveDescLevel () const
 
OptionOutputdescription (OptionOutput &out) const
 Writes a formatted description of options in this context. More...
 
std::string defaults (std::size_t prefixSize=0) const
 Returns the default command-line of this context. More...
 
bool assignDefaults (const ParsedOptions &exclude) const
 Assigns any default values to all options not in exclude. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const OptionContext &ctx)
 Writes a formatted description of options in this context to os. More...
 

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.

Member Typedef Documentation

typedef OptionList::const_iterator ProgramOptions::OptionContext::option_iterator

Type for identifying an option within a context.

Member Enumeration Documentation

Enumerator
find_name 
find_prefix 
find_name_or_prefix 
find_alias 

Constructor & Destructor Documentation

ProgramOptions::OptionContext::OptionContext ( const std::string &  caption = "",
DescriptionLevel  desc_default = desc_level_default 
)
ProgramOptions::OptionContext::~OptionContext ( )

Member Function Documentation

OptionContext & ProgramOptions::OptionContext::add ( const OptionGroup group)

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.

Here is the call graph for this function:

OptionContext & ProgramOptions::OptionContext::add ( const OptionContext other)

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&);

Here is the call graph for this function:

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.

Here is the call graph for this function:

bool ProgramOptions::OptionContext::assignDefaults ( const ParsedOptions exclude) const

Assigns any default values to all options not in exclude.

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

Here is the call graph for this function:

option_iterator ProgramOptions::OptionContext::begin ( ) const
inline
const std::string & ProgramOptions::OptionContext::caption ( ) const
std::string ProgramOptions::OptionContext::defaults ( std::size_t  prefixSize = 0) const

Returns the default command-line of this context.

Here is the call graph for this function:

OptionOutput & ProgramOptions::OptionContext::description ( OptionOutput out) const

Writes a formatted description of options in this context.

Here is the call graph for this function:

option_iterator ProgramOptions::OptionContext::end ( ) const
inline
OptionContext::option_iterator ProgramOptions::OptionContext::find ( const char *  key,
FindType  t = find_name 
) const

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.

Here is the call graph for this function:

const OptionGroup & ProgramOptions::OptionContext::findGroup ( const std::string &  caption) const

Here is the call graph for this function:

OptionRange ProgramOptions::OptionContext::findImpl ( const char *  key,
FindType  t,
unsigned  eMask = unsigned(-1) 
) const
inline

Here is the call graph for this function:

OptionContext::PrefixRange ProgramOptions::OptionContext::findImpl ( const char *  key,
FindType  t,
unsigned  eMask,
const std::string &  eCtx 
) const
DescriptionLevel ProgramOptions::OptionContext::getActiveDescLevel ( ) const
inline
std::size_t ProgramOptions::OptionContext::groups ( ) const
inline

Returns the number of groups in this context.

void ProgramOptions::OptionContext::setActiveDescLevel ( DescriptionLevel  level)

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).

std::size_t ProgramOptions::OptionContext::size ( ) const
inline

Returns the number of options in this context.

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.

Here is the call graph for this function:

const OptionGroup * ProgramOptions::OptionContext::tryFindGroup ( const std::string &  caption) const

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.


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