OBT::OptionNPrm Class Reference

The option flag with arguments. More...

#include <OBTOptionArgExtra.h>

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

List of all members.

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

Detailed Description

The option flag with arguments.

Author:
Beno�t Chanclou.

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.


Constructor & Destructor Documentation

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.

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

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

Definition at line 121 of file OBTOptionArgExtra.h.

00121 {}


Member Function Documentation

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.

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

std::string OBT::OptionNPrm::getPrm ( int  i = 0  )  const [inline]

Returns the parameter associated to a flag.

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

Definition at line 129 of file OBTOptionArgExtra.h.

00129 { return _flag && 0 <= i && i < _n ? _prm[ i ] : "" ; }

bool OptionNPrm::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 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 }


Member Data Documentation

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.


Generated on 1 Jan 2010 for OBT by  doxygen 1.6.1