library of assembled shared sources

http://lass.cocamware.com

lass::io::ArgParser Class Reference
[ArgParser]

the parser itself More...

#include <arg_parser.h>


Public Types

typedef std::vector< std::string > TArguments

Public Member Functions

 ArgParser ()
 Construct a quiet parser.
 ArgParser (const std::string &iProgramName, const std::string &iVersion="", const std::string &iPositionalArguments="")
 Construct a not so quiet parser.
bool parse (const std::string &iArguments, TArguments *oPositionals=0)
 parse arguments that come by a string.
bool parse (const TArguments &iArguments, TArguments *oPositionals=0)
 parse arguments
bool parse (int iArgc, char *iArgv[], TArguments *oPositionals=0)
 parse arguments from commandline
std::string usage () const

Private Types

typedef std::vector
< ArgParameter * > 
TParameters
typedef TParameters::size_type TSize

Private Member Functions

void subscribe (ArgParameter &iArg)
bool parseShort (const TArguments &iArguments, TSize &ioIndex)
bool parseLong (const TArguments &iArguments, TSize iIndex)
bool isValidLongName (const std::string &iLongName) const
 long names can only exists of alphanumerics and some extra characters '-'.
bool writeVersionOrHelp (const std::string &iArgument) const
void writeVersion () const
void writeHelp () const

Private Attributes

std::string programName_
std::string programVersion_
std::string positionals_
TParameters parameters_
bool isQuiet_

Friends

class ArgParameter


Detailed Description

the parser itself

Definition at line 99 of file arg_parser.h.


Member Typedef Documentation

typedef std::vector<std::string> lass::io::ArgParser::TArguments

Definition at line 103 of file arg_parser.h.

typedef std::vector<ArgParameter*> lass::io::ArgParser::TParameters [private]

Definition at line 120 of file arg_parser.h.

typedef TParameters::size_type lass::io::ArgParser::TSize [private]

Definition at line 121 of file arg_parser.h.


Constructor & Destructor Documentation

lass::io::ArgParser::ArgParser (  ) 

Construct a quiet parser.

A quiet parser won't write anything to the output (it will still log though), and it will throw as few exceptions as possible

Definition at line 59 of file arg_parser.cpp.

lass::io::ArgParser::ArgParser ( const std::string &  iProgramName,
const std::string &  iProgramVersion = "",
const std::string &  iPositionalArguments = "" 
)

Construct a not so quiet parser.

On wrong input, it will write info to the standard input and will throw some more exceptions.

Definition at line 72 of file arg_parser.cpp.


Member Function Documentation

bool lass::io::ArgParser::parse ( const std::string &  iArguments,
TArguments oPositionals = 0 
)

parse arguments that come by a string.

break string based on whitespace unless it's surrounded by quotes.

Note:
You shouldn't start the string with the program name like argc/argv do. The string will be parsed from the beginning, so the program name would be seen as the first positional if you did.

Definition at line 162 of file arg_parser.cpp.

References lass::stde::impl::whitespace().

Referenced by parse().

bool lass::io::ArgParser::parse ( const TArguments iArguments,
TArguments oPositionals = 0 
)

parse arguments

Note:
in contrary like argc/argv , you shouldn't store the program name as the first argument, since the parser will start with iArguments[0] . Hence, the parser would see the program name as the first positional if you did so.

Definition at line 89 of file arg_parser.cpp.

References parseLong(), and parseShort().

bool lass::io::ArgParser::parse ( int  iArgc,
char *  iArgv[],
TArguments oPositionals = 0 
)

parse arguments from commandline

Note:
we suppose iArgv[0] is the program name and will skipped by the parser. the parser will only take care of iArgv[1] and the following!

Definition at line 146 of file arg_parser.cpp.

References parse().

std::string lass::io::ArgParser::usage (  )  const

Definition at line 241 of file arg_parser.cpp.

References parameters_, positionals_, and programName_.

Referenced by parseLong(), parseShort(), and writeHelp().

void lass::io::ArgParser::subscribe ( ArgParameter iArg  )  [private]

bool lass::io::ArgParser::parseShort ( const TArguments iArguments,
TSize ioIndex 
) [private]

bool lass::io::ArgParser::parseLong ( const TArguments iArguments,
TSize  iIndex 
) [private]

bool lass::io::ArgParser::isValidLongName ( const std::string &  iLongName  )  const [private]

long names can only exists of alphanumerics and some extra characters '-'.

Definition at line 513 of file arg_parser.cpp.

Referenced by parseLong(), and subscribe().

bool lass::io::ArgParser::writeVersionOrHelp ( const std::string &  iArgument  )  const [private]

Definition at line 530 of file arg_parser.cpp.

References writeHelp(), and writeVersion().

Referenced by parseLong(), and parseShort().

void lass::io::ArgParser::writeVersion (  )  const [private]

Definition at line 547 of file arg_parser.cpp.

References LASS_COUT, programName_, and programVersion_.

Referenced by writeHelp(), and writeVersionOrHelp().

void lass::io::ArgParser::writeHelp (  )  const [private]

Definition at line 554 of file arg_parser.cpp.

References LASS_COUT, usage(), and writeVersion().

Referenced by writeVersionOrHelp().


Friends And Related Function Documentation

friend class ArgParameter [friend]

Definition at line 118 of file arg_parser.h.


Field Documentation

std::string lass::io::ArgParser::programName_ [private]

Definition at line 131 of file arg_parser.h.

Referenced by usage(), and writeVersion().

std::string lass::io::ArgParser::programVersion_ [private]

Definition at line 132 of file arg_parser.h.

Referenced by writeVersion().

std::string lass::io::ArgParser::positionals_ [private]

Definition at line 133 of file arg_parser.h.

Referenced by usage().

Definition at line 134 of file arg_parser.h.

Referenced by parseLong(), parseShort(), subscribe(), and usage().

Definition at line 135 of file arg_parser.h.

Referenced by parseLong(), lass::io::ArgParameter::parserIsQuiet(), and parseShort().


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

Generated on Mon Nov 10 14:22:09 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo