#include <CmdLineParser.hpp>
Public Types | |
| enum | Format { WINDOWS = 0x0001, UNIX = 0x0002 } |
| The switch formats. More... | |
| enum | Flag { ALLOW_WIN_FORMAT = WINDOWS, ALLOW_UNIX_FORMAT = UNIX, ALLOW_UNNAMED = 0x0004, ALLOW_ANY_FORMAT = (ALLOW_WIN_FORMAT | ALLOW_UNIX_FORMAT), DEFAULTS = ALLOW_ANY_FORMAT | ALLOW_UNNAMED } |
| The parsing flags. More... | |
| typedef const CmdLineSwitch * | SwitchCIter |
| An iterator into command line switch table. | |
| typedef std::vector< tstring > | StringVector |
| A vector of strings. | |
| typedef std::map< int, StringVector > | NamedArgs |
| The type used to store the named arguments. | |
| typedef StringVector | UnnamedArgs |
| The type used to store the unnamed arguments. | |
Public Member Functions | |
| CmdLineParser (SwitchCIter itFirstSwitch, SwitchCIter itLastSwitch) | |
| Default constructor. | |
| ~CmdLineParser () | |
| Destructor. | |
| const NamedArgs & | GetNamedArgs () const |
| Get the collection of named arguments. | |
| const UnnamedArgs & | GetUnnamedArgs () const |
| Get the collection of unnamed arguments. | |
| void | Parse (int argc, tchar *argv[], int nFlags=DEFAULTS) |
| Parse the command line. | |
| bool | IsSwitchSet (int nID) const |
| Check if a switch was provided. | |
| tstring | GetSwitchValue (int nID) const |
| Get the value for a switch. | |
| tstring | FormatSwitches (Format eFormat) const |
| Generate the list of switches for a usage message. | |
Private Types | |
| typedef const tchar * | CharCIter |
| An iterator for c-style strings. | |
Private Member Functions | |
| void | Reset () |
| Reset the internal state. | |
| SwitchCIter | FindSwitch (CharCIter itNameFirst, CharCIter itNameLast) |
| Try and match the argument to a switch definition. | |
Private Attributes | |
| SwitchCIter | m_itFirstSwitch |
| The first switch in the table. | |
| SwitchCIter | m_itLastSwitch |
| The last switch in the table. | |
| NamedArgs | m_mapNamedArgs |
| The collection of named arguments. | |
| UnnamedArgs | m_vecUnnamedArgs |
| The collection of unnamed arguments. | |
Classes | |
| struct | IsLongName |
| The predicate for matching the switches long name. More... | |
| struct | IsSeparator |
| The predicate for finding the name/value separator. More... | |
| struct | IsShortName |
| The predicate for matching the switches short name. More... | |
The parser supports both Unix style (eg -h & --help) and Windows style (eg /h & /help) switches. The value for the switch can be specifed after the switch name (eg -p <file>) or inline in either format (eg /p:<file> or --print=<file>). A switch can also be referenced multiple times and/or have multiple values (eg -x <value> -x <value> or -x <value>
).
| typedef const CmdLineSwitch* Core::CmdLineParser::SwitchCIter |
An iterator into command line switch table.
| typedef std::vector<tstring> Core::CmdLineParser::StringVector |
A vector of strings.
| typedef std::map<int, StringVector> Core::CmdLineParser::NamedArgs |
The type used to store the named arguments.
The type used to store the unnamed arguments.
typedef const tchar* Core::CmdLineParser::CharCIter [private] |
An iterator for c-style strings.
| Core::CmdLineParser::CmdLineParser | ( | SwitchCIter | itFirstSwitch, | |
| SwitchCIter | itLastSwitch | |||
| ) |
Default constructor.
| Core::CmdLineParser::~CmdLineParser | ( | ) |
Destructor.
| const CmdLineParser::NamedArgs & Core::CmdLineParser::GetNamedArgs | ( | ) | const [inline] |
Get the collection of named arguments.
| const CmdLineParser::UnnamedArgs & Core::CmdLineParser::GetUnnamedArgs | ( | ) | const [inline] |
Get the collection of unnamed arguments.
| void Core::CmdLineParser::Parse | ( | int | argc, | |
| tchar * | argv[], | |||
| int | nFlags = DEFAULTS | |||
| ) |
Parse the command line.
| bool Core::CmdLineParser::IsSwitchSet | ( | int | nID | ) | const |
Check if a switch was provided.
| tstring Core::CmdLineParser::GetSwitchValue | ( | int | nID | ) | const |
Get the value for a switch.
This only returns the first value that was parsed. To obtain the full list iterate the NamedArgs collection directly.
Generate the list of switches for a usage message.
| void Core::CmdLineParser::Reset | ( | ) | [private] |
Reset the internal state.
| CmdLineParser::SwitchCIter Core::CmdLineParser::FindSwitch | ( | CharCIter | itNameFirst, | |
| CharCIter | itNameLast | |||
| ) | [private] |
Try and match the argument to a switch definition.
The first switch in the table.
The last switch in the table.
NamedArgs Core::CmdLineParser::m_mapNamedArgs [private] |
The collection of named arguments.
The collection of unnamed arguments.
1.5.2