wibble 1.1
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
wibble::commandline::Engine Class Reference

Parse commandline options. More...

#include <engine.h>

Inheritance diagram for wibble::commandline::Engine:
Inheritance graph
[legend]
Collaboration diagram for wibble::commandline::Engine:
Collaboration graph
[legend]

Public Member Functions

const std::string & name () const
 
Optionadd (Option *o)
 Add an Option to this engine.
 
OptionGroupadd (OptionGroup *group)
 Add an OptionGroup to this engine.
 
Engineadd (Engine *o)
 Add a Engine to this engine.
 
template<typename T >
T * create (const std::string &name, char shortName, const std::string &longName, const std::string &usage=std::string(), const std::string &description=std::string())
 Create an option.
 
template<typename T >
T * add (const std::string &name, char shortName, const std::string &longName, const std::string &usage=std::string(), const std::string &description=std::string())
 Create an option and add to this engine.
 
OptionGroupcreateGroup (const std::string &description)
 Create an OptionGroup.
 
OptionGroupaddGroup (const std::string &description)
 Create an OptionGroup and add it to this engine.
 
EnginecreateEngine (const std::string &name, const std::string &usage=std::string(), const std::string &description=std::string(), const std::string &longDescription=std::string())
 Create a Engine.
 
EngineaddEngine (const std::string &name, const std::string &usage=std::string(), const std::string &description=std::string(), const std::string &longDescription=std::string())
 Create a Engine and add it to this engine as a command.
 
const std::vector< OptionGroup * > & groups () const
 Get the OptionGroups that have been added to this engine.
 
const std::vector< Option * > & options () const
 Get the Options that have been added to this engine.
 
const std::vector< Engine * > & commands () const
 Get the Engines that have been added to this engine.
 
Enginecommand (const std::string &name) const
 
bool hasOptions () const
 Returns true if this Engine has options to parse.
 
EnginefoundCommand () const
 Return the command that has been found in the commandline, or NULL if none have been found.
 
void dump (std::ostream &out, const std::string &prefix=std::string())
 
- Public Member Functions inherited from wibble::commandline::Managed
virtual ~Managed ()
 

Public Attributes

std::string primaryAlias
 
std::vector< std::string > aliases
 
std::string usage
 
std::string description
 
std::string longDescription
 
std::string examples
 
bool hidden
 
bool no_switches_after_first_arg
 

Protected Member Functions

void addWithoutAna (Option *o)
 
void addWithoutAna (const std::vector< Option * > &o)
 
void add (const std::string &alias, Engine *o)
 
void rebuild ()
 
std::pair< ArgList::iterator, boolparseFirstIfKnown (ArgList &list, ArgList::iterator begin)
 Handle the commandline switch at 'begin'.
 
ArgList::iterator parseKnownSwitches (ArgList &list, ArgList::iterator begin)
 Parse all known Options and leave the rest in list.
 
ArgList::iterator parseList (ArgList &list)
 Parse the list of arguments, starting at the beginning and removing the arguments it successfully parses.
 
ArgList::iterator parse (ArgList &list, ArgList::iterator begin)
 Parse all the switches in list, leaving only the non-switch arguments or the arguments following "--".
 
 Engine (MemoryManager *mman=0, const std::string &name=std::string(), const std::string &usage=std::string(), const std::string &description=std::string(), const std::string &longDescription=std::string())
 

Protected Attributes

std::vector< OptionGroup * > m_groups
 
std::vector< Option * > m_options
 
std::vector< Engine * > m_commands
 
std::map< char, Option * > m_short
 
std::map< std::string, Option * > m_long
 
std::map< std::string, Engine * > m_aliases
 
Enginem_found_command
 

Friends

class Parser
 

Detailed Description

Parse commandline options.

Normally it parses short or long switches all starting with '-'

If other engines are added, then looks in the commandline for a non-switch command to select the operation mode. This allow to have a custom set of commandline options for every non-switch command.

Constructor & Destructor Documentation

◆ Engine()

wibble::commandline::Engine::Engine ( MemoryManager mman = 0,
const std::string &  name = std::string(),
const std::string &  usage = std::string(),
const std::string &  description = std::string(),
const std::string &  longDescription = std::string() 
)
inlineprotected

Member Function Documentation

◆ add() [1/5]

void wibble::commandline::Engine::add ( const std::string &  alias,
Engine o 
)
protected

References m_aliases.

Referenced by add(), addEngine(), addGroup(), Engine2::Engine2(), and rebuild().

◆ add() [2/5]

template<typename T >
T * wibble::commandline::Engine::add ( const std::string &  name,
char  shortName,
const std::string &  longName,
const std::string &  usage = std::string(),
const std::string &  description = std::string() 
)
inline

Create an option and add to this engine.

References add(), description, name(), and usage.

◆ add() [3/5]

Engine * wibble::commandline::Engine::add ( Engine o)

Add a Engine to this engine.

References m_commands.

◆ add() [4/5]

Option * wibble::commandline::Engine::add ( Option o)

Add an Option to this engine.

References m_options.

◆ add() [5/5]

OptionGroup * wibble::commandline::Engine::add ( OptionGroup group)

Add an OptionGroup to this engine.

References m_groups.

◆ addEngine()

Engine * wibble::commandline::Engine::addEngine ( const std::string &  name,
const std::string &  usage = std::string(),
const std::string &  description = std::string(),
const std::string &  longDescription = std::string() 
)
inline

◆ addGroup()

OptionGroup * wibble::commandline::Engine::addGroup ( const std::string &  description)
inline

Create an OptionGroup and add it to this engine.

References add(), createGroup(), and description.

Referenced by wibble::commandline::StandardParser::StandardParser().

◆ addWithoutAna() [1/2]

