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
-logfile. The function returns a
matlab::data::ArrayFactory, which you use to produce
matlab::data::Arrayobjects that you pass into function calls.
For each library that you initialize, call
initMATLABLibrary, which takes two parameters:
Copy of the
shared_ptrthat was returned by
Path to the archive (
To call a function in an initialized library, call
unique_ptrthat 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::Arrayobjects, 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
unique_ptr, or allow it to go out of scope.
To terminate the application, either call
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