Classes | |
struct | TRTOption |
TRTOption defines a command line option. More... | |
struct | TRTParsedArgs |
TRTParsedArgs is returned by getOptions after it has parsed a command line argument list (argv). More... | |
Functions | |
bool | matches (const TRTOption &a, const TRTOption &b) |
Matching for TRTOptions is defined as follows: More... | |
int | getTRTOptionIndex (const std::vector< TRTOption > &options, const TRTOption &opt) |
getTRTOptionIndex returns the index of a TRTOption in a vector of TRTOptions, -1 if not found. More... | |
std::string | validateTRTOption (const std::set< char > &seenShortNames, const std::set< std::string > &seenLongNames, const TRTOption &opt) |
validateTRTOption will return a string containing an error message if options contain non-numeric characters, or if there are duplicate option names found. More... | |
std::string | validateTRTOptions (const std::vector< TRTOption > &options) |
validateTRTOptions will return a string containing an error message if any options contain non-numeric characters, or if there are duplicate option names found. More... | |
TRTParsedArgs | parseArgs (int argc, const char *const *argv, const std::vector< TRTOption > &options) |
parseArgs parses an argument list and returns a TRTParsedArgs with the fields set accordingly. More... | |
TRTParsedArgs | getOptions (int argc, const char *const *argv, const std::vector< TRTOption > &options) |
Parse the input arguments passed to main() and extract options as well as positional arguments. More... | |
Matching for TRTOptions is defined as follows:
If A and B both have longName set, A matches B if and only if A.longName == B.longName and (A.shortName == B.shortName if both have short name set).
If A only has shortName set and B only has longName set, then A does not match B. It is assumed that when 2 TRTOptions are compared, one of them is the definition of a TRTOption in the input to getOptions. As such, if the definition only has shortName set, it will never be equal to a TRTOption that does not have shortName set (and same for longName).
If A and B both have shortName set but B does not have longName set, A matches B if and only if A.shortName == B.shortName.
If A has neither long or short name set, A matches B if and only if B has neither long or short name set.
int nvinfer1::utility::getTRTOptionIndex | ( | const std::vector< TRTOption > & | options, |
const TRTOption & | opt | ||
) |
getTRTOptionIndex returns the index of a TRTOption in a vector of TRTOptions, -1 if not found.
std::string nvinfer1::utility::validateTRTOption | ( | const std::set< char > & | seenShortNames, |
const std::set< std::string > & | seenLongNames, | ||
const TRTOption & | opt | ||
) |
validateTRTOption will return a string containing an error message if options contain non-numeric characters, or if there are duplicate option names found.
Otherwise, returns the empty string.
std::string nvinfer1::utility::validateTRTOptions | ( | const std::vector< TRTOption > & | options | ) |
validateTRTOptions will return a string containing an error message if any options contain non-numeric characters, or if there are duplicate option names found.
Otherwise, returns the empty string.
TRTParsedArgs nvinfer1::utility::parseArgs | ( | int | argc, |
const char *const * | argv, | ||
const std::vector< TRTOption > & | options | ||
) |
parseArgs parses an argument list and returns a TRTParsedArgs with the fields set accordingly.
Assumes that options is validated. ErrMsg will be set if:
TRTParsedArgs nvinfer1::utility::getOptions | ( | int | argc, |
const char *const * | argv, | ||
const std::vector< TRTOption > & | options | ||
) |
Parse the input arguments passed to main() and extract options as well as positional arguments.
Options are supposed to be passed to main() with a preceding hyphen '-'.
If there is a single preceding hyphen, there should be exactly 1 character after the hyphen, which is interpreted as the option.
If there are 2 preceding hyphens, the entire argument (without the hyphens) is interpreted as the option.
If the option requires a value, the next argument is used as the value.
Positional arguments must not start with a hyphen.
If an argument requires a value, the next argument is interpreted as the value, even if it is the form of a valid option (i.e. –foo –bar will store "--bar" as a value for option "foo" if "foo" requires a value). We also support –name=value syntax. In this case, 'value' would be used as the value, NOT the next argument.
For options: { { 'a', "", false }, { 'b', "", false }, { 0, "cee", false }, { 'd', "", true }, { 'e', "", true }, { 'f', "foo", true } }
./main hello world -a -a –cee -d 12 -f 34 and ./main hello world -a -a –cee -d 12 –foo 34
will result in:
TRTParsedArgs { errMsg: "", values: { { 2, {} }, { 0, {} }, { 1, {} }, { 1, {"12"} }, { 0, {} }, { 1, {"34"} } } positionalArgs: {"hello", "world"}, }
Non-POSIX behavior:
[in] | argc | The number of arguments passed to main (including the file name, which is disregarded) |
[in] | argv | The arguments passed to main (including the file name, which is disregarded) |
[in] | options | List of TRTOptions to parse |