Generate C++ Class Interface to Model or Subsystem Code - MATLAB & Simulink (original) (raw)

Main Content

To generate a C++ class interface to model code, set model configuration parameter Code interface packaging (component) to C++ class. The generated interface encapsulates required model data into C++ class attributes and model entry point functions into C++ class methods. The benefits of C++ class encapsulation include:

C++ class encapsulation also works for right-click builds of nonvirtual subsystems. (For information on requirements that apply, see Generate C++ Class Interface to Nonvirtual Subsystem Code.)

Generate C++ Class Interface to Model Code

To generate encapsulated C++ class code from a model:

  1. Set model configuration parameter toC++. This selection also enables C++ class code interface packaging for the model.
  2. Verify that model configuration parameter Code interface packaging is set to C++ class.
  3. Examine the setting of Multi-instance code error diagnostic. Leave the parameter at its default value Error unless you need to alter the severity level for diagnostics displayed when a model violates requirements for generating multi-instance code.
  4. Generate code for the model.
  5. Examine the C++ model class code in the generated files_`model`_.h and_`model`_.cpp. For example, the following code excerpt from the H file generated for the example modelSecondOrderSystem shows the C++ class declaration for the model.
    /* Class declaration for model SecondOrderSystem /
    class SecondOrderSystemModelClass {
    /
    public data and function members /
    public:
    /
    External outputs /
    ExtY_SecondOrderSystem_T SecondOrderSystem_Y;
    /
    Model entry point functions /
    /
    model initialize function /
    void initialize();
    /
    model step function /
    void step();
    /
    model terminate function /
    void terminate();
    /
    Constructor /
    SecondOrderSystemModelClass();
    /
    Destructor /
    ~SecondOrderSystemModelClass();
    /
    Real-Time Model get method */
    RT_MODEL_SecondOrderSystem_T * getRTM();
    ...
    };
    For more information about generating and calling model entry-point functions, seeConfigure Generated C Function Interface for Model Entry-Point Functions.

Note

If you have an Embedded Coder® license and you have selected an ERT-based system target file for your model, use additional > pane parameters to customize the generated C++ class interface.

Generate C++ Class Interface to Nonvirtual Subsystem Code

You can generate C++ class interfaces for right-click builds of nonvirtual subsystems, if the following requirements are met:

To configure C++ class interfaces for a subsystem that meets the requirements:

  1. Open the containing model and select the subsystem block.
  2. Right-click the subsystem and select > .
  3. When the subsystem build completes, examine the C++ class interfaces in the generated files and the HTML code generation report. For more information about generating and calling model entry-point methods, see Configure Generated C Function Interface for Model Entry-Point Functions.

C++ Class Interface Limitations

See Also

Topics