Is there an example for using STL types with a deployed MATLAB C++ shared library component?

My C++ application has a bunch of data stored in the STL type:
vector< pair<string, double> >
I would like to use this data in my deployed MATLAB function, which is interfaced as a C++ shared library.
Are there any examples that show converting of STL types into the mwArray data types required to call the deployed MATLAB function?

 Accepted Answer

We have created an example that utilizes data stored within
vector< pair<string, double> >
STL types into mwArray cell array types, so that they can be utilized within the MATLAB function as cell arrays.
See the attached code below. Some notes on the example:
1. cellDriverMain.cpp is the main driver application code. It is a console application. Its basic operation is:
a. Initialize the deployed MATLAB component. This should only be done once per run, otherwise memory leaks may occur.
b. Construct the STL vector< pair<string, double> > data.
c. Construct the cell array type mwArray using the STL data. Please note that, as shown in the example, strings must be copied into a char array buffer before they can be set to an mwArray.
d. Call the MATLAB function using the mwArray inputs.
e. Return the output as mwArrays and displays it on the console.
f. Terminate the MATLAB deployed component. As with initialization, this must only be done once on the initialized component per run.
2. cellDiary is the example MATLAB function. It simply takes the input arguments and returns them as output. In the process, it will write logs of the input and output variables. Make sure to change the diary file location to an appropriate location on your machine, instead of the placeholder given, if you intend to compile it.
3. Screenshots of the expected console output and log output are also attached.

More Answers (0)

Products

Release

R2012a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!