library of assembled shared sources |
http://lass.cocamware.com |
#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 |
Definition at line 99 of file arg_parser.h.
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.
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.
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.
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
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
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] |
Definition at line 269 of file arg_parser.cpp.
References isValidLongName(), LASS_THROW, lass::io::ArgParameter::longName(), parameters_, and lass::io::ArgParameter::shortName().
Referenced by lass::io::ArgParameter::ArgParameter().
bool lass::io::ArgParser::parseShort | ( | const TArguments & | iArguments, | |
TSize & | ioIndex | |||
) | [private] |
Definition at line 317 of file arg_parser.cpp.
References lass::io::amNoValue, isQuiet_, LASS_ASSERT, LASS_COUT, lass::io::ArgParameter::mode(), parameters_, lass::io::ArgParameter::setValue(), lass::io::ArgParameter::shortName(), usage(), and writeVersionOrHelp().
Referenced by parse().
bool lass::io::ArgParser::parseLong | ( | const TArguments & | iArguments, | |
TSize | iIndex | |||
) | [private] |
Definition at line 406 of file arg_parser.cpp.
References isQuiet_, isValidLongName(), LASS_ASSERT, LASS_COUT, lass::io::ArgParameter::longName(), parameters_, usage(), and writeVersionOrHelp().
Referenced by parse().
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().
friend class ArgParameter [friend] |
Definition at line 118 of file arg_parser.h.
std::string lass::io::ArgParser::programName_ [private] |
std::string lass::io::ArgParser::programVersion_ [private] |
std::string lass::io::ArgParser::positionals_ [private] |
TParameters lass::io::ArgParser::parameters_ [private] |
Definition at line 134 of file arg_parser.h.
Referenced by parseLong(), parseShort(), subscribe(), and usage().
bool lass::io::ArgParser::isQuiet_ [private] |
Definition at line 135 of file arg_parser.h.
Referenced by parseLong(), lass::io::ArgParameter::parserIsQuiet(), and parseShort().
Generated on Mon Nov 10 14:22:09 2008 for Library of Assembled Shared Sources by 1.5.7.1 |