AJA NTV2 SDK  18.0.0.2717
NTV2 SDK 18.0.0.2717
AJACommandLineParser Class Reference

#include <commandline.h>

Public Member Functions

 AJACommandLineParser (int flags=0)
 
 AJACommandLineParser (const std::string &name, int flags=0)
 
 AJACommandLineParser (const AJACommandLineParser &other)
 
 ~AJACommandLineParser ()
 
void operator= (const AJACommandLineParser &other)
 
void SetFlags (int flags)
 
void Clear ()
 
void Reset (bool clearAll=false)
 
void Dump ()
 
bool HaveOption (const std::string &name) const
 
bool HavePositionalArg (const std::string &name) const
 
AJAStringList PositionalArgs () const
 
bool OptionByName (const std::string &name, AJACommandLineOption &opt) const
 
bool AddSubParser (AJACommandLineParser *sp)
 
bool Parse (const AJAStringList &args)
 
bool Parse (int argc, const char *argv[])
 
bool Parse (int argc, char *argv[])
 
bool IsSet (const std::string &name) const
 
AJAVariant Value (const std::string &name, size_t index=0) const
 
AJAVariantList Values (const std::string &name) const
 
std::string ValueString (const std::string &name, size_t index=0) const
 
AJAStringList ValueStrings (const std::string &name) const
 
bool AddOption (const AJACommandLineOption &option)
 
bool AddOptions (const std::vector< AJACommandLineOption > &options)
 
bool AddHelpOption (bool useShortName=false)
 
bool AddUsageOption (bool useShortName=false)
 
std::string Name () const
 
void SetUsageText (const std::string &usageText)
 
std::string UsageText ()
 
void SetHelpText (const std::string &helpText)
 
std::string HelpText ()
 
std::string CommandName ()
 

Detailed Description

Class that represents a command-line args parser.

Definition at line 179 of file commandline.h.

Constructor & Destructor Documentation

◆ AJACommandLineParser() [1/3]

AJACommandLineParser::AJACommandLineParser ( int  flags = 0)
explicit

Definition at line 155 of file commandline.cpp.

◆ AJACommandLineParser() [2/3]

AJACommandLineParser::AJACommandLineParser ( const std::string &  name,
int  flags = 0 
)
explicit

Definition at line 162 of file commandline.cpp.

◆ AJACommandLineParser() [3/3]

AJACommandLineParser::AJACommandLineParser ( const AJACommandLineParser other)

Definition at line 169 of file commandline.cpp.

◆ ~AJACommandLineParser()

AJACommandLineParser::~AJACommandLineParser ( )

Definition at line 174 of file commandline.cpp.

Member Function Documentation

◆ AddHelpOption()

bool AJACommandLineParser::AddHelpOption ( bool  useShortName = false)

Add default -?/–help option to this args parser. The caller must check if IsSet("help"), and then call HelpText, in order to retrieve the help text string for printing to the console.

Parameters
[in]useShortNameSpecify whether or not the help option should consume the '-h' shortname.

Definition at line 578 of file commandline.cpp.

◆ AddOption()

bool AJACommandLineParser::AddOption ( const AJACommandLineOption option)

Add a AJACommandLineOption to this args parser. This method will fail if another option with the same name has already been added to this parser.

Parameters
[in]optionThe AJACommandLineOption to add.
Returns
true if option was added successfully, otherwise false.

Definition at line 538 of file commandline.cpp.

◆ AddOptions()

bool AJACommandLineParser::AddOptions ( const std::vector< AJACommandLineOption > &  options)

Add a list of AJACommandLineOptions to this args parser. This method will fail if the list contains an option whose name has already been added to the args parser.

Parameters
[in]optionsThe list of AJACommandLineOptions to add.
Returns
true if options are added successfully, otherwise false.

Definition at line 563 of file commandline.cpp.

◆ AddSubParser()

bool AJACommandLineParser::AddSubParser ( AJACommandLineParser sp)

Register another AJACommandLineParser instance with this parser.

Parameters
[in]spThe subparser to add.
Returns
Returns true if the subparser was added successfully, otherwise false.

Definition at line 300 of file commandline.cpp.

◆ AddUsageOption()

bool AJACommandLineParser::AddUsageOption ( bool  useShortName = false)

Add default –usage option to this args parser. The caller must check if IsSet("usage"), and then call GetUsageText, in order to retrieve the usage text string for printing to the console.

Parameters
[in]useShortNameSpecify whether or not the usage option should consume the '-u' shortname.

Definition at line 590 of file commandline.cpp.

◆ Clear()

void AJACommandLineParser::Clear ( )

Delete all sub-parsers and options from this AJACommandLineParser.

Definition at line 209 of file commandline.cpp.

◆ CommandName()

std::string AJACommandLineParser::CommandName ( )
Returns
a copy of the command name string, if set; otherwise an empty string.

Definition at line 802 of file commandline.cpp.

◆ Dump()

void AJACommandLineParser::Dump ( )

Dump the contents of this AJACommandLineParser to stdout.

Definition at line 231 of file commandline.cpp.

◆ HaveOption()

bool AJACommandLineParser::HaveOption ( const std::string &  name) const

Determine this AJACommandLineParser has an option with the specified name.

Parameters
[in]nameThe name of the option to look up.
Returns
Returns true if the option is found, otherwise false.

Definition at line 260 of file commandline.cpp.

