@@ -339,6 +340,37 @@ The MxArray object uses scoped memory management. If you wish to pass an MxArray
plhs[0]=mat.releaseOwnership();
```
mxarray.hpp also includes a number of helper utilities that make working in mex-world a little easier. One such utility is the `ArgumentParser`. `ArgumentParser` automatically handles required and optional arguments to a method, and even enables named arguments as used in many core Matlab functions. For example, if you had a function with the following signature:
then you can create an `ArgumentParser` as follows:
```cpp
ArgumentParserparser("f");
parser.addVariant(2,2,"mask","dtype");
MxArrayVectorinputs=parser.parse(prhs,prhs+nrhs);
```
and that will make available the following calling syntaxes:
```matlab
f(first,second);
f(first,second,mask);
f(first,second,mask,dtype);
f(first,second,'dtype',dtype,'mask',mask);% optional ordering does not matter
f(first,second,'dtype',dtype);% only second optional argument provided
f(first,second,mask,'dtype',dtype);% mixture of ordered and named
```
Further, the output of the `parser.parse()` method will always contain the total number of required and optional arguments that the method can take, with unspecified arguments given by empty matrices. Thus, to check if an optional argument has been given, you can do:
The bridge interface defines a `Bridge` class which provides type conversion between std/OpenCV and Matlab types. A type conversion must provide the following:
conditionalError(nrhs>={{fun.req|length-fun.req|only|outputs|length}},"Too few required input arguments specified");
conditionalError(nrhs<={{fun.req|length+fun.opt|length-fun.req|only|outputs|length-fun.opt|only|outputs|length}},"Too many input arguments specified");
conditionalError(nlhs<={{fun.rtp|void|not+fun.req|outputs|length+fun.opt|outputs|length}},"Too many output arguments specified");