#include <CmdLineParser.h>
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. | |
Parser & | Set (unsigned flag) |
Set one or more flags. | |
Parser & | UnSet (unsigned flag) |
Unset one or more flags. | |
Parser & | Flags (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 |
CmdLine::Parser::Parser | ( | int | argc, | |
char ** | argv, | |||
unsigned | flags = 0 | |||
) | [inline] |
Starts the command-line parser.
[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) |
int Parser::Process | ( | ) |
After added all options then this function process the command-line parameters searching for options and their arguments.
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().
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;
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.
flag | The flag to be checked. To check for more than one flag at a time, use the operator | (or). |
true
if flag
is set; false
otherwise. References m_flags.
Parser& CmdLine::Parser::Set | ( | unsigned | flag | ) | [inline] |
Parser& CmdLine::Parser::UnSet | ( | unsigned | flag | ) | [inline] |
Parser& CmdLine::Parser::Flags | ( | unsigned | flag | ) | [inline] |
friend class OptionsINT [friend] |
friend class OptionsFLOAT [friend] |
friend class OptionsBOOL [friend] |
friend class OptionsCHAR [friend] |
friend class OptionsSTRING [friend] |
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().