Rudiments
Public Member Functions | List of all members
commandline Class Reference

Inherits object.

Public Member Functions

 commandline ()
 
 commandline (int32_t argc, const char **argv)
 
 ~commandline ()
 
void setArgumentCount (int32_t argc)
 
int32_t getArgumentCount ()
 
void setArgumentValues (const char **argv)
 
const char ** getArgumentValues ()
 
void setArguments (int32_t argc, const char **argv)
 
const char * getValue (const char *arg)
 
const char * getValue (const char *arg, const char *abbr)
 
bool isFound (const char *arg)
 
bool isFound (const char *arg, const char *abbr)
 
void convertToDictionary (dictionary< char *, char * > *dict)
 
bool clear ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The commandline class provides methods for parsing command line arguments.

Constructor & Destructor Documentation

◆ commandline() [1/2]

commandline::commandline ( )

Creates an instance of the commandline class.

◆ commandline() [2/2]

commandline::commandline ( int32_t  argc,
const char **  argv 
)

Creates an instance of the commandline class and sets its argument count and arguments to "argc" and "argv".

◆ ~commandline()

commandline::~commandline ( )

Deletes this instance of the commandline class.

Member Function Documentation

◆ clear()

bool commandline::clear ( )

Clears the argument count and argument values. Always returns true.

◆ convertToDictionary()

void commandline::convertToDictionary ( dictionary< char *, char * > *  dict)

Parses the command line into the supplied dictionary.

If an argument has no value, then the value for that key in the dictionary is set to an empty string.

◆ getArgumentCount()

int32_t commandline::getArgumentCount ( )

Returns the argument count.

◆ getArgumentValues()

const char** commandline::getArgumentValues ( )

Returns the argument values.

◆ getValue() [1/2]

const char* commandline::getValue ( const char *  arg)

Looks for either: -arg value or –arg=value on the command line and returns value.

Returns an empty string if just -arg or –arg is found, or NULL if neither are found.

◆ getValue() [2/2]

const char* commandline::getValue ( const char *  arg,
const char *  abbr 
)

Looks for the argument or an abbreviated version of it on the command line and returns the value.

For example, if "arg" is "name" and "abbr" is "n" then it looks for either:

-name value

or –name=value or -n value or –n==value

on the command line and returns value.

If both "arg" and "abbr" are found then the value for "arg" is returned.

Returns an empty string if just -name, –name, -n, or –n is found, or NULL if none are found.

◆ isFound() [1/2]

bool commandline::isFound ( const char *  arg)

Returns true if "-arg", "--arg" or "--arg=value" was found on the command line and false if it was not found.

This is useful for processing command line switches.

◆ isFound() [2/2]

bool commandline::isFound ( const char *  arg,
const char *  abbr 
)

Returns true if the argument or an abbreviated version of it was found on the command line and false if neither were found.

For example, if "arg" is "recursive" and "abbr" is "r" then it returns true if "-recursive", "--recursive", "-r", or "--r" was found on the command line.

This is useful for processing command line switches.

◆ setArgumentCount()

void commandline::setArgumentCount ( int32_t  argc)

Sets the argument count to "argc".

◆ setArguments()

void commandline::setArguments ( int32_t  argc,
const char **  argv 
)

Sets the argument count to "argc" and arguments to "argv".

◆ setArgumentValues()

void commandline::setArgumentValues ( const char **  argv)

Sets the argument values to "argv".