The option flag with arguments. More...
#include <OBTOptionArgExtra.h>
Public Member Functions | |
OptionMultiNPrm (const std::string &flagName, const std::string &helpMsg, const std::string &prmMsg, int n=1) | |
virtual | ~OptionMultiNPrm () |
virtual bool | parseArg () |
The method to parse the arguments. | |
virtual void | reset () |
Reset the presence flag to re-parse the command line. | |
virtual std::string | getHelp () const |
The help message given for the option. | |
int | getNbOptions () const |
Returns the number of time the flag is present. | |
std::string | getPrm (int i, int j=0) const |
Returns the parameter associated to a flag. | |
Protected Attributes | |
std::string | _prmMsg |
int | _n |
std::vector< std::vector < std::string > > | _prm |
The option flag with arguments.
An option flag with N parameter arguments, this option can be several time in the command line.
The parameters are returned by getPrm.
Usage:
In the command line
-o /usr/local file1.cfg -o ~/workspace file2.cfg
To retrieve such command arguments
OptionMultiNPrm oOption( "-o", "two parameters, the first is the path, the second is the file name", "<path> <file name>", 2 ) ;
To get the parameters
for( int i = 0 ; i < oOption.getNbOptions() ; i++ ) { // Get the parameters std::string path( oOption.getPrm( i, 0 ) ) ; // i=0 => "/usr/local", i=1 => "~/workspace" std::string fileName( oOption.getPrm( i, 1 ) ) ; // i=0 => "file1.cfg", i=1 => "file2.cfg" // do something ... }
Definition at line 166 of file OBTOptionArgExtra.h.
OBT::OptionMultiNPrm::OptionMultiNPrm | ( | const std::string & | flagName, | |
const std::string & | helpMsg, | |||
const std::string & | prmMsg, | |||
int | n = 1 | |||
) | [inline] |
Definition at line 169 of file OBTOptionArgExtra.h.
virtual OBT::OptionMultiNPrm::~OptionMultiNPrm | ( | ) | [inline, virtual] |
Definition at line 171 of file OBTOptionArgExtra.h.
virtual std::string OBT::OptionMultiNPrm::getHelp | ( | ) | const [inline, virtual] |
The help message given for the option.
Returns the option flag following by the help message.
Reimplemented from OBT::OptionArg.
Definition at line 174 of file OBTOptionArgExtra.h.
int OBT::OptionMultiNPrm::getNbOptions | ( | ) | const [inline] |
Returns the number of time the flag is present.
It is also the number of entries in the table which stores the parameters.
Definition at line 177 of file OBTOptionArgExtra.h.
00177 { return _prm.size() ; }
std::string OBT::OptionMultiNPrm::getPrm | ( | int | i, | |
int | j = 0 | |||
) | const [inline] |
Returns the parameter associated to a flag.
[in] | i | the option index |
[in] | j | the parameter index |
Definition at line 184 of file OBTOptionArgExtra.h.
bool OptionMultiNPrm::parseArg | ( | ) | [virtual] |
The method to parse the arguments.
Retrieves the argument which can be following the option flag. See OptionFlag::parseArg, OptionNPrm::parseArg, OptionMultiNPrm::parseArg for examples.
Implements OBT::OptionArg.
Definition at line 26 of file OBTOptionArgExtra.cpp.
References _n, _prm, and OBT::OptionArg::getNextArg().
00027 { 00028 std::vector< std::string > prm ; 00029 for( int i = 0; i < _n ; i++ ) prm.push_back( OptionArg::getNextArg() ) ; 00030 _prm.push_back( prm ) ; 00031 return true ; 00032 }
virtual void OBT::OptionMultiNPrm::reset | ( | ) | [inline, virtual] |
Reset the presence flag to re-parse the command line.
Reimplemented from OBT::OptionArg.
Definition at line 173 of file OBTOptionArgExtra.h.
00173 { _prm.clear() ; }
int OBT::OptionMultiNPrm::_n [protected] |
Definition at line 187 of file OBTOptionArgExtra.h.
Referenced by parseArg().
std::vector< std::vector< std::string > > OBT::OptionMultiNPrm::_prm [protected] |
Definition at line 188 of file OBTOptionArgExtra.h.
Referenced by parseArg().
std::string OBT::OptionMultiNPrm::_prmMsg [protected] |
Definition at line 186 of file OBTOptionArgExtra.h.