#include <commandlineparser.h>
|
| | CommandLineParser () |
| |
| | CommandLineParser (const char *) |
| |
| | CommandLineParser (const CommandLineParser &)=delete |
| |
| | CommandLineParser (int argc, char **argv) |
| |
| virtual | ~CommandLineParser () |
| |
| BufferString | envVarBase () const |
| |
| const OD::String & | getArg (int idx) const |
| |
| const OD::String & | getExecutable () const |
| |
| const OD::String & | getExecutableName () const |
| |
| BufferString | getFullSurveyPath (bool *iscursur=nullptr) const |
| |
| void | getNormalArguments (BufferStringSet &) const |
| |
| bool | getVal (const char *key, BufferString &, bool acceptnone=false, int valnr=1) const |
| |
| bool | getVal (const char *key, BufferStringSet &, bool acceptnone=false) const |
| |
| bool | getVal (const char *key, DBKey &, bool acceptnone=false, int valnr=1) const |
| |
| bool | getVal (const char *key, FilePath &, bool acceptnone=false, int valnr=1) const |
| |
| template<class T > |
| bool | getVal (const char *key, T &, bool acceptnone=false, int valnr=1) const |
| |
| template<class T > |
| bool | getVal (const char *key, TypeSet< T > &, bool acceptnone=false) const |
| |
| bool | hasKey (const char *) const |
| |
| bool | isKey (int) const |
| | Does the arg start with - or –.
|
| |
| bool | isKeyValue (int idx) const |
| |
| bool | isPresent (const char *) const |
| | Is string present as an argument.
|
| |
| BufferString | keyedString (const char *ky, int argnr=0) const |
| |
| template<class T > |
| T | keyedValue (const char *ky, int argnr=0) const |
| |
| const OD::String & | lastArg () const |
| |
| int | nrArgs () const |
| |
| CommandLineParser & | operator= (const CommandLineParser &)=delete |
| |
| void | setKeyHasValue (const char *key, int nrvals=1) const |
| |
Parser that takes the argc and argv and makes them parsable. An argument starting with – is considered a key, as well as arguments starting with "-", if not imedialtely followed by a number. Hence -create is a key, -9 or -.3 are not.
"bin/my_prog --nriter 4 parfile1.par --fast parfile2.par" can be parsed as follows:
int nriter;
if ( !parser.
getVal(
"nriter", nriter ) )
return false;
const bool fast = parser.
hasKey(
"fast");
return false;
Set of BufferString objects.
Definition bufstringset.h:24
bool isEmpty() const
Definition bufstringset.h:42
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition bufstring.h:38
Definition commandlineparser.h:49
void getNormalArguments(BufferStringSet &) const
bool hasKey(const char *) const
const OD::String & getExecutable() const
bool getVal(const char *key, BufferString &, bool acceptnone=false, int valnr=1) const
void setKeyHasValue(const char *key, int nrvals=1) const
<>
◆ CommandLineParser() [1/4]
| CommandLineParser::CommandLineParser |
( |
const char * | | ) |
|
◆ CommandLineParser() [2/4]
| CommandLineParser::CommandLineParser |
( |
int | argc, |
|
|
char ** | argv ) |
◆ CommandLineParser() [3/4]
| CommandLineParser::CommandLineParser |
( |
| ) |
|
Actual command line is used, i.e. the one set by SetProgramArgs
◆ ~CommandLineParser()
| virtual CommandLineParser::~CommandLineParser |
( |
| ) |
|
|
virtual |
◆ CommandLineParser() [4/4]
◆ addFilePath()
| static void CommandLineParser::addFilePath |
( |
const char * | , |
|
|
BufferString & | cmd ) |
|
static |
adds "\ and \" to protect for spaces in FilePaths
◆ addKey()
| static void CommandLineParser::addKey |
( |
const char * | key, |
|
|
BufferString & | cmd, |
|
|
const char * | valstr = 0 ) |
|
static |
adds a space before but not after
◆ createKey() [1/2]
| static BufferString CommandLineParser::createKey |
( |
const char * | key | ) |
|
|
inlinestatic |
◆ createKey() [2/2]
| static void CommandLineParser::createKey |
( |
const char * | key, |
|
|
BufferString & | res ) |
|
inlinestatic |
◆ ensureNrArgs()
| void CommandLineParser::ensureNrArgs |
( |
const char * | , |
|
|
int | ) const |
|
private |
◆ envVarBase()
◆ getArg()
| const OD::String & CommandLineParser::getArg |
( |
int | idx | ) |
const |
|
inline |
◆ getExecutable()
| const OD::String & CommandLineParser::getExecutable |
( |
| ) |
const |
◆ getExecutableName()
| const OD::String & CommandLineParser::getExecutableName |
( |
| ) |
const |
◆ getFullSurveyPath()
| BufferString CommandLineParser::getFullSurveyPath |
( |
bool * | iscursur = nullptr | ) |
const |
◆ getNormalArguments()
Gets all arguments that are not keys or key-values.
◆ getVal() [1/6]
| bool CommandLineParser::getVal |
( |
const char * | key, |
|
|
BufferString & | , |
|
|
bool | acceptnone = false, |
|
|
int | valnr = 1 ) const |
◆ getVal() [2/6]
| bool CommandLineParser::getVal |
( |
const char * | key, |
|
|
BufferStringSet & | , |
|
|
bool | acceptnone = false ) const |
◆ getVal() [3/6]
| bool CommandLineParser::getVal |
( |
const char * | key, |
|
|
DBKey & | , |
|
|
bool | acceptnone = false, |
|
|
int | valnr = 1 ) const |
◆ getVal() [4/6]
| bool CommandLineParser::getVal |
( |
const char * | key, |
|
|
FilePath & | , |
|
|
bool | acceptnone = false, |
|
|
int | valnr = 1 ) const |
◆ getVal() [5/6]
template<class T >
| bool CommandLineParser::getVal |
( |
const char * | key, |
|
|
T & | val, |
|
|
bool | acceptnone = false, |
|
|
int | valnr = 1 ) const |
|
inline |
Will parse argument valnr following key. If acceptnone is true, it will only give error if key is found, but no value can be parsed.
◆ getVal() [6/6]
template<class T >
| bool CommandLineParser::getVal |
( |
const char * | key, |
|
|
TypeSet< T > & | vals, |
|
|
bool | acceptnone = false ) const |
|
inline |
◆ hasKey()
| bool CommandLineParser::hasKey |
( |
const char * | | ) |
const |
◆ indexOf()
| int CommandLineParser::indexOf |
( |
const char * | , |
|
|
TypeSet< int > * | idxs = nullptr ) const |
|
private |
◆ init() [1/2]
| void CommandLineParser::init |
( |
const char * | | ) |
|
|
private |
◆ init() [2/2]
| void CommandLineParser::init |
( |
int | , |
|
|
char ** | ) |
|
private |
◆ isKey()
| bool CommandLineParser::isKey |
( |
int | | ) |
const |
Does the arg start with - or –.
◆ isKeyValue()
| bool CommandLineParser::isKeyValue |
( |
int | idx | ) |
const |
True if not a key, and previous is a key that has been set using setKeyHasValue.
◆ isPresent()
| bool CommandLineParser::isPresent |
( |
const char * | | ) |
const |
Is string present as an argument.
◆ keyedString()
| BufferString CommandLineParser::keyedString |
( |
const char * | ky, |
|
|
int | argnr = 0 ) const |
|
inline |
◆ keyedValue()
template<class T >
| T CommandLineParser::keyedValue |
( |
const char * | ky, |
|
|
int | argnr = 0 ) const |
|
inline |
◆ lastArg()
| const OD::String & CommandLineParser::lastArg |
( |
| ) |
const |
◆ nrArgs()
| int CommandLineParser::nrArgs |
( |
| ) |
const |
|
inline |
- Returns
- the lump sum (keys, values, and everything else, but program name
◆ operator=()
◆ sDataRootArg()
| static const char * CommandLineParser::sDataRootArg |
( |
| ) |
|
|
inlinestatic |
◆ sDefTransl()
| static const char * CommandLineParser::sDefTransl |
( |
| ) |
|
|
inlinestatic |
◆ setKeyHasValue()
| void CommandLineParser::setKeyHasValue |
( |
const char * | key, |
|
|
int | nrvals = 1 ) const |
Tell the parser that the nrvals arguments after key are values. nrvals<1 denotes a variable number of values, running up to the next key. This function is only needed if you will use getNormalArguments.
◆ sNeedTempSurv()
| static const char * CommandLineParser::sNeedTempSurv |
( |
| ) |
|
|
inlinestatic |
◆ sSurveyArg()
| static const char * CommandLineParser::sSurveyArg |
( |
| ) |
|
|
inlinestatic |
◆ argv_
◆ executable_
◆ keyswithvalue_
◆ nrvalues_
| TypeSet<int> CommandLineParser::nrvalues_ |
|
private |
◆ progname_