Core::CmdLineParser Class Reference

A command line parser. More...

#include <CmdLineParser.hpp>

List of all members.

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 CmdLineSwitchSwitchCIter
 An iterator into command line switch table.
typedef std::vector< tstringStringVector
 A vector of strings.
typedef std::map< int, StringVectorNamedArgs
 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 NamedArgsGetNamedArgs () const
 Get the collection of named arguments.
const UnnamedArgsGetUnnamedArgs () 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 tcharCharCIter
 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...


Detailed Description

A command line parser.

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>

).


Member Typedef Documentation

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.

typedef StringVector Core::CmdLineParser::UnnamedArgs

The type used to store the unnamed arguments.

typedef const tchar* Core::CmdLineParser::CharCIter [private]

An iterator for c-style strings.


Member Enumeration Documentation

enum Core::CmdLineParser::Format

The switch formats.

Enumerator:
WINDOWS  Allow Windows format switches.
UNIX  Allow Unix format switches.

enum Core::CmdLineParser::Flag

The parsing flags.

Enumerator:
ALLOW_WIN_FORMAT  Allow Windows format switches.
ALLOW_UNIX_FORMAT  Allow Unix format switches.
ALLOW_UNNAMED  Allow unnamed arguments.
ALLOW_ANY_FORMAT 
DEFAULTS 


Constructor & Destructor Documentation

Core::CmdLineParser::CmdLineParser ( SwitchCIter  itFirstSwitch,
SwitchCIter  itLastSwitch 
)

Default constructor.

Core::CmdLineParser::~CmdLineParser (  ) 

Destructor.


Member Function Documentation

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.

tstring Core::CmdLineParser::FormatSwitches ( Format  eFormat  )  const

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.


Member Data Documentation

SwitchCIter Core::CmdLineParser::m_itFirstSwitch [private]

The first switch in the table.

SwitchCIter Core::CmdLineParser::m_itLastSwitch [private]

The last switch in the table.

NamedArgs Core::CmdLineParser::m_mapNamedArgs [private]

The collection of named arguments.

UnnamedArgs Core::CmdLineParser::m_vecUnnamedArgs [private]

The collection of unnamed arguments.


The documentation for this class was generated from the following files:
Generated on Tue Jan 6 22:19:18 2009 for Core Library by  doxygen 1.5.2