MATLAB Compiler | ![]() ![]() |
C++ Interface Functions
The C++ interface functions process any input arguments and pass them to the implementation version of the function.
Note
In C++, the mlx F interface functions are also C functions in order to allow the feval interface to be uniform between C and C++.
|
mlxF Interface Function
The Compiler always generates the mlx
F
interface function, which is used by feval
. At times, the Compiler needs to use feval
to perform argument matching even if the user does not specifically call feval
. For example,
would use the feval
interface. The following C++ code is the corresponding feval
interface (mlxGasket
) from the Sierpinski Gasket example. This function calls the C++ Mgasket
function:
// // The function "mlxGasket" contains the feval interface // for the "gasket" M-function from file // "<matlab>\extern\examples\compiler\gasket.m" (lines 1-23). // The feval function calls the implementation version of // gasket through this function. This function processes // any input arguments and passes them to the // implementation version of the function, appearing above. // void mlxGasket(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) { MW_BEGIN_MLX(); { // ------------- Input Argument Processing --------------- mwArray mprhs[1]; mwArray mplhs[1]; int i; mclCppUndefineArrays(1, mplhs); if (nlhs > 1) { error( mwVarargin( mwArray( "Run-time Error: File: gasket Line:" " 1 Column: 1 The function \"gasket" "\" was called with more than the d" "eclared number of outputs (1)."))); } if (nrhs > 1) { error( mwVarargin( mwArray( "Run-time Error: File: gasket Line:" " 1 Column: 1 The function \"gasket" "\" was called with more than the d" "eclared number of inputs (1)."))); } for (i = 0; i < 1 && i < nrhs; ++i) { mprhs[i] = mwArray(prhs[i], 0); } for (; i < 1; ++i) { mprhs[i].MakeDIN(); } // ----------------- Call M-Function --------------------- mplhs[0] = Mgasket(nlhs, mprhs[0]); // ------------- Output Argument Processing -------------- plhs[0] = mplhs[0].FreezeData(); } MW_END_MLX(); }
F Interface Function
The Compiler always generates the F
interface function, which contains the "normal" C++ interface to the function. This code is the corresponding C++ interface function (gasket
) from the Sierpinski Gasket example. This function calls the C++ code:
// // The function "gasket" contains the normal interface for // the "gasket" M-function from file // "<matlab>\extern\examples\compiler\gasket.m" (lines 1-23). // This function processes any input arguments and passes // them to the implementation version of the function, // appearing above. // mwArray gasket(mwArray numPoints) { int nargout = 1; mwArray theImage = mwArray::UNDEFINED; // ----------------- Call M-Function --------------------- theImage = Mgasket(nargout, numPoints); // ------------- Output Argument Processing -------------- return theImage; }
NF Interface Function
The Compiler produces this interface function only when the M-function uses the variable nargout
. The nargout
interface allows the number of requested outputs to be specified via the nargout
argument, as opposed to the normal interface that dynamically calculates the number of outputs based on the number of non-NULL inputs it receives.
This is the corresponding N
F
interface function (NFoo
) for the foo.m example described earlier in this chapter. This function calls the Mfoo
function appearing in foo.cpp
:
// // The function "Nfoo" contains the nargout interface for // the "foo" M-function from file // "<matlab>\extern\examples\compiler\foo.m" (lines 1-8). // This interface is only produced if the M-function uses // the special variable "nargout". The nargout interface // allows the number of requested outputs to be specified // via the nargout argument, as opposed to the normal // interface, which dynamically calculates the number of // outputs based on the number of non-NULL inputs it // receives. This function processes any input arguments // and passes them to the implementation version of the // function, appearing above. // mwArray Nfoo(int nargout, mwArray * b, mwArray x, mwArray y) { // ------------- Input Argument Processing --------------- mwArray a = mwArray::UNDEFINED; mwArray b__ = mwArray::UNDEFINED; // ----------------- Call M-Function --------------------- a = Mfoo(&b__, nargout, x, y); // ------------- Input Argument Processing --------------- if (b != NULL) { *b = b__; } // ------------- Output Argument Processing -------------- return a; }
VF Interface Function
The Compiler produces this interface function only when the M-function uses the variable nargout
and has at least one output. The void
interface function specifies zero output arguments to the implementation version of the function, and in the event that the implementation version still returns an output (which, in MATLAB, would be assigned to the ans
variable), it deallocates the output.
This is the corresponding V
F
interface function (VFoo
) for the foo.m example described earlier in this chapter. This function calls the Mfoo
function appearing in foo.cpp
:
// // The function "Vfoo" contains the void interface for the // "foo" M-function from file // "<matlab>\extern\examples\compiler\foo.m" (lines 1-8). // The void interface is only produced if the M-function // uses the special variable "nargout", and has at least // one output. The void interface function specifies zero // output arguments to the implementation version of the // function, and in the event that the implementation // version still returns an output (which, in MATLAB, would // be assigned to the "ans" variable), it deallocates the // output. This function processes any input arguments and // passes them to the implementation version of the // function, appearing above. // void Vfoo(mwArray x, mwArray y) { // ------------- Input Argument Processing --------------- mwArray a = mwArray::UNDEFINED; mwArray b = mwArray::UNDEFINED; // ----------------- Call M-Function --------------------- a = Mfoo(&b, 0, x, y); }
![]() | C Interface Functions | Supported Executable Types | ![]() |