OBT::OptionMultiNPrm Class Reference

The option flag with arguments. More...

#include <OBTOptionArgExtra.h>

Inheritance diagram for OBT::OptionMultiNPrm:
[legend]
Collaboration diagram for OBT::OptionMultiNPrm:
[legend]

List of all members.

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

Detailed Description

The option flag with arguments.

Author:
Beno�t Chanclou.

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.


Constructor & Destructor Documentation

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.

00170                                                         : OptionArg( flagName, helpMsg ), _prmMsg( prmMsg ), _n( n ) {}

virtual OBT::OptionMultiNPrm::~OptionMultiNPrm (  )  [inline, virtual]

Definition at line 171 of file OBTOptionArgExtra.h.

00171 {}


Member Function Documentation

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.

00174 { return _flagName + " " + _prmMsg + ":  " + _helpMsg ; }

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.

Parameters:
[in] i the option index
[in] j the parameter index
Returns:
the jth parameter associated to the ith flag. Returns an empty string if i or j are out of range or if the option is not present. By default returns the first parameter.

Definition at line 184 of file OBTOptionArgExtra.h.

00184 { return 0 <= i && i < (int)_prm.size() && 0 <= j && j < _n ? _prm[ i ][ j ] : "" ; }

bool OptionMultiNPrm::parseArg (  )  [virtual]

The method to parse the arguments.

Returns:
true if the arguments can be parsed.

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() ; }


Member Data Documentation

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.


Generated on 1 Jan 2010 for OBT by  doxygen 1.6.1