Main Content

setData

Configure model data for C++ code generation

Description

example

setData(myCPPMappingObj, category, Name,Value) configures code mapping information for the model data specified by category.

Examples

collapse all

Configure the data visibility of model parameters to be public.

Open the model. Use the coder.mapping.api.get function to access the CodeMappingCPP object associated with the model.

open_system('rtwdemo_cppclass');
cm = coder.mapping.api.get('rtwdemo_cppclass');

To view the data visibility of the model parameters, use the getData function.

value = getData(cm, 'ModelParameters', 'DataVisibility')
value =

    'private'

To configure the data visibility, specify the 'DataVisibility' parameter using the setData function.

setData(cm, 'ModelParameters', 'DataVisibility', 'public');

Input Arguments

collapse all

C++ code mapping object, returned by a call to either the coder.mapping.utils.create function or the coder.mapping.api.get function.

Category of model data to configure, specified as one of these categories.

CategoryDescription
'Inports'Root-level input ports of a model, such as Inport and In Bus Element blocks.
'Outports'Root-level output ports of a model, such as Outport and Out Bus Element blocks.
'ModelParameters'Parameters that are defined within a model, such as parameters in the model workspace. Excludes model arguments.
'ModelParameterArguments'Parameters in the model workspace configured as model arguments. These parameters are exposed at the model block to enable each model instance to provide its own value.
'InternalData'Data elements that are internal to a model, such as block output signals, discrete block states, data stores, and zero-crossing signals.

Data Types: char | string

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: setData(myCPPMappingObj, 'Inports', 'DataVisibility', 'private')

How the methods, if any, are generated for the data elements. This configuration controls how application code can view and modify the class member data.

Member Access MethodDescription
'Method'The get and set methods for each element in the category appear in the generated class. Only set methods appear for model elements in the Inports category. Only get methods appear for model elements in the Outports category.
'Inlined method'The get and set methods defined in their declarations appear for each element in a category in the generated class. Only set methods appear for model elements in the Inports category. Only get methods appear for model elements in the Outports category.
'Structure-based method'Data elements appear as a structure in the class and aggregate get and set methods are generated for each category.
'Inlined structure-based method'Data elements appear as a structure in the class. Aggregate get and set methods defined in their declaration are generated for each category.
'None'If you configure the access of a model element category to None, get and set methods do not appear in the generated class. The application code can directly access the data.

Data Types: char | string

The visibility of the data category in generated code, specified as either private, public, or protected. If you configure data elements as public, they appear as public members of the generated class. If you configure elements as private, they appear as private members of the generated class.

Data Types: char | string

The access of model parameter arguments in generated code, specified as either 'pointer' or 'direct'. This parameter applies only to model parameter arguments whose data visibility is not set to 'Individual Arguments'.

Data Types: char | string

Introduced in R2021a