diff --git a/TET.m b/TET.m index 7204df24070c10ce37edae93b87ed52e813f7387..020eed2063e19619ac33a8d76f805b3e473b1d2b 100644 --- a/TET.m +++ b/TET.m @@ -12,6 +12,35 @@ classdef (Sealed) TET < handle function variableParser = getVariableParser(obj) variableParser = obj.variableParser; end + + %% Register an enumeration type with the TET. + % + % This function registers a Simulink compatibile enumeration type + % with the TET. This allows the enumerated value to be used in + % tables. + % Note: the enumeration must derive from Simulink.IntEnumType + % to be used in the Simulink model. + % Note: each enumerated value must have a distinct value, + % otherwise the type checker may allow invalid tables. + % + % obj - This object + % enum - A string representing the enumeration type name. + function type = registerEnumeration(obj, enum) + enumValues = enumeration(enum); + [~, enumConstants] = enumeration(enum); + if size(enumValues, 1) ~= size(enumConstants, 1) + throw(MException('TET:registerEnumeration', ... + 'Enumeration constants share the same concrete value')); + end + + type = ca.mcscert.jtet.expression.EnumerationVariableType(enum); + typeEnumConstants = type.enumerationValues; + for i=1:size(enumConstants, 1) + java.lang.String(enumConstants{i}) + typeEnumConstants.add(java.lang.String(enumConstants{i})); + end + obj.variableParser.addCustomType(enum, type); + end end methods (Access = private)