| OpenCV 3.4.3 Open Source Computer Vision

Classes | Public Member Functions | List of all members
matlab::ArgumentParser Class Reference
MATLAB Bridge

parses inputs to a method and resolves the argument names. More...

`#include "mxarray.hpp"`

## Public Member Functions
| ArgumentParser (const String &method_name)
void | addVariant (const String &name, size_t nreq, size_t nopt=0,...)
| add a function call variant to the parser More...
void | addVariant (const String &name, size_t nreq, size_t nopt, StringVector keys)
MxArrayVector | parse (const MxArrayVector &inputs)
| parse a vector of input arguments More...
bool | variantIs (const String &name)
| check if the valid variant is the key name More...

## Detailed Description

parses inputs to a method and resolves the argument names.

The ArgumentParser resolves the inputs to a method. It checks that all required arguments are specified and also allows named optional arguments. For example, the C++ function: void randn(Mat& mat, Mat& mean=Mat(), Mat& std=Mat()); could be called in Matlab using any of the following signatures:

out = randn(in);
out = randn(in, 0, 1);
out = randn(in, 'mean', 0, 'std', 1);

ArgumentParser also enables function overloading by allowing users to add variants to a method. For example, there may be two C++ sum() methods:

double sum(Mat& mat); % sum elements of a matrix
Mat sum(Mat& A, Mat& B); % add two matrices

by adding two variants to ArgumentParser, the correct underlying sum method can be called. If the function call is ambiguous, the ArgumentParser will fail with an error message.

The previous example could be parsed as:

// set up the Argument parser
ArgumentParser arguments;
arguments.addVariant("elementwise", 1);
arguments.addVariant("matrix", 2);
// parse the arguments
std::vector<MxArray> inputs;
inputs = arguments.parse(std::vector<MxArray>(prhs, prhs+nrhs));
// if we get here, one unique variant is valid
if (arguments.variantIs("elementwise")) {
// call elementwise sum()
}

## Constructor & Destructor Documentation

## § ArgumentParser()

matlab::ArgumentParser::ArgumentParser | ( | const String & | method_name | ) |
| inline

## Member Function Documentation

## § addVariant() [1/2]

void matlab::ArgumentParser::addVariant | ( | const String & | name,
|  | size_t | nreq,
|  | size_t | nopt = `0`,
|  |  | ...
| ) |  |
| inline

add a function call variant to the parser

Adds a function-call signature to the parser. The function call must be unique either in its number of arguments, or in the named-syntax. Currently this function does not check whether that invariant stands true.

This function is variadic. If should be called as follows: addVariant(2, 2, 'opt_1_name', 'opt_2_name');

## § addVariant() [2/2]

void matlab::ArgumentParser::addVariant | ( | const String & | name,
|  | size_t | nreq,
|  | size_t | nopt,
|  | StringVector | keys
| ) |  |
| inline

## § parse()

MxArrayVector matlab::ArgumentParser::parse | ( | const MxArrayVector & | inputs | ) |
| inline

parse a vector of input arguments

This method parses a vector of input arguments, attempting to match them to a Variant spec. For each input, the method attempts to cull any Variants which don't match the given inputs so far.

Once all inputs have been parsed, if there is one unique spec remaining, the output MxArray vector gets populated with the arguments, with named arguments removed. Any optional arguments that have not been encountered are set to an empty array.

If multiple variants or no variants match the given call, an error message is emitted

## § variantIs()

bool matlab::ArgumentParser::variantIs | ( | const String & | name | ) |
| inline

check if the valid variant is the key name

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

- /build/3_4-contrib_docs-lin64/opencv_contrib/modules/matlab/include/opencv2/matlab/mxarray.hpp