Documentation

Generate Customizable C++ Encapsulation Interface to Generated Code

This model shows the ability to generate a C++ class interface to code generated by Simulink Coder®. A generated C++ class encapsulates model data and methods. Using Embedded Coder®, the encapsulation interface is configurable via model-neutral configuration parameters and model-specific configurations, which support two styles of model step method interfaces (default step method and I/O arguments step method). This model also shows the ability to generate customizable C++ class interfaces for referenced models and for models to interact via those interfaces.

Open Example Model

Open the example model rtwdemo_cppclass.

open_system('rtwdemo_cppclass');

Instructions

  1. The model is preconfigured with a C++ class interface that defines root-level model input and output to be arguments on the step method, using the I/O arguments style interface. Generate code by double-clicking the blue button in the model. An HTML report is displayed automatically.

  2. Inspect the source in the generated files using the hyperlinks embedded in the report. Also follow the hyperlinks for the code generated for the referenced models.

  3. To view or change the interface configuration, double-click the yellow button in the model. On the Code Generation > Interface pane, select or clear the check boxes to change model-neutral settings, or click Configure C++ Class Interface to launch the model-specific configuration dialog box.

To configure a new or existing model for C++ encapsulation, choose C++ as the target language on the Code Generation pane, then go to the Interface pane and select C++ class as the Code interface packaging.

For more details and limitations, see Control Generation of C++ Class Interfaces in the Embedded Coder documentation.

C++ Class Interface with Referenced Models

open_system('rtwdemo_cppclass_refmid');

This model shows the ability to generate a customizable C++ class interface to code generated by Embedded Coder for a referenced model in the middle of a model reference hierarchy.

In the dialog box launched by the Configure C++ Class Interface button on the Configuration Parameters > Code Generation > Interface pane, make sure I/O arguments step method is selected for the Function specification.

Mixed Interface Styles in a Model Reference Hierarchy

open_system('rtwdemo_cppclass_refc');

This model shows that mixed interface styles can be used within a model reference hierarchy. This model uses the C code interface style (compiled with a C++ compiler), while the other models in the same hierarchy use C++ class interfaces.

Was this topic helpful?