Documentation

Writing C++ Driver Code Using the C++ MATLAB Data Array API

The basic workflow for using the generic interface for C++ shared libraries is as follows:

  • Call the free function initMATLABApplication, which optionally takes a vector of run time options like -nojvm and -logfile. The function returns a shared_ptr.

  • Initialize a matlab::data::ArrayFactory, which you use to produce matlab::data::Array objects that you pass into function calls.

  • For each library that you initialize, call initMATLABLibrary, which takes two parameters:

    • Copy of the shared_ptr that was returned by initMATLABApplication

    • Path to the archive (.ctf file)

  • To call a function in an initialized library, call feval or fevalAsync on the unique_ptr that was returned by initMATLABLibrary. There are several overloaded versions of each. They all take the name of the MATLAB® function as the first parameter. However, these differ in terms of whether they accept and return single matlab::data::Array objects, arrays of matlab::data::Array, or native types. The forms that return a native type must take the type as a template parameter.

  • To terminate a library, either call reset on its unique_ptr, or allow it to go out of scope.

  • To terminate the application, either call reset on its shared_ptr, or allow it to go out of scope. It does not terminate until all the libraries created underneath it have been terminated or gone out of scope.

For an example driver file using the C++ MATLAB Data Array API, see matrix_mda.cpp in matlabroot\extern\examples\compilersdk\c_cpp\matrix.

 matrix_mda.cpp

Related Topics