void wibble::commandline::Engine::addWithoutAna ( const std::vector< Option * > &  o)
protected

References addWithoutAna().

◆ addWithoutAna() [2/2]

void wibble::commandline::Engine::addWithoutAna ( Option o)
protected

References m_long, and m_short.

Referenced by addWithoutAna(), and rebuild().

◆ command()

Engine * wibble::commandline::Engine::command ( const std::string &  name) const
inline

◆ commands()

const std::vector< Engine * > & wibble::commandline::Engine::commands ( ) const
inline

Get the Engines that have been added to this engine.

References m_commands.

◆ create()

template<typename T >
T * wibble::commandline::Engine::create ( const std::string &  name,
char  shortName,
const std::string &  longName,
const std::string &  usage = std::string(),
const std::string &  description = std::string() 
)
inline

Create an option.

References wibble::commandline::MemoryManager::add(), description, name(), and usage.

◆ createEngine()

Engine * wibble::commandline::Engine::createEngine ( const std::string &  name,
const std::string &  usage = std::string(),
const std::string &  description = std::string(),
const std::string &  longDescription = std::string() 
)
inline

◆ createGroup()

OptionGroup * wibble::commandline::Engine::createGroup ( const std::string &  description)
inline

◆ dump()

void wibble::commandline::Engine::dump ( std::ostream &  out,
const std::string &  prefix = std::string() 
)

◆ foundCommand()

Engine * wibble::commandline::Engine::foundCommand ( ) const
inline

Return the command that has been found in the commandline, or NULL if none have been found.

References m_found_command.

Referenced by wibble::commandline::StandardParser::outputHelp(), and wibble::commandline::StandardParserWithMandatoryCommand::parse().

◆ groups()

const std::vector< OptionGroup * > & wibble::commandline::Engine::groups ( ) const
inline

Get the OptionGroups that have been added to this engine.

References m_groups.

◆ hasOptions()

bool wibble::commandline::Engine::hasOptions ( ) const
inline

Returns true if this Engine has options to parse.

References m_groups, and m_options.

◆ name()

const std::string & wibble::commandline::Engine::name ( ) const
inline

◆ options()

const std::vector< Option * > & wibble::commandline::Engine::options ( ) const
inline

Get the Options that have been added to this engine.

References m_options.

◆ parse()

ArgList::iterator wibble::commandline::Engine::parse ( ArgList list,
ArgList::iterator  begin 
)
protected

Parse all the switches in list, leaving only the non-switch arguments or the arguments following "--".

References wibble::commandline::ArgList::isSwitch(), m_aliases, m_commands, m_found_command, no_switches_after_first_arg, parse(), parseKnownSwitches(), and rebuild().

Referenced by parse(), and parseList().

◆ parseFirstIfKnown()

std::pair< ArgList::iterator, bool > wibble::commandline::Engine::parseFirstIfKnown ( ArgList list,
ArgList::iterator  begin 
)
protected

Handle the commandline switch at 'begin'.

If the switch at 'begin' cannot be handled, the list is untouched and 'begin',false is returned. Else, the switch is removed and the new begin is returned.

References wibble::commandline::ArgList::eraseAndAdvance(), m_long, m_short, and name().

Referenced by parseKnownSwitches().

◆ parseKnownSwitches()

ArgList::iterator wibble::commandline::Engine::parseKnownSwitches ( ArgList list,
ArgList::iterator  begin 
)
protected

Parse all known Options and leave the rest in list.

References wibble::commandline::ArgList::isSwitch(), no_switches_after_first_arg, and parseFirstIfKnown().

Referenced by parse().

◆ parseList()

ArgList::iterator wibble::commandline::Engine::parseList ( ArgList list)
inlineprotected

Parse the list of arguments, starting at the beginning and removing the arguments it successfully parses.

Returns
An iterator to the first unparsed argument (can be list.end())

References parse().

Referenced by wibble::commandline::Parser::parse().

◆ rebuild()

void wibble::commandline::Engine::rebuild ( )
protected

Friends And Related Symbol Documentation

◆ Parser

Member Data Documentation

◆ aliases

std::vector<std::string> wibble::commandline::Engine::aliases

Referenced by Engine2::Engine2().

◆ description

std::string wibble::commandline::Engine::description

◆ examples

std::string wibble::commandline::Engine::examples

◆ hidden

bool wibble::commandline::Engine::hidden

◆ longDescription

std::string wibble::commandline::Engine::longDescription

Referenced by addEngine(), and createEngine().

◆ m_aliases

std::map<std::string, Engine*> wibble::commandline::Engine::m_aliases
protected

Referenced by add(), command(), dump(), parse(), and rebuild().

◆ m_commands

std::vector<Engine*> wibble::commandline::Engine::m_commands
protected

Referenced by add(), commands(), dump(), parse(), and rebuild().

◆ m_found_command

Engine* wibble::commandline::Engine::m_found_command
protected

Referenced by foundCommand(), and parse().

◆ m_groups

std::vector<OptionGroup*> wibble::commandline::Engine::m_groups
protected

Referenced by add(), dump(), groups(), hasOptions(), and rebuild().

◆ m_long

std::map<std::string, Option*> wibble::commandline::Engine::m_long
protected

◆ m_options

std::vector<Option*> wibble::commandline::Engine::m_options
protected

Referenced by add(), dump(), hasOptions(), options(), and rebuild().

◆ m_short

std::map<char, Option*> wibble::commandline::Engine::m_short
protected

◆ no_switches_after_first_arg

bool wibble::commandline::Engine::no_switches_after_first_arg

Referenced by parse(), and parseKnownSwitches().

◆ primaryAlias

std::string wibble::commandline::Engine::primaryAlias

◆ usage

std::string wibble::commandline::Engine::usage

Referenced by add(), addEngine(), create(), and createEngine().


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