www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/GnrtCustomizableCEncapsulationInterfaceToGenCodeExample.m

    %% Customize C++ Encapsulation Interface to Generated Code
% Encapsulate a C++ class interface in generated code. Customize C++ class 
% interfaces for referenced models and how models interact through those interfaces.
%
%% Configure a Model with Custom C++ Encapsulation Interface
% If starting with a new model,
% 
% # Create a model with at least one inport and at least one outport.
% # Select *Configuration Parameters* > *Code Generation* and set the *Programming 
% language* to |C++|.
% # Select *Configuration Parameters* > *Interface*, click on *Code interface 
% packaging*, and select |C++ class|.
% # Click on *Configure C++ Class Interface* and customize the interface as
% needed. See *Apply Custom C++ Encapulation Interface* later in this
% example. Also see see <docid:ecoder_ug.brre9ro-1> in the
% Embedded Coder documentation.
%
%% About C++ Encapsulation Interfaces
% A generated C++ class encapsulates model data and methods. Using Embedded 
% Coder(R), the encapsulation interface is 
% configurable through model-neutral configuration parameters and model-specific 
% configurations. The interface supports 
% two styles of model step method interfaces (default step method and I/O
% arguments step method). The I/O arguments style interface can be used to 
% customize the step method prototype, and the Default step method style
% interface can be used to achieve the maximized supported feature set including 
% virtual bus across model boundaries
% and multitasking interface.
%
open_system('rtwdemo_cppclass');
%% Generate Code from the Example Model
% # Open the example model |rtwdemo_cppclass|.
% # Save a copy of the model to your current working folder.
% # To generate code, in the model, double-click the blue button. Or, build the model by pressing Ctrl+B. A code
% generation report is displayed. 
% # Use the code generation report to inspect the source in the generated
% files using the hyperlinks embedded in the report. 
% # Observe the customized model step and initialization classes
% |ModelClass::step_method| and |ModelClass::initialize| inside the file 
% |rtwdemo_cppclass.cpp|. 
% # To view the interface
% configuration, in the model, double-click the yellow button (labeled *View 
% Interface Configuration*). Or, select *Configuration Parameters* > *Code 
% Generation* > *Interface* and click *Configure C++ Class Interface*. 
% # Observe the customized arguments for the step function and how these relate to 
% the generated code.
%
% <<../cpp_class_arguments_modified.png>>
%
%% Change to Default Arguments and Rebuild Model
% If starting with a new model, you must populate the initial configuration
% for the C++ class interface.
% 
% # To populate the initial argument configuration for the model initialize and 
% step functions, click *Get Default Configuration*. 
% # To close the Model Interface dialog box, click *Apply* then *OK*. 
% # To close *Configuration Parameters*, click *OK*.
% # To generate code, in the model, double-click the blue button. Or, build the model by pressing Ctrl+B. A code 
% generation report is displayed.
% # Use the code generation report to inspect the customized model step and
% initialization classes
% |ModelClass::step_method| and |ModelClass::initialize| inside the file 
% |rtwdemo_cppclass.cpp|.
% # Observe the default arguments for the step function and
% how these relate to the generated code.
%
% <<../cpp_class_arguments_default.png>>
%
%% Apply Custom Arguments and Rebuild Model
% # To view the interface configuration, in the model, double-click the yellow 
% button (labeled *View Interface Configuration*). Or, select *Configuration 
% Parameters* > *Code Generation* > *Interface* and click *Configure C++ Class 
% Interface*. 
% # Move Port Name |Out1| to top of the Order and set its Category to Value.
% # To close the Model Interface dialog box, click *Apply* then *OK*.
% # To close *Configuration Parameters*, click *OK*.
% # To generate code, in the model, double-click the blue button. Or, build the model by pressing Ctrl+B. A code 
% generation report is displayed.
% # Use the code generation report to inspect the customized model step and 
% initialization classes
% |ModelClass::step_method| and |ModelClass::initialize| inside the file 
% |rtwdemo_cppclass.cpp|.
% # Observe the custom arguments appear in the generated code.
% 
%% Compare Default Interface (Maximum Support) with I/O Arguments Interface 
% The |rtwdemo_cppclass| model provides buttons to toggle the function 
% specification for the C++ class interface between the 
% default step method (in multitasking mode) and the I/O arguments step method.
% 
% # To configure the function specification for the default step method, in the 
% |rtwdemo_cppclass_refmid| model, double-click the yellow button (labeled *Use 
% Default Interface in
% MultiTasking Mode*).
% # To generate code, in the model, double-click the blue button. Or, build the model by pressing Ctrl+B. A code 
% generation report is displayed.
% # Use the code generation report to inspect the model step and
% initialization classes, then close the report.
% # To configure the function specification for the I/O arguments step method, in 
% the |rtwdemo_cppclass_refmid| model, double-click the yellow button (labeled *Use I/O 
% Arguments Interface*).
% # To generate code, in the model, double-click the blue button. Or, build the model by pressing Ctrl+B. A code 
% generation report is displayed.
% # Use the code generation report to inspect the model step and
% initialization classes, then close the report.
% 
%% Apply C++ Class Interface with Referenced Models
% The |rtwdemo_cppclass_refmid| model is one of the referenced models in the example model 
% |rtwdemo_cppclass|.
% 
% This referenced 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. 
%
% # Open the |rtwdemo_cppclass_refmid| referenced model by double-clicking on the 
% |Subsystem_with_MdlRef_blks| block then by double-clicking on the 
% |middle_instance_1| block.
% # To view the interface configuration, in the |rtwdemo_cppclass_refmid| model, 
% double-click the yellow button (labeled *View Interface Configuration*). Or, 
% select *Configuration Parameters* > *Code Generation* > *Interface* and click 
% *Configure C++ Class Interface*.
% # Observe that the configuration for the class interface for the referenced 
% model differs from the class interface for the top-level model (for example, the 
% name space differs).
open_system('rtwdemo_cppclass_refmid');
%% Apply Mixed C/C++ Interface Styles in a Model Reference Hierarchy
% The |rtwdemo_cppclass_refc| model is one of the referenced models in the example 
% model |rtwdemo_cppclass|.
%
% This referenced 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.
% 
% # Open the |rtwdemo_cppclass_refc| referenced model by double-clicking on the 
% |Subsystem_with_MdlRef_blks| block then double-clicking on the |ref_c_instance| 
% block.
% # Select *Configuration Parameters* > *Code Generation* > *Interface*. Observe 
% that *Code interface packaging* is set to *Nonreusable function* (for a C 
% function prototype).
% # To view the *Step function preview* for the function prototype, click on 
% *Configure Model Functions*, then click *Validate*.
open_system('rtwdemo_cppclass_refc');
%% More About
% For more details and limitations, see <docid:ecoder_ug.brre9ro-1> in the
% Embedded Coder documentation.