OpenCV
3.0.0-rc1
Open Source Computer Vision
|
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... | |
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:
ArgumentParser also enables function overloading by allowing users to add variants to a method. For example, there may be two C++ sum() methods:
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:
|
inline |
|
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');
|
inline |
|
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
|
inline |
check if the valid variant is the key name