Main Content

Simulink.data.dictionary.EnumTypeDefinition

Store enumerated type definition in data dictionary

Description

A Simulink.data.dictionary.EnumTypeDefinition object defines an enumerated data type in a data dictionary. You store the object in a data dictionary entry so models linked to the dictionary can use the enumerated type definition.

In the MATLAB® base workspace, Simulink.data.dictionary.EnumTypeDefinition objects retain information about an enumerated type but do not define the type for use by other variables or by models.

Creation

You can create a Simulink.data.dictionary.EnumTypeDefinition object several ways.

  • Interactively create a Simulink.data.dictionary.EnumTypeDefinition object using the Type Editor or Model Explorer.

  • Import the definitions of enumerated types to a data dictionary using the importEnumTypes function. Simulink® creates a Simulink.data.dictionary.EnumTypeDefinition object in the dictionary for each imported definition. The dictionary stores each object in an individual entry.

  • Programmatically create a Simulink.data.dictionary.EnumTypeDefinition object using the Simulink.data.dictionary.EnumTypeDefinition function described here.

Description

example

The Simulink.data.dictionary.EnumTypeDefinition function creates a Simulink.data.dictionary.EnumTypeDefinition object with default property values and a single enumeration member that has underlying integer value 0.

Properties

expand all

Flag to prefix enumerations with the class name in generated code, specified as true or false.

If you specify true, when you generate code the identifier of each enumeration member begins with the name of the enumeration class. For example, an enumeration class LEDcolor with enumeration members GREEN and RED defines the enumeration members in generated code as LEDcolor_GREEN and LEDcolor_RED.

Data Types: logical

Flag to control data type definition in generated code, specified as 'Auto', 'Imported', or 'Exported'. The table describes the behavior of generated code for each value.

ValueAction
Auto (default)

If you do not specify the property Headerfile, export the data type definition to model_types.h, where model is the model name.

If you specify Headerfile, import the data type definition from the specified header file.

Exported

Export the data type definition to a separate header file.

If you do not specify the property Headerfile, the header file name defaults to type.h, where type is the data type name.

Imported

Import the data type definition from a separate header file.

If you do not specify the property Headerfile, the header file name defaults to type.h, where type is the data type name.

Default enumeration member, specified as a character vector. Specify DefaultValue as the name of an enumeration member you have already defined.

When you create a Simulink.data.dictionary.EnumTypeDefinition object, DefaultValue is an empty character vector, '', and Simulink uses the first enumeration member as the default member.

Example: 'enumMember1'

Description of the enumerated data type, specified as a character vector. Use this property to explain the purpose of the type in generated code.

Example: 'Two possible colors of LED indicator: GREEN and RED.'

Data Types: char

Name of the header file that defines the enumerated data type in generated code, specified as a character vector. Use a .h extension to specify the file name.

If you do not specify HeaderFile, generated code uses a default header file name that depends on the value of the DataScope property.

Example: 'myTypeIncludeFile.h'

Data Types: char

Data type of the integer values underlying the enumeration members, specified as a character vector. Generated code stores the underlying integer values using the data type you specify.

You can specify one of these supported integer types:

  • 'int8'

  • 'int16'

  • 'int32'

  • 'uint8'

  • 'uint16'

  • 'uint32'

To store the underlying integer values in generated code using the native integer type of the target hardware, specify StorageType as an empty character vector, '', which is the default value.

Example: 'int16'

''

Object Functions

appendEnumeralAdd enumeration member to enumerated data type definition in data dictionary
removeEnumeralRemove enumeration member from enumerated data type definition in data dictionary

Examples

collapse all

Create an object that can store the definition of an enumerated type. By default, the new type defines a single enumeration member enum1 with underlying integer value 0.

myColors = Simulink.data.dictionary.EnumTypeDefinition
myColors = 

   Simulink.data.dictionary.EnumTypeDefinition
      enum1

Add some enumeration members to the definition of the type.

appendEnumeral(myColors,'Orange',1,'')
appendEnumeral(myColors,'Black',2,'')
appendEnumeral(myColors,'Cyan',3,'')
myColors
myColors = 

   Simulink.data.dictionary.EnumTypeDefinition
      enum1
      Orange
      Black
      Cyan

Remove the default enumeration member enum1. Since enum1 is the first enumeration member in the list, identify it with index 1.

removeEnumeral(myColors,1)
myColors
myColors = 

   Simulink.data.dictionary.EnumTypeDefinition
      Orange
      Black
      Cyan

Customize the enumerated type by configuring the properties of the object representing it.

myColors.Description = 'These are my favorite colors.';
myColors.DefaultValue = 'Cyan';
myColors.HeaderFile = 'colorsType.h';

Open the data dictionary myDictionary_ex_API.sldd and represent it with a Simulink.data.Dictionary object named myDictionaryObj.

myDictionaryObj = Simulink.data.dictionary.open('myDictionary_ex_API.sldd');

Import the object that defines the enumerated type myColors to the dictionary.

importFromBaseWorkspace(myDictionaryObj,'varList',{'myColors'});

Alternatives

You can use Model Explorer to add and modify enumerated data types stored in a data dictionary.

Version History

Introduced in R2015a