gatb.core-API-1.4.2
OptionsParser Class Reference

Implementation of the IOptionsParser interface. More...

#include <OptionsParser.hpp>

Inheritance diagram for OptionsParser:
Inheritance graph

Public Member Functions

 OptionsParser (const std::string &name="", const std::string &help="")
 
virtual ~OptionsParser ()
 
const std::string & getName () const
 
void setName (const std::string &name)
 
void setVisible (bool status)
 
bool isVisible () const
 
const std::string & getHelp () const
 
void setHelp (const std::string &help)
 
misc::IPropertiesparse (int argc, char **argv)
 
misc::IPropertiesparseString (const std::string &s)
 
misc::IPropertiesgetProperties ()
 
bool saw (const std::string &name) const
 
void push_back (IOptionsParser *parser, size_t expandDepth=0, bool visibility=true)
 
void push_front (IOptionsParser *parser, size_t expandDepth=0, bool visibility=true)
 
IOptionsParsergetParser (const std::string &name)
 
std::list< IOptionsParser * > & getParsers ()
 
misc::IPropertiesgetDefaultProperties ()
 
void accept (IOptionsParserVisitor &visitor, size_t depth=0)
 
- Public Member Functions inherited from SmartPointer
void use ()
 
void forget ()
 
- Public Member Functions inherited from ISmartPointer
virtual ~ISmartPointer ()
 

Additional Inherited Members

- Protected Member Functions inherited from SmartPointer
 SmartPointer ()
 
virtual ~SmartPointer ()
 

Detailed Description

Implementation of the IOptionsParser interface.

This implementation represents the 'composite' part of the Composite design pattern.

Example:

// We include what we need for the test
#include <list>
#include <iostream>
/********************************************************************************/
/* Command line parsing through IOptionParser */
/********************************************************************************/
int main (int argc, char* argv[])
{
IOptionsParser* root = new OptionsParser ("root");
root->push_back (SortingCountAlgorithm<>::getOptionsParser(false));
root->push_back (DebloomAlgorithm<>::getOptionsParser());
IOptionsParser* child1 = new OptionsParser ("child1");
root->push_back (child1);
if (IOptionsParser* bloomParser = root->getParser ("bloom")) { bloomParser->setVisible(false); }
child1->push_back (new OptionOneParam (STR_NB_CORES, "nb cores (0 for all)", false, "0"));
child1->push_back (new OptionOneParam (STR_MAX_MEMORY, "max memory (in MBytes)", false, "2000"));
child1->push_back (new OptionOneParam (STR_MAX_DISK, "max disk (in MBytes)", false, "0"));
child1->push_back (BranchingAlgorithm<>::getOptionsParser());
try
{
root->parse (argc, argv);
}
catch (OptionFailure& e)
{
e.displayErrors(std::cout);
}
printf ("-------------------------------------------------------------\n");
RawDumpPropertiesVisitor v;
root->getProperties()->accept (&v);
delete root;
}

Constructor & Destructor Documentation

OptionsParser ( const std::string &  name = "",
const std::string &  help = "" 
)

Constructor.

~OptionsParser ( )
virtual

Destructor.

Member Function Documentation

void accept ( IOptionsParserVisitor visitor,
size_t  depth = 0 
)
inlinevirtual

Visitor design pattern.

Implements IOptionsParser.

Reimplemented in Option.

IProperties * getDefaultProperties ( )
virtual

Return the default properties

Returns
the default properties.

Implements IOptionsParser.

const std::string& getHelp ( ) const
inlinevirtual

Get help.

Implements IOptionsParser.

const std::string& getName ( ) const
inlinevirtual

Get name.

Implements IOptionsParser.

IOptionsParser * getParser ( const std::string &  name)
virtual

Get a parser given its name.

Parameters
[in]name: name of the parser to be retrieved
Returns
the parser instance if found, 0 otherwise.

Implements IOptionsParser.

Reimplemented in Option.

std::list<IOptionsParser*>& getParsers ( )
inlinevirtual

Get the children parsers.

Returns
a list of parsers.

Implements IOptionsParser.

misc::IProperties* getProperties ( )
inlinevirtual

Return the properties found during parsing.

Returns
the parsed properties.

Implements IOptionsParser.

bool isVisible ( ) const
inlinevirtual

Get visibility status.

Implements IOptionsParser.

misc::IProperties * parse ( int  argc,
char **  argv 
)
virtual

Perform the analyze of the arguments.

Parameters
[in]argc: number of command line arguments.
[in]argv: table of arguments
Returns
object with information about the parsing.

Implements IOptionsParser.

misc::IProperties * parseString ( const std::string &  s)
virtual

Perform the analyze of the arguments.

Parameters
[in]s: string containing the options to be parsed
Returns
object with information about the parsing.

Implements IOptionsParser.

void push_back ( IOptionsParser parser,
size_t  expandDepth = 0,
bool  visibility = true 
)
virtual

Add a parser child at the back of known parsers.

Parameters
[in]parser: the child parser
[in]expandDepth: while depth is less than expandDepth, put all the children and not the 'parser' itself.
[in]visibility: visibility status.

Implements IOptionsParser.

void push_front ( IOptionsParser parser,
size_t  expandDepth = 0,
bool  visibility = true 
)
virtual

Add a parser child at the front of known parsers.

Parameters
[in]parser: the child parser
[in]expandDepth: while depth is less than expandDepth, put all the children and not the 'parser' itself.
[in]visibility: visibility status.

Implements IOptionsParser.

bool saw ( const std::string &  name) const
virtual

Tells whether an option has been seen during parsing.

Parameters
[in]name: name of the option to be checked
Returns
true if option was found during parsing, false otherwise.

Implements IOptionsParser.

void setHelp ( const std::string &  help)
inlinevirtual

Set help

Parameters
[in]help: the help string

Implements IOptionsParser.

void setName ( const std::string &  name)
inlinevirtual

Associate a name to the parser.

Parameters
[in]name: the name of the parser.

Implements IOptionsParser.

void setVisible ( bool  status)
inlinevirtual

Set visibility status.

Implements IOptionsParser.


The documentation for this class was generated from the following files: