OpenCV
3.4.19
Open Source Computer Vision
|
Designed for command line parsing. More...
#include <opencv2/core/utility.hpp>
Public Member Functions | |
CommandLineParser (int argc, const char *const argv[], const String &keys) | |
Constructor. More... | |
CommandLineParser (const CommandLineParser &parser) | |
Copy constructor. More... | |
~CommandLineParser () | |
Destructor. More... | |
void | about (const String &message) |
Set the about message. More... | |
bool | check () const |
Check for parsing errors. More... | |
template<typename T > | |
T | get (const String &name, bool space_delete=true) const |
Access arguments by name. More... | |
template<typename T > | |
T | get (int index, bool space_delete=true) const |
Access positional arguments by index. More... | |
String | getPathToApplication () const |
Returns application path. More... | |
bool | has (const String &name) const |
Check if field was provided in the command line. More... | |
CommandLineParser & | operator= (const CommandLineParser &parser) |
Assignment operator. More... | |
void | printErrors () const |
Print list of errors occurred. More... | |
void | printMessage () const |
Print help message. More... | |
Protected Member Functions | |
void | getByIndex (int index, bool space_delete, int type, void *dst) const |
void | getByName (const String &name, bool space_delete, int type, void *dst) const |
Protected Attributes | |
Impl * | impl |
Designed for command line parsing.
The sample below demonstrates how to use CommandLineParser:
The keys parameter is a string containing several blocks, each one is enclosed in curly braces and describes one argument. Each argument contains three parts separated by the |
symbol:
@
symbol)For example:
Note that there are no default values for help
and timestamp
so we can check their presence using the has()
method. Arguments with default values are considered to be always present. Use the get()
method in these cases to check their actual value instead.
String keys like get<String>("@image1")
return the empty string ""
by default - even with an empty default value. Use the special <none>
default value to enforce that the returned string must not be empty. (like in get<String>("@image2")
)
For the described keys:
cv::CommandLineParser::CommandLineParser | ( | int | argc, |
const char *const | argv[], | ||
const String & | keys | ||
) |
Constructor.
Initializes command line parser object
argc | number of command line arguments (from main()) |
argv | array of command line arguments (from main()) |
keys | string describing acceptable command line parameters (see class description for syntax) |
cv::CommandLineParser::CommandLineParser | ( | const CommandLineParser & | parser | ) |
Copy constructor.
cv::CommandLineParser::~CommandLineParser | ( | ) |
Destructor.
void cv::CommandLineParser::about | ( | const String & | message | ) |
Set the about message.
The about message will be shown when printMessage is called, right before arguments table.
bool cv::CommandLineParser::check | ( | ) | const |
Check for parsing errors.
Returns false if error occurred while accessing the parameters (bad conversion, missing arguments, etc.). Call printErrors to print error messages list.
|
inline |
Access arguments by name.
Returns argument converted to selected type. If the argument is not known or can not be converted to selected type, the error flag is set (can be checked with check).
For example, define:
Call:
Access:
name | name of the argument |
space_delete | remove spaces from the left and right of the string |
T | the argument will be converted to this type if possible |
@
-prefixed name:
|
inline |
Access positional arguments by index.
Returns argument converted to selected type. Indexes are counted from zero.
For example, define:
Call:
Access arguments:
index | index of the argument |
space_delete | remove spaces from the left and right of the string |
T | the argument will be converted to this type if possible |
|
protected |
|
protected |
String cv::CommandLineParser::getPathToApplication | ( | ) | const |
Returns application path.
This method returns the path to the executable from the command line (argv[0]
).
For example, if the application has been started with such a command:
this method will return ./bin
.
bool cv::CommandLineParser::has | ( | const String & | name | ) | const |
Check if field was provided in the command line.
name | argument name to check |
CommandLineParser& cv::CommandLineParser::operator= | ( | const CommandLineParser & | parser | ) |
Assignment operator.
void cv::CommandLineParser::printErrors | ( | ) | const |
Print list of errors occurred.
void cv::CommandLineParser::printMessage | ( | ) | const |
Print help message.
This method will print standard help message containing the about message and arguments description.
|
protected |