Jetson Inference
DNN Vision Library

Command line parser for extracting flags, values, and strings. More...

#include <commandLine.h>

Public Member Functions

 commandLine (const int argc, char **argv, const char *extraFlag=NULL)
 Constructor, takes the command line from main() More...
 
 commandLine (const int argc, char **argv, const char **extraArgs)
 Constructor, takes the command line from main() More...
 
bool GetFlag (const char *argName, bool allowOtherDelimiters=true) const
 Checks to see whether the specified flag was included on the command line. More...
 
float GetFloat (const char *argName, float defaultValue=0.0f, bool allowOtherDelimiters=true) const
 Get float argument. More...
 
int GetInt (const char *argName, int defaultValue=0, bool allowOtherDelimiters=true) const
 Get integer argument. More...
 
uint32_t GetUnsignedInt (const char *argName, uint32_t defaultValue=0, bool allowOtherDelimiters=true) const
 Get unsigned integer argument. More...
 
const char * GetString (const char *argName, const char *defaultValue=NULL, bool allowOtherDelimiters=true) const
 Get string argument. More...
 
const char * GetPosition (unsigned int position, const char *defaultValue=NULL) const
 Get positional string argument. More...
 
unsigned int GetPositionArgs () const
 Get the number of positional arguments in the command line. More...
 
void AddArg (const char *arg)
 Add an argument to the command line. More...
 
void AddArgs (const char **args)
 Add arguments to the command line. More...
 
void AddFlag (const char *flag)
 Add a flag to the command line. More...
 
void Print () const
 Print out the command line for reference. More...
 

Public Attributes

int argc
 The argument count that the object was created with from main() More...
 
char ** argv
 The argument strings that the object was created with from main() More...
 

Detailed Description

Command line parser for extracting flags, values, and strings.

Constructor & Destructor Documentation

◆ commandLine() [1/2]

commandLine::commandLine ( const int  argc,
char **  argv,
const char *  extraFlag = NULL 
)

Constructor, takes the command line from main()

◆ commandLine() [2/2]

commandLine::commandLine ( const int  argc,
char **  argv,
const char **  extraArgs 
)

Constructor, takes the command line from main()

Member Function Documentation

◆ AddArg()

void commandLine::AddArg ( const char *  arg)

Add an argument to the command line.

◆ AddArgs()

void commandLine::AddArgs ( const char **  args)

Add arguments to the command line.

◆ AddFlag()

void commandLine::AddFlag ( const char *  flag)

Add a flag to the command line.

◆ GetFlag()

bool commandLine::GetFlag ( const char *  argName,
bool  allowOtherDelimiters = true 
) const

Checks to see whether the specified flag was included on the command line.

For example, if argv contained --foo, then GetFlag("foo") would return true

Parameters
allowOtherDelimitersif true (default), the argName will be matched against occurances containing either - or _.
For example, --foo-bar and --foo_bar would be the same.
Returns
true, if the flag with argName was found false, if the flag with argName was not found

◆ GetFloat()

float commandLine::GetFloat ( const char *  argName,
float  defaultValue = 0.0f,
bool  allowOtherDelimiters = true 
) const

Get float argument.

For example if argv contained --foo=3.14159, then GetInt("foo") would return 3.14159f

Parameters
allowOtherDelimitersif true (default), the argName will be matched against occurances containing either - or _.
For example, --foo-bar and --foo_bar would be the same.
Returns
defaultValue if the argument couldn't be found. (0.0 by default). Otherwise, returns the value of the argument.

◆ GetInt()

int commandLine::GetInt ( const char *  argName,
int  defaultValue = 0,
bool  allowOtherDelimiters = true 
) const

Get integer argument.

For example if argv contained --foo=100, then GetInt("foo") would return 100

Parameters
allowOtherDelimitersif true (default), the argName will be matched against occurances containing either - or _.
For example, --foo-bar and --foo_bar would be the same.
Returns
defaultValue if the argument couldn't be found (0 by default). Otherwise, returns the value of the argument.

◆ GetPosition()

const char* commandLine::GetPosition ( unsigned int  position,
const char *  defaultValue = NULL 
) const

Get positional string argument.

Positional arguments aren't named, but rather referenced by their index in the list. For example if the command line contained my-program --foo=bar /path/to/my_file.txt, then GetString(0) would return `"/path/to/my_file.txt"

Returns
defaultValue if the argument couldn't be found (NULL by default). Otherwise, returns a pointer to the argument value string from the argv array.

◆ GetPositionArgs()

unsigned int commandLine::GetPositionArgs ( ) const

Get the number of positional arguments in the command line.

Positional arguments are those that don't have a name.

◆ GetString()

const char* commandLine::GetString ( const char *  argName,
const char *  defaultValue = NULL,
bool  allowOtherDelimiters = true 
) const

Get string argument.

For example if argv contained --foo=bar, then GetString("foo") would return "bar"

Parameters
allowOtherDelimitersif true (default), the argName will be matched against occurances containing either - or _.
For example, --foo-bar and --foo_bar would be the same.
Returns
defaultValue if the argument couldn't be found (NULL by default). Otherwise, returns a pointer to the argument value string from the argv array.

◆ GetUnsignedInt()

uint32_t commandLine::GetUnsignedInt ( const char *  argName,
uint32_t  defaultValue = 0,
bool  allowOtherDelimiters = true 
) const

Get unsigned integer argument.

For example if argv contained --foo=100, then GetUnsignedInt("foo") would return 100

Parameters
allowOtherDelimitersif true (default), the argName will be matched against occurances containing either - or _.
For example, --foo-bar and --foo_bar would be the same.
Returns
defaultValue if the argument couldn't be found, or if the value was negative (0 by default). Otherwise, returns the parsed value.

◆ Print()

void commandLine::Print ( ) const

Print out the command line for reference.

Member Data Documentation

◆ argc

int commandLine::argc

The argument count that the object was created with from main()

◆ argv

char** commandLine::argv

The argument strings that the object was created with from main()


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