Main Content

Simulink.dictionary.archdata.EnumType

Enumerated data type stored in Architectural Data section

Since R2023b

    Description

    Use a Simulink.dictionary.archdata.EnumType to represent a Simulink.data.dictionary.EnumTypeDefinition object in the Architectural Data section of a data dictionary.

    Creation

    You can add a Simulink.dictionary.archdata.EnumType object to a data dictionary in two ways:

    • Interactively create a Simulink.dictionary.archdata.EnumType object by using the Architectural Data Editor.

    • Programmatically create a Simulink.dictionary.archdata.EnumType object by using the addEnumType function.

    archData = Simulink.dictionary.archdata.create("dataDictionary.sldd");
    enum = addEnumType(archData,"myEnumType")
    enum = 
    
      EnumType with properties:
    
                Name: 'myEnumType'
         Description: ''
        DefaultValue: 'enum1'
         StorageType: 'Native Integer'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    Properties

    expand all

    Option to prefix enumeration members with the class name in generated code, specified as numeric or logical 1 (true) or 0 (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

    Specify the C++ namespace for the enumerated data type. When this property is specified, the generated C++ code places the definition of the enumerated data type within the specified namespace. If no namespace is specified, the definition of the enumerated data type is placed in the global namespace.

    This property requires an Embedded Coder® license.

    Example: myCompany::engine

    Data Types: char | string

    Data type definition behavior 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 to a separate header file.

    If you do not specify the property HeaderFile, the header file name defaults to types.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.dictionary.archdata.EnumType object, DefaultValue is 'enum1', and Simulink® uses the first enumeration member as the default enumeration member.

    Example: 'enumMember1'

    Custom description of the enumerated data type, specified as a character vector or string scalar.

    Example: 'This enumerated data type has a StorageType of uint32.'

    Data Types: char | string

    Enumeration members, specified as an array of Simulink.dictionary.archdata.Enumeral objects The array contains the enumeration members of the parent Simulink.dictionary.archdata.EnumType object.

    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

    Option to make the enumerated data type tunable, specified as numeric or logical 1 (true) or 0 (false).

    Example: enumType.IsTunableInCode

    Data Types: logical

    Name of the enumerated data type object, specified as a character vector or string scalar.

    Example: addEnumType(archData,"myEnumType")

    Data Types: char | string

    Architectural Data section containing the enumerated data type, specified as a Simulink.dictionary.ArchitecturalData object.

    Example: Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    Data type of the underlying integer values in the enumeration, 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:

    • 'Native Integer'

    • 'int8'

    • 'int16'

    • 'uint32'

    • 'uint8'

    • 'uint16'

    • 'uint32'

    To store the underlying integer values in generated code using the native integer type of the target hardware, specify StorageType as "Native Integer", which is the default value.

    Example: 'Native Integer'

    Example: 'uint8'

    Example: enumType.StorageType = "int32";

    Data Types: char | string

    Object Functions

    showView architectural data of Simulink data dictionary in Architectural Data Editor
    destroyDelete data element and remove from data interface
    moveToDesignDataMove interfaces, data types, and constants in Architectural Data section of Simulink data dictionary to design data
    moveToDictionaryMove architectural data of Simulink data dictionary to another data dictionary
    addEnumeralAdd enumeration member to enumerated data type in Architectural Data section of data dictionary
    getEnumeralGet enumeration member of enumerated data type in Architectural Data section of data dictionary
    getEnumeralNamesGet names of enumeration members present in enumerated data type in Architectural Data section of data dictionary
    removeEnumeralRemove enumeration member from enumerated data type definition in Architectural Data section of data dictionary

    Examples

    collapse all

    Create or open a data dictionary.

    dictName = "MyArchitecturalData.sldd";
    archData = Simulink.dictionary.archdata.create(dictName);
    

    Add an enumerated data type using the addEnumType function.

    colors = addEnumType(archData,"myColors")
    colors = 
    
      EnumType with properties:
    
                Name: 'myColors'
         Description: ''
        DefaultValue: 'enum1'
         StorageType: 'Native Integer'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    Specify the storage type and description for the enumerated data type.

    set(colors,"Description","These are my favorite colors.")
    set(colors,"StorageType","int16")
    colors
    colors = 
      EnumType with properties:
    
                Name: 'myColors'
         Description: 'These are my favorite colors.'
        DefaultValue: 'enum1'
         StorageType: 'int16'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    Add enumeration members to the architectural enumerated data type by using the addEnumeral function.

    addEnumeral(colors,"Red","0","Rose red");
    addEnumeral(colors,"Orange","1","Orange juice");
    addEnumeral(colors,"Yellow","2","Sunshine");
    addEnumeral(colors,"Green","3","Trees in summer");
    addEnumeral(colors,"Blue","4","Sky blue");
    addEnumeral(colors,"Indigo","5","Purple");
    addEnumeral(colors,"Violet","6","Deep purple");
    colors
    colors = 
    
      EnumType with properties:
    
                Name: 'myColors'
         Description: ''
        DefaultValue: 'enum1'
         StorageType: 'Native Integer'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    You can then use the enumeration members to define the DefaultValue of the architectural enumerated data type object.

    set(colors,"DefaultValue","Indigo");
    colors
    colors = 
    
      EnumType with properties:
    
                Name: 'myColors'
         Description: ''
        DefaultValue: 'Indigo'
         StorageType: 'Native Integer'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    You can use Simulink.data.dictionary.EnumTypeDefinition objects to define Simulink.dictionary.archdata.EnumType objects.

    Create a Simulink.data.dictionary.EnumTypeDefinition object. By default, the new type defines a single enumeration member enum1 with underlying integer value 0. Add enumeration members to the type definition using the appendEnumeral function.

    myShapes = Simulink.data.dictionary.EnumTypeDefinition;
    appendEnumeral(myShapes,"Line",1);
    appendEnumeral(myShapes,"Triangle",3);
    appendEnumeral(myShapes,"Square",4);
    appendEnumeral(myShapes,"Pentagon",5);
    myShapes
    myShapes = 
    
       Simulink.data.dictionary.EnumTypeDefinition
          enum1
          Line
          Triangle
          Square
          Pentagon

    To store the enumerated type definition in the Architectural Data section of a data dictionary use the addEnumType function, and specify the EnumTypeDefinition name-value argument.

    shapesArch = addEnumType(archdata,"MyShapes",...
        EnumTypeDefinition=myShapes)
    shapesArch = 
      EnumType with properties:
    
                Name: 'MyShapes'
         Description: 'These are my favorite shapes.'
        DefaultValue: 'Line'
         StorageType: 'Native Integer'
           Enumerals: [1×5 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    For more information regarding programmatic storage of architectural data, see Store Data in Architectural Data Section Programmatically.

    Version History

    Introduced in R2023b

    expand all