Main Content

setData

Configure model data for C++ code generation

Since R2021a

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 private.

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

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

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

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

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

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

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 pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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

Data access of inports, outports, or model parameter arguments in the generated code, specified as either 'Pointer' or 'Direct'.

You can configure data access for 'Inports', 'Outports', and 'ModelParameterArguments' categories:

  • 'Inports' whose member access method is set to 'Structure-based method' or 'Inlined structure-based method'.

  • 'Outports' whose member access method is set to 'Structure-based method' or 'Inlined structure-based method'.

  • 'ModelParameterArguments' whose data visibility is set to 'private' (not 'Individual Arguments').

Data Types: char | string

Version History

Introduced in R2021a