◆ HavePositionalArg()

bool AJACommandLineParser::HavePositionalArg ( const std::string &  name) const

Determine this AJACommandLineParser has a positional arg.

Parameters
[in]nameThe positional arg string to look up.
Returns
Returns true if the positional arg is found, otherwise false.

Definition at line 272 of file commandline.cpp.

◆ HelpText()

std::string AJACommandLineParser::HelpText ( )

Get the help text string for this args parser.

Returns
The help text string, if set, otherwise empty string.

Definition at line 655 of file commandline.cpp.

◆ IsSet()

bool AJACommandLineParser::IsSet ( const std::string &  name) const

Tests if the specified arg was set on the command-line.

Parameters
[in]nameThe arg name.
Returns
Returns true if the arg was set, otherwise false.

Definition at line 467 of file commandline.cpp.

◆ Name()

std::string AJACommandLineParser::Name ( ) const

Get the name of this command-line args parser.

Returns
The name of the parser, if any has been set, otherwise empty string.

Definition at line 601 of file commandline.cpp.

◆ operator=()

void AJACommandLineParser::operator= ( const AJACommandLineParser other)

Definition at line 178 of file commandline.cpp.

◆ OptionByName()

bool AJACommandLineParser::OptionByName ( const std::string &  name,
AJACommandLineOption opt 
) const

Look up AJACommandLineOption by name in this AJACommandLineParser.

Parameters
[in]nameThe name of the option to look up.
[out]optThe AJACommandLineOption to retrieve.
Returns
Returns true if the option is found, otherwise false.

Definition at line 287 of file commandline.cpp.

◆ Parse() [1/3]

bool AJACommandLineParser::Parse ( const AJAStringList args)

Parse a list of strings containing command-line args.

Parameters
[in]argsThe list of arg strings.
Returns
Returns true if the command-line args were parsed successfully, otherwise false.

Definition at line 311 of file commandline.cpp.

◆ Parse() [2/3]

bool AJACommandLineParser::Parse ( int  argc,
char *  argv[] 
)

Parse a list of strings containing command-line args.

Parameters
[in]argcThe arg count.
[in]argvThe list of arg strings.
Returns
Returns a non-zero exit code upon failure or use of –help or –usage.

Definition at line 455 of file commandline.cpp.

◆ Parse() [3/3]

bool AJACommandLineParser::Parse ( int  argc,
const char *  argv[] 
)

Parse a list of strings containing command-line args.

Parameters
[in]argcThe arg count.
[in]argvThe list of arg strings.
Returns
Returns a non-zero exit code upon failure or use of –help or –usage.

Definition at line 443 of file commandline.cpp.

◆ PositionalArgs()

AJAStringList AJACommandLineParser::PositionalArgs ( ) const

Get a vector containing all positional args parsed from the command line args.

Returns
Returns an AJAStringList of all positional args found.

Definition at line 282 of file commandline.cpp.

◆ Reset()

void AJACommandLineParser::Reset ( bool  clearAll = false)

Reset the values and "set" state of all sub-parsers and options in this AJACommandLineParser.

Parameters
[in]clearAllDelete all sub-parsers and options instead of resetting them?

Definition at line 215 of file commandline.cpp.

◆ SetFlags()

void AJACommandLineParser::SetFlags ( int  flags)

Override internal parser flags.

Definition at line 204 of file commandline.cpp.

◆ SetHelpText()

void AJACommandLineParser::SetHelpText ( const std::string &  helpText)

Set the help text string to print if help is invoked by the args parser.

Parameters
[in]helpTextThe help text string.

Definition at line 643 of file commandline.cpp.

◆ SetUsageText()

void AJACommandLineParser::SetUsageText ( const std::string &  usageText)

Set the usage text string to print if help is invoked by the args parser.

Parameters
[in]usageTextThe usage text string.

Definition at line 613 of file commandline.cpp.

◆ UsageText()

std::string AJACommandLineParser::UsageText ( )

Get the usage text string for this args parser.

Returns
The usage text string, if set, otherwise empty string.

Definition at line 625 of file commandline.cpp.

◆ Value()

AJAVariant AJACommandLineParser::Value ( const std::string &  name,
size_t  index = 0 
) const

Get a variant representing the value of the specified arg name.

Parameters
[in]nameThe arg name.
[in]indexThe index of the value to get.
Returns
AJAVariant representing the arg value, if the arg was set, otherwise 0.

Definition at line 483 of file commandline.cpp.

◆ Values()

AJAVariantList AJACommandLineParser::Values ( const std::string &  name) const

Get a list of variants representing the values of the specified arg name.

Parameters
[in]nameThe arg name.
Returns
AJAVariantList of values, empty if no values set.

Definition at line 488 of file commandline.cpp.

◆ ValueString()

std::string AJACommandLineParser::ValueString ( const std::string &  name,
size_t  index = 0 
) const

Get the string value for the specified arg name.

Parameters
[in]nameThe arg name.
[in]indexThe index of value to get.
Returns
std::string value of the arg, if set, otherwise empty std::string.

Definition at line 501 of file commandline.cpp.

◆ ValueStrings()

AJAStringList AJACommandLineParser::ValueStrings ( const std::string &  name) const

Get a list of string values for the specified arg name.

Parameters
[in]nameThe arg name.
Returns
AJAStringList of string values, empty if no values set.

Definition at line 522 of file commandline.cpp.


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