CmdLine::Parser Class Reference

#include <CmdLineParser.h>

Collaboration diagram for CmdLine::Parser:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Parser (int argc, char **argv, unsigned flags=0)
int Process ()
template<class T>
int Process (T &)
bool IsSet (unsigned flag) const
 Check if one or more flags are set.
ParserSet (unsigned flag)
 Set one or more flags.
ParserUnSet (unsigned flag)
 Unset one or more flags.
ParserFlags (unsigned flag)
 Reset the current flags and set new ones.

Public Attributes

class OptionsINT Int
class OptionsFLOAT Float
class OptionsBOOL Bool
class OptionsCHAR Char
class OptionsSTRING String

Private Attributes

int m_argc
char ** m_argv
unsigned m_flags

Friends

class OptionsINT
class OptionsFLOAT
class OptionsBOOL
class OptionsCHAR
class OptionsSTRING


Detailed Description

The user interface for the command-line parser.

Constructor & Destructor Documentation

CmdLine::Parser::Parser ( int  argc,
char **  argv,
unsigned  flags = 0 
) [inline]

Starts the command-line parser.

Parameters:
[in] argc The number of tokens in the command-line
[in] argv The array of string of tokens (in fact, the command-line)
[in] flags Flags controlling the behaviour of the Parser regarding verbosity, out of range occurrences and absence of values for options requiring arguments (CmdLine::SILENT, CmdLine::OUT_OF_RANGE, and CmdLine::NO_VALUE)


Member Function Documentation

int Parser::Process (  ) 

After added all options then this function process the command-line parameters searching for options and their arguments.

Returns:
The number of matched options

References Bool, Char, Float, Int, m_argc, m_argv, CmdLine::OptionsSTRING::Match(), CmdLine::OptionsCHAR::Match(), CmdLine::OptionsBOOL::Match(), CmdLine::OptionsFLOAT::Match(), CmdLine::OptionsINT::Match(), and String.

Referenced by Params::Initialize().

template<class T>
int CmdLine::Parser::Process ( T &  remains  )  [inline]

This version of Process() accepts a container of 'const char*', 'char*' or 'string' type that will holds the remaining command-line tokens, i.e, those that do not matched.

For example:

 (...)
 vector<string> remaining;

 int matched = Opts.Process( remaining );

 vector<string>::const_iterator ci = remaining.begin();

 cout << "\nMatched: " << matched << " Unrecognized: " << remaining.size();
 cout << "\nUnrecognized arguments:\n";
 while( ci != remaining.end() ) cout << *ci++ << endl;

Warning:
The container must provide the clear() and push_back() functions.

References Bool, Char, Float, Int, m_argc, m_argv, CmdLine::OptionsSTRING::Match(), CmdLine::OptionsCHAR::Match(), CmdLine::OptionsBOOL::Match(), CmdLine::OptionsFLOAT::Match(), CmdLine::OptionsINT::Match(), and String.

bool CmdLine::Parser::IsSet ( unsigned  flag  )  const [inline]

Check if one or more flags are set.

Parameters:
flag The flag to be checked. To check for more than one flag at a time, use the operator | (or).
Returns:
true if flag is set; false otherwise.

References m_flags.

Parser& CmdLine::Parser::Set ( unsigned  flag  )  [inline]

Set one or more flags.

Parameters:
flag The flag to be set. To set more than one flag at a time, use the operator | (or).
Returns:
The current object Parser.

References m_flags.

Parser& CmdLine::Parser::UnSet ( unsigned  flag  )  [inline]

Unset one or more flags.

Parameters:
flag The flag to be unset. To unset more than one flag at a time, use the operator | (or).
Returns:
The current object Parser.

References m_flags.

Parser& CmdLine::Parser::Flags ( unsigned  flag  )  [inline]

Reset the current flags and set new ones.

Parameters:
flag The flag to be set. To set more than one flag at a time, use the operator | (or).
Returns:
The current object Parser.

References m_flags.


Friends And Related Function Documentation

friend class OptionsINT [friend]

friend class OptionsFLOAT [friend]

friend class OptionsBOOL [friend]

friend class OptionsCHAR [friend]

friend class OptionsSTRING [friend]


Member Data Documentation

A database of integer options.

Referenced by Params::Initialize(), and Process().

A database of float options.

Referenced by Params::Initialize(), CmdLine::OptionsINT::Match(), and Process().

A database of boolean options.

Referenced by Params::Initialize(), and Process().

A database of char options.

Referenced by Params::Initialize(), and Process().

A database of string options.

Referenced by Params::Initialize(), and Process().

int CmdLine::Parser::m_argc [private]

Number of command-line "tokens".

Referenced by Process().

char** CmdLine::Parser::m_argv [private]

The "command-line" (pointer to) itself.

Referenced by Process().

unsigned CmdLine::Parser::m_flags [private]

Currently may hold SILENT, OUT_OF_RANGE and NO_VALUE flags

Referenced by CmdLine::OptionsSTRING::Add(), CmdLine::OptionsCHAR::Add(), CmdLine::OptionsFLOAT::Add(), CmdLine::OptionsINT::Add(), Flags(), IsSet(), Set(), and UnSet().


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