CLRX  1
An unofficial OpenCL extensions designed for Radeon GPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Public Member Functions | List of all members
CLRX::CLIParser Class Reference

The Command Line Parser (parses options and their arguments) More...

#include <CLIParser.h>

Inheritance diagram for CLRX::CLIParser:
CLRX::NonCopyableAndNonMovable

Classes

struct  OptTypeTrait< bool * >
 Option type trait for bool* type. More...
 
struct  OptTypeTrait< bool >
 Option type trait for boolean type. More...
 
struct  OptTypeTrait< const char * >
 Option type trait for const char* type. More...
 
struct  OptTypeTrait< const char ** >
 Option type trait for const char** type. More...
 
struct  OptTypeTrait< cxint * >
 Option type trait for cxint* type. More...
 
struct  OptTypeTrait< cxint >
 Option type trait for cxint type. More...
 
struct  OptTypeTrait< cxllong * >
 Option type trait for cxllong* type. More...
 
struct  OptTypeTrait< cxllong >
 Option type trait for cxllong type. More...
 
struct  OptTypeTrait< cxlong * >
 Option type trait for cxlong* type. More...
 
struct  OptTypeTrait< cxlong >
 Option type trait for cxlong type. More...
 
struct  OptTypeTrait< cxuint * >
 Option type trait for cxuint* type. More...
 
struct  OptTypeTrait< cxuint >
 Option type trait for cxuint type. More...
 
struct  OptTypeTrait< cxullong * >
 Option type trait for cxullong* type. More...
 
struct  OptTypeTrait< cxullong >
 Option type trait for cxullong type. More...
 
struct  OptTypeTrait< cxulong * >
 Option type trait for cxulong* type. More...
 
struct  OptTypeTrait< cxulong >
 Option type trait for cxulong type. More...
 
struct  OptTypeTrait< double * >
 Option type trait for double* type. More...
 
struct  OptTypeTrait< double >
 Option type trait for double type. More...
 
struct  OptTypeTrait< float * >
 Option type trait for float* type. More...
 
struct  OptTypeTrait< float >
 Option type trait for float type. More...
 

Public Member Functions

 CLIParser (const char *programName, const CLIOption *options, cxuint argc, const char **argv)
 constructor More...
 
void setPackageName (const char *pkgName)
 set package name
 
void parse ()
 parse options from arguments
 
bool handleHelpOrUsage (std::ostream &os=std::cout) const
 handle printing of help or usage. returns false when help or usage not enabled
 
cxuint findOption (char shortName) const
 find option by shortName, returns optionId
 
cxuint findOption (const char *longName) const
 find option by longName, returns optionId
 
template<typename T >
getOptArg (cxuint optionId) const
 get option argument if it provided
 
template<typename T >
getShortOptArg (char shortName) const
 get option argument if it provided
 
template<typename T >
getLongOptArg (const char *longName) const
 get option argument if it provided
 
template<typename T >
const T * getOptArgArray (cxuint optionId, size_t &length) const
 get option argument array if it provided More...
 
template<typename T >
const T * getShortOptArgArray (char shortName, size_t &length) const
 get option argument array if it provided More...
 
template<typename T >
const T * getLongOptArgArray (const char *longName, size_t &length) const
 get option argument array if it provided More...
 
bool hasOptArg (cxuint optionId) const
 returns true when argument provided for specified option
 
bool hasShortOptArg (char shortName) const
 returns true when argument provided for specified option
 
bool hasLongOptArg (const char *longName) const
 returns true when argument provided for specified option
 
bool hasOption (cxuint optionId) const
 returns true if option included in command line
 
bool hasShortOption (char shortName) const
 returns true if option included in command line
 
bool hasLongOption (const char *longName) const
 returns true if option included in command line
 
cxuint getArgsNum () const
 get left over arguments number
 
const char *const * getArgs () const
 get left over arguments (null-terminated)
 
void printHelp (std::ostream &os=std::cout) const
 print help for program (lists options)
 
void printUsage (std::ostream &os=std::cout) const
 print usage
 
void printVersion (std::ostream &os=std::cout) const
 print version
 
- Public Member Functions inherited from CLRX::NonCopyableAndNonMovable
 NonCopyableAndNonMovable ()
 constructor
 
 NonCopyableAndNonMovable (const NonCopyableAndNonMovable &)=delete
 copy-constructor
 
 NonCopyableAndNonMovable (NonCopyableAndNonMovable &&)=delete
 move-constructor
 
NonCopyableAndNonMovableoperator= (const NonCopyableAndNonMovable &)=delete
 copy-assignment
 
NonCopyableAndNonMovableoperator= (NonCopyableAndNonMovable &&)=delete
 move-asignment
 

Detailed Description

The Command Line Parser (parses options and their arguments)

This class implements a command-line parser which provides short options and long options with/without arguments. Argument can be a string, number, boolean, and list of previous. Conventions of the option's (and their arguments) syntax was adapted from popt library.

Option argument can be attached in the next argument or in the rest of the argument (after '=' or not for short options). If argument option is optional then can be attached in a next argument only when argument does not have option (otherwise argument will be treated likes next option).

Elements of option argument array are separated by comma. Commas and backslashes can be entered by using backslash escapes in a string array element. An element of string array can also be empty.

Option identified by optionId which is order number. First optionId is 0. Option can have short name, long name or both. Option without argument must have argType set likes CLIArgType::NONE (no type, no argument). Argument name (argName) is optional (can be null).

IMPORTANT NOTICE: Option's list and argument's list must be available and unmodified while whole lifecycle of this CLIParser. For whole lifecycle of any option argument or left over argument, a CLIParser must be alive. (because it keeps values of these arguments).

Constructor & Destructor Documentation

CLRX::CLIParser::CLIParser ( const char *  programName,
const CLIOption options,
cxuint  argc,
const char **  argv 
)

constructor

Parameters
programNamename of program
optionsnull-terminated (shortName==0, longName==NULL) options list
argcargc
argvargv

Member Function Documentation

template<typename T >
const T* CLRX::CLIParser::getOptArgArray ( cxuint  optionId,
size_t &  length 
) const
inline

get option argument array if it provided

Parameters
optionIdid of option
lengthlength of array
Returns
argument array
template<typename T >
const T* CLRX::CLIParser::getShortOptArgArray ( char  shortName,
size_t &  length 
) const
inline

get option argument array if it provided

Parameters
shortNameshort name of option
lengthlength of array
Returns
argument array
template<typename T >
const T* CLRX::CLIParser::getLongOptArgArray ( const char *  longName,
size_t &  length 
) const
inline

get option argument array if it provided

Parameters
longNamelong name of option
lengthlength of array
Returns
argument value

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