The option flag with arguments. More...
#include <OBTOptionArgExtra.h>
Public Member Functions | |
OptionNPrm (const std::string &flagName, const std::string &helpMsg, const std::string prmMsg, int n=1) | |
virtual | ~OptionNPrm () |
virtual bool | parseArg () |
The method to parse the arguments. | |
virtual std::string | getHelp () const |
The help message given for the option. | |
std::string | getPrm (int i=0) const |
Returns the parameter associated to a flag. | |
Protected Attributes | |
std::string | _prmMsg |
int | _n |
std::vector< std::string > | _prm |
The option flag with arguments.
An option flag with N parameter arguments, this option can be only once in the command line.
The parameters are returned by getPrm.
Usage:
In the command line
-o /usr/local file.cfg -traceFile out.log
To retrieve such command arguments
OptionNPrm oOption( "-o", "two parameters, the first is the path, the second is the file name", "<path> <file name>", 2 ) ; OptionNPrm traceFileOption( "-traceFile", "the trace file", "<outup file>", 1 ) ;
To get the parameters
if( oOption.isPresent() ) { // -o is in the command line // Get the parameters std::string path( optionO.getPrm( 0 ) ) ; // => "/usr/local" std::string fileName( optionO.getPrm( 1 ) ) ; // => "file.cfg" // do something ... } if( traceFileOption.isPresent() ) { // -traceFile is in the command line // Get the file name std::string fileName( traceFileOption.getPrm() ) ; // default first parameter => "out.log" // do something ... }
Definition at line 115 of file OBTOptionArgExtra.h.
OBT::OptionNPrm::OptionNPrm | ( | const std::string & | flagName, | |
const std::string & | helpMsg, | |||
const std::string | prmMsg, | |||
int | n = 1 | |||
) | [inline] |
Definition at line 118 of file OBTOptionArgExtra.h.
virtual OBT::OptionNPrm::~OptionNPrm | ( | ) | [inline, virtual] |
Definition at line 121 of file OBTOptionArgExtra.h.
virtual std::string OBT::OptionNPrm::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 123 of file OBTOptionArgExtra.h.
std::string OBT::OptionNPrm::getPrm | ( | int | i = 0 |
) | const [inline] |
Returns the parameter associated to a flag.
[in] | i | the parameter index |
Definition at line 129 of file OBTOptionArgExtra.h.
bool OptionNPrm::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 19 of file OBTOptionArgExtra.cpp.
References OBT::OptionArg::_flag, _n, _prm, OBT::OptionArg::getNextArg(), and OBT::OptionArg::throwError().
00020 { 00021 if( _flag ) throwError( "This option cannot be used more than once" ) ; 00022 for( int i = 0; i < _n ; i++ ) _prm.push_back( OptionArg::getNextArg() ) ; 00023 return true ; 00024 }
int OBT::OptionNPrm::_n [protected] |
Definition at line 132 of file OBTOptionArgExtra.h.
Referenced by parseArg().
std::vector< std::string > OBT::OptionNPrm::_prm [protected] |
Definition at line 133 of file OBTOptionArgExtra.h.
Referenced by parseArg().
std::string OBT::OptionNPrm::_prmMsg [protected] |
Definition at line 131 of file OBTOptionArgExtra.h.