For code generation, to customize an enumeration, in the static methods section of the class definition, include customized versions of the methods listed in this table.
Method | Description | Default Value Returned or Specified | When to Use |
---|---|---|---|
| Returns the default enumerated value. | First value in the enumeration class definition. | For a default value that is different than the first
enumeration value, provide a |
| Specifies the file that defines an externally defined enumerated type. |
| To use an externally defined enumerated type, provide
a |
| Specifies whether the class name becomes a prefix in the generated code. |
| If you want the class name to become a prefix in the
generated code, set the return value of the |
If the value of a variable that is cast to an enumerated type does not match one of the enumerated type values:
Generated MEX reports an error.
Generated C/C++ code replaces the value of the variable with the enumerated type default value.
Unless you specify otherwise, the default value for an enumerated
type is the first value in the enumeration class definition. To specify
a different default value, add your own getDefaultValue
method
to the methods section. In this example, the first enumeration member
value is LEDcolor.GREEN
, but the getDefaultValue
method
returns LEDcolor.RED
:
classdef LEDcolor < int32 enumeration GREEN(1), RED(2) end methods (Static) function y = getDefaultValue() y = LEDcolor.RED; end end end
To specify that an enumerated type is defined in an external
file, provide a customized getHeaderFile
method.
This example specifies that LEDcolor
is defined
in the external file my_LEDcolor.h
.
classdef LEDcolor < int32 enumeration GREEN(1), RED(2) end methods(Static) function y=getHeaderFile() y='my_LEDcolor.h'; end end end
You must provide my_LEDcolor.h
. For example:
enum LEDcolor { GREEN = 1, RED }; typedef enum LEDcolor LEDcolor;
By default, the generated enumerated type value name does not include the class name prefix. For example:
enum LEDcolor { GREEN = 1, RED }; typedef enum LEDcolor LEDcolor;
To include the class name prefix, provide an addClassNameToEnumNames
method
that returns true
. For example:
classdef LEDcolor < int32 enumeration GREEN(1), RED(2) end methods(Static) function y = addClassNameToEnumNames() y=true; end end end
In the generated type definition, the enumerated value names
include the class prefix LEDcolor
.
enum LEDcolor { LEDcolor_GREEN = 1, LEDcolor_RED }; typedef enum LEDcolor LEDcolor;